blob: ec5b0c980b14cb7b7c312611d3b19f698ec9f680 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
package de.danoeh.antennapod.activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import com.actionbarsherlock.app.SherlockListActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import de.danoeh.antennapod.adapter.DownloadLogAdapter;
import de.danoeh.antennapod.feed.EventDistributor;
import de.danoeh.antennapod.preferences.UserPreferences;
import de.danoeh.antennapod.service.download.DownloadStatus;
import de.danoeh.antennapod.storage.DBReader;
import java.util.List;
/**
* Displays completed and failed downloads in a list.
*/
public class DownloadLogActivity extends SherlockListActivity {
private static final String TAG = "DownloadLogActivity";
private List<DownloadStatus> downloadLog;
private DownloadLogAdapter dla;
@Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(UserPreferences.getTheme());
super.onCreate(savedInstanceState);
dla = new DownloadLogAdapter(this, itemAccess);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setListAdapter(dla);
loadData();
}
@Override
protected void onPause() {
super.onPause();
EventDistributor.getInstance().unregister(contentUpdate);
}
@Override
protected void onResume() {
super.onResume();
EventDistributor.getInstance().register(contentUpdate);
dla.notifyDataSetChanged();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
break;
default:
return false;
}
return true;
}
private void loadData() {
AsyncTask<Void, Void, List<DownloadStatus>> loadTask = new AsyncTask<Void, Void, List<DownloadStatus>>() {
@Override
protected List<DownloadStatus> doInBackground(Void... voids) {
return DBReader.getDownloadLog(DownloadLogActivity.this);
}
@Override
protected void onPostExecute(List<DownloadStatus> downloadStatuses) {
super.onPostExecute(downloadStatuses);
if (downloadStatuses != null) {
downloadLog = downloadStatuses;
if (dla != null) {
dla.notifyDataSetChanged();
}
} else {
Log.e(TAG, "Could not load download log");
}
}
};
loadTask.execute();
}
private DownloadLogAdapter.ItemAccess itemAccess = new DownloadLogAdapter.ItemAccess() {
@Override
public int getCount() {
return (downloadLog != null) ? downloadLog.size() : 0;
}
@Override
public DownloadStatus getItem(int position) {
return (downloadLog != null) ? downloadLog.get(position) : null;
}
};
private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() {
@Override
public void update(EventDistributor eventDistributor, Integer arg) {
if ((arg & EventDistributor.DOWNLOADLOG_UPDATE) != 0) {
loadData();
}
}
};
}
|