summaryrefslogtreecommitdiffstats
path: root/src/de/animux/android/andmal/api/manga/MangaList.java
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2010-08-25 08:03:05 +0200
committerAlexander Sulfrian <alexander@sulfrian.net>2010-08-25 08:03:05 +0200
commitbf24af1ed9808dc918dc81f0383103b6c51600a6 (patch)
treed899dae5a08c94b5184a558c16c9f743aee0c3c7 /src/de/animux/android/andmal/api/manga/MangaList.java
parent8a8dc0a2ac4f3552568d9e14bf5ae121394b055c (diff)
downloadAndMAL-bf24af1ed9808dc918dc81f0383103b6c51600a6.tar.gz
AndMAL-bf24af1ed9808dc918dc81f0383103b6c51600a6.tar.xz
AndMAL-bf24af1ed9808dc918dc81f0383103b6c51600a6.zip
refactoring, mangalist, settings (current problem: refresh other list after changing the settings)HEADmaster
Diffstat (limited to 'src/de/animux/android/andmal/api/manga/MangaList.java')
-rw-r--r--src/de/animux/android/andmal/api/manga/MangaList.java86
1 files changed, 86 insertions, 0 deletions
diff --git a/src/de/animux/android/andmal/api/manga/MangaList.java b/src/de/animux/android/andmal/api/manga/MangaList.java
new file mode 100644
index 0000000..00a89e4
--- /dev/null
+++ b/src/de/animux/android/andmal/api/manga/MangaList.java
@@ -0,0 +1,86 @@
+package de.animux.android.andmal.api.manga;
+
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+import de.animux.android.andmal.api.MalList;
+import de.animux.android.andmal.api.MalObject;
+import de.animux.android.andmal.api.MalObjectStore;
+import de.animux.android.andmal.api.MalState;
+import de.animux.android.andmal.util.SortedLinkedList;
+
+public class MangaList extends MalList implements MalObjectStore<Manga> {
+
+ // cache last instance of this class to restore if a new one is created with
+ // the same username and password
+ private static MangaList cache;
+ private Map<MalState, Collection<MalObject>> mangas;
+
+ public MangaList(String username, String password) {
+ super(username, password);
+
+ if (((cache != null) && cache.getUsername().equals(username))
+ && cache.getPassword().equals(username)) {
+ mangas = cache.getObjects();
+ } else {
+ cache = this;
+ needsRefresh = true;
+ }
+ }
+
+ public MangaList() {
+ super();
+
+ if (cache != null && cache.getUsername() != null
+ && cache.getUsername().equals(this.getUsername())) {
+ mangas = cache.getObjects();
+ } else {
+ cache = this;
+ needsRefresh = true;
+ }
+ }
+
+ @Override
+ public void refresh() {
+ if (this.getUsername() == null)
+ return;
+
+ mangas = new HashMap<MalState, Collection<MalObject>>();
+ mangas.put(State.READING, new SortedLinkedList<MalObject>());
+ mangas.put(State.COMPLETED, new SortedLinkedList<MalObject>());
+ mangas.put(State.ONHOLD, new SortedLinkedList<MalObject>());
+ mangas.put(State.DROPPED, new SortedLinkedList<MalObject>());
+ mangas.put(State.PLANTOREAD, new SortedLinkedList<MalObject>());
+
+ try {
+ URL url = new URL(
+ "http://myanimelist.net/malappinfo.php?status=all&type=manga&u="
+ + this.getUsername());
+ InputStream stream = url.openStream();
+
+ SAXParser sax = SAXParserFactory.newInstance().newSAXParser();
+ sax.parse(stream, new MangaListParser(this));
+ needsRefresh = false;
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void add(Manga object) {
+ if (mangas.containsKey(State.valueOf(object.getPersonalStatus()))) {
+ mangas.get(State.valueOf(object.getPersonalStatus())).add(object);
+ }
+ }
+
+ @Override
+ public Map<MalState, Collection<MalObject>> getObjects() {
+ return mangas;
+ }
+}