Merge branch 'develop' into refactor_remote_operation_to_create_folder
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / activity / LogHistoryActivity.java
1 /* ownCloud Android client application
2 * Copyright (C) 2012-2013 ownCloud Inc.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 */
17
18 package com.owncloud.android.ui.activity;
19
20 import java.io.File;
21 import java.util.ArrayList;
22
23 import android.content.Intent;
24 import android.os.Bundle;
25 import android.preference.Preference;
26 import android.preference.Preference.OnPreferenceChangeListener;
27 import android.view.View;
28 import android.view.View.OnClickListener;
29 import android.widget.Button;
30 import android.widget.ListView;
31
32 import com.actionbarsherlock.app.ActionBar;
33 import com.actionbarsherlock.app.SherlockPreferenceActivity;
34 import com.actionbarsherlock.view.MenuItem;
35 import com.owncloud.android.R;
36 import com.owncloud.android.ui.adapter.LogListAdapter;
37 import com.owncloud.android.utils.FileStorageUtils;
38
39
40
41
42 public class LogHistoryActivity extends SherlockPreferenceActivity implements OnPreferenceChangeListener {
43 String logpath = FileStorageUtils.getLogPath();
44 File logDIR = null;
45
46 @Override
47 protected void onCreate(Bundle savedInstanceState) {
48 super.onCreate(savedInstanceState);
49
50 setContentView(R.layout.log_send_file);
51 setTitle("Log History");
52 ActionBar actionBar = getSherlock().getActionBar();
53 actionBar.setDisplayHomeAsUpEnabled(true);
54 ListView listView = (ListView) findViewById(android.R.id.list);
55 Button deleteHistoryButton = (Button) findViewById(R.id.deleteLogHistoryButton);
56
57 deleteHistoryButton.setOnClickListener(new OnClickListener() {
58
59 @Override
60 public void onClick(View v) {
61 File dir = new File(logpath);
62 if (dir != null) {
63 File[] files = dir.listFiles();
64 if(files!=null) {
65 for(File f: files) {
66 f.delete();
67 }
68 }
69 dir.delete();
70 }
71 Intent intent = new Intent(getBaseContext(), Preferences.class);
72 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
73 startActivity(intent);
74 }
75
76 });
77
78
79 if(logpath != null){
80 logDIR = new File(logpath);
81 }
82
83 if(logDIR != null && logDIR.isDirectory()) {
84 File[] files = logDIR.listFiles();
85
86 if (files != null && files.length != 0) {
87 ArrayList<String> logfiles_name = new ArrayList<String>();
88 for (File file : files) {
89 logfiles_name.add(file.getName());
90 }
91 String[] logFiles2Array = logfiles_name.toArray(new String[logfiles_name.size()]);
92 LogListAdapter listadapter = new LogListAdapter(this,logFiles2Array);
93 listView.setAdapter(listadapter);
94 }
95 }
96 }
97
98
99 @Override
100 public boolean onMenuItemSelected(int featureId, MenuItem item) {
101 super.onMenuItemSelected(featureId, item);
102 Intent intent;
103
104 switch (item.getItemId()) {
105
106 case android.R.id.home:
107 intent = new Intent(getBaseContext(), Preferences.class);
108 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
109 startActivity(intent);
110 break;
111 default:
112 return false;
113 }
114 return true;
115 }
116 @Override
117 public boolean onPreferenceChange(Preference arg0, Object arg1) {
118 return false;
119 }
120 }