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 116272578..23534e4f8 100644 --- a/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java +++ b/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java @@ -20,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; @@ -30,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; @@ -221,6 +223,12 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc return true; }); + ui.findPreference(UserPreferences.PREF_COMPACT_NOTIFICATION_BUTTONS) + .setOnPreferenceClickListener(preference -> { + showNotificationButtonsDialog(); + return true; + }); + ui.findPreference(UserPreferences.PREF_UPDATE_INTERVAL) .setOnPreferenceClickListener(preference -> { showUpdateIntervalTimePreferencesDialog(); @@ -735,6 +743,52 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc builder.create().show(); } + private void showNotificationButtonsDialog() { + final Context context = ui.getActivity(); + final List preferredButtons = UserPreferences.getCompactNotificationButtons(); + final String[] allButtonNames = context.getResources().getStringArray( + R.array.compact_notification_buttons_options); + boolean[] checked = new boolean[allButtonNames.length]; // booleans default to false in java + + 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_compact_notification_buttons_dialog_title), 2)); + builder.setMultiChoiceItems(allButtonNames, checked, (dialog, which, isChecked) -> { + checked[which] = isChecked; + + if (isChecked) { + if (preferredButtons.size() < 2) { + preferredButtons.add(which); + } 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; + 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.setCompactNotificationButtons(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 675687fb8..ecdcd3517 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -49,6 +49,10 @@ android:key="prefPersistNotify" android:summary="@string/pref_persistNotify_sum" android:title="@string/pref_persistNotify_title"/> + (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) { + String str = TextUtils.join(",", items); + prefs.edit() + .putString(PREF_COMPACT_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 729ea9e7a..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(); - int numActions = 0; // we start and 0 and then increment by 1 for each call to addAction // always let them rewind @@ -867,6 +866,9 @@ public class PlaybackService extends Service { notificationBuilder.addAction(android.R.drawable.ic_media_rew, getString(R.string.rewind_label), rewindButtonPendingIntent); + if(UserPreferences.showRewindOnCompactNotification()) { + compactActionList.add(numActions); + } numActions++; if (playerStatus == PlayerStatus.PLAYING) { @@ -891,6 +893,9 @@ public class PlaybackService extends Service { notificationBuilder.addAction(android.R.drawable.ic_media_ff, getString(R.string.fast_forward_label), ffButtonPendingIntent); + if(UserPreferences.showFastForwardOnCompactNotification()) { + compactActionList.add(numActions); + } numActions++; if (UserPreferences.isFollowQueue()) { @@ -899,7 +904,10 @@ public class PlaybackService extends Service { notificationBuilder.addAction(android.R.drawable.ic_media_next, getString(R.string.skip_episode_label), skipButtonPendingIntent); - compactActionList.add(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 ffb4eadad..fba22b985 100644 --- a/core/src/main/res/values/arrays.xml +++ b/core/src/main/res/values/arrays.xml @@ -213,4 +213,9 @@ 500 + + @string/rewind_label + @string/fast_forward_label + @string/skip_episode_label + diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index 29d4eabbb..4575f665e 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -374,6 +374,10 @@ Always expand the notification to show playback buttons. Persistent Playback Controls Keep notification and lockscreen controls when playback is paused. + 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