Merge pull request #1843 from saqura/develop
Optionally show rewind/forward buttons on the lockscreen
This commit is contained in:
commit
ab88df91ba
|
@ -90,6 +90,30 @@ public class PreferencesTest extends ActivityInstrumentationTestCase2<Preference
|
||||||
assertTrue(solo.waitForCondition(() -> persistNotify == UserPreferences.isPersistNotify(), Timeout.getLargeTimeout()));
|
assertTrue(solo.waitForCondition(() -> 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<buttons.length; i++) {
|
||||||
|
assertTrue(solo.searchText(buttons[i]));
|
||||||
|
if (solo.isTextChecked(buttons[i])) {
|
||||||
|
solo.clickOnText(buttons[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Now try to check all checkboxes
|
||||||
|
solo.clickOnText(buttons[0]);
|
||||||
|
solo.clickOnText(buttons[1]);
|
||||||
|
solo.clickOnText(buttons[2]);
|
||||||
|
// Make sure that the third checkbox is unchecked
|
||||||
|
assertTrue(!solo.isTextChecked(buttons[2]));
|
||||||
|
solo.clickOnText(solo.getString(R.string.confirm_label));
|
||||||
|
solo.waitForDialogToClose(1000);
|
||||||
|
assertTrue(solo.waitForCondition(() -> UserPreferences.showRewindOnCompactNotification(), Timeout.getLargeTimeout()));
|
||||||
|
assertTrue(solo.waitForCondition(() -> UserPreferences.showFastForwardOnCompactNotification(), Timeout.getLargeTimeout()));
|
||||||
|
assertTrue(solo.waitForCondition(() -> !UserPreferences.showSkipOnCompactNotification(), Timeout.getLargeTimeout()));
|
||||||
|
}
|
||||||
|
|
||||||
public void testEnqueueAtFront() {
|
public void testEnqueueAtFront() {
|
||||||
final boolean enqueueAtFront = UserPreferences.enqueueAtFront();
|
final boolean enqueueAtFront = UserPreferences.enqueueAtFront();
|
||||||
solo.clickOnText(solo.getString(R.string.pref_queueAddToFront_title));
|
solo.clickOnText(solo.getString(R.string.pref_queueAddToFront_title));
|
||||||
|
|
|
@ -20,6 +20,7 @@ import android.preference.ListPreference;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.preference.PreferenceScreen;
|
import android.preference.PreferenceScreen;
|
||||||
|
import android.support.design.widget.Snackbar;
|
||||||
import android.support.v4.app.ActivityCompat;
|
import android.support.v4.app.ActivityCompat;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
|
@ -30,6 +31,7 @@ import android.text.format.DateFormat;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
import android.widget.ListView;
|
||||||
|
|
||||||
import com.afollestad.materialdialogs.MaterialDialog;
|
import com.afollestad.materialdialogs.MaterialDialog;
|
||||||
|
|
||||||
|
@ -221,6 +223,12 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ui.findPreference(UserPreferences.PREF_COMPACT_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 +743,52 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc
|
||||||
builder.create().show();
|
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
|
// CHOOSE DATA FOLDER
|
||||||
|
|
||||||
private void requestPermission() {
|
private void requestPermission() {
|
||||||
|
|
|
@ -49,6 +49,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"/>
|
||||||
|
<Preference
|
||||||
|
android:key="prefCompactNotificationButtons"
|
||||||
|
android:summary="@string/pref_compact_notification_buttons_sum"
|
||||||
|
android:title="@string/pref_compact_notification_buttons_title"/>
|
||||||
<de.danoeh.antennapod.preferences.SwitchCompatPreference
|
<de.danoeh.antennapod.preferences.SwitchCompatPreference
|
||||||
android:defaultValue="true"
|
android:defaultValue="true"
|
||||||
android:enabled="true"
|
android:enabled="true"
|
||||||
|
|
|
@ -52,6 +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_COMPACT_NOTIFICATION_BUTTONS = "prefCompactNotificationButtons";
|
||||||
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";
|
||||||
|
|
||||||
|
@ -115,6 +116,9 @@ public class UserPreferences {
|
||||||
public static final int EPISODE_CLEANUP_DEFAULT = 0;
|
public static final int EPISODE_CLEANUP_DEFAULT = 0;
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
|
private static final int NOTIFICATION_BUTTON_REWIND = 0;
|
||||||
|
private static final int NOTIFICATION_BUTTON_FAST_FORWARD = 1;
|
||||||
|
private static final int NOTIFICATION_BUTTON_SKIP = 2;
|
||||||
private static int EPISODE_CACHE_SIZE_UNLIMITED = -1;
|
private static int EPISODE_CACHE_SIZE_UNLIMITED = -1;
|
||||||
public static int FEED_ORDER_COUNTER = 0;
|
public static int FEED_ORDER_COUNTER = 0;
|
||||||
public static int FEED_ORDER_ALPHABETICAL = 1;
|
public static int FEED_ORDER_ALPHABETICAL = 1;
|
||||||
|
@ -165,6 +169,42 @@ public class UserPreferences {
|
||||||
return new ArrayList<>(Arrays.asList(TextUtils.split(hiddenItems, ",")));
|
return new ArrayList<>(Arrays.asList(TextUtils.split(hiddenItems, ",")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<Integer> getCompactNotificationButtons() {
|
||||||
|
String[] buttons = TextUtils.split(
|
||||||
|
prefs.getString(PREF_COMPACT_NOTIFICATION_BUTTONS,
|
||||||
|
String.valueOf(NOTIFICATION_BUTTON_SKIP)),
|
||||||
|
",");
|
||||||
|
List<Integer> notificationButtons = new ArrayList<>();
|
||||||
|
for (int i=0; i<buttons.length; i++) {
|
||||||
|
notificationButtons.add(Integer.parseInt(buttons[i]));
|
||||||
|
}
|
||||||
|
return notificationButtons;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function to return whether the specified button should be shown on compact
|
||||||
|
* notifications.
|
||||||
|
*
|
||||||
|
* @param buttonId Either NOTIFICATION_BUTTON_REWIND, NOTIFICATION_BUTTON_FAST_FORWARD or
|
||||||
|
* NOTIFICATION_BUTTON_SKIP.
|
||||||
|
* @return {@code true} if button should be shown, {@code false} otherwise
|
||||||
|
*/
|
||||||
|
private static boolean showButtonOnCompactNotification(int buttonId) {
|
||||||
|
return getCompactNotificationButtons().contains(buttonId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean showRewindOnCompactNotification() {
|
||||||
|
return showButtonOnCompactNotification(NOTIFICATION_BUTTON_REWIND);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean showFastForwardOnCompactNotification() {
|
||||||
|
return showButtonOnCompactNotification(NOTIFICATION_BUTTON_FAST_FORWARD);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean showSkipOnCompactNotification() {
|
||||||
|
return showButtonOnCompactNotification(NOTIFICATION_BUTTON_SKIP);
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
@ -198,9 +238,9 @@ public class UserPreferences {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if notifications are persistent
|
* Returns true if the lockscreen background should be set to the current episode's image
|
||||||
*
|
*
|
||||||
* @return {@code true} if notifications are persistent, {@code false} otherwise
|
* @return {@code true} if the lockscreen background should be set, {@code false} otherwise
|
||||||
*/
|
*/
|
||||||
public static boolean setLockscreenBackground() {
|
public static boolean setLockscreenBackground() {
|
||||||
return prefs.getBoolean(PREF_LOCKSCREEN_BACKGROUND, true);
|
return prefs.getBoolean(PREF_LOCKSCREEN_BACKGROUND, true);
|
||||||
|
@ -512,6 +552,13 @@ public class UserPreferences {
|
||||||
.apply();
|
.apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setCompactNotificationButtons(List<Integer> items) {
|
||||||
|
String str = TextUtils.join(",", items);
|
||||||
|
prefs.edit()
|
||||||
|
.putString(PREF_COMPACT_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)
|
||||||
|
|
|
@ -858,7 +858,6 @@ 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();
|
||||||
|
|
||||||
|
|
||||||
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
|
||||||
|
@ -867,6 +866,9 @@ 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(UserPreferences.showRewindOnCompactNotification()) {
|
||||||
|
compactActionList.add(numActions);
|
||||||
|
}
|
||||||
numActions++;
|
numActions++;
|
||||||
|
|
||||||
if (playerStatus == PlayerStatus.PLAYING) {
|
if (playerStatus == PlayerStatus.PLAYING) {
|
||||||
|
@ -891,6 +893,9 @@ 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(UserPreferences.showFastForwardOnCompactNotification()) {
|
||||||
|
compactActionList.add(numActions);
|
||||||
|
}
|
||||||
numActions++;
|
numActions++;
|
||||||
|
|
||||||
if (UserPreferences.isFollowQueue()) {
|
if (UserPreferences.isFollowQueue()) {
|
||||||
|
@ -899,7 +904,10 @@ 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);
|
||||||
compactActionList.add(numActions++);
|
if(UserPreferences.showSkipOnCompactNotification()) {
|
||||||
|
compactActionList.add(numActions);
|
||||||
|
}
|
||||||
|
numActions++;
|
||||||
}
|
}
|
||||||
|
|
||||||
PendingIntent stopButtonPendingIntent = getPendingIntentForMediaAction(
|
PendingIntent stopButtonPendingIntent = getPendingIntentForMediaAction(
|
||||||
|
|
|
@ -213,4 +213,9 @@
|
||||||
<item>500</item>
|
<item>500</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="compact_notification_buttons_options">
|
||||||
|
<item>@string/rewind_label</item>
|
||||||
|
<item>@string/fast_forward_label</item>
|
||||||
|
<item>@string/skip_episode_label</item>
|
||||||
|
</string-array>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -374,6 +374,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_compact_notification_buttons_title">Set Lockscreen Buttons</string>
|
||||||
|
<string name="pref_compact_notification_buttons_sum">Change the playback buttons on the lockscreen. The play/pause button is always included.</string>
|
||||||
|
<string name="pref_compact_notification_buttons_dialog_title">Select a maximum of %1$d items</string>
|
||||||
|
<string name="pref_compact_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…
Reference in New Issue