From 1e458433b9176f01861b5976f7e22a74d7e07870 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Wed, 8 Jan 2014 20:03:45 -0800 Subject: #242 Fix listened to podcasts not always being deleted --- .../dsub/service/DownloadServiceImpl.java | 22 ++++++++++++++++++++-- .../service/DownloadServiceLifecycleSupport.java | 8 ++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) (limited to 'src') 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 downloadList = new ArrayList(); private final List backgroundDownloadList = new ArrayList(); + private final List toDelete = new ArrayList(); 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 songs, int currentPlayingIndex, int currentPlayingPosition) { + public void restore(List songs, List 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 getToDelete() { return toDelete; } + @Override public synchronized List getDownloads() { List temp = new ArrayList(); @@ -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 songs = new ArrayList(); + private List toDelete = new ArrayList(); private int currentPlayingIndex; private int currentPlayingPosition; private boolean renameCurrent = false; -- cgit v1.2.3