From 569281e423b93cf67db2141b49f04103036d4db5 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sat, 18 Jul 2015 18:19:13 -0700 Subject: Update action mode to support albums, color when selected --- .../daneren2005/dsub/adapter/EntryGridAdapter.java | 3 +- .../daneren2005/dsub/adapter/SectionAdapter.java | 53 ++++++++++++++-------- .../dsub/fragments/SelectDirectoryFragment.java | 39 ++++++++-------- .../dsub/fragments/SubsonicFragment.java | 50 ++++++++++++++------ .../github/daneren2005/dsub/view/AlbumView.java | 2 + .../github/daneren2005/dsub/view/SongView.java | 10 +--- .../github/daneren2005/dsub/view/UpdateView.java | 11 ++++- app/src/main/res/layout/song_list_item.xml | 8 ---- 8 files changed, 105 insertions(+), 71 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 0c699b89..a0008a73 100644 --- a/app/src/main/java/github/daneren2005/dsub/adapter/EntryGridAdapter.java +++ b/app/src/main/java/github/daneren2005/dsub/adapter/EntryGridAdapter.java @@ -59,6 +59,7 @@ public class EntryGridAdapter extends SectionAdapter { showArtist = true; } } + checkable = true; } @Override @@ -82,7 +83,7 @@ public class EntryGridAdapter extends SectionAdapter { albumView.setObject(entry, imageLoader); } else if(viewType == VIEW_TYPE_SONG) { SongView songView = (SongView) view; - songView.setObject(entry, checkable && !entry.isVideo() && currentActionMode != null); + songView.setObject(entry, checkable && !entry.isVideo()); } } 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 93c55985..9d577409 100644 --- a/app/src/main/java/github/daneren2005/dsub/adapter/SectionAdapter.java +++ b/app/src/main/java/github/daneren2005/dsub/adapter/SectionAdapter.java @@ -32,6 +32,7 @@ import android.view.ViewGroup; import android.view.Window; import android.view.WindowManager; +import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -52,8 +53,9 @@ public abstract class SectionAdapter extends RecyclerView.Adapter onItemClickedListener; protected List selected = new ArrayList<>(); + protected List selectedViews = new ArrayList<>(); protected ActionMode currentActionMode; - protected boolean checkable = true; + protected boolean checkable = false; protected SectionAdapter() {} public SectionAdapter(Context context, List section) { @@ -101,19 +103,23 @@ public abstract class SectionAdapter extends RecyclerView.Adapter extends RecyclerView.Adapter extends RecyclerView.Adapter extends RecyclerView.Adapter= Build.VERSION_CODES.LOLLIPOP) { TypedValue typedValue = new TypedValue(); @@ -406,7 +418,10 @@ public abstract class SectionAdapter extends RecyclerView.Adapter updateView: selectedViews) { + updateView.setChecked(false); + } + selectedViews.clear(); Window window = ((SubsonicFragmentActivity) context).getWindow(); window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); 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 370d1e51..2ab8316c 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -301,7 +301,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Section entryGridAdapter.clearSelected(); return true; case R.id.menu_add_playlist: - List songs = getSelectedSongs(); + List songs = getSelectedEntries(); if(songs.isEmpty()) { songs = entries; } @@ -823,7 +823,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Section playNow(shuffle, append, false); } private void playNow(final boolean shuffle, final boolean append, final boolean playNext) { - List songs = getSelectedSongs(); + List songs = getSelectedEntries(); if(!songs.isEmpty()) { download(songs, append, false, !append, playNext, shuffle); entryGridAdapter.clearSelected(); @@ -844,7 +844,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Section } } - private List getSelectedSongs() { + private List getSelectedEntries() { return entryGridAdapter.getSelected(); } @@ -859,7 +859,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Section return indexes; } - private void download(final List songs, final boolean append, final boolean save, final boolean autoplay, final boolean playNext, final boolean shuffle) { + private void download(final List entries, final boolean append, final boolean save, final boolean autoplay, final boolean playNext, final boolean shuffle) { if (getDownloadService() == null) { return; } @@ -869,28 +869,30 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Section // Conditions for using play now button if(!append && !save && autoplay && !playNext && !shuffle) { // Call playNow which goes through and tries to use bookmark information - playNow(songs, playlistName, playlistId); + playNow(entries, playlistName, playlistId); return; } - LoadingTask onValid = new LoadingTask(context) { + RecursiveLoader onValid = new RecursiveLoader(context) { @Override - protected Void doInBackground() throws Throwable { + protected Boolean doInBackground() throws Throwable { if (!append) { getDownloadService().clear(); } + getSongsRecursively(entries, songs); - getDownloadService().download(songs, save, autoplay, playNext, shuffle); + DownloadService downloadService = getDownloadService(); + downloadService.download(songs, save, autoplay, playNext, shuffle); if (playlistName != null) { - getDownloadService().setSuggestedPlaylistName(playlistName, playlistId); + downloadService.setSuggestedPlaylistName(playlistName, playlistId); } else { - getDownloadService().setSuggestedPlaylistName(null, null); + downloadService.setSuggestedPlaylistName(null, null); } return null; } @Override - protected void done(Void result) { + protected void done(Boolean result) { if (autoplay) { context.openNowPlaying(); } else if (save) { @@ -906,7 +908,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Section checkLicenseAndTrialPeriod(onValid); } private void downloadBackground(final boolean save) { - List songs = getSelectedSongs(); + List songs = getSelectedEntries(); if(playlistId != null) { songs = entries; } @@ -918,21 +920,22 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Section downloadBackground(save, songs); } } - private void downloadBackground(final boolean save, final List songs) { + private void downloadBackground(final boolean save, final List entries) { if (getDownloadService() == null) { return; } warnIfStorageUnavailable(); - LoadingTask onValid = new LoadingTask(context) { + RecursiveLoader onValid = new RecursiveLoader(context) { @Override - protected Void doInBackground() throws Throwable { + protected Boolean doInBackground() throws Throwable { + getSongsRecursively(entries, songs); getDownloadService().downloadBackground(songs, save); return null; } @Override - protected void done(Void result) { + protected void done(Boolean result) { Util.toast(context, context.getResources().getQuantityString(R.plurals.select_album_n_songs_downloading, songs.size(), songs.size())); } }; @@ -941,7 +944,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Section } private void delete() { - List songs = getSelectedSongs(); + List songs = getSelectedEntries(); if(songs.isEmpty()) { for(Entry entry: entries) { if(entry.isDirectory()) { @@ -1068,7 +1071,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Section } public void unstarSelected() { - List selected = getSelectedSongs(); + List selected = getSelectedEntries(); if(selected.size() == 0) { selected = entries; } 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 c5c5a132..438649c3 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/SubsonicFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/SubsonicFragment.java @@ -1616,22 +1616,33 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR protected void playNow(List entries) { playNow(entries, null, null); } - protected void playNow(List entries, String playlistName, String playlistId) { - Entry bookmark = null; - for(Entry entry: entries) { - if(entry.getBookmark() != null) { - bookmark = entry; - break; + protected void playNow(final List entries, final String playlistName, final String playlistId) { + new RecursiveLoader(context) { + @Override + protected Boolean doInBackground() throws Throwable { + getSongsRecursively(entries, songs); + return null; } - } - // If no bookmark found, just play from start - if(bookmark == null) { - playNow(entries, 0, playlistName, playlistId); - } else { - // If bookmark found, then give user choice to start from there or to start over - playBookmark(entries, bookmark, playlistName, playlistId); - } + @Override + protected void done(Boolean result) { + Entry bookmark = null; + for(Entry entry: songs) { + if(entry.getBookmark() != null) { + bookmark = entry; + break; + } + } + + // If no bookmark found, just play from start + if(bookmark == null) { + playNow(songs, 0, playlistName, playlistId); + } else { + // If bookmark found, then give user choice to start from there or to start over + playBookmark(songs, bookmark, playlistName, playlistId); + } + } + }.execute(); } protected void playNow(List entries, int position) { playNow(entries, position, null, null); @@ -1834,12 +1845,21 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR protected MusicService musicService; protected static final int MAX_SONGS = 500; protected boolean playNowOverride = false; - protected List songs; + protected List songs = new ArrayList<>(); public RecursiveLoader(Activity context) { super(context); + musicService = MusicServiceFactory.getMusicService(context); } + protected void getSongsRecursively(List entry) throws Exception { + getSongsRecursively(entry, songs); + } + protected void getSongsRecursively(List entry, List songs) throws Exception { + MusicDirectory dir = new MusicDirectory(); + dir.addChildren(entry); + getSongsRecursively(dir, songs); + } protected void getSongsRecursively(MusicDirectory parent, List songs) throws Exception { if (songs.size() > MAX_SONGS) { return; diff --git a/app/src/main/java/github/daneren2005/dsub/view/AlbumView.java b/app/src/main/java/github/daneren2005/dsub/view/AlbumView.java index 3104864a..e521babf 100644 --- a/app/src/main/java/github/daneren2005/dsub/view/AlbumView.java +++ b/app/src/main/java/github/daneren2005/dsub/view/AlbumView.java @@ -60,6 +60,8 @@ public class AlbumView extends UpdateView2 { starButton = (ImageButton) findViewById(R.id.album_star); starButton.setFocusable(false); moreButton = (ImageView) findViewById(R.id.more_button); + + checkable = true; } public void setShowArtist(boolean showArtist) { diff --git a/app/src/main/java/github/daneren2005/dsub/view/SongView.java b/app/src/main/java/github/daneren2005/dsub/view/SongView.java index dcde0f92..b9c5fa50 100644 --- a/app/src/main/java/github/daneren2005/dsub/view/SongView.java +++ b/app/src/main/java/github/daneren2005/dsub/view/SongView.java @@ -42,7 +42,6 @@ import java.io.File; public class SongView extends UpdateView2 { private static final String TAG = SongView.class.getSimpleName(); - private CheckedTextView checkedTextView; private TextView titleTextView; private TextView artistTextView; private TextView durationTextView; @@ -71,7 +70,6 @@ public class SongView extends UpdateView2 { super(context); LayoutInflater.from(context).inflate(R.layout.song_list_item, this, true); - checkedTextView = (CheckedTextView) findViewById(R.id.song_check); titleTextView = (TextView) findViewById(R.id.song_title); artistTextView = (TextView) findViewById(R.id.song_artist); durationTextView = (TextView) findViewById(R.id.song_duration); @@ -138,7 +136,6 @@ public class SongView extends UpdateView2 { titleTextView.setText(title); artistTextView.setText(artist); - checkedTextView.setVisibility(checkable ? View.VISIBLE : View.GONE); this.setBackgroundColor(0x00000000); ratingBar.setVisibility(View.GONE); @@ -191,7 +188,7 @@ public class SongView extends UpdateView2 { @Override protected void update() { if(loaded) { - setObjectImpl(item, checkedTextView.getVisibility() == View.VISIBLE); + setObjectImpl(item, item2); } if (downloadService == null || downloadFile == null) { return; @@ -297,11 +294,6 @@ public class SongView extends UpdateView2 { } } - @Override - public void setChecked(boolean checked) { - checkedTextView.setChecked(checked); - } - public MusicDirectory.Entry getEntry() { return item; } diff --git a/app/src/main/java/github/daneren2005/dsub/view/UpdateView.java b/app/src/main/java/github/daneren2005/dsub/view/UpdateView.java index e639eaa8..fd74c872 100644 --- a/app/src/main/java/github/daneren2005/dsub/view/UpdateView.java +++ b/app/src/main/java/github/daneren2005/dsub/view/UpdateView.java @@ -20,6 +20,7 @@ package github.daneren2005.dsub.view; import android.content.Context; import android.content.res.TypedArray; +import android.graphics.drawable.Drawable; import android.os.Handler; import android.os.Looper; import android.support.v7.widget.RecyclerView; @@ -64,6 +65,7 @@ public abstract class UpdateView extends LinearLayout { protected int isRated = 0; protected int rating = 0; protected SilentBackgroundTask imageTask = null; + protected Drawable startBackgroundDrawable; protected final boolean autoUpdate; protected boolean checkable; @@ -270,7 +272,14 @@ public abstract class UpdateView extends LinearLayout { return checkable; } public void setChecked(boolean checked) { - + View child = getChildAt(0); + if (checked && startBackgroundDrawable == null) { + startBackgroundDrawable = child.getBackground(); + child.setBackgroundColor(DrawableTint.getColorRes(context, R.attr.colorPrimary)); + } else if (!checked && startBackgroundDrawable != null) { + child.setBackgroundDrawable(startBackgroundDrawable); + startBackgroundDrawable = null; + } } public void onClick() { diff --git a/app/src/main/res/layout/song_list_item.xml b/app/src/main/res/layout/song_list_item.xml index c64c1a45..429dc142 100644 --- a/app/src/main/res/layout/song_list_item.xml +++ b/app/src/main/res/layout/song_list_item.xml @@ -6,14 +6,6 @@ android:layout_height="?android:attr/listPreferredItemHeight" android:background="?attr/selectableItemBackground"> - -