Add material 3 appearance to MultiSelectListPreference

This commit is contained in:
Bnyro 2023-05-31 21:54:23 +02:00
parent dca3eb4b5e
commit 2f9e632ae2

View File

@ -2,6 +2,7 @@ package com.github.libretube.ui.base
import androidx.preference.EditTextPreference
import androidx.preference.ListPreference
import androidx.preference.MultiSelectListPreference
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import com.github.libretube.R
@ -42,6 +43,24 @@ abstract class BasePreferenceFragment : PreferenceFragmentCompat() {
.setNegativeButton(R.string.cancel, null)
.show()
}
is MultiSelectListPreference -> {
val selectedItems = preference.entryValues.map {
preference.values.contains(it)
}.toBooleanArray()
MaterialAlertDialogBuilder(requireContext())
.setTitle(preference.title)
.setMultiChoiceItems(preference.entries, selectedItems) { dialog, _, _ ->
val newValues = preference.entryValues
.filterIndexed { index, _ -> selectedItems[index] }
.map { it.toString() }
.toMutableSet()
if (preference.callChangeListener(newValues)) {
preference.values = newValues
}
}
.setNegativeButton(R.string.cancel, null)
.show()
}
is EditTextPreference -> {
val binding = DialogTextPreferenceBinding.inflate(layoutInflater)
binding.input.setText(preference.text)