OC-922: Synchronize folder, refresh folder size
[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 public class LogHistoryActivity extends SherlockPreferenceActivity implements OnPreferenceChangeListener {
42 String logpath = FileStorageUtils.getLogPath();
43 File logDIR = null;
44
45 @Override
46 protected void onCreate(Bundle savedInstanceState) {
47 super.onCreate(savedInstanceState);
48
49 setContentView(R.layout.log_send_file);
50 setTitle("Log History");
51 ActionBar actionBar = getSherlock().getActionBar();
52 actionBar.setDisplayHomeAsUpEnabled(true);
53 ListView listView = (ListView) findViewById(android.R.id.list);
54 Button deleteHistoryButton = (Button) findViewById(R.id.deleteLogHistoryButton);
55 deleteHistoryButton.setOnClickListener(new OnClickListener() {
56
57 @Override
58 public void onClick(View v) {
59 File dir = new File(logpath);
60 if (dir != null) {
61 File[] files = dir.listFiles();
62 if(files!=null) {
63 for(File f: files) {
64 f.delete();
65 }
66 }
67 dir.delete();
68 }
69 Intent intent = new Intent(getBaseContext(), Preferences.class);
70 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
71 startActivity(intent);
72 }
73
74 });
75
76
77 if(logpath != null){
78 logDIR = new File(logpath);
79 }
80
81 if(logDIR != null && logDIR.isDirectory()) {
82 File[] files = logDIR.listFiles();
83
84 if (files != null && files.length != 0) {
85 ArrayList<String> logfiles_name = new ArrayList<String>();
86 for (File file : files) {
87 logfiles_name.add(file.getName());
88 }
89 String[] logFiles2Array = logfiles_name.toArray(new String[logfiles_name.size()]);
90 LogListAdapter listadapter = new LogListAdapter(this,logFiles2Array);
91 listView.setAdapter(listadapter);
92 }
93 }
94 }
95
96
97 @Override
98 public boolean onMenuItemSelected(int featureId, MenuItem item) {
99 super.onMenuItemSelected(featureId, item);
100 Intent intent;
101
102 switch (item.getItemId()) {
103
104 case android.R.id.home:
105 intent = new Intent(getBaseContext(), Preferences.class);
106 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
107 startActivity(intent);
108 break;
109 default:
110 return false;
111 }
112 return true;
113 }
114 @Override
115 public boolean onPreferenceChange(Preference arg0, Object arg1) {
116 return false;
117 }
118 }