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.
This commit is contained in:
parent
65bb7d9911
commit
4d47ba6405
@ -6,6 +6,7 @@ import android.app.Activity;
|
|||||||
import android.app.TimePickerDialog;
|
import android.app.TimePickerDialog;
|
||||||
import android.content.ActivityNotFoundException;
|
import android.content.ActivityNotFoundException;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
@ -221,6 +222,12 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc
|
|||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ui.findPreference(UserPreferences.PREF_NOTIFICATION_BUTTONS)
|
||||||
|
.setOnPreferenceClickListener(preference -> {
|
||||||
|
showNotificationButtonsDialog();
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
ui.findPreference(UserPreferences.PREF_UPDATE_INTERVAL)
|
ui.findPreference(UserPreferences.PREF_UPDATE_INTERVAL)
|
||||||
.setOnPreferenceClickListener(preference -> {
|
.setOnPreferenceClickListener(preference -> {
|
||||||
showUpdateIntervalTimePreferencesDialog();
|
showUpdateIntervalTimePreferencesDialog();
|
||||||
@ -735,6 +742,59 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc
|
|||||||
builder.create().show();
|
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
|
// CHOOSE DATA FOLDER
|
||||||
|
|
||||||
private void requestPermission() {
|
private void requestPermission() {
|
||||||
|
@ -55,14 +55,10 @@
|
|||||||
android:key="prefPersistNotify"
|
android:key="prefPersistNotify"
|
||||||
android:summary="@string/pref_persistNotify_sum"
|
android:summary="@string/pref_persistNotify_sum"
|
||||||
android:title="@string/pref_persistNotify_title"/>
|
android:title="@string/pref_persistNotify_title"/>
|
||||||
<com.afollestad.materialdialogs.prefs.MaterialMultiSelectListPreference
|
<Preference
|
||||||
android:entries="@array/prioritised_notification_buttons_options"
|
android:key="prefNotificationButtons"
|
||||||
android:entryValues="@array/prioritised_notification_buttons_values"
|
android:summary="@string/pref_notification_buttons_sum"
|
||||||
android:defaultValue="@array/prioritised_notification_buttons_default_values"
|
android:title="@string/pref_notification_buttons_title"/>
|
||||||
android:title="@string/pref_prioritised_notification_buttons_title"
|
|
||||||
android:key="prefPrioritisedNotificationButtons"
|
|
||||||
android:summary="@string/pref_prioritised_notification_buttons_sum"
|
|
||||||
app:useStockLayout="true"/>
|
|
||||||
<de.danoeh.antennapod.preferences.SwitchCompatPreference
|
<de.danoeh.antennapod.preferences.SwitchCompatPreference
|
||||||
android:defaultValue="true"
|
android:defaultValue="true"
|
||||||
android:enabled="true"
|
android:enabled="true"
|
||||||
|
@ -38,7 +38,7 @@ subprojects {
|
|||||||
project.ext {
|
project.ext {
|
||||||
compileSdkVersion = 23
|
compileSdkVersion = 23
|
||||||
buildToolsVersion = "23.0.2"
|
buildToolsVersion = "23.0.2"
|
||||||
minSdkVersion = 11
|
minSdkVersion = 10
|
||||||
targetSdkVersion = 23
|
targetSdkVersion = 23
|
||||||
|
|
||||||
supportVersion = "23.2.1"
|
supportVersion = "23.2.1"
|
||||||
|
@ -22,7 +22,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import de.danoeh.antennapod.core.R;
|
import de.danoeh.antennapod.core.R;
|
||||||
@ -53,7 +52,7 @@ public class UserPreferences {
|
|||||||
public static final String PREF_DRAWER_FEED_COUNTER = "prefDrawerFeedIndicator";
|
public static final String PREF_DRAWER_FEED_COUNTER = "prefDrawerFeedIndicator";
|
||||||
public static final String PREF_EXPANDED_NOTIFICATION = "prefExpandNotify";
|
public static final String PREF_EXPANDED_NOTIFICATION = "prefExpandNotify";
|
||||||
public static final String PREF_PERSISTENT_NOTIFICATION = "prefPersistNotify";
|
public static final String PREF_PERSISTENT_NOTIFICATION = "prefPersistNotify";
|
||||||
public static final String PREF_PRIORITISED_NOTIFICATION_BUTTONS = "prefPrioritisedNotificationButtons";
|
public static final String PREF_NOTIFICATION_BUTTONS = "prefNotificationButtons";
|
||||||
public static final String PREF_LOCKSCREEN_BACKGROUND = "prefLockscreenBackground";
|
public static final String PREF_LOCKSCREEN_BACKGROUND = "prefLockscreenBackground";
|
||||||
public static final String PREF_SHOW_DOWNLOAD_REPORT = "prefShowDownloadReport";
|
public static final String PREF_SHOW_DOWNLOAD_REPORT = "prefShowDownloadReport";
|
||||||
public static final String PREF_SHOW_SUBSCRIPTIONS_IN_DRAWER = "prefShowSubscriptionsInDrawer";
|
public static final String PREF_SHOW_SUBSCRIPTIONS_IN_DRAWER = "prefShowSubscriptionsInDrawer";
|
||||||
@ -168,6 +167,11 @@ public class UserPreferences {
|
|||||||
return new ArrayList<>(Arrays.asList(TextUtils.split(hiddenItems, ",")));
|
return new ArrayList<>(Arrays.asList(TextUtils.split(hiddenItems, ",")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<String> getNotificationButtons() {
|
||||||
|
String hiddenItems = prefs.getString(PREF_NOTIFICATION_BUTTONS, "skip");
|
||||||
|
return new ArrayList<>(Arrays.asList(TextUtils.split(hiddenItems, ",")));
|
||||||
|
}
|
||||||
|
|
||||||
public static int getFeedOrder() {
|
public static int getFeedOrder() {
|
||||||
String value = prefs.getString(PREF_DRAWER_FEED_ORDER, "0");
|
String value = prefs.getString(PREF_DRAWER_FEED_ORDER, "0");
|
||||||
return Integer.parseInt(value);
|
return Integer.parseInt(value);
|
||||||
@ -182,10 +186,6 @@ public class UserPreferences {
|
|||||||
return prefs.getBoolean(PREF_SHOW_SUBSCRIPTIONS_IN_DRAWER, true);
|
return prefs.getBoolean(PREF_SHOW_SUBSCRIPTIONS_IN_DRAWER, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Set<String> getPrioritisedNotificationButtons() {
|
|
||||||
return prefs.getStringSet(PREF_PRIORITISED_NOTIFICATION_BUTTONS, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns notification priority.
|
* Returns notification priority.
|
||||||
*
|
*
|
||||||
@ -533,6 +533,13 @@ public class UserPreferences {
|
|||||||
.apply();
|
.apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setNotificationButtons(List<String> items) {
|
||||||
|
String str = TextUtils.join(",", items);
|
||||||
|
prefs.edit()
|
||||||
|
.putString(PREF_NOTIFICATION_BUTTONS, str)
|
||||||
|
.apply();
|
||||||
|
}
|
||||||
|
|
||||||
public static void setQueueLocked(boolean locked) {
|
public static void setQueueLocked(boolean locked) {
|
||||||
prefs.edit()
|
prefs.edit()
|
||||||
.putBoolean(PREF_QUEUE_LOCKED, locked)
|
.putBoolean(PREF_QUEUE_LOCKED, locked)
|
||||||
|
@ -30,7 +30,6 @@ import android.widget.Toast;
|
|||||||
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.Glide;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import de.danoeh.antennapod.core.ClientConfig;
|
import de.danoeh.antennapod.core.ClientConfig;
|
||||||
import de.danoeh.antennapod.core.R;
|
import de.danoeh.antennapod.core.R;
|
||||||
@ -859,7 +858,7 @@ public class PlaybackService extends Service {
|
|||||||
.setPriority(UserPreferences.getNotifyPriority()); // set notification priority
|
.setPriority(UserPreferences.getNotifyPriority()); // set notification priority
|
||||||
IntList compactActionList = new IntList();
|
IntList compactActionList = new IntList();
|
||||||
|
|
||||||
Set<String> prioritisedButtons = UserPreferences.getPrioritisedNotificationButtons();
|
final List<String> notificationButtons = UserPreferences.getNotificationButtons();
|
||||||
int numActions = 0; // we start and 0 and then increment by 1 for each call to addAction
|
int numActions = 0; // we start and 0 and then increment by 1 for each call to addAction
|
||||||
|
|
||||||
// always let them rewind
|
// always let them rewind
|
||||||
@ -868,7 +867,7 @@ public class PlaybackService extends Service {
|
|||||||
notificationBuilder.addAction(android.R.drawable.ic_media_rew,
|
notificationBuilder.addAction(android.R.drawable.ic_media_rew,
|
||||||
getString(R.string.rewind_label),
|
getString(R.string.rewind_label),
|
||||||
rewindButtonPendingIntent);
|
rewindButtonPendingIntent);
|
||||||
if(prioritisedButtons.contains("0")) {
|
if(notificationButtons.contains("rewind")) {
|
||||||
// show the rewind button even on the lock screen
|
// show the rewind button even on the lock screen
|
||||||
compactActionList.add(numActions++);
|
compactActionList.add(numActions++);
|
||||||
} else {
|
} else {
|
||||||
@ -898,7 +897,7 @@ public class PlaybackService extends Service {
|
|||||||
notificationBuilder.addAction(android.R.drawable.ic_media_ff,
|
notificationBuilder.addAction(android.R.drawable.ic_media_ff,
|
||||||
getString(R.string.fast_forward_label),
|
getString(R.string.fast_forward_label),
|
||||||
ffButtonPendingIntent);
|
ffButtonPendingIntent);
|
||||||
if(prioritisedButtons.contains("1")) {
|
if(notificationButtons.contains("fastforward")) {
|
||||||
// show the fast forward button even on the lock screen
|
// show the fast forward button even on the lock screen
|
||||||
compactActionList.add(numActions++);
|
compactActionList.add(numActions++);
|
||||||
} else {
|
} else {
|
||||||
@ -911,7 +910,7 @@ public class PlaybackService extends Service {
|
|||||||
notificationBuilder.addAction(android.R.drawable.ic_media_next,
|
notificationBuilder.addAction(android.R.drawable.ic_media_next,
|
||||||
getString(R.string.skip_episode_label),
|
getString(R.string.skip_episode_label),
|
||||||
skipButtonPendingIntent);
|
skipButtonPendingIntent);
|
||||||
if(prioritisedButtons.contains("2")) {
|
if(notificationButtons.contains("skip")) {
|
||||||
// show the skip button even on the lock screen
|
// show the skip button even on the lock screen
|
||||||
compactActionList.add(numActions++);
|
compactActionList.add(numActions++);
|
||||||
} else {
|
} else {
|
||||||
|
@ -212,18 +212,18 @@
|
|||||||
<item>500</item>
|
<item>500</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
<string-array name="prioritised_notification_buttons_options">
|
<string-array name="notification_buttons_options">
|
||||||
<item>@string/rewind_label</item>
|
<item>@string/rewind_label</item>
|
||||||
<item>@string/fast_forward_label</item>
|
<item>@string/fast_forward_label</item>
|
||||||
<item>@string/skip_episode_label</item>
|
<item>@string/skip_episode_label</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
<string-array name="prioritised_notification_buttons_values">
|
<string-array name="notification_buttons_values">
|
||||||
<item>0</item>
|
<item>rewind</item>
|
||||||
<item>1</item>
|
<item>fastforward</item>
|
||||||
<item>2</item>
|
<item>skip</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
<string-array name="prioritised_notification_buttons_default_values">
|
<string-array name="notification_buttons_default_values">
|
||||||
<item>2</item>
|
<item>skip</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -384,8 +384,10 @@
|
|||||||
<string name="pref_expandNotify_sum">Always expand the notification to show playback buttons.</string>
|
<string name="pref_expandNotify_sum">Always expand the notification to show playback buttons.</string>
|
||||||
<string name="pref_persistNotify_title">Persistent Playback Controls</string>
|
<string name="pref_persistNotify_title">Persistent Playback Controls</string>
|
||||||
<string name="pref_persistNotify_sum">Keep notification and lockscreen controls when playback is paused.</string>
|
<string name="pref_persistNotify_sum">Keep notification and lockscreen controls when playback is paused.</string>
|
||||||
<string name="pref_prioritised_notification_buttons_title">Prioritise Notification Buttons</string>
|
<string name="pref_notification_buttons_title">Select Notification Buttons</string>
|
||||||
<string name="pref_prioritised_notification_buttons_sum">Change the playback buttons on the lock screen notification.</string>
|
<string name="pref_notification_buttons_sum">Change the playback buttons on the lock screen notification.</string>
|
||||||
|
<string name="pref_notification_buttons_dialog_title">Select a maximum of %1$d items</string>
|
||||||
|
<string name="pref_notification_buttons_dialog_error">You can only select a maximum of %1$d items.</string>
|
||||||
<string name="pref_show_subscriptions_in_drawer_title">Show Subscriptions</string>
|
<string name="pref_show_subscriptions_in_drawer_title">Show Subscriptions</string>
|
||||||
<string name="pref_show_subscriptions_in_drawer_sum">Show subscription list directly in navigation drawer</string>
|
<string name="pref_show_subscriptions_in_drawer_sum">Show subscription list directly in navigation drawer</string>
|
||||||
<string name="pref_lockscreen_background_title">Set Lockscreen Background</string>
|
<string name="pref_lockscreen_background_title">Set Lockscreen Background</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user