mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-01-07 10:00:31 +05:30
Add material 3 appearance to MultiSelectListPreference
This commit is contained in:
parent
dca3eb4b5e
commit
2f9e632ae2
@ -2,6 +2,7 @@ package com.github.libretube.ui.base
|
|||||||
|
|
||||||
import androidx.preference.EditTextPreference
|
import androidx.preference.EditTextPreference
|
||||||
import androidx.preference.ListPreference
|
import androidx.preference.ListPreference
|
||||||
|
import androidx.preference.MultiSelectListPreference
|
||||||
import androidx.preference.Preference
|
import androidx.preference.Preference
|
||||||
import androidx.preference.PreferenceFragmentCompat
|
import androidx.preference.PreferenceFragmentCompat
|
||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
@ -42,6 +43,24 @@ abstract class BasePreferenceFragment : PreferenceFragmentCompat() {
|
|||||||
.setNegativeButton(R.string.cancel, null)
|
.setNegativeButton(R.string.cancel, null)
|
||||||
.show()
|
.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 -> {
|
is EditTextPreference -> {
|
||||||
val binding = DialogTextPreferenceBinding.inflate(layoutInflater)
|
val binding = DialogTextPreferenceBinding.inflate(layoutInflater)
|
||||||
binding.input.setText(preference.text)
|
binding.input.setText(preference.text)
|
||||||
|
Loading…
Reference in New Issue
Block a user