diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/github/daneren2005/dsub/service/DownloadServiceImpl.java | 22 | ||||
-rw-r--r-- | src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java | 8 |
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; |