diff options
author | Tom Hennen <TomHennen@users.noreply.github.com> | 2016-04-04 19:20:14 -0400 |
---|---|---|
committer | Tom Hennen <TomHennen@users.noreply.github.com> | 2016-04-04 19:20:14 -0400 |
commit | ab88df91bac8e58343933aba50fcad545a60d096 (patch) | |
tree | ab9117992294ef0da01fe805a1a078c1664c12e4 /app/src/main/java | |
parent | e75ab9c1fa18817761491660819c7515cf8cbc36 (diff) | |
parent | e3408565dcc15cd97548b664773bc684dca4edeb (diff) | |
download | AntennaPod-ab88df91bac8e58343933aba50fcad545a60d096.zip |
Merge pull request #1843 from saqura/develop
Optionally show rewind/forward buttons on the lockscreen
Diffstat (limited to 'app/src/main/java')
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java | 54 |
1 files changed, 54 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..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<Integer> 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() { |