Add IntSliderPreference

This commit is contained in:
tarsin committed 2023-06-05 00:05:25 +08:00
1 parent f3519f6f8a
commit 6490598fc3
3 files changed
+17 -1

No files matched your search

@@ -95,7 +95,7 @@ object Settings : DefaultPreferences() {
var favCloudCount by intPref("fav_cloud", 0)
var recentFavCat by intPref("recent_fav_cat", FavListUrlBuilder.FAV_CAT_ALL)
var defaultFavSlot by intPref("default_favorite_2", INVALID_DEFAULT_FAV_SLOT) // -1 for local, 0 - 9 for cloud favorite, other for no default fav slot
val securityDelay by intPref("require_unlock_delay", 0)
var securityDelay by intPref("require_unlock_delay", 0)
var proxyType by intPref("proxy_type", EhProxySelector.TYPE_SYSTEM)
var proxyPort by intPref("proxy_port", -1)
var clipboardTextHashCode by intPref("clipboard_text_hash_code", 0)
@@ -13,6 +13,7 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
@@ -27,9 +28,11 @@ 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.SliderPref
import com.jamal.composeprefs3.ui.prefs.SpannedTextPref
import com.jamal.composeprefs3.ui.prefs.SwitchPref
import com.jamal.composeprefs3.ui.prefs.TextPref
import kotlin.math.roundToInt
import kotlin.reflect.KMutableProperty0
@Composable
@@ -61,6 +64,13 @@ fun SwitchPreference(title: String, summary: String?, value: KMutableProperty0<B
SwitchPref(checked = v, onMutate = ::mutate, title = title, summary = summary, enabled = enabled)
}
@Composable
fun IntSliderPreference(maxValue: Int, minValue: Int = 0, step: Int = maxValue - minValue - 1, title: String, value: KMutableProperty0<Int>, enabled: Boolean = true) {
var v by remember { mutableIntStateOf(value.get()) }
fun set(float: Float) = value.set(float.roundToInt().also { v = it })
SliderPref(title = title, defaultValue = v.toFloat(), onValueChangeFinished = ::set, valueRange = minValue.toFloat()..maxValue.toFloat(), showValue = true, steps = step, enabled = enabled)
}
@Composable
fun UrlPreference(title: String, url: String) {
val context = LocalContext.current
@@ -44,6 +44,12 @@ fun SecurityScreen() {
value = Settings::security,
enabled = LocalContext.current.isAuthenticationSupported(),
)
IntSliderPreference(
maxValue = 30,
title = stringResource(id = R.string.settings_privacy_require_unlock_delay),
value = Settings::securityDelay,
enabled = LocalContext.current.isAuthenticationSupported(),
)
SwitchPreference(
title = stringResource(id = R.string.settings_privacy_secure),
summary = stringResource(id = R.string.settings_privacy_secure_summary),