Explorar el Código

feat: 在起效替换中显示重新分段

HapeLee hace 3 meses
padre
commit
8167a7e30b

+ 16 - 9
app/src/main/java/io/legado/app/ui/book/read/sheet/EffectiveReplacesSheet.kt

@@ -38,6 +38,7 @@ import io.legado.app.ui.widget.components.text.AppText
 import kotlinx.coroutines.launch
 import kotlinx.coroutines.launch
 
 
 private const val CHINESE_CONVERT_ID = -1L
 private const val CHINESE_CONVERT_ID = -1L
+private const val RE_SEGMENT_ID = -2L
 
 
 @Composable
 @Composable
 fun EffectiveReplacesSheet(
 fun EffectiveReplacesSheet(
@@ -51,16 +52,18 @@ fun EffectiveReplacesSheet(
     val scope = rememberCoroutineScope()
     val scope = rememberCoroutineScope()
     val chineseConvertActive = ReadConfig.chineseConverterType > 0
     val chineseConvertActive = ReadConfig.chineseConverterType > 0
     val chineseConvertItem = remember { ReplaceRule(CHINESE_CONVERT_ID, "繁简转换") }
     val chineseConvertItem = remember { ReplaceRule(CHINESE_CONVERT_ID, "繁简转换") }
+    val reSegmentActive = ReadBook.book?.getReSegment() == true
+    val reSegmentItem = remember { ReplaceRule(RE_SEGMENT_ID, "") }
 
 
     val effectiveRules = remember(show) {
     val effectiveRules = remember(show) {
         ReadBook.curTextChapter?.effectiveReplaceRules ?: emptyList()
         ReadBook.curTextChapter?.effectiveReplaceRules ?: emptyList()
     }
     }
 
 
-    val items = remember(show, effectiveRules, chineseConvertActive) {
-        if (chineseConvertActive) {
-            effectiveRules + chineseConvertItem
-        } else {
-            effectiveRules
+    val items = remember(show, effectiveRules, chineseConvertActive, reSegmentActive) {
+        buildList {
+            addAll(effectiveRules)
+            if (chineseConvertActive) add(chineseConvertItem)
+            if (reSegmentActive) add(reSegmentItem)
         }
         }
     }
     }
 
 
@@ -92,7 +95,7 @@ fun EffectiveReplacesSheet(
                         onClick = {
                         onClick = {
                             if (rule.id == CHINESE_CONVERT_ID) {
                             if (rule.id == CHINESE_CONVERT_ID) {
                                 onNavigateToTextEffects()
                                 onNavigateToTextEffects()
-                            } else {
+                            } else if (rule.id != RE_SEGMENT_ID) {
                                 onOpenReplaceEditor(rule.id, rule.pattern)
                                 onOpenReplaceEditor(rule.id, rule.pattern)
                             }
                             }
                         },
                         },
@@ -109,12 +112,16 @@ fun EffectiveReplacesSheet(
                         ) {
                         ) {
                             Column(modifier = Modifier.weight(1f)) {
                             Column(modifier = Modifier.weight(1f)) {
                                 AppText(
                                 AppText(
-                                    text = rule.name,
+                                    text = if (rule.id == RE_SEGMENT_ID) {
+                                        stringResource(R.string.re_segment)
+                                    } else {
+                                        rule.name
+                                    },
                                     style = LegadoTheme.typography.labelLargeEmphasized,
                                     style = LegadoTheme.typography.labelLargeEmphasized,
                                     maxLines = 1,
                                     maxLines = 1,
                                     overflow = TextOverflow.Ellipsis,
                                     overflow = TextOverflow.Ellipsis,
                                 )
                                 )
-                                if (rule.id != CHINESE_CONVERT_ID) {
+                                if (rule.id >= 0) {
                                     Row(verticalAlignment = Alignment.CenterVertically) {
                                     Row(verticalAlignment = Alignment.CenterVertically) {
                                         AppText(
                                         AppText(
                                             text = rule.pattern,
                                             text = rule.pattern,
@@ -142,7 +149,7 @@ fun EffectiveReplacesSheet(
                                     }
                                     }
                                 }
                                 }
                             }
                             }
-                            MediumTonalButton(
+                            if (rule.id != RE_SEGMENT_ID) MediumTonalButton(
                                 onClick = {
                                 onClick = {
                                     disabledIds = disabledIds + rule.id
                                     disabledIds = disabledIds + rule.id
                                     isEdited = true
                                     isEdited = true