Implement Compose SimpleMenuPreference
This commit is contained in:
1 parent
8f1f76c3d1
commit
5be2b77e42
4 files changed
+24
-2
No files matched your search
@@ -62,7 +62,7 @@ object Settings : DefaultPreferences() {
|
||||
val listMode by intFromStrPref(KEY_LIST_MODE, 0)
|
||||
val detailSize by intFromStrPref(KEY_DETAIL_SIZE, 0)
|
||||
val thumbResolution by intFromStrPref(KEY_THUMB_RESOLUTION, 0)
|
||||
val readCacheSize by intFromStrPref(KEY_READ_CACHE_SIZE, 640)
|
||||
var readCacheSize by intFromStrPref(KEY_READ_CACHE_SIZE, 640)
|
||||
var launchPage by intFromStrPref("launch_page", 0)
|
||||
|
||||
val showComments by boolPref("show_gallery_comments", true)
|
||||
|
||||
@@ -50,6 +50,12 @@ fun AdvancedScreen() {
|
||||
title = stringResource(id = R.string.settings_advanced_dump_logcat),
|
||||
summary = stringResource(id = R.string.settings_advanced_dump_logcat_summary),
|
||||
)
|
||||
SimpleMenuPreference(
|
||||
title = stringResource(id = R.string.settings_advanced_read_cache_size),
|
||||
entry = R.array.read_cache_size_entries,
|
||||
entryValueRes = R.array.read_cache_size_entry_values,
|
||||
value = Settings::readCacheSize,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.hippo.ehviewer.ui.settings
|
||||
|
||||
import androidx.annotation.ArrayRes
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Row
|
||||
@@ -23,11 +24,13 @@ import androidx.compose.ui.graphics.painter.Painter
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.graphics.vector.rememberVectorPainter
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringArrayResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.AnnotatedString
|
||||
import com.hippo.ehviewer.ui.login.LocalNavController
|
||||
import com.hippo.ehviewer.ui.openBrowser
|
||||
import com.hippo.ehviewer.ui.settings.PreferenceTokens.PreferenceTextPadding
|
||||
import com.jamal.composeprefs3.ui.prefs.DropDownPref
|
||||
import com.jamal.composeprefs3.ui.prefs.SliderPref
|
||||
import com.jamal.composeprefs3.ui.prefs.SpannedTextPref
|
||||
import com.jamal.composeprefs3.ui.prefs.SwitchPref
|
||||
@@ -81,3 +84,17 @@ fun UrlPreference(title: String, url: String) {
|
||||
fun HtmlPreference(title: String, summary: AnnotatedString? = null, onClick: () -> Unit = {}) {
|
||||
SpannedTextPref(title = title, summary = summary, onClick = onClick)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun SimpleMenuPreference(title: String, @ArrayRes entry: Int, @ArrayRes entryValueRes: Int, value: KMutableProperty0<Int>) {
|
||||
val entryArray = stringArrayResource(id = entry)
|
||||
val valuesArray = stringArrayResource(id = entryValueRes)
|
||||
val map = remember {
|
||||
val iter = entryArray.iterator()
|
||||
valuesArray.associateWith { iter.next() }
|
||||
}
|
||||
var v by remember { mutableIntStateOf(value.get()) }
|
||||
fun set(new: String) = value.set(new.toInt().also { v = it })
|
||||
check(entryArray.size == valuesArray.size)
|
||||
DropDownPref(title = title, defaultValue = v.toString(), onValueChange = ::set, useSelectedAsSummary = true, entries = map)
|
||||
}
|
||||
@@ -19,7 +19,6 @@ import androidx.compose.ui.unit.dp
|
||||
|
||||
@Composable
|
||||
fun DropDownPref(
|
||||
key: String,
|
||||
title: String,
|
||||
modifier: Modifier = Modifier,
|
||||
summary: String? = null,
|
||||
|
||||
Reference in new issue
Block a user