aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2020-09-12 11:46:08 -0700
committerScott Jackson <daneren2005@gmail.com>2020-09-12 11:46:08 -0700
commit04f1c5ae49c518ca38b51a3074e18cc4917117ff (patch)
tree281be080da91d2b5aac78dcad404e6ea1c2f2970
parentb375100232222afee33c68184059dc93487a1a86 (diff)
downloaddsub-04f1c5ae49c518ca38b51a3074e18cc4917117ff.tar.gz
dsub-04f1c5ae49c518ca38b51a3074e18cc4917117ff.tar.bz2
dsub-04f1c5ae49c518ca38b51a3074e18cc4917117ff.zip
#1002 Delete from media store before renaming file since in Android 11 it deletes the actual file instead of just the media store record
-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);