From 65bb7d9911acfc03cb2ef786c857ebcc5fb45677 Mon Sep 17 00:00:00 2001 From: saqura Date: Sat, 2 Apr 2016 21:37:05 +0200 Subject: 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 ++++++++ 1 file changed, 8 insertions(+) (limited to 'app') 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"/> + Date: Sun, 3 Apr 2016 00:32:55 +0200 Subject: 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 ++--- 2 files changed, 64 insertions(+), 8 deletions(-) (limited to 'app') 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"/> - + Date: Sun, 3 Apr 2016 20:22:03 +0200 Subject: 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. --- .../de/test/antennapod/ui/PreferencesTest.java | 24 ++++++++ .../preferences/PreferenceController.java | 66 ++++++++++------------ app/src/main/res/xml/preferences.xml | 6 +- 3 files changed, 57 insertions(+), 39 deletions(-) (limited to 'app') 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 - - for(int i=0; i < allButtonIDs.length; i++) { - String id = allButtonIDs[i]; - if(preferredButtons.contains(id)) { + 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_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(); - } + 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 { - 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"/>