diff options
author | ByteHamster <ByteHamster@users.noreply.github.com> | 2023-10-12 18:13:55 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-12 18:13:55 +0200 |
commit | c732ecba8b27860713b65d12e2e43b13d8801701 (patch) | |
tree | 3093cf2629509b173e26153759ec958a66739123 /app/src/main | |
parent | c38b2634582d74fe3a7c7a4273cac8750dbc7e7d (diff) | |
download | AntennaPod-c732ecba8b27860713b65d12e2e43b13d8801701.zip |
User material3 dialog in 'mobile updates' setting (#6682)
Diffstat (limited to 'app/src/main')
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/preferences/MaterialMultiSelectListPreference.java | 47 | ||||
-rw-r--r-- | app/src/main/res/xml/preferences_downloads.xml | 2 |
2 files changed, 48 insertions, 1 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/preferences/MaterialMultiSelectListPreference.java b/app/src/main/java/de/danoeh/antennapod/preferences/MaterialMultiSelectListPreference.java new file mode 100644 index 000000000..9bc148bc6 --- /dev/null +++ b/app/src/main/java/de/danoeh/antennapod/preferences/MaterialMultiSelectListPreference.java @@ -0,0 +1,47 @@ +package de.danoeh.antennapod.preferences; + +import android.content.Context; +import android.content.DialogInterface; +import android.util.AttributeSet; +import androidx.preference.MultiSelectListPreference; +import com.google.android.material.dialog.MaterialAlertDialogBuilder; + +import java.util.HashSet; +import java.util.Set; + +public class MaterialMultiSelectListPreference extends MultiSelectListPreference { + + public MaterialMultiSelectListPreference(Context context) { + super(context); + } + + public MaterialMultiSelectListPreference(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); + + boolean[] selected = new boolean[getEntries().length]; + CharSequence[] values = getEntryValues(); + for (int i = 0; i < values.length; i++) { + selected[i] = getValues().contains(values[i].toString()); + } + builder.setMultiChoiceItems(getEntries(), selected, + (DialogInterface dialog, int which, boolean isChecked) -> selected[which] = isChecked); + builder.setPositiveButton(android.R.string.ok, (dialog, which) -> { + Set<String> selectedValues = new HashSet<>(); + for (int i = 0; i < values.length; i++) { + if (selected[i]) { + selectedValues.add(getEntryValues()[i].toString()); + } + } + setValues(selectedValues); + }); + builder.show(); + } +} diff --git a/app/src/main/res/xml/preferences_downloads.xml b/app/src/main/res/xml/preferences_downloads.xml index 18fc7df11..e1a1b9b00 100644 --- a/app/src/main/res/xml/preferences_downloads.xml +++ b/app/src/main/res/xml/preferences_downloads.xml @@ -48,7 +48,7 @@ </PreferenceCategory> <PreferenceCategory android:title="@string/download_pref_details"> - <MultiSelectListPreference + <de.danoeh.antennapod.preferences.MaterialMultiSelectListPreference android:defaultValue="@array/mobile_update_default_value" android:entries="@array/mobile_update_entries" android:entryValues="@array/mobile_update_values" |