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
|
package de.animux.android.andmal;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import de.animux.android.andmal.api.anime.Anime;
import de.animux.android.andmal.api.anime.AnimeList;
import de.animux.android.andmal.api.anime.State;
import de.animux.android.andmal.util.SeparatedListAdapter;
import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.SimpleAdapter;
public class AnimeListActivity extends Activity {
public final static String ITEM_TITLE = "title";
public final static String ITEM_CAPTION = "caption";
public final static int INITIAL_SYNC = 0;
public Map<String, ?> createItem(String title, String caption) {
Map<String, String> item = new HashMap<String, String>();
item.put(ITEM_TITLE, title);
item.put(ITEM_CAPTION, caption);
return item;
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
showDialog(INITIAL_SYNC);
AnimeList animeList = null;
try {
animeList = new AnimeList("AlexanderS");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
dismissDialog(INITIAL_SYNC);
SeparatedListAdapter adapter = new SeparatedListAdapter(this);
Map<State, java.util.List<Anime>> animes = animeList.getAnimes();
for (State s : State.values())
addAnimes(adapter, animes.get(s), s.toString());
ListView list = new ListView(this);
list.setAdapter(adapter);
this.setContentView(list);
}
private void addAnimes(SeparatedListAdapter adapter,
Collection<Anime> animes, String sectionName) {
if (animes != null && animes.size() > 0) {
java.util.List<Map<String, ?>> listSection = new LinkedList<Map<String, ?>>();
for (Anime a : animes) {
listSection.add(createItem(a.getTitle(), a.getWatchedEpisodes()
+ "/" + a.getEpisodes()));
}
adapter.addSection(sectionName, new SimpleAdapter(this,
listSection, R.layout.list_item, new String[] { ITEM_TITLE,
ITEM_CAPTION }, new int[] { R.id.list_item_title,
R.id.list_item_other }));
}
}
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case INITIAL_SYNC:
ProgressDialog dialog = ProgressDialog.show(this, "",
"Loading list. Please wait...", true);
return dialog;
default:
return super.onCreateDialog(id);
}
}
}
|