From 8436b8572c9eab3211b93e63b05c561c22afdc85 Mon Sep 17 00:00:00 2001 From: saqura Date: Fri, 1 Apr 2016 18:02:56 +0200 Subject: [PATCH 1/6] Fix documentation of setLockscreenBackground() --- .../danoeh/antennapod/core/preferences/UserPreferences.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java b/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java index 2088ab637..58caedc3e 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java +++ b/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java @@ -203,9 +203,9 @@ public class UserPreferences { } /** - * Returns true if notifications are persistent + * Returns true if the lockscreen background should be set to the current episode's image * - * @return {@code true} if notifications are persistent, {@code false} otherwise + * @return {@code true} if the lockscreen background should be set, {@code false} otherwise */ public static boolean setLockscreenBackground() { return prefs.getBoolean(PREF_LOCKSCREEN_BACKGROUND, true); From 13d0a3570b3634da777a791e89008ad7cef5bd29 Mon Sep 17 00:00:00 2001 From: saqura Date: Fri, 1 Apr 2016 18:05:58 +0200 Subject: [PATCH 2/6] Optionally show rewind/ff buttons on lockscreen Show additional playback buttons (rewind and fast forward) in the notification on the lockscreen if the option "Expand Notification" is enabled. Fixes #337 Fixes #571 --- .../core/preferences/UserPreferences.java | 10 ++++++++++ .../core/service/playback/PlaybackService.java | 15 +++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java b/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java index 58caedc3e..222c69a1d 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java +++ b/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java @@ -193,6 +193,16 @@ public class UserPreferences { } } + /** + * Returns true if additional playback buttons should be shown in the notification even when + * on the lockscreen + * + * @return {@code true} if additional playback buttons should be shown, {@code false} otherwise + */ + public static boolean showAdditionalNotificationButtons() { + return prefs.getBoolean(PREF_EXPANDED_NOTIFICATION, false); + } + /** * Returns true if notifications are persistent * diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java index 729ea9e7a..9b37ce76d 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java @@ -867,7 +867,13 @@ public class PlaybackService extends Service { notificationBuilder.addAction(android.R.drawable.ic_media_rew, getString(R.string.rewind_label), rewindButtonPendingIntent); - numActions++; + if(UserPreferences.showAdditionalNotificationButtons()) { + // always show the rewind button (even on the lockscreen) + compactActionList.add(numActions++); + } else { + numActions++; + } + if (playerStatus == PlayerStatus.PLAYING) { PendingIntent pauseButtonPendingIntent = getPendingIntentForMediaAction( @@ -891,7 +897,12 @@ public class PlaybackService extends Service { notificationBuilder.addAction(android.R.drawable.ic_media_ff, getString(R.string.fast_forward_label), ffButtonPendingIntent); - numActions++; + if(UserPreferences.showAdditionalNotificationButtons()) { + // always show the ff button (even on the lockscreen) + compactActionList.add(numActions++); + } else { + numActions++; + } if (UserPreferences.isFollowQueue()) { PendingIntent skipButtonPendingIntent = getPendingIntentForMediaAction( From 65bb7d9911acfc03cb2ef786c857ebcc5fb45677 Mon Sep 17 00:00:00 2001 From: saqura Date: Sat, 2 Apr 2016 21:37:05 +0200 Subject: [PATCH 3/6] Add option to pick lock screen playback buttons This adds the option to pick which playback buttons to prioritise on the notification. This allows choosing the playback buttons on the lock screen. The default playback buttons have not changed and are still set to play/pause (this is always displayed) and skip. Note: This commit raises the minimum sdk version from 10 to 11! --- app/src/main/res/xml/preferences.xml | 8 ++++++++ build.gradle | 2 +- .../core/preferences/UserPreferences.java | 6 ++++++ .../core/service/playback/PlaybackService.java | 18 ++++++++++++------ core/src/main/res/values/arrays.xml | 14 ++++++++++++++ core/src/main/res/values/strings.xml | 2 ++ 6 files changed, 43 insertions(+), 7 deletions(-) diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index 93df4e3e0..e40de7c46 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -55,6 +55,14 @@ android:key="prefPersistNotify" android:summary="@string/pref_persistNotify_sum" android:title="@string/pref_persistNotify_title"/> + getPrioritisedNotificationButtons() { + return prefs.getStringSet(PREF_PRIORITISED_NOTIFICATION_BUTTONS, null); + } + /** * Returns notification priority. * diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java index 9b37ce76d..7a7c2d635 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java @@ -30,6 +30,7 @@ import android.widget.Toast; import com.bumptech.glide.Glide; import java.util.List; +import java.util.Set; import de.danoeh.antennapod.core.ClientConfig; import de.danoeh.antennapod.core.R; @@ -858,7 +859,7 @@ public class PlaybackService extends Service { .setPriority(UserPreferences.getNotifyPriority()); // set notification priority IntList compactActionList = new IntList(); - + Set prioritisedButtons = UserPreferences.getPrioritisedNotificationButtons(); int numActions = 0; // we start and 0 and then increment by 1 for each call to addAction // always let them rewind @@ -867,8 +868,8 @@ public class PlaybackService extends Service { notificationBuilder.addAction(android.R.drawable.ic_media_rew, getString(R.string.rewind_label), rewindButtonPendingIntent); - if(UserPreferences.showAdditionalNotificationButtons()) { - // always show the rewind button (even on the lockscreen) + if(prioritisedButtons.contains("0")) { + // show the rewind button even on the lock screen compactActionList.add(numActions++); } else { numActions++; @@ -897,8 +898,8 @@ public class PlaybackService extends Service { notificationBuilder.addAction(android.R.drawable.ic_media_ff, getString(R.string.fast_forward_label), ffButtonPendingIntent); - if(UserPreferences.showAdditionalNotificationButtons()) { - // always show the ff button (even on the lockscreen) + if(prioritisedButtons.contains("1")) { + // show the fast forward button even on the lock screen compactActionList.add(numActions++); } else { numActions++; @@ -910,7 +911,12 @@ public class PlaybackService extends Service { notificationBuilder.addAction(android.R.drawable.ic_media_next, getString(R.string.skip_episode_label), skipButtonPendingIntent); - compactActionList.add(numActions++); + if(prioritisedButtons.contains("2")) { + // show the skip button even on the lock screen + compactActionList.add(numActions++); + } else { + numActions++; + } } PendingIntent stopButtonPendingIntent = getPendingIntentForMediaAction( diff --git a/core/src/main/res/values/arrays.xml b/core/src/main/res/values/arrays.xml index 80da376be..ea2bb7a52 100644 --- a/core/src/main/res/values/arrays.xml +++ b/core/src/main/res/values/arrays.xml @@ -212,4 +212,18 @@ 500 + + @string/rewind_label + @string/fast_forward_label + @string/skip_episode_label + + + 0 + 1 + 2 + + + 2 + + diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index 5391435b7..b2f4e11f9 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -384,6 +384,8 @@ Always expand the notification to show playback buttons. Persistent Playback Controls Keep notification and lockscreen controls when playback is paused. + Prioritise Notification Buttons + Change the playback buttons on the lock screen notification. Show Subscriptions Show subscription list directly in navigation drawer Set Lockscreen Background From 4d47ba640550714968fbb4e5c07ab913474db6c0 Mon Sep 17 00:00:00 2001 From: saqura Date: Sun, 3 Apr 2016 00:32:55 +0200 Subject: [PATCH 4/6] Add dialog to choose lock screen playback buttons This adds a dialog to choose the playback buttons on the lock screen notification. It only allows selecting a maximum of two values, because the lock screen notification can only display up to 3 buttons and the play/pause button is always included. It defaults to additionally show the skip button. The minimum sdk has been changed back to 10. --- .../preferences/PreferenceController.java | 60 +++++++++++++++++++ app/src/main/res/xml/preferences.xml | 12 ++-- build.gradle | 2 +- .../core/preferences/UserPreferences.java | 19 ++++-- .../service/playback/PlaybackService.java | 9 ++- core/src/main/res/values/arrays.xml | 14 ++--- core/src/main/res/values/strings.xml | 6 +- 7 files changed, 93 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java b/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java index 116272578..0e79b46ea 100644 --- a/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java +++ b/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java @@ -6,6 +6,7 @@ import android.app.Activity; import android.app.TimePickerDialog; import android.content.ActivityNotFoundException; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; @@ -221,6 +222,12 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc return true; }); + ui.findPreference(UserPreferences.PREF_NOTIFICATION_BUTTONS) + .setOnPreferenceClickListener(preference -> { + showNotificationButtonsDialog(); + return true; + }); + ui.findPreference(UserPreferences.PREF_UPDATE_INTERVAL) .setOnPreferenceClickListener(preference -> { showUpdateIntervalTimePreferencesDialog(); @@ -735,6 +742,59 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc builder.create().show(); } + private void showNotificationButtonsDialog() { + final Context context = ui.getActivity(); + final List preferredButtons = UserPreferences.getNotificationButtons(); + final String[] allButtonNames = context.getResources().getStringArray( + R.array.notification_buttons_options); + final String[] allButtonIDs = context.getResources().getStringArray( + R.array.notification_buttons_values); + boolean[] checked = new boolean[allButtonIDs.length]; // booleans default to false in java + + for(int i=0; i < allButtonIDs.length; i++) { + String id = allButtonIDs[i]; + if(preferredButtons.contains(id)) { + checked[i] = true; + } + } + + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setTitle(String.format(context.getResources().getString( + R.string.pref_notification_buttons_dialog_title), 2)); + builder.setMultiChoiceItems(allButtonNames, checked,new DialogInterface.OnMultiChoiceClickListener() { + int count = preferredButtons.size(); + + public void onClick(DialogInterface dialog, int which, boolean isChecked) { + checked[which] = isChecked; + if (isChecked) { + if (count < 2) { + preferredButtons.add(allButtonIDs[which]); + count++; + } else { + // Only allow a maximum of two selections. This is because the notification + // on the lock screen can only display 3 buttons, and the play/pause button + // is always included. + checked[which] = false; + ((AlertDialog) dialog).getListView().setItemChecked(which, false); + Toast.makeText( + context, + String.format(context.getResources().getString( + R.string.pref_notification_buttons_dialog_error), 2), + Toast.LENGTH_SHORT).show(); + } + } else { + preferredButtons.remove(allButtonIDs[which]); + count--; + } + } + }); + builder.setPositiveButton(R.string.confirm_label, (dialog, which) -> { + UserPreferences.setNotificationButtons(preferredButtons); + }); + builder.setNegativeButton(R.string.cancel_label, null); + builder.create().show(); + } + // CHOOSE DATA FOLDER private void requestPermission() { diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index e40de7c46..b3707f023 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -55,14 +55,10 @@ android:key="prefPersistNotify" android:summary="@string/pref_persistNotify_sum" android:title="@string/pref_persistNotify_title"/> - + (Arrays.asList(TextUtils.split(hiddenItems, ","))); } + public static List getNotificationButtons() { + String hiddenItems = prefs.getString(PREF_NOTIFICATION_BUTTONS, "skip"); + return new ArrayList<>(Arrays.asList(TextUtils.split(hiddenItems, ","))); + } + public static int getFeedOrder() { String value = prefs.getString(PREF_DRAWER_FEED_ORDER, "0"); return Integer.parseInt(value); @@ -182,10 +186,6 @@ public class UserPreferences { return prefs.getBoolean(PREF_SHOW_SUBSCRIPTIONS_IN_DRAWER, true); } - public static Set getPrioritisedNotificationButtons() { - return prefs.getStringSet(PREF_PRIORITISED_NOTIFICATION_BUTTONS, null); - } - /** * Returns notification priority. * @@ -533,6 +533,13 @@ public class UserPreferences { .apply(); } + public static void setNotificationButtons(List items) { + String str = TextUtils.join(",", items); + prefs.edit() + .putString(PREF_NOTIFICATION_BUTTONS, str) + .apply(); + } + public static void setQueueLocked(boolean locked) { prefs.edit() .putBoolean(PREF_QUEUE_LOCKED, locked) diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java index 7a7c2d635..39dc35535 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java @@ -30,7 +30,6 @@ import android.widget.Toast; import com.bumptech.glide.Glide; import java.util.List; -import java.util.Set; import de.danoeh.antennapod.core.ClientConfig; import de.danoeh.antennapod.core.R; @@ -859,7 +858,7 @@ public class PlaybackService extends Service { .setPriority(UserPreferences.getNotifyPriority()); // set notification priority IntList compactActionList = new IntList(); - Set prioritisedButtons = UserPreferences.getPrioritisedNotificationButtons(); + final List notificationButtons = UserPreferences.getNotificationButtons(); int numActions = 0; // we start and 0 and then increment by 1 for each call to addAction // always let them rewind @@ -868,7 +867,7 @@ public class PlaybackService extends Service { notificationBuilder.addAction(android.R.drawable.ic_media_rew, getString(R.string.rewind_label), rewindButtonPendingIntent); - if(prioritisedButtons.contains("0")) { + if(notificationButtons.contains("rewind")) { // show the rewind button even on the lock screen compactActionList.add(numActions++); } else { @@ -898,7 +897,7 @@ public class PlaybackService extends Service { notificationBuilder.addAction(android.R.drawable.ic_media_ff, getString(R.string.fast_forward_label), ffButtonPendingIntent); - if(prioritisedButtons.contains("1")) { + if(notificationButtons.contains("fastforward")) { // show the fast forward button even on the lock screen compactActionList.add(numActions++); } else { @@ -911,7 +910,7 @@ public class PlaybackService extends Service { notificationBuilder.addAction(android.R.drawable.ic_media_next, getString(R.string.skip_episode_label), skipButtonPendingIntent); - if(prioritisedButtons.contains("2")) { + if(notificationButtons.contains("skip")) { // show the skip button even on the lock screen compactActionList.add(numActions++); } else { diff --git a/core/src/main/res/values/arrays.xml b/core/src/main/res/values/arrays.xml index ea2bb7a52..04e0d97cd 100644 --- a/core/src/main/res/values/arrays.xml +++ b/core/src/main/res/values/arrays.xml @@ -212,18 +212,18 @@ 500 - + @string/rewind_label @string/fast_forward_label @string/skip_episode_label - - 0 - 1 - 2 + + rewind + fastforward + skip - - 2 + + skip diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index b2f4e11f9..25da5ec1d 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -384,8 +384,10 @@ Always expand the notification to show playback buttons. Persistent Playback Controls Keep notification and lockscreen controls when playback is paused. - Prioritise Notification Buttons - Change the playback buttons on the lock screen notification. + Select Notification Buttons + Change the playback buttons on the lock screen notification. + Select a maximum of %1$d items + You can only select a maximum of %1$d items. Show Subscriptions Show subscription list directly in navigation drawer Set Lockscreen Background From e215e162ad6c833ad3d3c5953e35e294eea8f25d Mon Sep 17 00:00:00 2001 From: saqura Date: Sun, 3 Apr 2016 01:02:03 +0200 Subject: [PATCH 5/6] Update lock screen button preference summary --- core/src/main/res/values/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index 25da5ec1d..6edc8b32b 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -385,7 +385,7 @@ Persistent Playback Controls Keep notification and lockscreen controls when playback is paused. Select Notification Buttons - Change the playback buttons on the lock screen notification. + Change the playback buttons on the lock screen notification. The play/pause button is always included. Select a maximum of %1$d items You can only select a maximum of %1$d items. Show Subscriptions From e3408565dcc15cd97548b664773bc684dca4edeb Mon Sep 17 00:00:00 2001 From: saqura Date: Sun, 3 Apr 2016 20:22:03 +0200 Subject: [PATCH 6/6] Update compact notification buttons dialog The preference dialog to select which buttons are shown in compact notifications now provides feedback via a snackbar. The internal preference storage handling has been cleaned up. A testcase for the dialog has been added. --- .../test/antennapod/ui/PreferencesTest.java | 24 +++++++ .../preferences/PreferenceController.java | 62 +++++++++---------- app/src/main/res/xml/preferences.xml | 6 +- .../core/preferences/UserPreferences.java | 56 ++++++++++++----- .../service/playback/PlaybackService.java | 26 +++----- core/src/main/res/values/arrays.xml | 11 +--- core/src/main/res/values/strings.xml | 8 +-- 7 files changed, 109 insertions(+), 84 deletions(-) diff --git a/app/src/androidTest/java/de/test/antennapod/ui/PreferencesTest.java b/app/src/androidTest/java/de/test/antennapod/ui/PreferencesTest.java index 54741502c..040f4150b 100644 --- a/app/src/androidTest/java/de/test/antennapod/ui/PreferencesTest.java +++ b/app/src/androidTest/java/de/test/antennapod/ui/PreferencesTest.java @@ -90,6 +90,30 @@ public class PreferencesTest extends ActivityInstrumentationTestCase2 persistNotify == UserPreferences.isPersistNotify(), Timeout.getLargeTimeout())); } + public void testSetLockscreenButtons() { + String[] buttons = res.getStringArray(R.array.compact_notification_buttons_options); + solo.clickOnText(solo.getString(R.string.pref_compact_notification_buttons_title)); + solo.waitForDialogToOpen(1000); + // First uncheck every checkbox + for (int i=0; i UserPreferences.showRewindOnCompactNotification(), Timeout.getLargeTimeout())); + assertTrue(solo.waitForCondition(() -> UserPreferences.showFastForwardOnCompactNotification(), Timeout.getLargeTimeout())); + assertTrue(solo.waitForCondition(() -> !UserPreferences.showSkipOnCompactNotification(), Timeout.getLargeTimeout())); + } + public void testEnqueueAtFront() { final boolean enqueueAtFront = UserPreferences.enqueueAtFront(); solo.clickOnText(solo.getString(R.string.pref_queueAddToFront_title)); diff --git a/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java b/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java index 0e79b46ea..23534e4f8 100644 --- a/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java +++ b/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java @@ -6,7 +6,6 @@ import android.app.Activity; import android.app.TimePickerDialog; import android.content.ActivityNotFoundException; import android.content.Context; -import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; @@ -21,6 +20,7 @@ import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceManager; import android.preference.PreferenceScreen; +import android.support.design.widget.Snackbar; import android.support.v4.app.ActivityCompat; import android.support.v4.content.ContextCompat; import android.support.v7.app.AlertDialog; @@ -31,6 +31,7 @@ import android.text.format.DateFormat; import android.util.Log; import android.widget.EditText; import android.widget.Toast; +import android.widget.ListView; import com.afollestad.materialdialogs.MaterialDialog; @@ -222,7 +223,7 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc return true; }); - ui.findPreference(UserPreferences.PREF_NOTIFICATION_BUTTONS) + ui.findPreference(UserPreferences.PREF_COMPACT_NOTIFICATION_BUTTONS) .setOnPreferenceClickListener(preference -> { showNotificationButtonsDialog(); return true; @@ -744,52 +745,45 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc private void showNotificationButtonsDialog() { final Context context = ui.getActivity(); - final List preferredButtons = UserPreferences.getNotificationButtons(); + final List preferredButtons = UserPreferences.getCompactNotificationButtons(); final String[] allButtonNames = context.getResources().getStringArray( - R.array.notification_buttons_options); - final String[] allButtonIDs = context.getResources().getStringArray( - R.array.notification_buttons_values); - boolean[] checked = new boolean[allButtonIDs.length]; // booleans default to false in java + R.array.compact_notification_buttons_options); + boolean[] checked = new boolean[allButtonNames.length]; // booleans default to false in java - for(int i=0; i < allButtonIDs.length; i++) { - String id = allButtonIDs[i]; - if(preferredButtons.contains(id)) { + for(int i=0; i < checked.length; i++) { + if(preferredButtons.contains(i)) { checked[i] = true; } } AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(String.format(context.getResources().getString( - R.string.pref_notification_buttons_dialog_title), 2)); - builder.setMultiChoiceItems(allButtonNames, checked,new DialogInterface.OnMultiChoiceClickListener() { - int count = preferredButtons.size(); + R.string.pref_compact_notification_buttons_dialog_title), 2)); + builder.setMultiChoiceItems(allButtonNames, checked, (dialog, which, isChecked) -> { + checked[which] = isChecked; - public void onClick(DialogInterface dialog, int which, boolean isChecked) { - checked[which] = isChecked; - if (isChecked) { - if (count < 2) { - preferredButtons.add(allButtonIDs[which]); - count++; - } else { - // Only allow a maximum of two selections. This is because the notification - // on the lock screen can only display 3 buttons, and the play/pause button - // is always included. - checked[which] = false; - ((AlertDialog) dialog).getListView().setItemChecked(which, false); - Toast.makeText( - context, - String.format(context.getResources().getString( - R.string.pref_notification_buttons_dialog_error), 2), - Toast.LENGTH_SHORT).show(); - } + if (isChecked) { + if (preferredButtons.size() < 2) { + preferredButtons.add(which); } else { - preferredButtons.remove(allButtonIDs[which]); - count--; + // Only allow a maximum of two selections. This is because the notification + // on the lock screen can only display 3 buttons, and the play/pause button + // is always included. + checked[which] = false; + ListView selectionView = ((AlertDialog) dialog).getListView(); + selectionView.setItemChecked(which, false); + Snackbar.make( + selectionView, + String.format(context.getResources().getString( + R.string.pref_compact_notification_buttons_dialog_error), 2), + Snackbar.LENGTH_SHORT).show(); } + } else { + preferredButtons.remove((Integer) which); } }); builder.setPositiveButton(R.string.confirm_label, (dialog, which) -> { - UserPreferences.setNotificationButtons(preferredButtons); + UserPreferences.setCompactNotificationButtons(preferredButtons); }); builder.setNegativeButton(R.string.cancel_label, null); builder.create().show(); diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index b3707f023..5861db186 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -56,9 +56,9 @@ android:summary="@string/pref_persistNotify_sum" android:title="@string/pref_persistNotify_title"/> + android:key="prefCompactNotificationButtons" + android:summary="@string/pref_compact_notification_buttons_sum" + android:title="@string/pref_compact_notification_buttons_title"/> (Arrays.asList(TextUtils.split(hiddenItems, ","))); } - public static List getNotificationButtons() { - String hiddenItems = prefs.getString(PREF_NOTIFICATION_BUTTONS, "skip"); - return new ArrayList<>(Arrays.asList(TextUtils.split(hiddenItems, ","))); + public static List getCompactNotificationButtons() { + String[] buttons = TextUtils.split( + prefs.getString(PREF_COMPACT_NOTIFICATION_BUTTONS, + String.valueOf(NOTIFICATION_BUTTON_SKIP)), + ","); + List notificationButtons = new ArrayList<>(); + for (int i=0; i items) { + public static void setCompactNotificationButtons(List items) { String str = TextUtils.join(",", items); prefs.edit() - .putString(PREF_NOTIFICATION_BUTTONS, str) + .putString(PREF_COMPACT_NOTIFICATION_BUTTONS, str) .apply(); } diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java index 39dc35535..edea3962f 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java @@ -858,7 +858,6 @@ public class PlaybackService extends Service { .setPriority(UserPreferences.getNotifyPriority()); // set notification priority IntList compactActionList = new IntList(); - final List notificationButtons = UserPreferences.getNotificationButtons(); int numActions = 0; // we start and 0 and then increment by 1 for each call to addAction // always let them rewind @@ -867,13 +866,10 @@ public class PlaybackService extends Service { notificationBuilder.addAction(android.R.drawable.ic_media_rew, getString(R.string.rewind_label), rewindButtonPendingIntent); - if(notificationButtons.contains("rewind")) { - // show the rewind button even on the lock screen - compactActionList.add(numActions++); - } else { - numActions++; + if(UserPreferences.showRewindOnCompactNotification()) { + compactActionList.add(numActions); } - + numActions++; if (playerStatus == PlayerStatus.PLAYING) { PendingIntent pauseButtonPendingIntent = getPendingIntentForMediaAction( @@ -897,12 +893,10 @@ public class PlaybackService extends Service { notificationBuilder.addAction(android.R.drawable.ic_media_ff, getString(R.string.fast_forward_label), ffButtonPendingIntent); - if(notificationButtons.contains("fastforward")) { - // show the fast forward button even on the lock screen - compactActionList.add(numActions++); - } else { - numActions++; + if(UserPreferences.showFastForwardOnCompactNotification()) { + compactActionList.add(numActions); } + numActions++; if (UserPreferences.isFollowQueue()) { PendingIntent skipButtonPendingIntent = getPendingIntentForMediaAction( @@ -910,12 +904,10 @@ public class PlaybackService extends Service { notificationBuilder.addAction(android.R.drawable.ic_media_next, getString(R.string.skip_episode_label), skipButtonPendingIntent); - if(notificationButtons.contains("skip")) { - // show the skip button even on the lock screen - compactActionList.add(numActions++); - } else { - numActions++; + if(UserPreferences.showSkipOnCompactNotification()) { + compactActionList.add(numActions); } + numActions++; } PendingIntent stopButtonPendingIntent = getPendingIntentForMediaAction( diff --git a/core/src/main/res/values/arrays.xml b/core/src/main/res/values/arrays.xml index 04e0d97cd..66a033b57 100644 --- a/core/src/main/res/values/arrays.xml +++ b/core/src/main/res/values/arrays.xml @@ -212,18 +212,9 @@ 500 - + @string/rewind_label @string/fast_forward_label @string/skip_episode_label - - rewind - fastforward - skip - - - skip - - diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index 6edc8b32b..4d9f5d26e 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -384,10 +384,10 @@ Always expand the notification to show playback buttons. Persistent Playback Controls Keep notification and lockscreen controls when playback is paused. - Select Notification Buttons - Change the playback buttons on the lock screen notification. The play/pause button is always included. - Select a maximum of %1$d items - You can only select a maximum of %1$d items. + Set Lockscreen Buttons + Change the playback buttons on the lockscreen. The play/pause button is always included. + Select a maximum of %1$d items + You can only select a maximum of %1$d items. Show Subscriptions Show subscription list directly in navigation drawer Set Lockscreen Background