From c732ecba8b27860713b65d12e2e43b13d8801701 Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Thu, 12 Oct 2023 18:13:55 +0200 Subject: [PATCH] User material3 dialog in 'mobile updates' setting (#6682) --- .../MaterialMultiSelectListPreference.java | 47 +++++++++++++++++++ .../main/res/xml/preferences_downloads.xml | 2 +- 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/de/danoeh/antennapod/preferences/MaterialMultiSelectListPreference.java 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 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 @@ -