diff options
author | saqura <saqura@saqura.xyz> | 2016-04-03 00:32:55 +0200 |
---|---|---|
committer | saqura <saqura@saqura.xyz> | 2016-04-03 00:37:49 +0200 |
commit | 4d47ba640550714968fbb4e5c07ab913474db6c0 (patch) | |
tree | decea30e7c1129ad641149a85fac375942dd2567 /app/src/main | |
parent | 65bb7d9911acfc03cb2ef786c857ebcc5fb45677 (diff) | |
download | AntennaPod-4d47ba640550714968fbb4e5c07ab913474db6c0.zip |
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.
Diffstat (limited to 'app/src/main')
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java | 60 | ||||
-rw-r--r-- | app/src/main/res/xml/preferences.xml | 12 |
2 files changed, 64 insertions, 8 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<String> 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"/> - <com.afollestad.materialdialogs.prefs.MaterialMultiSelectListPreference - android:entries="@array/prioritised_notification_buttons_options" - android:entryValues="@array/prioritised_notification_buttons_values" - android:defaultValue="@array/prioritised_notification_buttons_default_values" - android:title="@string/pref_prioritised_notification_buttons_title" - android:key="prefPrioritisedNotificationButtons" - android:summary="@string/pref_prioritised_notification_buttons_sum" - app:useStockLayout="true"/> + <Preference + android:key="prefNotificationButtons" + android:summary="@string/pref_notification_buttons_sum" + android:title="@string/pref_notification_buttons_title"/> <de.danoeh.antennapod.preferences.SwitchCompatPreference android:defaultValue="true" android:enabled="true" |