commit de1a676084eaf25f94a674e1c4db7444530d6744
parent c12ba73f28b6f161d61c6a12f241ff7bedbdf27a
Author: rhunk <101876869+rhunk@users.noreply.github.com>
Date: Fri, 26 May 2023 20:46:04 +0200
config: unique selection value
Diffstat:
3 files changed, 58 insertions(+), 0 deletions(-)
diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/config/ConfigAccessor.kt b/app/src/main/kotlin/me/rhunk/snapenhance/config/ConfigAccessor.kt
@@ -44,6 +44,10 @@ open class ConfigAccessor(
return get(key).value() as Map<String, Boolean>
}
+ fun state(key: ConfigProperty): String {
+ return get(key).value() as String
+ }
+
fun get(key: ConfigProperty): ConfigValue<*> {
return configMap[key]!!
}
diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/config/impl/ConfigStateSelection.kt b/app/src/main/kotlin/me/rhunk/snapenhance/config/impl/ConfigStateSelection.kt
@@ -0,0 +1,28 @@
+package me.rhunk.snapenhance.config.impl
+
+import me.rhunk.snapenhance.config.ConfigValue
+
+class ConfigStateSelection(
+ private val keys: List<String>,
+ var state: String = ""
+) : ConfigValue<String>() {
+
+ fun keys(): List<String> {
+ return keys
+ }
+ override fun value(): String {
+ return state
+ }
+
+ fun value(key: String) {
+ state = key
+ }
+
+ override fun write(): String {
+ return state
+ }
+
+ override fun read(value: String) {
+ state = value
+ }
+}+
\ No newline at end of file
diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/features/impl/ui/menus/impl/SettingsMenu.kt b/app/src/main/kotlin/me/rhunk/snapenhance/features/impl/ui/menus/impl/SettingsMenu.kt
@@ -13,6 +13,7 @@ import me.rhunk.snapenhance.Constants
import me.rhunk.snapenhance.config.ConfigProperty
import me.rhunk.snapenhance.config.impl.ConfigIntegerValue
import me.rhunk.snapenhance.config.impl.ConfigStateListValue
+import me.rhunk.snapenhance.config.impl.ConfigStateSelection
import me.rhunk.snapenhance.config.impl.ConfigStateValue
import me.rhunk.snapenhance.config.impl.ConfigStringValue
import me.rhunk.snapenhance.features.impl.ui.menus.AbstractMenu
@@ -89,6 +90,30 @@ class SettingsMenu : AbstractMenu() {
ViewAppearanceHelper.applyTheme(viewModel, switch)
switch
}
+ is ConfigStateSelection -> {
+ val button = Button(viewModel.context)
+ updateButtonText(button, property.valueContainer.value())
+
+ button.setOnClickListener {_ ->
+ val builder = AlertDialog.Builder(viewModel.context)
+ builder.setTitle(context.translation.get(property.nameKey))
+
+ builder.setSingleChoiceItems(
+ property.valueContainer.keys().toTypedArray(),
+ property.valueContainer.keys().indexOf(property.valueContainer.value())
+ ) { _, which ->
+ property.valueContainer.value(property.valueContainer.keys()[which])
+ }
+
+ builder.setPositiveButton("OK") { _, _ ->
+ updateButtonText(button, property.valueContainer.value())
+ }
+
+ builder.show()
+ }
+ ViewAppearanceHelper.applyTheme(viewModel, button)
+ button
+ }
is ConfigStateListValue -> {
val button = Button(viewModel.context)
updateButtonText(button, property.valueContainer.toString())