aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2014-07-12 15:15:51 -0700
committerScott Jackson <daneren2005@gmail.com>2014-07-12 15:15:51 -0700
commitc4116b07e7aa6d60532cdcf334b698437b6725b5 (patch)
tree2d4f2857c7357436d0ac9ddd152f9a3ff92aca31
parent1bce73fa27683972021150de93ca7a5b66652e79 (diff)
downloaddsub-c4116b07e7aa6d60532cdcf334b698437b6725b5.tar.gz
dsub-c4116b07e7aa6d60532cdcf334b698437b6725b5.tar.bz2
dsub-c4116b07e7aa6d60532cdcf334b698437b6725b5.zip
#361 Make sure to delete from store when deleting song
-rw-r--r--src/github/daneren2005/dsub/fragments/SubsonicFragment.java7
-rw-r--r--src/github/daneren2005/dsub/service/MediaStoreService.java11
-rw-r--r--src/github/daneren2005/dsub/util/CacheCleaner.java5
-rw-r--r--src/github/daneren2005/dsub/util/FileUtil.java4
-rw-r--r--src/github/daneren2005/dsub/util/Util.java7
5 files changed, 29 insertions, 5 deletions
diff --git a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java
index 54709ec0..1a5f3ea4 100644
--- a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java
+++ b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java
@@ -55,6 +55,7 @@ import github.daneren2005.dsub.domain.PodcastEpisode;
import github.daneren2005.dsub.domain.Share;
import github.daneren2005.dsub.service.DownloadFile;
import github.daneren2005.dsub.service.DownloadService;
+import github.daneren2005.dsub.service.MediaStoreService;
import github.daneren2005.dsub.service.MusicService;
import github.daneren2005.dsub.service.MusicServiceFactory;
import github.daneren2005.dsub.service.OfflineException;
@@ -1173,7 +1174,8 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
File dir = FileUtil.getArtistDirectory(context, artist);
if(dir == null) return;
- Util.recursiveDelete(dir);
+ MediaStoreService mediaStore = new MediaStoreService(context);
+ Util.recursiveDelete(dir, mediaStore);
if(Util.isOffline(context)) {
refresh();
}
@@ -1183,7 +1185,8 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
File dir = FileUtil.getAlbumDirectory(context, album);
if(dir == null) return;
- Util.recursiveDelete(dir);
+ MediaStoreService mediaStore = new MediaStoreService(context);
+ Util.recursiveDelete(dir, mediaStore);
if(Util.isOffline(context)) {
refresh();
}
diff --git a/src/github/daneren2005/dsub/service/MediaStoreService.java b/src/github/daneren2005/dsub/service/MediaStoreService.java
index d9e84515..ea500e2a 100644
--- a/src/github/daneren2005/dsub/service/MediaStoreService.java
+++ b/src/github/daneren2005/dsub/service/MediaStoreService.java
@@ -94,6 +94,17 @@ public class MediaStoreService {
}
}
+ public void deleteFromMediaStore(File file) {
+ ContentResolver contentResolver = context.getContentResolver();
+
+ int n = contentResolver.delete(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
+ MediaStore.MediaColumns.DATA + "=?",
+ new String[]{file.getAbsolutePath()});
+ if (n > 0) {
+ Log.i(TAG, "Deleting media store row for " + file);
+ }
+ }
+
private void insertAlbumArt(int albumId, DownloadFile downloadFile) {
ContentResolver contentResolver = context.getContentResolver();
diff --git a/src/github/daneren2005/dsub/util/CacheCleaner.java b/src/github/daneren2005/dsub/util/CacheCleaner.java
index dc38140f..cbc2389a 100644
--- a/src/github/daneren2005/dsub/util/CacheCleaner.java
+++ b/src/github/daneren2005/dsub/util/CacheCleaner.java
@@ -14,6 +14,8 @@ import android.os.StatFs;
import github.daneren2005.dsub.domain.Playlist;
import github.daneren2005.dsub.service.DownloadFile;
import github.daneren2005.dsub.service.DownloadService;
+import github.daneren2005.dsub.service.MediaStoreService;
+
import java.util.*;
/**
@@ -27,10 +29,12 @@ public class CacheCleaner {
private final Context context;
private final DownloadService downloadService;
+ private final MediaStoreService mediaStore;
public CacheCleaner(Context context, DownloadService downloadService) {
this.context = context;
this.downloadService = downloadService;
+ this.mediaStore = new MediaStoreService(context);
}
public void clean() {
@@ -112,6 +116,7 @@ public class CacheCleaner {
long size = file.length();
if (Util.delete(file)) {
bytesDeleted += size;
+ mediaStore.deleteFromMediaStore(file);
}
}
}
diff --git a/src/github/daneren2005/dsub/util/FileUtil.java b/src/github/daneren2005/dsub/util/FileUtil.java
index a73d9718..fa259b96 100644
--- a/src/github/daneren2005/dsub/util/FileUtil.java
+++ b/src/github/daneren2005/dsub/util/FileUtil.java
@@ -55,6 +55,7 @@ import github.daneren2005.dsub.domain.MusicDirectory;
import github.daneren2005.dsub.domain.MusicFolder;
import github.daneren2005.dsub.domain.PodcastChannel;
import github.daneren2005.dsub.domain.PodcastEpisode;
+import github.daneren2005.dsub.service.MediaStoreService;
import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.io.Input;
@@ -365,7 +366,8 @@ public class FileUtil {
}
public static boolean deleteMusicDirectory(Context context) {
File musicDirectory = FileUtil.getMusicDirectory(context);
- return Util.recursiveDelete(musicDirectory);
+ MediaStoreService mediaStore = new MediaStoreService(context);
+ return Util.recursiveDelete(musicDirectory, mediaStore);
}
public static void deleteSerializedCache(Context context) {
for(File file: context.getCacheDir().listFiles()) {
diff --git a/src/github/daneren2005/dsub/util/Util.java b/src/github/daneren2005/dsub/util/Util.java
index cea5813e..f8e4cf95 100644
--- a/src/github/daneren2005/dsub/util/Util.java
+++ b/src/github/daneren2005/dsub/util/Util.java
@@ -68,6 +68,7 @@ import github.daneren2005.dsub.provider.DSubWidgetProvider;
import github.daneren2005.dsub.receiver.MediaButtonIntentReceiver;
import github.daneren2005.dsub.service.DownloadFile;
import github.daneren2005.dsub.service.DownloadService;
+import github.daneren2005.dsub.service.MediaStoreService;
import org.apache.http.HttpEntity;
@@ -615,18 +616,20 @@ public final class Util {
}
return true;
}
- public static boolean recursiveDelete(File dir) {
+ public static boolean recursiveDelete(File dir, MediaStoreService mediaStore) {
if (dir != null && dir.exists()) {
File[] list = dir.listFiles();
if(list != null) {
for(File file: list) {
if(file.isDirectory()) {
- if(!recursiveDelete(file)) {
+ if(!recursiveDelete(file, mediaStore)) {
return false;
}
} else if(file.exists()) {
if(!file.delete()) {
return false;
+ } else {
+ mediaStore.deleteFromMediaStore(file);
}
}
}