aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/github/daneren2005/dsub/service
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2016-05-30 16:24:54 -0500
committerScott Jackson <daneren2005@gmail.com>2016-05-30 16:24:54 -0500
commit3b6f5ba72e52cade383d1d0361a4974f965ae728 (patch)
tree08fc7252f5173b22ba8971cd98de75542d462e95 /app/src/main/java/github/daneren2005/dsub/service
parent403a0b8e6d0d45ffda1c32baa89c187876fa53ef (diff)
parentfb6048141ee594dc2d30a96be3150b6a94983852 (diff)
downloaddsub-3b6f5ba72e52cade383d1d0361a4974f965ae728.tar.gz
dsub-3b6f5ba72e52cade383d1d0361a4974f965ae728.tar.bz2
dsub-3b6f5ba72e52cade383d1d0361a4974f965ae728.zip
Merge remote-tracking branch 'origin/master' into playback_speed
Diffstat (limited to 'app/src/main/java/github/daneren2005/dsub/service')
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/CachedMusicService.java17
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java13
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/MusicService.java2
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/OfflineMusicService.java2
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/RESTMusicService.java26
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/parser/AbstractParser.java16
6 files changed, 52 insertions, 24 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/service/CachedMusicService.java b/app/src/main/java/github/daneren2005/dsub/service/CachedMusicService.java
index 3be04cff..1a17dfb3 100644
--- a/app/src/main/java/github/daneren2005/dsub/service/CachedMusicService.java
+++ b/app/src/main/java/github/daneren2005/dsub/service/CachedMusicService.java
@@ -22,8 +22,6 @@ import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collections;
-import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
@@ -59,7 +57,6 @@ import github.daneren2005.dsub.util.SongDBHandler;
import github.daneren2005.dsub.util.SyncUtil;
import github.daneren2005.dsub.util.TimeLimitedCache;
import github.daneren2005.dsub.util.FileUtil;
-import github.daneren2005.dsub.util.UpdateHelper;
import github.daneren2005.dsub.util.Util;
import static github.daneren2005.dsub.domain.MusicDirectory.Entry;
@@ -926,8 +923,18 @@ public class CachedMusicService implements MusicService {
}
@Override
- public MusicDirectory getNewestPodcastEpisodes(int count, Context context, ProgressListener progressListener) throws Exception {
- return musicService.getNewestPodcastEpisodes(count, context, progressListener);
+ public MusicDirectory getNewestPodcastEpisodes(boolean refresh, Context context, ProgressListener progressListener, int count) throws Exception {
+ MusicDirectory result = null;
+
+ String cacheName = getCacheName(context, "newestPodcastEpisodes");
+ try {
+ result = musicService.getNewestPodcastEpisodes(refresh, context, progressListener, count);
+ FileUtil.serialize(context, result, cacheName);
+ } catch(IOException e) {
+ result = FileUtil.deserialize(context, cacheName, MusicDirectory.class, 24);
+ } finally {
+ return result;
+ }
}
@Override
diff --git a/app/src/main/java/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java b/app/src/main/java/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java
index ce2c81f2..5e9e04fc 100644
--- a/app/src/main/java/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java
+++ b/app/src/main/java/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java
@@ -56,6 +56,7 @@ import static github.daneren2005.dsub.domain.PlayerState.PREPARING;
public class DownloadServiceLifecycleSupport {
private static final String TAG = DownloadServiceLifecycleSupport.class.getSimpleName();
public static final String FILENAME_DOWNLOADS_SER = "downloadstate2.ser";
+ private static final int DEBOUNCE_TIME = 200;
private final DownloadService downloadService;
private Looper eventLooper;
@@ -400,10 +401,10 @@ public class DownloadServiceLifecycleSupport {
} else if(event.getAction() == KeyEvent.ACTION_UP) {
switch (event.getKeyCode()) {
case RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE:
- case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
downloadService.togglePlayPause();
break;
case KeyEvent.KEYCODE_HEADSETHOOK:
+ case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
if(lastPressTime < (System.currentTimeMillis() - 500)) {
lastPressTime = System.currentTimeMillis();
downloadService.togglePlayPause();
@@ -413,11 +414,17 @@ public class DownloadServiceLifecycleSupport {
break;
case RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS:
case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
- downloadService.previous();
+ if(lastPressTime < (System.currentTimeMillis() - DEBOUNCE_TIME)) {
+ lastPressTime = System.currentTimeMillis();
+ downloadService.previous();
+ }
break;
case RemoteControlClient.FLAG_KEY_MEDIA_NEXT:
case KeyEvent.KEYCODE_MEDIA_NEXT:
- downloadService.next();
+ if(lastPressTime < (System.currentTimeMillis() - DEBOUNCE_TIME)) {
+ lastPressTime = System.currentTimeMillis();
+ downloadService.next();
+ }
break;
case KeyEvent.KEYCODE_MEDIA_REWIND:
downloadService.rewind();
diff --git a/app/src/main/java/github/daneren2005/dsub/service/MusicService.java b/app/src/main/java/github/daneren2005/dsub/service/MusicService.java
index 876b45fd..22f154c4 100644
--- a/app/src/main/java/github/daneren2005/dsub/service/MusicService.java
+++ b/app/src/main/java/github/daneren2005/dsub/service/MusicService.java
@@ -149,7 +149,7 @@ public interface MusicService {
MusicDirectory getPodcastEpisodes(boolean refresh, String id, Context context, ProgressListener progressListener) throws Exception;
- MusicDirectory getNewestPodcastEpisodes(int count, Context context, ProgressListener progressListener) throws Exception;
+ MusicDirectory getNewestPodcastEpisodes(boolean refresh, Context context, ProgressListener progressListener, int count) throws Exception;
void refreshPodcasts(Context context, ProgressListener progressListener) throws Exception;
diff --git a/app/src/main/java/github/daneren2005/dsub/service/OfflineMusicService.java b/app/src/main/java/github/daneren2005/dsub/service/OfflineMusicService.java
index e1929bf8..e004101d 100644
--- a/app/src/main/java/github/daneren2005/dsub/service/OfflineMusicService.java
+++ b/app/src/main/java/github/daneren2005/dsub/service/OfflineMusicService.java
@@ -775,7 +775,7 @@ public class OfflineMusicService implements MusicService {
}
@Override
- public MusicDirectory getNewestPodcastEpisodes(int count, Context context, ProgressListener progressListener) throws Exception {
+ public MusicDirectory getNewestPodcastEpisodes(boolean refresh, Context context, ProgressListener progressListener, int count) throws Exception {
throw new OfflineException(ERRORMSG);
}
diff --git a/app/src/main/java/github/daneren2005/dsub/service/RESTMusicService.java b/app/src/main/java/github/daneren2005/dsub/service/RESTMusicService.java
index 7a2edf79..4c3a121d 100644
--- a/app/src/main/java/github/daneren2005/dsub/service/RESTMusicService.java
+++ b/app/src/main/java/github/daneren2005/dsub/service/RESTMusicService.java
@@ -1336,8 +1336,8 @@ public class RESTMusicService implements MusicService {
}
@Override
- public MusicDirectory getNewestPodcastEpisodes(int count, Context context, ProgressListener progressListener) throws Exception {
- Reader reader = getReader(context, progressListener, "getNewestPodcasts", null, Arrays.asList("count"), Arrays.<Object>asList(count));
+ public MusicDirectory getNewestPodcastEpisodes(boolean refresh, Context context, ProgressListener progressListener, int count) throws Exception {
+ Reader reader = getReader(context, progressListener, "getNewestPodcasts", null, Arrays.asList("count"), Arrays.<Object>asList(count), true);
try {
return new PodcastEntryParser(context, getInstance(context)).parse(null, reader, progressListener);
@@ -1769,13 +1769,13 @@ public class RESTMusicService implements MusicService {
int count = offline.getInt(Constants.OFFLINE_SCROBBLE_COUNT, 0);
int retry = 0;
for(int i = 1; i <= count; i++) {
- String id = offline.getString(Constants.OFFLINE_SCROBBLE_ID + i, null);
- long time = offline.getLong(Constants.OFFLINE_SCROBBLE_TIME + i, 0);
- if(id != null) {
- scrobble(id, true, time, context, progressListener);
- } else {
- String search = offline.getString(Constants.OFFLINE_SCROBBLE_SEARCH + i, "");
- try{
+ try {
+ String id = offline.getString(Constants.OFFLINE_SCROBBLE_ID + i, null);
+ long time = offline.getLong(Constants.OFFLINE_SCROBBLE_TIME + i, 0);
+ if(id != null) {
+ scrobble(id, true, time, context, progressListener);
+ } else {
+ String search = offline.getString(Constants.OFFLINE_SCROBBLE_SEARCH + i, "");
SearchCritera critera = new SearchCritera(search, 0, 0, 1);
SearchResult result = searchNew(critera, context, progressListener);
if(result.getSongs().size() == 1){
@@ -1787,10 +1787,10 @@ public class RESTMusicService implements MusicService {
throw new Exception("Song not found on server");
}
}
- catch(Exception e){
- Log.e(TAG, e.toString());
- retry++;
- }
+ }
+ catch(Exception e){
+ Log.e(TAG, e.toString());
+ retry++;
}
}
diff --git a/app/src/main/java/github/daneren2005/dsub/service/parser/AbstractParser.java b/app/src/main/java/github/daneren2005/dsub/service/parser/AbstractParser.java
index 4ee37dad..d6e1a002 100644
--- a/app/src/main/java/github/daneren2005/dsub/service/parser/AbstractParser.java
+++ b/app/src/main/java/github/daneren2005/dsub/service/parser/AbstractParser.java
@@ -133,7 +133,16 @@ public abstract class AbstractParser {
}
protected int nextParseEvent() throws Exception {
- return parser.next();
+ try {
+ return parser.next();
+ } catch(Exception e) {
+ if(ServerInfo.isMadsonic6(context, instance)) {
+ ServerInfo overrideInfo = new ServerInfo();
+ overrideInfo.saveServerInfo(context, instance);
+ }
+
+ throw e;
+ }
}
protected String getElementName() {
@@ -162,6 +171,11 @@ public abstract class AbstractParser {
protected void validate() throws Exception {
if (!rootElementFound) {
+ if(ServerInfo.isMadsonic6(context, instance)) {
+ ServerInfo overrideInfo = new ServerInfo();
+ overrideInfo.saveServerInfo(context, instance);
+ }
+
throw new Exception(context.getResources().getString(R.string.background_task_parse_error));
}
}