diff options
author | Scott Jackson <daneren2005@gmail.com> | 2015-12-29 17:53:04 -0800 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2015-12-29 17:53:04 -0800 |
commit | efdb68d9ca8623f5e2c744ae63e626891861c52b (patch) | |
tree | 36440ef25965364e094ec4f322edfd9fb5a811a1 /app/src/main | |
parent | 675ec2eaaa3f852d16f46d32309bc4d989e4e47b (diff) | |
download | dsub-efdb68d9ca8623f5e2c744ae63e626891861c52b.tar.gz dsub-efdb68d9ca8623f5e2c744ae63e626891861c52b.tar.bz2 dsub-efdb68d9ca8623f5e2c744ae63e626891861c52b.zip |
#575: Add batch star/unstar
Diffstat (limited to 'app/src/main')
8 files changed, 97 insertions, 91 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/adapter/EntryGridAdapter.java b/app/src/main/java/github/daneren2005/dsub/adapter/EntryGridAdapter.java index 38931482..5693ba56 100644 --- a/app/src/main/java/github/daneren2005/dsub/adapter/EntryGridAdapter.java +++ b/app/src/main/java/github/daneren2005/dsub/adapter/EntryGridAdapter.java @@ -46,7 +46,6 @@ public class EntryGridAdapter extends SectionAdapter<Entry> { private boolean largeAlbums; private boolean showArtist = false; private boolean removeFromPlaylist = false; - private boolean removeStarred = true; private View header; public EntryGridAdapter(Context context, List<Entry> entries, ImageLoader imageLoader, boolean largeCell) { @@ -136,9 +135,6 @@ public class EntryGridAdapter extends SectionAdapter<Entry> { public void setRemoveFromPlaylist(boolean removeFromPlaylist) { this.removeFromPlaylist = removeFromPlaylist; } - public void setRemoveStarred(boolean removeStarred) { - this.removeStarred = removeStarred; - } @Override public void onCreateActionModeMenu(Menu menu, MenuInflater menuInflater) { @@ -151,8 +147,10 @@ public class EntryGridAdapter extends SectionAdapter<Entry> { if(!removeFromPlaylist) { menu.removeItem(R.id.menu_remove_playlist); } - if(removeStarred) { - menu.removeItem(R.id.menu_unstar); + + if(!selected.isEmpty()) { + boolean isStarred = selected.get(0).isStarred(); + menu.findItem(R.id.menu_star).setTitle(isStarred ? R.string.common_unstar : R.string.common_star); } } } diff --git a/app/src/main/java/github/daneren2005/dsub/adapter/PodcastChannelAdapter.java b/app/src/main/java/github/daneren2005/dsub/adapter/PodcastChannelAdapter.java index a95abeda..aeb98a6b 100644 --- a/app/src/main/java/github/daneren2005/dsub/adapter/PodcastChannelAdapter.java +++ b/app/src/main/java/github/daneren2005/dsub/adapter/PodcastChannelAdapter.java @@ -126,7 +126,7 @@ public class PodcastChannelAdapter extends SectionAdapter<Serializable> implemen } menu.removeItem(R.id.menu_remove_playlist); - menu.removeItem(R.id.menu_unstar); + menu.removeItem(R.id.menu_star); } @Override diff --git a/app/src/main/java/github/daneren2005/dsub/adapter/SectionAdapter.java b/app/src/main/java/github/daneren2005/dsub/adapter/SectionAdapter.java index d5f9a6ea..fbed4d7a 100644 --- a/app/src/main/java/github/daneren2005/dsub/adapter/SectionAdapter.java +++ b/app/src/main/java/github/daneren2005/dsub/adapter/SectionAdapter.java @@ -414,14 +414,15 @@ public abstract class SectionAdapter<T> extends RecyclerView.Adapter<UpdateViewH @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { currentActionMode = mode; - onCreateActionModeMenu(menu, mode.getMenuInflater()); - MenuUtil.hideMenuItems(context, menu, updateView); T item = holder.getItem(); selected.add(item); selectedViews.add(updateView); setChecked(updateView, true); + onCreateActionModeMenu(menu, mode.getMenuInflater()); + MenuUtil.hideMenuItems(context, menu, updateView); + mode.setTitle(context.getResources().getString(R.string.select_album_n_selected, selected.size())); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_COLOR_ACTION_BAR, true)) { TypedValue typedValue = new TypedValue(); diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java index d2282117..76fde7e5 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -305,9 +305,6 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Section case R.id.menu_show_all: setShowAll(); return true; - case R.id.menu_unstar: - unstarSelected(); - return true; case R.id.menu_top_tracks: showTopTracks(); return true; @@ -682,7 +679,6 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Section if(albumListType == null || "starred".equals(albumListType)) { entryGridAdapter = new EntryGridAdapter(context, entries, getImageLoader(), largeAlbums); entryGridAdapter.setRemoveFromPlaylist(playlistId != null); - entryGridAdapter.setRemoveStarred(albumListType == null); } else { if("alphabeticalByName".equals(albumListType)) { entryGridAdapter = new AlphabeticalAlbumAdapter(context, entries, getImageLoader(), largeAlbums); @@ -953,70 +949,28 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Section }.execute(); } - public void unstarSelected() { - List<Entry> selected = getSelectedEntries(); - if(selected.size() == 0) { - selected = entries; - } - if(selected.size() == 0) { - return; - } - final List<Entry> unstar = new ArrayList<Entry>(); - unstar.addAll(selected); + @Override + protected void toggleSelectedStarred() { + UpdateHelper.OnStarChange onStarChange = null; + if(albumListType != null && "starred".equals(albumListType)) { + onStarChange = new UpdateHelper.OnStarChange() { + @Override + public void starChange(boolean starred) { - new LoadingTask<Void>(context, true) { - @Override - protected Void doInBackground() throws Throwable { - MusicService musicService = MusicServiceFactory.getMusicService(context); - List<Entry> entries = new ArrayList<Entry>(); - List<Entry> artists = new ArrayList<Entry>(); - List<Entry> albums = new ArrayList<Entry>(); - for(Entry entry: unstar) { - if(entry.isDirectory() && Util.isTagBrowsing(context)) { - if(entry.isAlbum()) { - albums.add(entry); - } else { - artists.add(entry); - } - } else { - entries.add(entry); - } } - musicService.setStarred(entries, artists, albums, false, this, context); - for(Entry entry: unstar) { - new UpdateHelper.EntryInstanceUpdater(entry) { - @Override - public void update(Entry found) { - found.setStarred(false); + @Override + public void starCommited(boolean starred) { + if(!starred) { + for (Entry entry : entries) { + entryGridAdapter.removeItem(entry); } - }.execute(); - } - - return null; - } - - @Override - protected void done(Void result) { - Util.toast(context, context.getResources().getString(R.string.starring_content_unstarred, Integer.toString(unstar.size()))); - - for(Entry entry: unstar) { - entryGridAdapter.removeItem(entry); - } - } - - @Override - protected void error(Throwable error) { - String msg; - if (error instanceof OfflineException || error instanceof ServerTooOldException) { - msg = getErrorMessage(error); - } else { - msg = context.getResources().getString(R.string.starring_content_error, Integer.toString(unstar.size())) + " " + getErrorMessage(error); + } } + }; + } - Util.toast(context, msg, false); - } - }.execute(); + UpdateHelper.toggleStarred(context, getSelectedEntries(), onStarChange); } private void checkLicenseAndTrialPeriod(LoadingTask onValid) { @@ -1349,6 +1303,11 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Section starButton.setImageResource(DrawableTint.getDrawableRes(context, R.attr.star_outline)); } } + + @Override + public void starCommited(boolean starred) { + + } }); } }); diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SubsonicFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SubsonicFragment.java index c503ec6c..33d9bbff 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/SubsonicFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/SubsonicFragment.java @@ -221,6 +221,9 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR addToPlaylist(songs); clearSelected(); return true; + case R.id.menu_star:case R.id.menu_unstar: + toggleSelectedStarred(); + return true; } return false; @@ -1898,6 +1901,10 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR } } + protected void toggleSelectedStarred() { + UpdateHelper.toggleStarred(context, getSelectedEntries()); + } + public abstract class RecursiveLoader extends LoadingTask<Boolean> { protected MusicService musicService; protected static final int MAX_SONGS = 500; diff --git a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java index 0d23d51a..ba473dfc 100644 --- a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java +++ b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java @@ -2571,6 +2571,11 @@ public class DownloadService extends Service { onMetadataUpdate(METADATA_UPDATED_STAR); } } + + @Override + public void starCommited(boolean starred) { + + } }); } public void toggleRating(int rating) { diff --git a/app/src/main/java/github/daneren2005/dsub/util/UpdateHelper.java b/app/src/main/java/github/daneren2005/dsub/util/UpdateHelper.java index c7e0a04b..725f0827 100644 --- a/app/src/main/java/github/daneren2005/dsub/util/UpdateHelper.java +++ b/app/src/main/java/github/daneren2005/dsub/util/UpdateHelper.java @@ -27,6 +27,7 @@ import android.util.Log; import android.view.View; import android.widget.RatingBar; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -51,9 +52,24 @@ public final class UpdateHelper { } public static void toggleStarred(final Context context, final Entry entry, final OnStarChange onStarChange) { - final boolean starred = !entry.isStarred(); - entry.setStarred(starred); + toggleStarred(context, Arrays.asList(entry), onStarChange); + } + + public static void toggleStarred(Context context, List<Entry> entries) { + toggleStarred(context, entries, null); + } + public static void toggleStarred(final Context context, final List<Entry> entries, final OnStarChange onStarChange) { + if(entries.isEmpty()) { + return; + } + + final Entry firstEntry = entries.get(0); + final boolean starred = !firstEntry.isStarred(); + for(Entry entry: entries) { + entry.setStarred(starred); + } if(onStarChange != null) { + onStarChange.entries = entries; onStarChange.starChange(starred); } @@ -61,22 +77,30 @@ public final class UpdateHelper { @Override protected Void doInBackground() throws Throwable { MusicService musicService = MusicServiceFactory.getMusicService(context); - if(entry.isDirectory() && Util.isTagBrowsing(context) && !Util.isOffline(context)) { - if(entry.isAlbum()) { - musicService.setStarred(null, null, Arrays.asList(entry), starred, null, context); + List<Entry> songs = new ArrayList<Entry>(); + List<Entry> artists = new ArrayList<Entry>(); + List<Entry> albums = new ArrayList<Entry>(); + for(Entry entry: entries) { + if(entry.isDirectory() && Util.isTagBrowsing(context)) { + if(entry.isAlbum()) { + albums.add(entry); + } else { + artists.add(entry); + } } else { - musicService.setStarred(null, Arrays.asList(entry), null, starred, null, context); + songs.add(entry); } - } else { - musicService.setStarred(Arrays.asList(entry), null, null, starred, null, context); } - - new EntryInstanceUpdater(entry) { - @Override - public void update(Entry found) { - found.setStarred(starred); - } - }.execute(); + musicService.setStarred(songs, artists, albums, starred, this, context); + + for(Entry entry: entries) { + new UpdateHelper.EntryInstanceUpdater(entry) { + @Override + public void update(Entry found) { + found.setStarred(starred); + } + }.execute(); + } return null; } @@ -84,13 +108,21 @@ public final class UpdateHelper { @Override protected void done(Void result) { // UpdateView - Util.toast(context, context.getResources().getString(starred ? R.string.starring_content_starred : R.string.starring_content_unstarred, entry.getTitle())); + int starMsgId = starred ? R.string.starring_content_starred : R.string.starring_content_unstarred; + String starMsgBody = (entries.size() > 1) ? Integer.toString(entries.size()) : firstEntry.getTitle(); + Util.toast(context, context.getResources().getString(starMsgId, starMsgBody)); + + if(onStarChange != null) { + onStarChange.starCommited(starred); + } } @Override protected void error(Throwable error) { Log.w(TAG, "Failed to star", error); - entry.setStarred(!starred); + for(Entry entry: entries) { + entry.setStarred(!starred); + } if(onStarChange != null) { onStarChange.starChange(!starred); } @@ -99,7 +131,8 @@ public final class UpdateHelper { if (error instanceof OfflineException || error instanceof ServerTooOldException) { msg = getErrorMessage(error); } else { - msg = context.getResources().getString(R.string.starring_content_error, entry.getTitle()) + " " + getErrorMessage(error); + String errorBody = (entries.size() > 1) ? Integer.toString(entries.size()) : firstEntry.getTitle(); + msg = context.getResources().getString(R.string.starring_content_error, errorBody) + " " + getErrorMessage(error); } Util.toast(context, msg, false); @@ -255,7 +288,10 @@ public final class UpdateHelper { } public static abstract class OnStarChange { + protected List<Entry> entries; + public abstract void starChange(boolean starred); + public abstract void starCommited(boolean starred); } public static abstract class OnRatingChange { public abstract void ratingChange(int rating); diff --git a/app/src/main/res/menu/multiselect_media.xml b/app/src/main/res/menu/multiselect_media.xml index 6adb4567..85bb5217 100644 --- a/app/src/main/res/menu/multiselect_media.xml +++ b/app/src/main/res/menu/multiselect_media.xml @@ -34,8 +34,8 @@ android:title="@string/menu.remove_playlist"/> <item - android:id="@+id/menu_unstar" - android:title="@string/common.unstar"/> + android:id="@+id/menu_star" + android:title="@string/common.star"/> <group android:id="@+id/hide_play_next"> <item |