Преглед изворни кода

fix(read): correct spacing values and translation state

HapeLee пре 4 месеци
родитељ
комит
f5ad56a2a8

+ 3 - 1
app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt

@@ -5562,8 +5562,10 @@ class ReadBookViewModel(
 
     private fun toggleTranslation() {
         val book = ReadBook.book ?: return
-        book.setTranslationMode(!book.getTranslationMode())
+        val enabled = !book.getTranslationMode()
+        book.setTranslationMode(enabled)
         book.save()
+        _uiState.update { it.copy(translationMode = enabled) }
         ReadBook.loadContent(false)
     }
 

+ 3 - 2
app/src/main/java/io/legado/app/ui/book/read/sheet/TextTitleSheet.kt

@@ -228,6 +228,7 @@ internal fun LayoutSpacingPage(
             title = stringResource(R.string.text_letter_spacing),
             value = (letterSpacing * 100) + 50,
             valueRange = 0f..100f,
+            valueFormat = { ((it - 50) / 100f).toString() },
             onValueChange = { value ->
                 letterSpacing = (value - 50) / 100f
                 onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.LetterSpacing(letterSpacing)))
@@ -237,7 +238,7 @@ internal fun LayoutSpacingPage(
             title = stringResource(R.string.line_size),
             value = lineSpacing,
             valueRange = 0f..20f,
-            showDecimal = true,
+            valueFormat = { ((it - 10) / 10f).toString() },
             onValueChange = { value ->
                 lineSpacing = value
                 onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.LineSpacing(value.toInt())))
@@ -247,7 +248,7 @@ internal fun LayoutSpacingPage(
             title = stringResource(R.string.paragraph_size),
             value = paragraphSpacing,
             valueRange = 0f..20f,
-            showDecimal = true,
+            valueFormat = { (it / 10f).toString() },
             onValueChange = { value ->
                 paragraphSpacing = value
                 onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.ParagraphSpacing(value.toInt())))

+ 2 - 1
app/src/main/java/io/legado/app/ui/widget/components/ValueStepper.kt

@@ -22,6 +22,7 @@ fun ValueStepper(
     modifier: Modifier = Modifier,
     enabled: Boolean = true,
     showDecimal: Boolean = false,
+    valueFormat: ((Float) -> String)? = null,
 ) {
     Row(
         modifier = modifier,
@@ -36,7 +37,7 @@ fun ValueStepper(
             enabled = enabled,
             icon = Icons.Default.Remove,
         )
-        val displayText = if (showDecimal) {
+        val displayText = valueFormat?.invoke(displayValue) ?: if (showDecimal) {
             displayValue.toString()
         } else {
             displayValue.toInt().toString()

+ 2 - 0
app/src/main/java/io/legado/app/ui/widget/components/settingItem/TinySettingItems.kt

@@ -257,6 +257,7 @@ fun TinySliderSettingItem(
     color: Color? = LegadoTheme.colorScheme.surfaceContainerLow,
     enabled: Boolean = true,
     showDecimal: Boolean = false,
+    valueFormat: ((Float) -> String)? = null,
     onValueChange: (Float) -> Unit,
 ) {
     var expanded by remember { mutableStateOf(false) }
@@ -280,6 +281,7 @@ fun TinySliderSettingItem(
                 onValueChange = onValueChange,
                 enabled = enabled,
                 showDecimal = showDecimal,
+                valueFormat = valueFormat,
             )
         },
         expandContent = {