diff --git a/app/src/main/java/com/github/libretube/ui/base/BasePreferenceFragment.kt b/app/src/main/java/com/github/libretube/ui/base/BasePreferenceFragment.kt index 78d7ff3ea..855256384 100644 --- a/app/src/main/java/com/github/libretube/ui/base/BasePreferenceFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/base/BasePreferenceFragment.kt @@ -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)