aboutsummaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2015-07-18 18:19:13 -0700
committerScott Jackson <daneren2005@gmail.com>2015-07-18 18:19:13 -0700
commit569281e423b93cf67db2141b49f04103036d4db5 (patch)
treeaf0def4c718a3ae42841b45bbae0c24c936befed /app/src
parent32ab835977f1544dd299508f66861881528004be (diff)
downloaddsub-569281e423b93cf67db2141b49f04103036d4db5.tar.gz
dsub-569281e423b93cf67db2141b49f04103036d4db5.tar.bz2
dsub-569281e423b93cf67db2141b49f04103036d4db5.zip
Update action mode to support albums, color when selected
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/java/github/daneren2005/dsub/adapter/EntryGridAdapter.java3
-rw-r--r--app/src/main/java/github/daneren2005/dsub/adapter/SectionAdapter.java53
-rw-r--r--app/src/main/java/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java39
-rw-r--r--app/src/main/java/github/daneren2005/dsub/fragments/SubsonicFragment.java50
-rw-r--r--app/src/main/java/github/daneren2005/dsub/view/AlbumView.java2
-rw-r--r--app/src/main/java/github/daneren2005/dsub/view/SongView.java10
-rw-r--r--app/src/main/java/github/daneren2005/dsub/view/UpdateView.java11
-rw-r--r--app/src/main/res/layout/song_list_item.xml8
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<Entry> {
showArtist = true;
}
}
+ checkable = true;
}
@Override
@@ -82,7 +83,7 @@ public class EntryGridAdapter extends SectionAdapter<Entry> {
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<T> extends RecyclerView.Adapter<UpdateViewH
protected boolean singleSectionHeader;
protected OnItemClickedListener<T> onItemClickedListener;
protected List<T> selected = new ArrayList<>();
+ protected List<UpdateView> selectedViews = new ArrayList<>();
protected ActionMode currentActionMode;
- protected boolean checkable = true;
+ protected boolean checkable = false;
protected SectionAdapter() {}
public SectionAdapter(Context context, List<T> section) {
@@ -101,19 +103,23 @@ public abstract class SectionAdapter<T> extends RecyclerView.Adapter<UpdateViewH
public void onClick(View v) {
T item = holder.getItem();
updateView.onClick();
- if (updateView.isCheckable() && currentActionMode != null) {
- if (selected.contains(item)) {
- selected.remove(item);
- setChecked(updateView, false);
- } else {
- selected.add(item);
- setChecked(updateView, true);
- }
-
- if(selected.isEmpty()) {
- currentActionMode.finish();
- } else {
- currentActionMode.setTitle(context.getResources().getString(R.string.select_album_n_selected, selected.size()));
+ if (currentActionMode != null) {
+ if(updateView.isCheckable()) {
+ if (selected.contains(item)) {
+ selected.remove(item);
+ selectedViews.remove(updateView);
+ setChecked(updateView, false);
+ } else {
+ selected.add(item);
+ selectedViews.add(updateView);
+ setChecked(updateView, true);
+ }
+
+ if (selected.isEmpty()) {
+ currentActionMode.finish();
+ } else {
+ currentActionMode.setTitle(context.getResources().getString(R.string.select_album_n_selected, selected.size()));
+ }
}
} else if (onItemClickedListener != null) {
onItemClickedListener.onItemClicked(item);
@@ -149,7 +155,11 @@ public abstract class SectionAdapter<T> extends RecyclerView.Adapter<UpdateViewH
updateView.getChildAt(0).setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
- startActionMode(holder);
+ if(currentActionMode == null) {
+ startActionMode(holder);
+ } else {
+ updateView.getChildAt(0).performClick();
+ }
return true;
}
});
@@ -321,10 +331,12 @@ public abstract class SectionAdapter<T> extends RecyclerView.Adapter<UpdateViewH
if(singleSectionHeader) {
index++;
}
-
- this.notifyItemChanged(index);
}
selected.clear();
+
+ for(UpdateView updateView: selectedViews) {
+ updateView.setChecked(false);
+ }
}
public void removeItem(T item) {
@@ -369,9 +381,9 @@ public abstract class SectionAdapter<T> extends RecyclerView.Adapter<UpdateViewH
T item = holder.getItem();
selected.add(item);
+ selectedViews.add(updateView);
setChecked(updateView, true);
- notifyDataSetChanged();
mode.setTitle(context.getResources().getString(R.string.select_album_n_selected, selected.size()));
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
TypedValue typedValue = new TypedValue();
@@ -406,7 +418,10 @@ public abstract class SectionAdapter<T> extends RecyclerView.Adapter<UpdateViewH
public void onDestroyActionMode(ActionMode mode) {
currentActionMode = null;
selected.clear();
- notifyDataSetChanged();
+ for(UpdateView<T> 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<Entry> songs = getSelectedSongs();
+ List<Entry> 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<Entry> songs = getSelectedSongs();
+ List<Entry> 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<Entry> getSelectedSongs() {
+ private List<Entry> getSelectedEntries() {
return entryGridAdapter.getSelected();
}
@@ -859,7 +859,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Section
return indexes;
}
- private void download(final List<Entry> songs, final boolean append, final boolean save, final boolean autoplay, final boolean playNext, final boolean shuffle) {
+ private void download(final List<Entry> 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<Void> onValid = new LoadingTask<Void>(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<Entry> songs = getSelectedSongs();
+ List<Entry> 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<Entry> songs) {
+ private void downloadBackground(final boolean save, final List<Entry> entries) {
if (getDownloadService() == null) {
return;
}
warnIfStorageUnavailable();
- LoadingTask<Void> onValid = new LoadingTask<Void>(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<Entry> songs = getSelectedSongs();
+ List<Entry> 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<Entry> selected = getSelectedSongs();
+ List<Entry> 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<Entry> entries) {
playNow(entries, null, null);
}
- protected void playNow(List<Entry> entries, String playlistName, String playlistId) {
- Entry bookmark = null;
- for(Entry entry: entries) {
- if(entry.getBookmark() != null) {
- bookmark = entry;
- break;
+ protected void playNow(final List<Entry> 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<Entry> 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<Entry> songs;
+ protected List<Entry> songs = new ArrayList<>();
public RecursiveLoader(Activity context) {
super(context);
+ musicService = MusicServiceFactory.getMusicService(context);
}
+ protected void getSongsRecursively(List<Entry> entry) throws Exception {
+ getSongsRecursively(entry, songs);
+ }
+ protected void getSongsRecursively(List<Entry> entry, List<Entry> songs) throws Exception {
+ MusicDirectory dir = new MusicDirectory();
+ dir.addChildren(entry);
+ getSongsRecursively(dir, songs);
+ }
protected void getSongsRecursively(MusicDirectory parent, List<Entry> 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<MusicDirectory.Entry, ImageLoader> {
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<MusicDirectory.Entry, Boolean> {
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<MusicDirectory.Entry, Boolean> {
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<MusicDirectory.Entry, Boolean> {
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<MusicDirectory.Entry, Boolean> {
@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<MusicDirectory.Entry, Boolean> {
}
}
- @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<T> extends LinearLayout {
protected int isRated = 0;
protected int rating = 0;
protected SilentBackgroundTask<Void> imageTask = null;
+ protected Drawable startBackgroundDrawable;
protected final boolean autoUpdate;
protected boolean checkable;
@@ -270,7 +272,14 @@ public abstract class UpdateView<T> 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">
- <CheckedTextView
- android:id="@+id/song_check"
- android:layout_width="wrap_content"
- android:layout_height="fill_parent"
- android:gravity="center_vertical"
- android:checkMark="?android:attr/listChoiceIndicatorMultiple"
- android:paddingLeft="3dip"/>
-
<LinearLayout android:orientation="vertical"
android:layout_width="0dip"
android:layout_height="wrap_content"