summaryrefslogtreecommitdiffstats
path: root/src/de/animux/android/andmal/api/manga
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/de/animux/android/andmal/api/manga/Manga.java209
-rw-r--r--src/de/animux/android/andmal/api/manga/MangaList.java86
-rw-r--r--src/de/animux/android/andmal/api/manga/MangaListParser.java50
-rw-r--r--src/de/animux/android/andmal/api/manga/State.java38
4 files changed, 383 insertions, 0 deletions
diff --git a/src/de/animux/android/andmal/api/manga/Manga.java b/src/de/animux/android/andmal/api/manga/Manga.java
new file mode 100644
index 0000000..25670df
--- /dev/null
+++ b/src/de/animux/android/andmal/api/manga/Manga.java
@@ -0,0 +1,209 @@
+package de.animux.android.andmal.api.manga;
+
+import de.animux.android.andmal.api.MalObject;
+
+public class Manga extends MalObject {
+
+ private int id;
+ private String title;
+ private String synonyms;
+ private int type;
+ private int chapters;
+ private int volumes;
+ private int status;
+ private String start;
+ private String end;
+ private String image;
+
+ private int personalId;
+ private int personalReadChapters;
+ private int personalReadVolumes;
+ private String personalStart;
+ private String personalEnd;
+ private int personalScore;
+ private int personalStatus;
+ private int personalRereading;
+ private int personalRereadingChapters;
+ private int personalLastUpdated;
+ private String personalTags;
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getSynonyms() {
+ return synonyms;
+ }
+
+ public void setSynonyms(String synonyms) {
+ this.synonyms = synonyms;
+ }
+
+ public int getType() {
+ return type;
+ }
+
+ public void setType(int type) {
+ this.type = type;
+ }
+
+ public int getChapters() {
+ return chapters;
+ }
+
+ public void setChapters(int chapters) {
+ this.chapters = chapters;
+ }
+
+ public int getVolumes() {
+ return volumes;
+ }
+
+ public void setVolumes(int volumes) {
+ this.volumes = volumes;
+ }
+
+ public int getStatus() {
+ return status;
+ }
+
+ public void setStatus(int status) {
+ this.status = status;
+ }
+
+ public String getStart() {
+ return start;
+ }
+
+ public void setStart(String start) {
+ this.start = start;
+ }
+
+ public String getEnd() {
+ return end;
+ }
+
+ public void setEnd(String end) {
+ this.end = end;
+ }
+
+ public String getImage() {
+ return image;
+ }
+
+ public void setImage(String image) {
+ this.image = image;
+ }
+
+ public int getPersonalId() {
+ return personalId;
+ }
+
+ public void setPersonalId(int personalId) {
+ this.personalId = personalId;
+ }
+
+ public int getPersonalReadChapters() {
+ return personalReadChapters;
+ }
+
+ public void setPersonalReadChapters(int personalReadChapters) {
+ this.personalReadChapters = personalReadChapters;
+ }
+
+ public int getPersonalReadVolumes() {
+ return personalReadVolumes;
+ }
+
+ public void setPersonalReadVolumes(int personalReadVolumes) {
+ this.personalReadVolumes = personalReadVolumes;
+ }
+
+ public String getPersonalStart() {
+ return personalStart;
+ }
+
+ public void setPersonalStart(String personalStart) {
+ this.personalStart = personalStart;
+ }
+
+ public String getPersonalEnd() {
+ return personalEnd;
+ }
+
+ public void setPersonalEnd(String personalEnd) {
+ this.personalEnd = personalEnd;
+ }
+
+ public int getPersonalScore() {
+ return personalScore;
+ }
+
+ public void setPersonalScore(int personalScore) {
+ this.personalScore = personalScore;
+ }
+
+ public int getPersonalStatus() {
+ return personalStatus;
+ }
+
+ public void setPersonalStatus(int personalStatus) {
+ this.personalStatus = personalStatus;
+ }
+
+ public int getPersonalRereading() {
+ return personalRereading;
+ }
+
+ public void setPersonalRereading(int personalRereading) {
+ this.personalRereading = personalRereading;
+ }
+
+ public int getPersonalRereadingChapters() {
+ return personalRereadingChapters;
+ }
+
+ public void setPersonalRereadingChapters(int personalRereadingChapters) {
+ this.personalRereadingChapters = personalRereadingChapters;
+ }
+
+ public int getPersonalLastUpdated() {
+ return personalLastUpdated;
+ }
+
+ public void setPersonalLastUpdated(int personalLastUpdated) {
+ this.personalLastUpdated = personalLastUpdated;
+ }
+
+ public String getPersonalTags() {
+ return personalTags;
+ }
+
+ public void setPersonalTags(String personalTags) {
+ this.personalTags = personalTags;
+ }
+
+ @Override
+ public String getTitle() {
+ return this.title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ @Override
+ public int compareTo(MalObject arg0) {
+ return 0;
+ }
+
+ @Override
+ public String getProgress() {
+ return getPersonalReadChapters() + "/" + getChapters() + " ("
+ + getPersonalReadVolumes() + "/" + getVolumes() + ")";
+ }
+}
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;
+ }
+}
diff --git a/src/de/animux/android/andmal/api/manga/MangaListParser.java b/src/de/animux/android/andmal/api/manga/MangaListParser.java
new file mode 100644
index 0000000..7e0ec4b
--- /dev/null
+++ b/src/de/animux/android/andmal/api/manga/MangaListParser.java
@@ -0,0 +1,50 @@
+package de.animux.android.andmal.api.manga;
+
+import de.animux.android.andmal.api.MalListParser;
+import de.animux.android.andmal.api.MalObjectStore;
+
+public class MangaListParser extends MalListParser<Manga> {
+
+ private Manga currentManga;
+
+ public MangaListParser(MalObjectStore<Manga> objectStore) {
+ super(objectStore);
+ currentManga = new Manga();
+ }
+
+ @Override
+ public void addElement(String name, String value) {
+ if (name.equals("manga")) {
+ objectStore.add(currentManga);
+ currentManga = new Manga();
+ } else if (name.equals("series_mangadb_id")) {
+ currentManga.setId(Integer.valueOf(value));
+ } else if (name.equals("series_title")) {
+ currentManga.setTitle(value);
+ } else if (name.equals("series_synonyms")) {
+ currentManga.setSynonyms(value);
+ } else if (name.equals("series_type")) {
+ currentManga.setType(Integer.valueOf(value));
+ } else if (name.equals("series_chapters")) {
+ currentManga.setChapters(Integer.valueOf(value));
+ } else if (name.equals("volumes")) {
+ currentManga.setVolumes(Integer.valueOf(value));
+ } else if (name.equals("series_status")) {
+ currentManga.setStatus(Integer.valueOf(value));
+ } else if (name.equals("series_start")) {
+ currentManga.setStart(value);
+ } else if (name.equals("series_end")) {
+ currentManga.setEnd(value);
+ } else if (name.equals("series_image")) {
+ currentManga.setImage(value);
+ } else if (name.equals("my_id")) {
+ currentManga.setPersonalId(Integer.valueOf(value));
+ } else if (name.equals("my_read_chapters")) {
+ currentManga.setPersonalReadChapters(Integer.valueOf(value));
+ } else if (name.equals("my_read_volumes")) {
+ currentManga.setPersonalReadVolumes(Integer.valueOf(value));
+ } else if (name.equals("my_status")) {
+ currentManga.setPersonalStatus(Integer.valueOf(value));
+ }
+ }
+}
diff --git a/src/de/animux/android/andmal/api/manga/State.java b/src/de/animux/android/andmal/api/manga/State.java
new file mode 100644
index 0000000..a39fe78
--- /dev/null
+++ b/src/de/animux/android/andmal/api/manga/State.java
@@ -0,0 +1,38 @@
+package de.animux.android.andmal.api.manga;
+
+import de.animux.android.andmal.api.MalState;
+
+public enum State implements MalState {
+ READING (1, "Reading"),
+ COMPLETED (2, "Completed"),
+ ONHOLD (3, "On Hold"),
+ DROPPED (4, "Dropped"),
+ PLANTOREAD (6, "Plan to read");
+
+ private final int id;
+ private final String name;
+
+ State(int id, String name) {
+ this.id = id;
+ this.name = name;
+ }
+
+ @Override
+ public String toString() {
+ return name;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ static State valueOf(int id) {
+ for (State s : State.values()) {
+ if (s.getId() == id) {
+ return s;
+ }
+ }
+
+ return null;
+ }
+} \ No newline at end of file