diff options
author | daneren2005 <daneren2005@gmail.com> | 2014-07-02 13:36:43 -0700 |
---|---|---|
committer | daneren2005 <daneren2005@gmail.com> | 2014-07-02 13:36:43 -0700 |
commit | 1b4dfc3bf40c11d375854e9d867d7c4d28bae780 (patch) | |
tree | 7065a5401cbf6d1a1408121b4e3a4f2dbce89865 /src | |
parent | 3623dfe5f845e6f398872f996bc2df7883335239 (diff) | |
download | dsub-1b4dfc3bf40c11d375854e9d867d7c4d28bae780.tar.gz dsub-1b4dfc3bf40c11d375854e9d867d7c4d28bae780.tar.bz2 dsub-1b4dfc3bf40c11d375854e9d867d7c4d28bae780.zip |
#361 Fix a bunch of cases not being saved to MediaStore
Diffstat (limited to 'src')
-rw-r--r-- | src/github/daneren2005/dsub/service/DownloadFile.java | 38 |
1 files changed, 31 insertions, 7 deletions
diff --git a/src/github/daneren2005/dsub/service/DownloadFile.java b/src/github/daneren2005/dsub/service/DownloadFile.java index c82607f5..2d073d11 100644 --- a/src/github/daneren2005/dsub/service/DownloadFile.java +++ b/src/github/daneren2005/dsub/service/DownloadFile.java @@ -263,15 +263,22 @@ public class DownloadFile implements BufferFile { public void delete() { cancelDownload(); + + // Remove from mediaStore BEFORE deleting file since it calls getCompleteFile + deleteFromStore(); + + // Delete all possible versions of the file Util.delete(partialFile); Util.delete(completeFile); Util.delete(saveFile); - mediaStoreService.deleteFromMediaStore(this); } public void unpin() { if (saveFile.exists()) { + // Delete old store entry before renaming to pinned file + deleteFromStore(); saveFile.renameTo(completeFile); + saveToStore(); } } @@ -305,14 +312,17 @@ public class DownloadFile implements BufferFile { public void setPlaying(boolean isPlaying) { try { if(saveWhenDone && !isPlaying) { + deleteFromStore(); Util.renameFile(completeFile, saveFile); + saveToStore(); saveWhenDone = false; } else if(completeWhenDone && !isPlaying) { if(save) { Util.renameFile(partialFile, saveFile); - mediaStoreService.saveInMediaStore(DownloadFile.this); + saveToStore(); } else { Util.renameFile(partialFile, completeFile); + saveToStore(); } completeWhenDone = false; } @@ -325,6 +335,7 @@ public class DownloadFile implements BufferFile { public void renamePartial() { try { Util.renameFile(partialFile, completeFile); + saveToStore(); } catch(IOException ex) { Log.w(TAG, "Failed to rename file " + partialFile + " to " + completeFile, ex); } @@ -332,6 +343,21 @@ public class DownloadFile implements BufferFile { public boolean getPlaying() { return isPlaying; } + + private void deleteFromStore() { + try { + mediaStoreService.deleteFromMediaStore(this); + } catch(Exception e) { + Log.w(TAG, "Failed to remove from store", e); + } + } + private void saveToStore() { + try { + mediaStoreService.saveInMediaStore(this); + } catch(Exception e) { + Log.w(TAG, "Failed to save in media store", e); + } + } @Override public String toString() { @@ -372,7 +398,9 @@ public class DownloadFile implements BufferFile { if(isPlaying) { saveWhenDone = true; } else { + deleteFromStore(); Util.renameFile(completeFile, saveFile); + DownloadFile.this.saveToStore(); } } else { Log.i(TAG, completeFile + " already exists. Skipping."); @@ -429,14 +457,10 @@ public class DownloadFile implements BufferFile { } else { if(save) { Util.renameFile(partialFile, saveFile); - try { - mediaStoreService.saveInMediaStore(DownloadFile.this); - } catch(Exception e) { - Log.w(TAG, "Failed to save in media store", e); - } } else { Util.renameFile(partialFile, completeFile); } + DownloadFile.this.saveToStore(); } } catch(InterruptedException x) { |