mirror of
https://github.com/Aviortheking/Neo-Store.git
synced 2025-04-23 19:32:16 +00:00
Add: ListPreference constructor
This commit is contained in:
parent
b41715a2f0
commit
311ddd584a
@ -318,6 +318,27 @@ class SettingsFragment : ScreenFragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun <T> LinearLayoutCompat.addList(
|
||||||
|
key: Preferences.Key<T>,
|
||||||
|
title: String,
|
||||||
|
values: List<T>,
|
||||||
|
valueToString: (T) -> String,
|
||||||
|
) {
|
||||||
|
addPreference(key, title, { valueToString(Preferences[key]) }) {
|
||||||
|
MaterialAlertDialogBuilder(it)
|
||||||
|
.setTitle(title)
|
||||||
|
.setSingleChoiceItems(
|
||||||
|
values.map(valueToString).toTypedArray(),
|
||||||
|
values.indexOf(Preferences[key])
|
||||||
|
) { dialog, which ->
|
||||||
|
dialog.dismiss()
|
||||||
|
post { Preferences[key] = values[which] }
|
||||||
|
}
|
||||||
|
.setNegativeButton(R.string.cancel, null)
|
||||||
|
.create()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private class Preference<T>(
|
private class Preference<T>(
|
||||||
private val key: Preferences.Key<T>,
|
private val key: Preferences.Key<T>,
|
||||||
fragment: Fragment,
|
fragment: Fragment,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user