summaryrefslogtreecommitdiffstats
path: root/src/de/animux/android/andmal/api
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2010-08-17 01:56:11 +0200
committerAlexander Sulfrian <alexander@sulfrian.net>2010-08-17 02:19:39 +0200
commitd773a39a1f07ae4b8021222a47c16b048d7fd435 (patch)
tree3558cbd77c8e6aa54f5593b556fcbf330fea0120 /src/de/animux/android/andmal/api
downloadAndMAL-d773a39a1f07ae4b8021222a47c16b048d7fd435.tar.gz
AndMAL-d773a39a1f07ae4b8021222a47c16b048d7fd435.tar.xz
AndMAL-d773a39a1f07ae4b8021222a47c16b048d7fd435.zip
initial commit
Diffstat (limited to 'src/de/animux/android/andmal/api')
-rw-r--r--src/de/animux/android/andmal/api/anime/Anime.java197
-rw-r--r--src/de/animux/android/andmal/api/anime/AnimeList.java117
-rw-r--r--src/de/animux/android/andmal/api/anime/State.java36
3 files changed, 350 insertions, 0 deletions
diff --git a/src/de/animux/android/andmal/api/anime/Anime.java b/src/de/animux/android/andmal/api/anime/Anime.java
new file mode 100644
index 0000000..d4f542f
--- /dev/null
+++ b/src/de/animux/android/andmal/api/anime/Anime.java
@@ -0,0 +1,197 @@
+package de.animux.android.andmal.api.anime;
+
+public class Anime implements Comparable<Anime> {
+
+ private int id;
+ private String title;
+ private String synonyms;
+ private int type;
+ private int episodes;
+ private int status;
+ private String start;
+ private String end;
+ private String image;
+ private int myId;
+ private int watchedEpisodes;
+ private String myStart;
+ private String myEnd;
+ private int myScore;
+ private int myStatus;
+ private int rewatching;
+ private int rewatchingEpisodes;
+ private int lastUpdate;
+ private String tags;
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ 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 getEpisodes() {
+ return episodes;
+ }
+
+ public void setEpisodes(int episodes) {
+ this.episodes = episodes;
+ }
+
+ 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 getMyId() {
+ return myId;
+ }
+
+ public void setMyId(int myId) {
+ this.myId = myId;
+ }
+
+ public int getWatchedEpisodes() {
+ return watchedEpisodes;
+ }
+
+ public void setWatchedEpisodes(int watchedEpisodes) {
+ this.watchedEpisodes = watchedEpisodes;
+ }
+
+ public String getMyStart() {
+ return myStart;
+ }
+
+ public void setMyStart(String myStart) {
+ this.myStart = myStart;
+ }
+
+ public String getMyEnd() {
+ return myEnd;
+ }
+
+ public void setMyEnd(String myEnd) {
+ this.myEnd = myEnd;
+ }
+
+ public int getMyScore() {
+ return myScore;
+ }
+
+ public void setMyScore(int myScore) {
+ this.myScore = myScore;
+ }
+
+ public int getMyStatus() {
+ return myStatus;
+ }
+
+ public void setMyStatus(int myStatus) {
+ this.myStatus = myStatus;
+ }
+
+ public int getRewatching() {
+ return rewatching;
+ }
+
+ public void setRewatching(int rewatching) {
+ this.rewatching = rewatching;
+ }
+
+ public int getRewatchingEpisodes() {
+ return rewatchingEpisodes;
+ }
+
+ public void setRewatchingEpisodes(int rewatchingEpisodes) {
+ this.rewatchingEpisodes = rewatchingEpisodes;
+ }
+
+ public int getLastUpdate() {
+ return lastUpdate;
+ }
+
+ public void setLastUpdate(int lastUpdate) {
+ this.lastUpdate = lastUpdate;
+ }
+
+ public String getTags() {
+ return tags;
+ }
+
+ public void setTags(String tags) {
+ this.tags = tags;
+ }
+
+ @Override
+ public String toString() {
+ return getTitle();
+ }
+
+ @Override
+ public int compareTo(Anime arg0) {
+ int compareTitle = arg0.getTitle().compareTo(getTitle());
+ if (compareTitle != 0) {
+ return compareTitle;
+ }
+ else {
+ if (arg0.getId() != getId()) {
+ return getId() - arg0.getId();
+ }
+ }
+
+ return 0;
+ }
+
+}
diff --git a/src/de/animux/android/andmal/api/anime/AnimeList.java b/src/de/animux/android/andmal/api/anime/AnimeList.java
new file mode 100644
index 0000000..78a1e09
--- /dev/null
+++ b/src/de/animux/android/andmal/api/anime/AnimeList.java
@@ -0,0 +1,117 @@
+package de.animux.android.andmal.api.anime;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import java.net.URL;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.parsers.FactoryConfigurationError;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+import de.animux.android.andmal.api.anime.State;
+import de.animux.android.andmal.util.SortedLinkedList;
+
+public class AnimeList extends DefaultHandler {
+
+ private Anime currentAnime;
+ private StringBuffer currentValue;
+
+ private HashMap<State,List<Anime>> animes;
+
+ public AnimeList(String user) throws IOException,
+ ParserConfigurationException, SAXException,
+ FactoryConfigurationError {
+ currentAnime = null;
+ currentValue = new StringBuffer();
+
+ animes = new HashMap<State, List<Anime>>();
+ animes.put(State.WATCHING, new SortedLinkedList<Anime>());
+ animes.put(State.COMPLETED, new SortedLinkedList<Anime>());
+ animes.put(State.ONHOLD, new SortedLinkedList<Anime>());
+ animes.put(State.DROPPED, new SortedLinkedList<Anime>());
+ animes.put(State.PLANTOWATCH, new SortedLinkedList<Anime>());
+
+ URL url = new URL("http://myanimelist.net/malappinfo.php?status=all&type=anime&u=" + user);
+ InputStream stream = url.openStream();
+
+ SAXParser sax = SAXParserFactory.newInstance().newSAXParser();
+ sax.parse(stream, this);
+ }
+
+ public Anime getCurrentAnime() {
+ return currentAnime;
+ }
+
+ public StringBuffer getCurrentValue() {
+ return currentValue;
+ }
+
+ public Map<State, List<Anime>> getAnimes() {
+ return animes;
+ }
+
+ @Override
+ public void characters(char[] ch, int start, int length)
+ throws SAXException {
+ currentValue.append(new String(ch).substring(start, length - start)
+ .replaceAll("&amp;", "&"));
+ }
+
+ @Override
+ public void endElement(String uri, String localName, String qName)
+ throws SAXException {
+
+ if (localName.equals("anime")) {
+ if (animes.containsKey(State.valueOf(currentAnime.getMyStatus()))) {
+ animes.get(State.valueOf(currentAnime.getMyStatus())).add(currentAnime);
+ }
+
+ } else if (localName.equals("series_animedb_id")) {
+ currentAnime.setId(Integer.valueOf(currentValue.toString()));
+ } else if (localName.equals("series_title")) {
+ currentAnime.setTitle(currentValue.toString());
+ } else if (localName.equals("series_synonyms")) {
+ currentAnime.setSynonyms(currentValue.toString());
+ } else if (localName.equals("series_type")) {
+ currentAnime.setType(Integer.valueOf(currentValue.toString()));
+ } else if (localName.equals("series_episodes")) {
+ currentAnime.setEpisodes(Integer.valueOf(currentValue.toString()));
+ } else if (localName.equals("series_status")) {
+ currentAnime.setStatus(Integer.valueOf(currentValue.toString()));
+ } else if (localName.equals("series_start")) {
+ currentAnime.setStart(currentValue.toString());
+ } else if (localName.equals("series_end")) {
+ currentAnime.setEnd(currentValue.toString());
+ } else if (localName.equals("series_image")) {
+ currentAnime.setImage(currentValue.toString());
+ } else if (localName.equals("my_id")) {
+ currentAnime.setMyId(Integer.valueOf(currentValue.toString()));
+ } else if (localName.equals("my_watched_episodes")) {
+ currentAnime.setWatchedEpisodes(Integer.valueOf(currentValue
+ .toString()));
+ } else if (localName.equals("my_status")) {
+ currentAnime.setMyStatus(Integer.valueOf(currentValue.toString()));
+ }
+
+ currentValue.setLength(0);
+ }
+
+ @Override
+ public void startElement(String uri, String localName, String qName,
+ Attributes attributes) throws SAXException {
+
+ currentValue.setLength(0);
+ if (localName.equals("anime")) {
+ currentAnime = new Anime();
+ }
+ }
+}
diff --git a/src/de/animux/android/andmal/api/anime/State.java b/src/de/animux/android/andmal/api/anime/State.java
new file mode 100644
index 0000000..639b761
--- /dev/null
+++ b/src/de/animux/android/andmal/api/anime/State.java
@@ -0,0 +1,36 @@
+package de.animux.android.andmal.api.anime;
+
+public enum State {
+ WATCHING (1, "Watching"),
+ COMPLETED (2, "Completed"),
+ ONHOLD (3, "On Hold"),
+ DROPPED (4, "Dropped"),
+ PLANTOWATCH (6, "Plan to watch");
+
+ 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