aboutsummaryrefslogtreecommitdiff
path: root/src/github
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2015-03-19 17:22:50 -0700
committerScott Jackson <daneren2005@gmail.com>2015-03-19 17:22:50 -0700
commit1e4c579f55d3d56529a3863f9bde0bfe470011be (patch)
tree7f4b8f988037d0361855b28e9a1399a847ec8007 /src/github
parent3578521ad997f424f6edd3e14117546cc50bf03f (diff)
downloaddsub-1e4c579f55d3d56529a3863f9bde0bfe470011be.tar.gz
dsub-1e4c579f55d3d56529a3863f9bde0bfe470011be.tar.bz2
dsub-1e4c579f55d3d56529a3863f9bde0bfe470011be.zip
#472 Un-normalize dates for Subsonic 5.1+
Diffstat (limited to 'src/github')
-rw-r--r--src/github/daneren2005/dsub/domain/Bookmark.java6
-rw-r--r--src/github/daneren2005/dsub/domain/Share.java9
-rw-r--r--src/github/daneren2005/dsub/service/parser/BookmarkParser.java31
-rw-r--r--src/github/daneren2005/dsub/service/parser/ShareParser.java34
4 files changed, 73 insertions, 7 deletions
diff --git a/src/github/daneren2005/dsub/domain/Bookmark.java b/src/github/daneren2005/dsub/domain/Bookmark.java
index 4a86b1bd..df3535d0 100644
--- a/src/github/daneren2005/dsub/domain/Bookmark.java
+++ b/src/github/daneren2005/dsub/domain/Bookmark.java
@@ -80,6 +80,9 @@ public class Bookmark implements Serializable {
this.created = null;
}
}
+ public void setCreated(Date created) {
+ this.created = created;
+ }
public Date getChanged() {
return changed;
@@ -96,4 +99,7 @@ public class Bookmark implements Serializable {
this.changed = null;
}
}
+ public void setChanged(Date changed) {
+ this.changed = changed;
+ }
}
diff --git a/src/github/daneren2005/dsub/domain/Share.java b/src/github/daneren2005/dsub/domain/Share.java
index 31ab7b8d..aa22956d 100644
--- a/src/github/daneren2005/dsub/domain/Share.java
+++ b/src/github/daneren2005/dsub/domain/Share.java
@@ -97,6 +97,9 @@ public class Share implements Serializable {
this.created = null;
}
}
+ public void setCreated(Date created) {
+ this.created = created;
+ }
public Date getLastVisited() {
return lastVisited;
@@ -113,6 +116,9 @@ public class Share implements Serializable {
this.lastVisited = null;
}
}
+ public void setLastVisited(Date lastVisited) {
+ this.lastVisited = lastVisited;
+ }
public Date getExpires() {
return expires;
@@ -129,6 +135,9 @@ public class Share implements Serializable {
this.expires = null;
}
}
+ public void setExpires(Date expires) {
+ this.expires = expires;
+ }
public Long getVisitCount() {
return visitCount;
diff --git a/src/github/daneren2005/dsub/service/parser/BookmarkParser.java b/src/github/daneren2005/dsub/service/parser/BookmarkParser.java
index 332172a3..8e04749c 100644
--- a/src/github/daneren2005/dsub/service/parser/BookmarkParser.java
+++ b/src/github/daneren2005/dsub/service/parser/BookmarkParser.java
@@ -22,11 +22,17 @@ import android.content.Context;
import github.daneren2005.dsub.R;
import github.daneren2005.dsub.domain.Bookmark;
import github.daneren2005.dsub.domain.MusicDirectory;
+import github.daneren2005.dsub.domain.ServerInfo;
import github.daneren2005.dsub.util.ProgressListener;
import org.xmlpull.v1.XmlPullParser;
import java.io.Reader;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
import java.util.ArrayList;
+import java.util.Date;
import java.util.List;
+import java.util.Locale;
+import java.util.TimeZone;
/**
* @author Scott Jackson
@@ -42,8 +48,14 @@ public class BookmarkParser extends MusicDirectoryEntryParser {
List<MusicDirectory.Entry> bookmarks = new ArrayList<MusicDirectory.Entry>();
Bookmark bookmark = null;
int eventType;
-
- do {
+
+ boolean isDateNormalized = ServerInfo.checkServerVersion(context, "1.11");
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.ENGLISH);
+ if(isDateNormalized) {
+ dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
+ }
+
+ do {
eventType = nextParseEvent();
if (eventType == XmlPullParser.START_TAG) {
@@ -51,8 +63,19 @@ public class BookmarkParser extends MusicDirectoryEntryParser {
if ("bookmark".equals(name)) {
bookmark = new Bookmark();
- bookmark.setChanged(get("changed"));
- bookmark.setCreated(get("created"));
+
+ try {
+ bookmark.setCreated(dateFormat.parse(get("created")));
+ } catch (Exception e) {
+ bookmark.setCreated((Date) null);
+ }
+
+ try {
+ bookmark.setChanged(dateFormat.parse(get("changed")));
+ } catch (Exception e) {
+ bookmark.setChanged((Date) null);
+ }
+
bookmark.setComment(get("comment"));
bookmark.setPosition(getInteger("position"));
bookmark.setUsername(get("username"));
diff --git a/src/github/daneren2005/dsub/service/parser/ShareParser.java b/src/github/daneren2005/dsub/service/parser/ShareParser.java
index e18e1414..fdad8375 100644
--- a/src/github/daneren2005/dsub/service/parser/ShareParser.java
+++ b/src/github/daneren2005/dsub/service/parser/ShareParser.java
@@ -22,6 +22,7 @@ import android.content.Context;
import android.content.SharedPreferences;
import github.daneren2005.dsub.R;
+import github.daneren2005.dsub.domain.ServerInfo;
import github.daneren2005.dsub.domain.Share;
import github.daneren2005.dsub.util.Constants;
import github.daneren2005.dsub.util.ProgressListener;
@@ -29,8 +30,13 @@ import github.daneren2005.dsub.util.Util;
import org.xmlpull.v1.XmlPullParser;
import java.io.Reader;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
import java.util.ArrayList;
+import java.util.Date;
import java.util.List;
+import java.util.Locale;
+import java.util.TimeZone;
/**
* @author Joshua Bahnsen
@@ -56,6 +62,12 @@ public class ShareParser extends MusicDirectoryEntryParser {
serverUrl += '/';
}
serverUrl += "share/";
+
+ boolean isDateNormalized = ServerInfo.checkServerVersion(context, "1.11");
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.ENGLISH);
+ if(isDateNormalized) {
+ dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
+ }
do {
eventType = nextParseEvent();
@@ -65,12 +77,28 @@ public class ShareParser extends MusicDirectoryEntryParser {
if ("share".equals(name)) {
share = new Share();
- share.setCreated(get("created"));
+
+ try {
+ share.setCreated(dateFormat.parse(get("created")));
+ } catch (Exception e) {
+ share.setCreated((Date) null);
+ }
share.setUrl(get("url").replaceFirst(".*/([^/?]+).*", serverUrl + "$1"));
share.setDescription(get("description"));
- share.setExpires(get("expires"));
+
+ try {
+ share.setExpires(dateFormat.parse(get("expires")));
+ } catch (Exception e) {
+ share.setExpires((Date) null);
+ }
share.setId(get("id"));
- share.setLastVisited(get("lastVisited"));
+
+ try {
+ share.setLastVisited(dateFormat.parse(get("lastVisited")));
+ } catch (Exception e) {
+ share.setLastVisited((Date) null);
+ }
+
share.setUsername(get("username"));
share.setVisitCount(getLong("visitCount"));
dir.add(share);