summaryrefslogtreecommitdiff
path: root/app/src/main/java/de/danoeh/antennapod
diff options
context:
space:
mode:
authorsaqura <saqura@saqura.xyz>2016-04-03 00:32:55 +0200
committersaqura <saqura@saqura.xyz>2016-04-03 00:37:49 +0200
commit4d47ba640550714968fbb4e5c07ab913474db6c0 (patch)
treedecea30e7c1129ad641149a85fac375942dd2567 /app/src/main/java/de/danoeh/antennapod
parent65bb7d9911acfc03cb2ef786c857ebcc5fb45677 (diff)
downloadAntennaPod-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/java/de/danoeh/antennapod')
-rw-r--r--app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java60
1 files changed, 60 insertions, 0 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() {