[DO NOT USE] Tweak SimpleMenuPreferenceInt to receive a MutableState
This commit is contained in:
1 parent
623ab63d8d
commit
d2b5e5ec01
3 files changed
+15
-10
No files matched your search
@@ -40,6 +40,7 @@ import com.hippo.ehviewer.Settings
|
||||
import com.hippo.ehviewer.client.EhEngine
|
||||
import com.hippo.ehviewer.client.data.FavListUrlBuilder
|
||||
import com.hippo.ehviewer.client.systemDns
|
||||
import com.hippo.ehviewer.ui.compose.observed
|
||||
import com.hippo.ehviewer.ui.legacy.BaseDialogBuilder
|
||||
import com.hippo.ehviewer.ui.legacy.EditTextDialogBuilder
|
||||
import com.hippo.ehviewer.ui.login.LocalNavController
|
||||
@@ -127,7 +128,7 @@ fun AdvancedScreen() {
|
||||
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,
|
||||
value = Settings::readCacheSize.observed,
|
||||
)
|
||||
SimpleMenuPreference(
|
||||
title = stringResource(id = R.string.settings_advanced_app_language_title),
|
||||
|
||||
@@ -108,26 +108,29 @@ fun DownloadScreen() {
|
||||
summary = if (Settings.mediaScan) stringResource(id = R.string.settings_download_media_scan_summary_on) else stringResource(id = R.string.settings_download_media_scan_summary_off),
|
||||
value = Settings::mediaScan,
|
||||
)
|
||||
val multiThreadDownload = Settings::multiThreadDownload.observed
|
||||
SimpleMenuPreferenceInt(
|
||||
title = stringResource(id = R.string.settings_download_concurrency),
|
||||
summary = stringResource(id = R.string.settings_download_concurrency_summary, Settings.multiThreadDownload),
|
||||
summary = stringResource(id = R.string.settings_download_concurrency_summary, multiThreadDownload.value),
|
||||
entry = R.array.multi_thread_download_entries,
|
||||
entryValueRes = R.array.multi_thread_download_entry_values,
|
||||
value = Settings::multiThreadDownload,
|
||||
value = multiThreadDownload,
|
||||
)
|
||||
val downloadDelay = Settings::downloadDelay.observed
|
||||
SimpleMenuPreferenceInt(
|
||||
title = stringResource(id = R.string.settings_download_download_delay),
|
||||
summary = stringResource(id = R.string.settings_download_download_delay_summary, Settings.downloadDelay),
|
||||
summary = stringResource(id = R.string.settings_download_download_delay_summary, downloadDelay.value),
|
||||
entry = R.array.download_delay_entries,
|
||||
entryValueRes = R.array.download_delay_entry_values,
|
||||
value = Settings::downloadDelay,
|
||||
value = downloadDelay,
|
||||
)
|
||||
val preloadImage = Settings::preloadImage.observed
|
||||
SimpleMenuPreferenceInt(
|
||||
title = stringResource(id = R.string.settings_download_preload_image),
|
||||
summary = stringResource(id = R.string.settings_download_preload_image_summary, Settings.preloadImage),
|
||||
summary = stringResource(id = R.string.settings_download_preload_image_summary, preloadImage.value),
|
||||
entry = R.array.preload_image_entries,
|
||||
entryValueRes = R.array.preload_image_entry_values,
|
||||
value = Settings::preloadImage,
|
||||
value = preloadImage,
|
||||
)
|
||||
SwitchPreference(
|
||||
title = stringResource(id = R.string.settings_download_download_origin_image),
|
||||
|
||||
@@ -13,6 +13,7 @@ import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.MutableState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
@@ -86,15 +87,15 @@ fun HtmlPreference(title: String, summary: AnnotatedString? = null, onClick: ()
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun SimpleMenuPreferenceInt(title: String, summary: String? = null, @ArrayRes entry: Int, @ArrayRes entryValueRes: Int, value: KMutableProperty0<Int>) {
|
||||
fun SimpleMenuPreferenceInt(title: String, summary: String? = null, @ArrayRes entry: Int, @ArrayRes entryValueRes: Int, value: MutableState<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 })
|
||||
var v by value
|
||||
fun set(new: String) { v = new.toInt() }
|
||||
check(entryArray.size == valuesArray.size)
|
||||
DropDownPref(title = title, summary = summary, defaultValue = v.toString(), onValueChange = ::set, useSelectedAsSummary = summary.isNullOrBlank(), entries = map)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user