diff options
author | Alexander Sulfrian <alexander@sulfrian.net> | 2010-08-17 02:58:24 +0200 |
---|---|---|
committer | Alexander Sulfrian <alexander@sulfrian.net> | 2010-08-17 02:58:24 +0200 |
commit | 8a8dc0a2ac4f3552568d9e14bf5ae121394b055c (patch) | |
tree | 33f3d5a6a060024079d1c9af954f31c3ecb24508 /src/de/animux/android | |
parent | d773a39a1f07ae4b8021222a47c16b048d7fd435 (diff) | |
download | AndMAL-8a8dc0a2ac4f3552568d9e14bf5ae121394b055c.tar.gz AndMAL-8a8dc0a2ac4f3552568d9e14bf5ae121394b055c.tar.xz AndMAL-8a8dc0a2ac4f3552568d9e14bf5ae121394b055c.zip |
fix progressdialog
loading of the list in own thread
refresh ui afterwards with handler (only first thread can change the view)
Diffstat (limited to 'src/de/animux/android')
-rw-r--r-- | src/de/animux/android/andmal/AnimeListActivity.java | 57 |
1 files changed, 39 insertions, 18 deletions
diff --git a/src/de/animux/android/andmal/AnimeListActivity.java b/src/de/animux/android/andmal/AnimeListActivity.java index 8db6635..566fa1d 100644 --- a/src/de/animux/android/andmal/AnimeListActivity.java +++ b/src/de/animux/android/andmal/AnimeListActivity.java @@ -3,6 +3,7 @@ package de.animux.android.andmal; import java.util.Collection; import java.util.HashMap; import java.util.LinkedList; +import java.util.List; import java.util.Map; import de.animux.android.andmal.api.anime.Anime; @@ -14,6 +15,8 @@ import android.app.Activity; import android.app.Dialog; import android.app.ProgressDialog; import android.os.Bundle; +import android.os.Handler; +import android.os.Message; import android.widget.ListView; import android.widget.SimpleAdapter; @@ -24,6 +27,10 @@ public class AnimeListActivity extends Activity { public final static int INITIAL_SYNC = 0; + private AnimeList animeList; + + private UpdateUIHandler updateUIHandler = new UpdateUIHandler(); + public Map<String, ?> createItem(String title, String caption) { Map<String, String> item = new HashMap<String, String>(); item.put(ITEM_TITLE, title); @@ -31,6 +38,26 @@ public class AnimeListActivity extends Activity { return item; } + private class UpdateUIHandler extends Handler { + @Override + public void handleMessage(Message msg) { + SeparatedListAdapter adapter = new SeparatedListAdapter( + AnimeListActivity.this); + Map<de.animux.android.andmal.api.anime.State, List<Anime>> animes = animeList + .getAnimes(); + + for (State s : State.values()) + addAnimes(adapter, animes.get(s), s.toString()); + + ListView list = new ListView(AnimeListActivity.this); + list.setAdapter(adapter); + + dismissDialog(INITIAL_SYNC); + + AnimeListActivity.this.setContentView(list); + } + } + /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { @@ -38,25 +65,18 @@ public class AnimeListActivity extends Activity { showDialog(INITIAL_SYNC); - AnimeList animeList = null; - try { - animeList = new AnimeList("AlexanderS"); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - dismissDialog(INITIAL_SYNC); + new Thread() { + public void run() { + try { + animeList = new AnimeList("AlexanderS"); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } - 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); + updateUIHandler.sendEmptyMessage(0); + } + }.start(); } private void addAnimes(SeparatedListAdapter adapter, @@ -82,6 +102,7 @@ public class AnimeListActivity extends Activity { case INITIAL_SYNC: ProgressDialog dialog = ProgressDialog.show(this, "", "Loading list. Please wait...", true); + dialog.show(); return dialog; default: return super.onCreateDialog(id); |