User material3 dialog in 'mobile updates' setting (#6682)
This commit is contained in:
parent
c38b263458
commit
c732ecba8b
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -48,7 +48,7 @@
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
<PreferenceCategory android:title="@string/download_pref_details">
|
<PreferenceCategory android:title="@string/download_pref_details">
|
||||||
<MultiSelectListPreference
|
<de.danoeh.antennapod.preferences.MaterialMultiSelectListPreference
|
||||||
android:defaultValue="@array/mobile_update_default_value"
|
android:defaultValue="@array/mobile_update_default_value"
|
||||||
android:entries="@array/mobile_update_entries"
|
android:entries="@array/mobile_update_entries"
|
||||||
android:entryValues="@array/mobile_update_values"
|
android:entryValues="@array/mobile_update_values"
|
||||||
|
|
Loading…
Reference in New Issue