Migrate ListPreference to Material Design 3
This commit is contained in:
parent
4513711981
commit
ef97411fbb
|
@ -409,7 +409,6 @@ public class PreferencesTest {
|
||||||
clickPreference(R.string.network_pref);
|
clickPreference(R.string.network_pref);
|
||||||
onView(withText(R.string.pref_automatic_download_title)).perform(click());
|
onView(withText(R.string.pref_automatic_download_title)).perform(click());
|
||||||
onView(withText(R.string.pref_episode_cleanup_title)).perform(click());
|
onView(withText(R.string.pref_episode_cleanup_title)).perform(click());
|
||||||
onView(withId(R.id.select_dialog_listview)).perform(swipeUp());
|
|
||||||
onView(withText(R.string.episode_cleanup_after_listening)).perform(click());
|
onView(withText(R.string.episode_cleanup_after_listening)).perform(click());
|
||||||
Awaitility.await().atMost(1000, MILLISECONDS)
|
Awaitility.await().atMost(1000, MILLISECONDS)
|
||||||
.until(() -> {
|
.until(() -> {
|
||||||
|
@ -455,7 +454,6 @@ public class PreferencesTest {
|
||||||
// Find next value (wrapping around to next)
|
// Find next value (wrapping around to next)
|
||||||
int newIndex = (currentIndex + 1) % deltas.length;
|
int newIndex = (currentIndex + 1) % deltas.length;
|
||||||
onView(withText(deltas[newIndex] + " seconds")).perform(click());
|
onView(withText(deltas[newIndex] + " seconds")).perform(click());
|
||||||
onView(withText("Confirm")).perform(click());
|
|
||||||
|
|
||||||
Awaitility.await().atMost(1000, MILLISECONDS)
|
Awaitility.await().atMost(1000, MILLISECONDS)
|
||||||
.until(() -> UserPreferences.getRewindSecs() == deltas[newIndex]);
|
.until(() -> UserPreferences.getRewindSecs() == deltas[newIndex]);
|
||||||
|
@ -477,7 +475,6 @@ public class PreferencesTest {
|
||||||
int newIndex = (currentIndex + 1) % deltas.length;
|
int newIndex = (currentIndex + 1) % deltas.length;
|
||||||
|
|
||||||
onView(withText(deltas[newIndex] + " seconds")).perform(click());
|
onView(withText(deltas[newIndex] + " seconds")).perform(click());
|
||||||
onView(withText("Confirm")).perform(click());
|
|
||||||
|
|
||||||
Awaitility.await().atMost(1000, MILLISECONDS)
|
Awaitility.await().atMost(1000, MILLISECONDS)
|
||||||
.until(() -> UserPreferences.getFastForwardSecs() == deltas[newIndex]);
|
.until(() -> UserPreferences.getFastForwardSecs() == deltas[newIndex]);
|
||||||
|
|
|
@ -37,9 +37,7 @@ public class SkipPreferenceDialog {
|
||||||
|
|
||||||
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(context);
|
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(context);
|
||||||
builder.setTitle(direction == SkipDirection.SKIP_FORWARD ? R.string.pref_fast_forward : R.string.pref_rewind);
|
builder.setTitle(direction == SkipDirection.SKIP_FORWARD ? R.string.pref_fast_forward : R.string.pref_rewind);
|
||||||
builder.setSingleChoiceItems(choices, checked, null);
|
builder.setSingleChoiceItems(choices, checked, (dialog, which) -> {
|
||||||
builder.setNegativeButton(R.string.cancel_label, null);
|
|
||||||
builder.setPositiveButton(R.string.confirm_label, (dialog, which) -> {
|
|
||||||
int choice = ((AlertDialog) dialog).getListView().getCheckedItemPosition();
|
int choice = ((AlertDialog) dialog).getListView().getCheckedItemPosition();
|
||||||
if (choice < 0 || choice >= values.length) {
|
if (choice < 0 || choice >= values.length) {
|
||||||
System.err.printf("Choice in showSkipPreference is out of bounds %d", choice);
|
System.err.printf("Choice in showSkipPreference is out of bounds %d", choice);
|
||||||
|
@ -53,9 +51,11 @@ public class SkipPreferenceDialog {
|
||||||
if (textView != null) {
|
if (textView != null) {
|
||||||
textView.setText(NumberFormat.getInstance().format(seconds));
|
textView.setText(NumberFormat.getInstance().format(seconds));
|
||||||
}
|
}
|
||||||
|
dialog.dismiss();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
builder.create().show();
|
builder.setNegativeButton(R.string.cancel_label, null);
|
||||||
|
builder.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum SkipDirection {
|
public enum SkipDirection {
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
package de.danoeh.antennapod.preferences;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import androidx.preference.ListPreference;
|
||||||
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||||
|
|
||||||
|
public class MaterialListPreference extends ListPreference {
|
||||||
|
|
||||||
|
public MaterialListPreference(Context context) {
|
||||||
|
super(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MaterialListPreference(Context context, AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onClick() {
|
||||||
|
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(getContext());
|
||||||
|
builder.setTitle(getTitle());
|
||||||
|
builder.setIcon(getDialogIcon());
|
||||||
|
builder.setNegativeButton(getNegativeButtonText(), null);
|
||||||
|
|
||||||
|
CharSequence[] values = getEntryValues();
|
||||||
|
int selected = -1;
|
||||||
|
for (int i = 0; i < values.length; i++) {
|
||||||
|
if (values[i].toString().equals(getValue())) {
|
||||||
|
selected = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
builder.setSingleChoiceItems(getEntries(), selected, (dialog, which) -> {
|
||||||
|
dialog.dismiss();
|
||||||
|
if (which >= 0 && getEntryValues() != null) {
|
||||||
|
String value = getEntryValues()[which].toString();
|
||||||
|
if (callChangeListener(value)) {
|
||||||
|
setValue(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
builder.show();
|
||||||
|
}
|
||||||
|
}
|
|
@ -40,7 +40,7 @@
|
||||||
android:summary="@string/pref_feed_skip_sum"
|
android:summary="@string/pref_feed_skip_sum"
|
||||||
android:title="@string/pref_feed_skip" />
|
android:title="@string/pref_feed_skip" />
|
||||||
|
|
||||||
<ListPreference
|
<de.danoeh.antennapod.preferences.MaterialListPreference
|
||||||
android:entries="@array/spnAutoDeleteItems"
|
android:entries="@array/spnAutoDeleteItems"
|
||||||
android:entryValues="@array/spnAutoDeleteValues"
|
android:entryValues="@array/spnAutoDeleteValues"
|
||||||
android:icon="@drawable/ic_delete"
|
android:icon="@drawable/ic_delete"
|
||||||
|
@ -48,7 +48,7 @@
|
||||||
android:summary="@string/feed_auto_download_global"
|
android:summary="@string/feed_auto_download_global"
|
||||||
android:title="@string/auto_delete_label" />
|
android:title="@string/auto_delete_label" />
|
||||||
|
|
||||||
<ListPreference
|
<de.danoeh.antennapod.preferences.MaterialListPreference
|
||||||
android:defaultValue="off"
|
android:defaultValue="off"
|
||||||
android:entries="@array/spnVolumeReductionItems"
|
android:entries="@array/spnVolumeReductionItems"
|
||||||
android:entryValues="@array/spnVolumeReductionValues"
|
android:entryValues="@array/spnVolumeReductionValues"
|
||||||
|
|
|
@ -8,14 +8,14 @@
|
||||||
android:title="@string/pref_automatic_download_title"
|
android:title="@string/pref_automatic_download_title"
|
||||||
search:summary="@string/pref_automatic_download_sum"
|
search:summary="@string/pref_automatic_download_sum"
|
||||||
android:defaultValue="false"/>
|
android:defaultValue="false"/>
|
||||||
<ListPreference
|
<de.danoeh.antennapod.preferences.MaterialListPreference
|
||||||
android:defaultValue="25"
|
android:defaultValue="25"
|
||||||
android:entries="@array/episode_cache_size_entries"
|
android:entries="@array/episode_cache_size_entries"
|
||||||
android:key="prefEpisodeCacheSize"
|
android:key="prefEpisodeCacheSize"
|
||||||
android:title="@string/pref_episode_cache_title"
|
android:title="@string/pref_episode_cache_title"
|
||||||
android:summary="@string/pref_episode_cache_summary"
|
android:summary="@string/pref_episode_cache_summary"
|
||||||
android:entryValues="@array/episode_cache_size_values"/>
|
android:entryValues="@array/episode_cache_size_values"/>
|
||||||
<ListPreference
|
<de.danoeh.antennapod.preferences.MaterialListPreference
|
||||||
android:defaultValue="-1"
|
android:defaultValue="-1"
|
||||||
android:entries="@array/episode_cleanup_entries"
|
android:entries="@array/episode_cleanup_entries"
|
||||||
android:key="prefEpisodeCleanup"
|
android:key="prefEpisodeCleanup"
|
||||||
|
|
|
@ -62,14 +62,14 @@
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
<PreferenceCategory android:title="@string/reassign_hardware_buttons">
|
<PreferenceCategory android:title="@string/reassign_hardware_buttons">
|
||||||
<ListPreference
|
<de.danoeh.antennapod.preferences.MaterialListPreference
|
||||||
android:defaultValue="@string/keycode_media_fast_forward"
|
android:defaultValue="@string/keycode_media_fast_forward"
|
||||||
android:entries="@array/button_action_options"
|
android:entries="@array/button_action_options"
|
||||||
android:entryValues="@array/button_action_values"
|
android:entryValues="@array/button_action_values"
|
||||||
android:key="prefHardwareForwardButton"
|
android:key="prefHardwareForwardButton"
|
||||||
android:title="@string/pref_hardware_forward_button_title"
|
android:title="@string/pref_hardware_forward_button_title"
|
||||||
android:summary="@string/pref_hardware_forward_button_summary"/>
|
android:summary="@string/pref_hardware_forward_button_summary"/>
|
||||||
<ListPreference
|
<de.danoeh.antennapod.preferences.MaterialListPreference
|
||||||
android:defaultValue="@string/keycode_media_rewind"
|
android:defaultValue="@string/keycode_media_rewind"
|
||||||
android:entries="@array/button_action_options"
|
android:entries="@array/button_action_options"
|
||||||
android:entryValues="@array/button_action_values"
|
android:entryValues="@array/button_action_values"
|
||||||
|
@ -85,7 +85,7 @@
|
||||||
android:key="prefEnqueueDownloaded"
|
android:key="prefEnqueueDownloaded"
|
||||||
android:summary="@string/pref_enqueue_downloaded_summary"
|
android:summary="@string/pref_enqueue_downloaded_summary"
|
||||||
android:title="@string/pref_enqueue_downloaded_title" />
|
android:title="@string/pref_enqueue_downloaded_title" />
|
||||||
<ListPreference
|
<de.danoeh.antennapod.preferences.MaterialListPreference
|
||||||
android:defaultValue="BACK"
|
android:defaultValue="BACK"
|
||||||
android:entries="@array/enqueue_location_options"
|
android:entries="@array/enqueue_location_options"
|
||||||
android:entryValues="@array/enqueue_location_values"
|
android:entryValues="@array/enqueue_location_values"
|
||||||
|
@ -97,7 +97,7 @@
|
||||||
android:key="prefFollowQueue"
|
android:key="prefFollowQueue"
|
||||||
android:summary="@string/pref_followQueue_sum"
|
android:summary="@string/pref_followQueue_sum"
|
||||||
android:title="@string/pref_followQueue_title"/>
|
android:title="@string/pref_followQueue_title"/>
|
||||||
<ListPreference
|
<de.danoeh.antennapod.preferences.MaterialListPreference
|
||||||
android:defaultValue="30"
|
android:defaultValue="30"
|
||||||
android:entries="@array/smart_mark_as_played_values"
|
android:entries="@array/smart_mark_as_played_values"
|
||||||
android:entryValues="@array/smart_mark_as_played_values"
|
android:entryValues="@array/smart_mark_as_played_values"
|
||||||
|
@ -113,7 +113,7 @@
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
<PreferenceCategory android:title="@string/experimental_pref">
|
<PreferenceCategory android:title="@string/experimental_pref">
|
||||||
<ListPreference
|
<de.danoeh.antennapod.preferences.MaterialListPreference
|
||||||
android:defaultValue="exoplayer"
|
android:defaultValue="exoplayer"
|
||||||
android:entries="@array/media_player_options"
|
android:entries="@array/media_player_options"
|
||||||
android:key="prefMediaPlayer"
|
android:key="prefMediaPlayer"
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
xmlns:search="http://schemas.android.com/apk/com.bytehamster.lib.preferencesearch">
|
xmlns:search="http://schemas.android.com/apk/com.bytehamster.lib.preferencesearch">
|
||||||
|
|
||||||
<PreferenceCategory android:title="@string/appearance">
|
<PreferenceCategory android:title="@string/appearance">
|
||||||
<ListPreference
|
<de.danoeh.antennapod.preferences.MaterialListPreference
|
||||||
android:entryValues="@array/theme_values"
|
android:entryValues="@array/theme_values"
|
||||||
android:entries="@array/theme_options"
|
android:entries="@array/theme_options"
|
||||||
android:title="@string/pref_set_theme_title"
|
android:title="@string/pref_set_theme_title"
|
||||||
|
@ -33,7 +33,7 @@
|
||||||
android:title="@string/pref_nav_drawer_feed_order_title"
|
android:title="@string/pref_nav_drawer_feed_order_title"
|
||||||
android:key="prefDrawerFeedOrder"
|
android:key="prefDrawerFeedOrder"
|
||||||
android:summary="@string/pref_nav_drawer_feed_order_sum"/>
|
android:summary="@string/pref_nav_drawer_feed_order_sum"/>
|
||||||
<ListPreference
|
<de.danoeh.antennapod.preferences.MaterialListPreference
|
||||||
android:entryValues="@array/nav_drawer_feed_counter_values"
|
android:entryValues="@array/nav_drawer_feed_counter_values"
|
||||||
android:entries="@array/nav_drawer_feed_counter_options"
|
android:entries="@array/nav_drawer_feed_counter_options"
|
||||||
android:title="@string/pref_nav_drawer_feed_counter_title"
|
android:title="@string/pref_nav_drawer_feed_counter_title"
|
||||||
|
@ -76,7 +76,7 @@
|
||||||
android:title="@string/pref_lockscreen_background_title"/>
|
android:title="@string/pref_lockscreen_background_title"/>
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
<PreferenceCategory android:title="@string/behavior">
|
<PreferenceCategory android:title="@string/behavior">
|
||||||
<ListPreference
|
<de.danoeh.antennapod.preferences.MaterialListPreference
|
||||||
android:entryValues="@array/default_page_values"
|
android:entryValues="@array/default_page_values"
|
||||||
android:entries="@array/default_page_titles"
|
android:entries="@array/default_page_titles"
|
||||||
android:key="prefDefaultPage"
|
android:key="prefDefaultPage"
|
||||||
|
|
Loading…
Reference in New Issue