Просмотр исходного кода

fix(read): 自定义页眉页脚的 {PageRemaining} 不再在剩 0 页时替换成本章完

自定义模板是用户自己拼的,占位符两侧通常还有自己写的文案(「剩 {PageRemaining}
页」)。翻到章节最后一页时把数字整个换成一句「本章完」,整行就读不通了——变成
「剩 本章完 页」。要这种语义,用户在模板里自己写就行,不该由占位符替他决定。

于是 `formatCustomTipPageRemaining` 去掉 `chapterCompleteText` 参数与对应分支,
只剩两种取值:章节未排完且页数未知 → `-`(余量无从算起,与「本章完」不是一回事);
其余一律出数字。

**这条规则本来就只在自定义模板里**:`formatCustomTipPageRemaining` 全项目仅
PageView 一个调用点(`{PageRemaining}` 的求值),内置页眉页脚项里没有「本章剩余
页数」这个类型。所以本次等于全应用不再出现「本章完」,没有别的显示路径受影响。
`R.string.chapter_complete` 随之无引用,四个语言文件(en/zh-rCN/zh-rTW/zh-rHK)
一并删除。

测试 4 条同步(首条由断言「本章完」改为断言「0」)。全量单测 447 全绿。

回归:把某个页眉/页脚位置设为自定义,模板写 `剩 {PageRemaining} 页`,翻到章节
最后一页应显示「剩 0 页」;章节尚未排完时仍显示「剩 - 页」。

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
5151561 3 месяцев назад
Родитель
Сommit
cc7f3989df

+ 11 - 8
app/src/main/java/io/legado/app/ui/book/read/page/CustomTipPageRemaining.kt

@@ -1,16 +1,19 @@
 package io.legado.app.ui.book.read.page
 
+/**
+ * 自定义页眉/页脚模板里 `{PageRemaining}` 的取值。
+ *
+ * **刻意只出数字,剩 0 页也不换成「本章完」**:模板是用户自己拼的,占位符两侧往往还有
+ * 自己写的文案(「剩 {PageRemaining} 页」),中途把数字换成一句话会让整行读不通。
+ * 要「本章完」这种语义,用户在模板里自己写即可。
+ *
+ * 唯一的非数字取值是 `-`:章节还没排完且页数未知,此时余量无从算起。
+ */
 internal fun formatCustomTipPageRemaining(
     pageSize: Int,
     pageIndex: Int,
     isChapterCompleted: Boolean,
-    chapterCompleteText: String,
 ): String {
-    val pageRemaining = (pageSize - pageIndex - 1).coerceAtLeast(0)
-    return when {
-        isChapterCompleted && pageRemaining == 0 -> chapterCompleteText
-        isChapterCompleted -> pageRemaining.toString()
-        pageSize <= 0 -> "-"
-        else -> pageRemaining.toString()
-    }
+    if (!isChapterCompleted && pageSize <= 0) return "-"
+    return (pageSize - pageIndex - 1).coerceAtLeast(0).toString()
 }

+ 0 - 1
app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt

@@ -529,7 +529,6 @@ class PageView(
             pageSize = textPage.pageSize,
             pageIndex = textPage.index,
             isChapterCompleted = textPage.textChapter.isCompleted,
-            chapterCompleteText = context.getString(R.string.chapter_complete),
         )
         val readProgressDisplay = textPage.readProgress
         val wholeBookPage = ReadBook.getWholeBookPageState(textPage.chapterIndex, textPage.index)

+ 0 - 1
app/src/main/res/values-zh-rCN/strings.xml

@@ -2409,7 +2409,6 @@
     <string name="placeholder_page_index">当前页码</string>
     <string name="placeholder_page_size">本章页数</string>
     <string name="placeholder_page_remaining">本章剩余页数</string>
-    <string name="chapter_complete">本章完</string>
     <string name="placeholder_read_progress">阅读进度</string>
     <string name="placeholder_full_page_index">全文页码</string>
     <string name="placeholder_full_page_size">全文页数</string>

+ 0 - 1
app/src/main/res/values-zh-rHK/strings.xml

@@ -1670,7 +1670,6 @@
     <string name="placeholder_page_index">當前頁碼</string>
     <string name="placeholder_page_size">本章頁數</string>
     <string name="placeholder_page_remaining">本章剩餘頁數</string>
-    <string name="chapter_complete">本章完</string>
     <string name="placeholder_read_progress">閱讀進度</string>
     <string name="custom_regex_rule">自訂正則規則</string>
     <string name="custom_tag_colors">自訂標籤顏色</string>

+ 0 - 1
app/src/main/res/values-zh-rTW/strings.xml

@@ -1597,7 +1597,6 @@
     <string name="placeholder_page_index">當前頁碼</string>
     <string name="placeholder_page_size">本章頁數</string>
     <string name="placeholder_page_remaining">本章剩餘頁數</string>
-    <string name="chapter_complete">本章完</string>
     <string name="placeholder_read_progress">閱讀進度</string>
     <string name="cover_selected_images_count">已選擇 %1$d 張圖片</string>
     <string name="confirm_skip_to_chapter">是否跳轉到此章節?</string>

+ 0 - 1
app/src/main/res/values/strings.xml

@@ -1224,7 +1224,6 @@
     <string name="placeholder_page_index">PageIndex</string>
     <string name="placeholder_page_size">PageSize</string>
     <string name="placeholder_page_remaining">PageRemaining</string>
-    <string name="chapter_complete">End of chapter</string>
     <string name="placeholder_read_progress">ReadProgress</string>
     <string name="placeholder_full_page_index">FullPageIndex</string>
     <string name="placeholder_full_page_size">FullPageSize</string>

+ 5 - 9
app/src/test/java/io/legado/app/ui/book/read/page/CustomTipPageRemainingTest.kt

@@ -6,48 +6,44 @@ import org.junit.Test
 class CustomTipPageRemainingTest {
 
     @Test
-    fun `completed chapter shows chapter complete on last page`() {
+    fun `最后一页也只出数字不出本章完`() {
         val display = formatCustomTipPageRemaining(
             pageSize = 10,
             pageIndex = 9,
             isChapterCompleted = true,
-            chapterCompleteText = "本章完",
         )
 
-        assertEquals("本章完", display)
+        assertEquals("0", display)
     }
 
     @Test
-    fun `completed chapter keeps remaining page count before last page`() {
+    fun `排完的章节给出剩余页数`() {
         val display = formatCustomTipPageRemaining(
             pageSize = 10,
             pageIndex = 5,
             isChapterCompleted = true,
-            chapterCompleteText = "本章完",
         )
 
         assertEquals("4", display)
     }
 
     @Test
-    fun `incomplete chapter omits approximation marker without reporting chapter complete`() {
+    fun `未排完的章节最后一页同样出数字`() {
         val display = formatCustomTipPageRemaining(
             pageSize = 10,
             pageIndex = 9,
             isChapterCompleted = false,
-            chapterCompleteText = "本章完",
         )
 
         assertEquals("0", display)
     }
 
     @Test
-    fun `incomplete chapter without pages keeps unknown marker`() {
+    fun `未排完且页数未知时出未知标记`() {
         val display = formatCustomTipPageRemaining(
             pageSize = 0,
             pageIndex = 0,
             isChapterCompleted = false,
-            chapterCompleteText = "本章完",
         )
 
         assertEquals("-", display)