diff options
author | Scott Jackson <daneren2005@gmail.com> | 2013-01-23 21:32:32 -0800 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2013-01-23 21:32:32 -0800 |
commit | 89637322e012f8c6277513783b5721eb79487e7d (patch) | |
tree | 53a4bfdbca00b86a682baef96f85bfc2e39a3e27 /subsonic-android/src/github | |
parent | 96d30caf5fcde2ad4ba2faa9303178c7032190cd (diff) | |
download | dsub-89637322e012f8c6277513783b5721eb79487e7d.tar.gz dsub-89637322e012f8c6277513783b5721eb79487e7d.tar.bz2 dsub-89637322e012f8c6277513783b5721eb79487e7d.zip |
Closes #75 Add ability to delete albums/artists en mass
Diffstat (limited to 'subsonic-android/src/github')
3 files changed, 41 insertions, 0 deletions
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 @@ -295,6 +295,9 @@ public class SelectAlbumActivity extends SubsonicTabActivity { 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(); getDownloadService().download(songs, false, true, true, false); @@ -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<Indexes> task = new TabActivityBackgroundTask<Indexes>(this) { @@ -233,6 +243,9 @@ public class SelectArtistActivity extends SubsonicTabActivity implements Adapter 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); |