aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/DownloadFile.java14
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/MediaStoreService.java7
2 files changed, 14 insertions, 7 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/service/DownloadFile.java b/app/src/main/java/github/daneren2005/dsub/service/DownloadFile.java
index 30e06982..7686b468 100644
--- a/app/src/main/java/github/daneren2005/dsub/service/DownloadFile.java
+++ b/app/src/main/java/github/daneren2005/dsub/service/DownloadFile.java
@@ -321,9 +321,11 @@ public class DownloadFile implements BufferFile {
saveWhenDone = false;
} else if(completeWhenDone && !isPlaying) {
if(save) {
+ deleteFromStore();
Util.renameFile(partialFile, saveFile);
saveToStore();
} else {
+ deleteFromStore();
Util.renameFile(partialFile, completeFile);
saveToStore();
}
@@ -337,6 +339,7 @@ public class DownloadFile implements BufferFile {
}
public void renamePartial() {
try {
+ deleteFromStore();
Util.renameFile(partialFile, completeFile);
saveToStore();
} catch(IOException ex) {
@@ -348,10 +351,12 @@ public class DownloadFile implements BufferFile {
}
private void deleteFromStore() {
- try {
- mediaStoreService.deleteFromMediaStore(this);
- } catch(Exception e) {
- Log.w(TAG, "Failed to remove from store", e);
+ if(!Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_HIDE_MEDIA, false)) {
+ try {
+ mediaStoreService.deleteFromMediaStore(this);
+ } catch (Exception e) {
+ Log.w(TAG, "Failed to remove from store", e);
+ }
}
}
private void saveToStore() {
@@ -490,6 +495,7 @@ public class DownloadFile implements BufferFile {
if(isPlaying) {
completeWhenDone = true;
} else {
+ deleteFromStore();
if(save) {
Util.renameFile(partialFile, saveFile);
} else {
diff --git a/app/src/main/java/github/daneren2005/dsub/service/MediaStoreService.java b/app/src/main/java/github/daneren2005/dsub/service/MediaStoreService.java
index 0aa3269f..28bd488a 100644
--- a/app/src/main/java/github/daneren2005/dsub/service/MediaStoreService.java
+++ b/app/src/main/java/github/daneren2005/dsub/service/MediaStoreService.java
@@ -49,9 +49,6 @@ public class MediaStoreService {
MusicDirectory.Entry song = downloadFile.getSong();
File songFile = downloadFile.getCompleteFile();
- // Delete existing row in case the song has been downloaded before.
- deleteFromMediaStore(downloadFile);
-
ContentResolver contentResolver = context.getContentResolver();
ContentValues values = new ContentValues();
if(!song.isVideo()) {
@@ -76,6 +73,10 @@ public class MediaStoreService {
values.put(MediaStore.Audio.AudioColumns.IS_MUSIC, 1);
Uri uri = contentResolver.insert(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, values);
+ if(uri == null) {
+ Log.e(TAG, "URI for media store is null");
+ return;
+ }
// Look up album, and add cover art if found.
Cursor cursor = contentResolver.query(uri, new String[]{MediaStore.Audio.AudioColumns.ALBUM_ID}, null, null, null);