aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2016-01-29 14:57:03 -0800
committerScott Jackson <daneren2005@gmail.com>2016-01-29 14:57:03 -0800
commit2153ff1bee4c7826ea902b1f1fddf2d2933b2b5b (patch)
treea0378519690d83b2c6610707d2bc127424d5c309
parent734339b93c8e29db8caa11a13017a1acf1831f14 (diff)
downloaddsub-2153ff1bee4c7826ea902b1f1fddf2d2933b2b5b.tar.gz
dsub-2153ff1bee4c7826ea902b1f1fddf2d2933b2b5b.tar.bz2
dsub-2153ff1bee4c7826ea902b1f1fddf2d2933b2b5b.zip
Fixes #476: Add Batch Mode for Now Playing tab
-rw-r--r--app/src/main/java/github/daneren2005/dsub/adapter/DownloadFileAdapter.java25
-rw-r--r--app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java41
-rw-r--r--app/src/main/java/github/daneren2005/dsub/fragments/SubsonicFragment.java3
-rw-r--r--app/src/main/java/github/daneren2005/dsub/util/Constants.java1
-rw-r--r--app/src/main/java/github/daneren2005/dsub/util/Util.java6
-rw-r--r--app/src/main/res/menu/multiselect_nowplaying.xml27
-rw-r--r--app/src/main/res/menu/multiselect_nowplaying_offline.xml9
-rw-r--r--app/src/main/res/menu/nowplaying.xml5
-rw-r--r--app/src/main/res/menu/nowplaying_context.xml4
-rw-r--r--app/src/main/res/menu/nowplaying_context_offline.xml2
-rw-r--r--app/src/main/res/menu/nowplaying_offline.xml5
-rw-r--r--app/src/main/res/values/attrs.xml1
-rw-r--r--app/src/main/res/values/strings.xml1
-rw-r--r--app/src/main/res/values/themes.xml3
14 files changed, 119 insertions, 14 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/adapter/DownloadFileAdapter.java b/app/src/main/java/github/daneren2005/dsub/adapter/DownloadFileAdapter.java
index d4613994..5b3dc289 100644
--- a/app/src/main/java/github/daneren2005/dsub/adapter/DownloadFileAdapter.java
+++ b/app/src/main/java/github/daneren2005/dsub/adapter/DownloadFileAdapter.java
@@ -16,13 +16,18 @@
package github.daneren2005.dsub.adapter;
import android.content.Context;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import java.util.List;
+import github.daneren2005.dsub.R;
import github.daneren2005.dsub.service.DownloadFile;
+import github.daneren2005.dsub.util.Util;
import github.daneren2005.dsub.view.FastScroller;
import github.daneren2005.dsub.view.SongView;
import github.daneren2005.dsub.view.UpdateView;
@@ -33,6 +38,7 @@ public class DownloadFileAdapter extends SectionAdapter<DownloadFile> implements
public DownloadFileAdapter(Context context, List<DownloadFile> entries, OnItemClickedListener onItemClickedListener) {
super(context, entries);
this.onItemClickedListener = onItemClickedListener;
+ this.checkable = true;
}
@Override
@@ -43,7 +49,7 @@ public class DownloadFileAdapter extends SectionAdapter<DownloadFile> implements
@Override
public void onBindViewHolder(UpdateView.UpdateViewHolder holder, DownloadFile item, int viewType) {
SongView songView = (SongView) holder.getUpdateView();
- songView.setObject(item.getSong(), false);
+ songView.setObject(item.getSong(), Util.isBatchMode(context));
songView.setDownloadFile(item);
}
@@ -56,4 +62,21 @@ public class DownloadFileAdapter extends SectionAdapter<DownloadFile> implements
public String getTextToShowInBubble(int position) {
return null;
}
+
+ @Override
+ public void onCreateActionModeMenu(Menu menu, MenuInflater menuInflater) {
+ if(Util.isOffline(context)) {
+ menuInflater.inflate(R.menu.multiselect_nowplaying_offline, menu);
+ } else {
+ menuInflater.inflate(R.menu.multiselect_nowplaying, menu);
+ }
+
+ if(!selected.isEmpty()) {
+ MenuItem starItem = menu.findItem(R.id.menu_star);
+ if(starItem != null) {
+ boolean isStarred = selected.get(0).getSong().isStarred();
+ starItem.setTitle(isStarred ? R.string.common_unstar : R.string.common_star);
+ }
+ }
+ }
}
diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java
index f18b22a0..5de9c595 100644
--- a/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java
+++ b/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java
@@ -457,6 +457,10 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
mediaRouteButton.setRouteSelector(downloadService.getRemoteSelector());
}
}
+
+ if(Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_BATCH_MODE, false)) {
+ menu.findItem(R.id.menu_batch_mode).setChecked(true);
+ }
}
@Override
@@ -474,7 +478,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
menuInflater.inflate(R.menu.nowplaying_context_offline, menu);
} else {
menuInflater.inflate(R.menu.nowplaying_context, menu);
- menu.findItem(R.id.menu_star).setTitle(downloadFile.getSong().isStarred() ? R.string.common_unstar : R.string.common_star);
+ menu.findItem(R.id.song_menu_star).setTitle(downloadFile.getSong().isStarred() ? R.string.common_unstar : R.string.common_star);
}
if (downloadFile.getSong().getParent() == null) {
@@ -620,9 +624,6 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
}
createNewPlaylist(entries, true);
return true;
- case R.id.menu_star:
- UpdateHelper.toggleStarred(context, song.getSong());
- return true;
case R.id.menu_rate:
UpdateHelper.setRating(context, song.getSong());
return true;
@@ -634,11 +635,6 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
startTimer();
}
return true;
- case R.id.menu_add_playlist:
- songs = new ArrayList<Entry>(1);
- songs.add(song.getSong());
- addToPlaylist(songs);
- return true;
case R.id.menu_info:
displaySongInfo(song.getSong());
return true;
@@ -663,7 +659,18 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
// Any failed condition will get here
Util.toast(context, "Failed to start equalizer. Try restarting.");
return true;
- } default:
+ }case R.id.menu_batch_mode:
+ if(Util.isBatchMode(context)) {
+ Util.setBatchMode(context, false);
+ songListAdapter.notifyDataSetChanged();
+ } else {
+ Util.setBatchMode(context, true);
+ songListAdapter.notifyDataSetChanged();
+ }
+ context.supportInvalidateOptionsMenu();
+
+ return true;
+ default:
return false;
}
}
@@ -1369,4 +1376,18 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
break;
}
}
+
+ @Override
+ protected List<Entry> getSelectedEntries() {
+ List<DownloadFile> selected = getCurrentAdapter().getSelected();
+ List<Entry> entries = new ArrayList<>();
+
+ for(DownloadFile downloadFile: selected) {
+ if(downloadFile.getSong() != null) {
+ entries.add(downloadFile.getSong());
+ }
+ }
+
+ return 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 bc2418eb..0cb433c2 100644
--- a/app/src/main/java/github/daneren2005/dsub/fragments/SubsonicFragment.java
+++ b/app/src/main/java/github/daneren2005/dsub/fragments/SubsonicFragment.java
@@ -326,6 +326,9 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
public boolean onContextItemSelected(MenuItem menuItem, Object selectedItem) {
Artist artist = selectedItem instanceof Artist ? (Artist) selectedItem : null;
Entry entry = selectedItem instanceof Entry ? (Entry) selectedItem : null;
+ if(selectedItem instanceof DownloadFile) {
+ entry = ((DownloadFile) selectedItem).getSong();
+ }
List<Entry> songs = new ArrayList<Entry>(1);
songs.add(entry);
diff --git a/app/src/main/java/github/daneren2005/dsub/util/Constants.java b/app/src/main/java/github/daneren2005/dsub/util/Constants.java
index bfb85492..00682947 100644
--- a/app/src/main/java/github/daneren2005/dsub/util/Constants.java
+++ b/app/src/main/java/github/daneren2005/dsub/util/Constants.java
@@ -169,6 +169,7 @@ public final class Constants {
public static final String PREFERENCES_KEY_COLOR_ACTION_BAR = "colorActionBar";
public static final String PREFERENCES_KEY_SHUFFLE_BY_ALBUM = "shuffleByAlbum";
public static final String PREFERENCES_KEY_RESUME_PLAY_QUEUE_NEVER = "neverResumePlayQueue";
+ public static final String PREFERENCES_KEY_BATCH_MODE = "batchMode";
public static final String OFFLINE_SCROBBLE_COUNT = "scrobbleCount";
public static final String OFFLINE_SCROBBLE_ID = "scrobbleID";
diff --git a/app/src/main/java/github/daneren2005/dsub/util/Util.java b/app/src/main/java/github/daneren2005/dsub/util/Util.java
index 6975b1bf..98bbe1df 100644
--- a/app/src/main/java/github/daneren2005/dsub/util/Util.java
+++ b/app/src/main/java/github/daneren2005/dsub/util/Util.java
@@ -377,6 +377,12 @@ public final class Util {
int cacheSize = Integer.parseInt(prefs.getString(Constants.PREFERENCES_KEY_CACHE_SIZE, "-1"));
return cacheSize == -1 ? Integer.MAX_VALUE : cacheSize;
}
+ public static boolean isBatchMode(Context context) {
+ return Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_BATCH_MODE, false);
+ }
+ public static void setBatchMode(Context context, boolean batchMode) {
+ Util.getPreferences(context).edit().putBoolean(Constants.PREFERENCES_KEY_BATCH_MODE, batchMode).commit();
+ }
public static String getRestUrl(Context context, String method) {
return getRestUrl(context, method, true);
diff --git a/app/src/main/res/menu/multiselect_nowplaying.xml b/app/src/main/res/menu/multiselect_nowplaying.xml
new file mode 100644
index 00000000..9d361bf0
--- /dev/null
+++ b/app/src/main/res/menu/multiselect_nowplaying.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<menu xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:compat="http://schemas.android.com/apk/res-auto">
+ <item
+ android:id="@+id/menu_download"
+ android:title="@string/common.download"
+ android:icon="?attr/download"
+ compat:showAsAction="ifRoom|withText"/>
+
+ <item
+ android:id="@+id/menu_delete"
+ android:title="@string/menu.delete_cache"
+ android:icon="?attr/remove"
+ compat:showAsAction="ifRoom|withText"/>
+
+ <item
+ android:id="@+id/menu_cache"
+ android:title="@string/common.pin"/>
+
+ <item
+ android:id="@+id/menu_add_playlist"
+ android:title="@string/menu.add_playlist"/>
+
+ <item
+ android:id="@+id/menu_star"
+ android:title="@string/common.star"/>
+</menu>
diff --git a/app/src/main/res/menu/multiselect_nowplaying_offline.xml b/app/src/main/res/menu/multiselect_nowplaying_offline.xml
new file mode 100644
index 00000000..044836c6
--- /dev/null
+++ b/app/src/main/res/menu/multiselect_nowplaying_offline.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<menu xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:compat="http://schemas.android.com/apk/res-auto">
+ <item
+ android:id="@+id/menu_delete"
+ android:title="@string/menu.delete_cache"
+ android:icon="?attr/remove"
+ compat:showAsAction="ifRoom|withText"/>
+</menu>
diff --git a/app/src/main/res/menu/nowplaying.xml b/app/src/main/res/menu/nowplaying.xml
index 60255692..9c198e9a 100644
--- a/app/src/main/res/menu/nowplaying.xml
+++ b/app/src/main/res/menu/nowplaying.xml
@@ -33,6 +33,11 @@
android:title="@string/equalizer.label"
android:checkable="true"/>
+ <item
+ android:id="@+id/menu_batch_mode"
+ android:title="@string/download.batch_mode"
+ android:checkable="true"/>
+
<item
android:id="@+id/menu_screen_on_off"
android:title="@string/download.menu_screen_on"
diff --git a/app/src/main/res/menu/nowplaying_context.xml b/app/src/main/res/menu/nowplaying_context.xml
index 60d6288e..06f4afcb 100644
--- a/app/src/main/res/menu/nowplaying_context.xml
+++ b/app/src/main/res/menu/nowplaying_context.xml
@@ -26,7 +26,7 @@
<group android:id="@+id/hide_star">
<item
- android:id="@+id/menu_star"
+ android:id="@+id/song_menu_star"
android:title="@string/common.star"/>
</group>
@@ -44,7 +44,7 @@
<group android:id="@+id/server_1.8">
<item
- android:id="@+id/menu_add_playlist"
+ android:id="@+id/song_menu_add_playlist"
android:title="@string/menu.add_playlist"/>
</group>
</menu>
diff --git a/app/src/main/res/menu/nowplaying_context_offline.xml b/app/src/main/res/menu/nowplaying_context_offline.xml
index 5f8009ff..14c95ab6 100644
--- a/app/src/main/res/menu/nowplaying_context_offline.xml
+++ b/app/src/main/res/menu/nowplaying_context_offline.xml
@@ -22,7 +22,7 @@
<group android:id="@+id/hide_star">
<item
- android:id="@+id/menu_star"
+ android:id="@+id/song_menu_star"
android:title="@string/common.star"/>
</group>
</menu>
diff --git a/app/src/main/res/menu/nowplaying_offline.xml b/app/src/main/res/menu/nowplaying_offline.xml
index bba5ba00..d1f6f706 100644
--- a/app/src/main/res/menu/nowplaying_offline.xml
+++ b/app/src/main/res/menu/nowplaying_offline.xml
@@ -25,6 +25,11 @@
android:id="@+id/menu_equalizer"
android:title="@string/equalizer.label"
android:checkable="true"/>
+
+ <item
+ android:id="@+id/menu_batch_mode"
+ android:title="@string/download.batch_mode"
+ android:checkable="true"/>
<item
android:id="@+id/menu_screen_on_off"
diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml
index d97a3b21..c8553dc0 100644
--- a/app/src/main/res/values/attrs.xml
+++ b/app/src/main/res/values/attrs.xml
@@ -37,6 +37,7 @@
<attr name="rating_good" format="reference"/>
<attr name="radio" format="reference"/>
<attr name="star_outline" format="reference"/>
+ <attr name="download" format="reference"/>
<attr name="drawerItemsIcons" format="reference"/>
<attr name="drawerHome" format="reference"/>
<attr name="drawerLibrary" format="reference"/>
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 821f2ad3..b7efff1a 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -232,6 +232,7 @@
<string name="download.restore_play_queue">continue from where you left off on another device at</string>
<string name="download.thumbs_up">Thumbs Up</string>
<string name="download.thumbs_down">Thumbs Down</string>
+ <string name="download.batch_mode">Batch Mode</string>
<string name="sync.new_podcasts">New podcasts available</string>
<string name="sync.new_playlists">New songs in playlists</string>
diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml
index 790d91de..4915c012 100644
--- a/app/src/main/res/values/themes.xml
+++ b/app/src/main/res/values/themes.xml
@@ -38,6 +38,7 @@
<item name="rating_good">@drawable/ic_action_rating_good_light</item>
<item name="radio">@drawable/ic_menu_radio_dark</item>
<item name="star_outline">@drawable/ic_toggle_star_outline_light</item>
+ <item name="download">@drawable/ic_menu_download_dark</item>
<item name="drawerHome">@drawable/main_offline_light</item>
<item name="drawerLibrary">@drawable/ic_menu_library_light</item>
<item name="drawerPlaylists">@drawable/ic_menu_playlist_light</item>
@@ -103,6 +104,7 @@
<item name="rating_good">@drawable/ic_action_rating_good_dark</item>
<item name="radio">@drawable/ic_menu_radio_dark</item>
<item name="star_outline">@drawable/ic_toggle_star_outline_dark</item>
+ <item name="download">@drawable/ic_menu_download_dark</item>
<item name="drawerHome">@drawable/main_offline_dark</item>
<item name="drawerLibrary">@drawable/ic_menu_library_dark</item>
<item name="drawerPlaylists">@drawable/ic_menu_playlist_dark</item>
@@ -190,6 +192,7 @@
<item name="add_person">@drawable/ic_menu_add_person_light</item>
<item name="password">@drawable/ic_menu_password_light</item>
<item name="radio">@drawable/ic_menu_radio_light</item>
+ <item name="download">@drawable/ic_menu_download_light</item>
<item name="actionModeBackground">@color/background_material_light</item>
<item name="actionModeStyle">@style/LightActionMode</item>
<item name="actionModeCloseButtonStyle">@style/DarkCloseButton</item>