From 89637322e012f8c6277513783b5721eb79487e7d Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Wed, 23 Jan 2013 21:32:32 -0800 Subject: Closes #75 Add ability to delete albums/artists en mass --- subsonic-android/res/menu/select_album_context.xml | 4 ++++ .../res/menu/select_album_context_offline.xml | 4 ++++ subsonic-android/res/menu/select_artist_context.xml | 4 ++++ .../res/menu/select_artist_context_offline.xml | 6 +++++- .../daneren2005/dsub/activity/SelectAlbumActivity.java | 11 +++++++++++ .../daneren2005/dsub/activity/SelectArtistActivity.java | 13 +++++++++++++ .../src/github/daneren2005/dsub/util/Util.java | 17 +++++++++++++++++ 7 files changed, 58 insertions(+), 1 deletion(-) (limited to 'subsonic-android') diff --git a/subsonic-android/res/menu/select_album_context.xml b/subsonic-android/res/menu/select_album_context.xml index ddfd134e..00fe7993 100644 --- a/subsonic-android/res/menu/select_album_context.xml +++ b/subsonic-android/res/menu/select_album_context.xml @@ -25,6 +25,10 @@ android:id="@+id/album_menu_pin" android:title="@string/common.pin" /> + + + + \ No newline at end of file diff --git a/subsonic-android/res/menu/select_artist_context.xml b/subsonic-android/res/menu/select_artist_context.xml index 428e23a1..23d64c4e 100644 --- a/subsonic-android/res/menu/select_artist_context.xml +++ b/subsonic-android/res/menu/select_artist_context.xml @@ -25,4 +25,8 @@ android:id="@+id/artist_menu_pin" android:title="@string/common.pin" /> + + diff --git a/subsonic-android/res/menu/select_artist_context_offline.xml b/subsonic-android/res/menu/select_artist_context_offline.xml index 2a6ed744..c80db020 100644 --- a/subsonic-android/res/menu/select_artist_context_offline.xml +++ b/subsonic-android/res/menu/select_artist_context_offline.xml @@ -14,5 +14,9 @@ + /> + + diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java index f1072e39..392401bf 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java @@ -294,6 +294,9 @@ public class SelectAlbumActivity extends SubsonicTabActivity { break; case R.id.album_menu_star: toggleStarred(entry); + break; + case R.id.album_menu_delete: + deleteRecursively(entry); break; case R.id.song_menu_play_now: getDownloadService().clear(); @@ -593,6 +596,14 @@ public class SelectAlbumActivity extends SubsonicTabActivity { Util.toast(this, R.string.download_no_streaming_player); } } + + public void deleteRecursively(MusicDirectory.Entry album) { + File dir = FileUtil.getAlbumDirectory(this, album); + Util.recursiveDelete(dir); + if(Util.isOffline(this)) { + refresh(); + } + } private void checkLicenseAndTrialPeriod(Runnable onValid) { if (licenseValid) { diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SelectArtistActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SelectArtistActivity.java index 225b70ee..b439df15 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SelectArtistActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SelectArtistActivity.java @@ -39,8 +39,10 @@ import github.daneren2005.dsub.service.MusicServiceFactory; import github.daneren2005.dsub.view.ArtistAdapter; import github.daneren2005.dsub.util.BackgroundTask; import github.daneren2005.dsub.util.Constants; +import github.daneren2005.dsub.util.FileUtil; import github.daneren2005.dsub.util.TabActivityBackgroundTask; import github.daneren2005.dsub.util.Util; +import java.io.File; import java.util.ArrayList; import java.util.List; @@ -126,6 +128,14 @@ public class SelectArtistActivity extends SubsonicTabActivity implements Adapter private void selectFolder() { folderButton.showContextMenu(); } + + public void deleteRecursively(Artist artist) { + File dir = FileUtil.getArtistDirectory(this, artist); + Util.recursiveDelete(dir); + if(Util.isOffline(this)) { + refresh(); + } + } private void load() { BackgroundTask task = new TabActivityBackgroundTask(this) { @@ -232,6 +242,9 @@ public class SelectArtistActivity extends SubsonicTabActivity implements Adapter break; case R.id.artist_menu_pin: downloadRecursively(artist.getId(), true, true, false, false, true); + break; + case R.id.artist_menu_delete: + deleteRecursively(artist); break; default: return super.onContextItemSelected(menuItem); diff --git a/subsonic-android/src/github/daneren2005/dsub/util/Util.java b/subsonic-android/src/github/daneren2005/dsub/util/Util.java index 1733bf62..0b7118d0 100644 --- a/subsonic-android/src/github/daneren2005/dsub/util/Util.java +++ b/subsonic-android/src/github/daneren2005/dsub/util/Util.java @@ -369,6 +369,23 @@ public final class Util { } return true; } + public static boolean recursiveDelete(File dir) { + if (dir != null && dir.exists()) { + for(File file: dir.listFiles()) { + if(file.isDirectory()) { + if(!recursiveDelete(file)) { + return false; + } + } else if(file.exists()) { + if(!file.delete()) { + return false; + } + } + } + return dir.delete(); + } + return false; + } public static void toast(Context context, int messageId) { toast(context, messageId, true); -- cgit v1.2.3