blob: 536b3f433c79f940b4091609bcdde57995762ae6 (
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
|
package de.danoeh.antennapod.activity;
import android.annotation.SuppressLint;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import com.actionbarsherlock.app.SherlockListActivity;
import de.danoeh.antennapod.AppConfig;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.miroguide.con.MiroException;
import de.danoeh.antennapod.miroguide.con.MiroService;
/** Shows a list of available categories and offers a search button. */
public class MiroGuideMainActivity extends SherlockListActivity {
private static final String TAG = "MiroGuideMainActivity";
private static String[] categories;
private ArrayAdapter<String> listAdapter;
private TextView txtvStatus;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setContentView(R.layout.miro_categorylist);
txtvStatus = (TextView) findViewById(android.R.id.empty);
}
@Override
protected void onPause() {
super.onPause();
}
@Override
protected void onResume() {
super.onResume();
if (categories != null) {
createAdapter();
} else {
loadCategories();
}
}
private void createAdapter() {
if (categories != null) {
listAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, categories);
txtvStatus.setText(R.string.no_items_label);
setListAdapter(listAdapter);
}
}
private void loadCategories() {
AsyncTask<Void, Void, Void> listLoader = new AsyncTask<Void, Void, Void>() {
private String[] c;
private MiroException exception;
@Override
protected void onPostExecute(Void result) {
if (exception != null) {
if (AppConfig.DEBUG) Log.d(TAG, "Successfully loaded categories");
categories = c;
createAdapter();
} else {
Log.e(TAG, "Error happened while trying to load categories");
txtvStatus.setText(exception.getMessage());
}
}
@Override
protected void onPreExecute() {
txtvStatus.setText(R.string.loading_categories_label);
}
@SuppressLint({ "NewApi", "NewApi" })
@Override
protected Void doInBackground(Void... params) {
MiroService service = new MiroService();
try {
c = service.getCategories();
} catch (MiroException e) {
e.printStackTrace();
exception = e;
}
return null;
}
};
if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
listLoader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} else {
listLoader.execute();
}
}
}
|