aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2014-01-08 20:03:45 -0800
committerScott Jackson <daneren2005@gmail.com>2014-01-08 20:03:45 -0800
commit1e458433b9176f01861b5976f7e22a74d7e07870 (patch)
tree729f0c1c306bd4e8f9235b7f5e9a44ed7a2d723a /src
parentf17d185d277bca41e961fb365506e6ae946176fc (diff)
downloaddsub-1e458433b9176f01861b5976f7e22a74d7e07870.tar.gz
dsub-1e458433b9176f01861b5976f7e22a74d7e07870.tar.bz2
dsub-1e458433b9176f01861b5976f7e22a74d7e07870.zip
#242 Fix listened to podcasts not always being deleted
Diffstat (limited to 'src')
-rw-r--r--src/github/daneren2005/dsub/service/DownloadServiceImpl.java22
-rw-r--r--src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java8
2 files changed, 26 insertions, 4 deletions
diff --git a/src/github/daneren2005/dsub/service/DownloadServiceImpl.java b/src/github/daneren2005/dsub/service/DownloadServiceImpl.java
index 671b164a..684b9227 100644
--- a/src/github/daneren2005/dsub/service/DownloadServiceImpl.java
+++ b/src/github/daneren2005/dsub/service/DownloadServiceImpl.java
@@ -93,6 +93,7 @@ public class DownloadServiceImpl extends Service implements DownloadService {
private boolean isPartial = true;
private final List<DownloadFile> downloadList = new ArrayList<DownloadFile>();
private final List<DownloadFile> backgroundDownloadList = new ArrayList<DownloadFile>();
+ private final List<DownloadFile> toDelete = new ArrayList<DownloadFile>();
private final Handler handler = new Handler();
private Handler mediaPlayerHandler;
private final DownloadServiceLifecycleSupport lifecycleSupport = new DownloadServiceLifecycleSupport(this);
@@ -354,7 +355,7 @@ public class DownloadServiceImpl extends Service implements DownloadService {
}
}
- public void restore(List<MusicDirectory.Entry> songs, int currentPlayingIndex, int currentPlayingPosition) {
+ public void restore(List<MusicDirectory.Entry> songs, List<MusicDirectory.Entry> toDelete, int currentPlayingIndex, int currentPlayingPosition) {
SharedPreferences prefs = Util.getPreferences(this);
remoteState = RemoteControlState.values()[prefs.getInt(Constants.PREFERENCES_KEY_CONTROL_MODE, 0)];
if(remoteState != RemoteControlState.LOCAL) {
@@ -379,6 +380,12 @@ public class DownloadServiceImpl extends Service implements DownloadService {
}
autoPlayStart = false;
}
+
+ if(toDelete != null) {
+ for(MusicDirectory.Entry entry: toDelete) {
+ this.toDelete.add(forSong(entry));
+ }
+ }
}
@Override
@@ -523,7 +530,11 @@ public class DownloadServiceImpl extends Service implements DownloadService {
currentPlaying.delete();
}
}
-
+ for(DownloadFile podcast: toDelete) {
+ podcast.delete();
+ }
+ toDelete.clear();
+
reset();
downloadList.clear();
revision++;
@@ -666,6 +677,8 @@ public class DownloadServiceImpl extends Service implements DownloadService {
return downloadList;
}
+ public List<DownloadFile> getToDelete() { return toDelete; }
+
@Override
public synchronized List<DownloadFile> getDownloads() {
List<DownloadFile> temp = new ArrayList<DownloadFile>();
@@ -1294,6 +1307,11 @@ public class DownloadServiceImpl extends Service implements DownloadService {
}
}
+ // Finished loading, delete when list is cleared
+ if(downloadFile.getSong() instanceof PodcastEpisode) {
+ toDelete.add(downloadFile);
+ }
+
wakeLock.release();
}
});
diff --git a/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java b/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java
index 225e352b..f0b7ceb1 100644
--- a/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java
+++ b/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java
@@ -260,6 +260,9 @@ public class DownloadServiceLifecycleSupport {
for (DownloadFile downloadFile : songs) {
state.songs.add(downloadFile.getSong());
}
+ for (DownloadFile downloadFile : downloadService.getToDelete()) {
+ state.toDelete.add(downloadFile.getSong());
+ }
state.currentPlayingIndex = downloadService.getCurrentPlayingIndex();
state.currentPlayingPosition = downloadService.getPlayerPosition();
@@ -285,7 +288,7 @@ public class DownloadServiceLifecycleSupport {
currentPlaying.renamePartial();
}
- downloadService.restore(state.songs, state.currentPlayingIndex, state.currentPlayingPosition);
+ downloadService.restore(state.songs, state.toDelete, state.currentPlayingIndex, state.currentPlayingPosition);
}
private void handleKeyEvent(KeyEvent event) {
@@ -378,9 +381,10 @@ public class DownloadServiceLifecycleSupport {
}
private static class State implements Serializable {
- private static final long serialVersionUID = -6346438781062572270L;
+ private static final long serialVersionUID = -6346438781062572271L;
private List<MusicDirectory.Entry> songs = new ArrayList<MusicDirectory.Entry>();
+ private List<MusicDirectory.Entry> toDelete = new ArrayList<MusicDirectory.Entry>();
private int currentPlayingIndex;
private int currentPlayingPosition;
private boolean renameCurrent = false;