阅读界面小标题使用替换规则

pull/1343/head
gedoor 3 years ago
parent 535001acc0
commit d41d48d072
  1. 13
      app/src/main/java/io/legado/app/data/entities/BookChapter.kt
  2. 16
      app/src/main/java/io/legado/app/model/ReadBook.kt
  3. 9
      app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt

@ -5,7 +5,9 @@ import androidx.room.Entity
import androidx.room.ForeignKey
import androidx.room.Ignore
import androidx.room.Index
import com.github.liuyueyi.quick.transfer.ChineseUtils
import io.legado.app.R
import io.legado.app.help.AppConfig
import io.legado.app.model.analyzeRule.AnalyzeUrl
import io.legado.app.model.analyzeRule.RuleDataInterface
import io.legado.app.utils.*
@ -71,8 +73,9 @@ data class BookChapter(
@Suppress("unused")
fun getDisplayTitle(
replaceRules: List<ReplaceRule>? = null,
useReplace: Boolean = true
replaceRules: Array<ReplaceRule>? = null,
useReplace: Boolean = true,
chineseConvert: Boolean = true,
): String {
var displayTitle = title
if (useReplace && replaceRules != null) {
@ -90,6 +93,12 @@ data class BookChapter(
}
}
}
if (chineseConvert) {
when (AppConfig.chineseConverterType) {
1 -> displayTitle = ChineseUtils.t2s(displayTitle)
2 -> displayTitle = ChineseUtils.s2t(displayTitle)
}
}
return when {
!isVip -> displayTitle
isPay -> appCtx.getString(R.string.payed_title, displayTitle)

@ -1,7 +1,6 @@
package io.legado.app.model
import androidx.lifecycle.MutableLiveData
import com.github.liuyueyi.quick.transfer.ChineseUtils
import io.legado.app.constant.AppLog
import io.legado.app.constant.BookType
import io.legado.app.data.appDb
@ -338,15 +337,14 @@ object ReadBook : CoroutineScope by MainScope() {
Coroutine.async {
removeLoading(chapter.index)
if (chapter.index in durChapterIndex - 1..durChapterIndex + 1) {
chapter.title = when (AppConfig.chineseConverterType) {
1 -> ChineseUtils.t2s(chapter.title)
2 -> ChineseUtils.s2t(chapter.title)
else -> chapter.title
}
val contents = ContentProcessor.get(book.name, book.origin)
.getContent(book, chapter, content)
val contentProcessor = ContentProcessor.get(book.name, book.origin)
val displayTitle = chapter.getDisplayTitle(
contentProcessor.getReplaceRules(),
book.getUseReplaceRule()
)
val contents = contentProcessor.getContent(book, chapter, content)
val textChapter = ChapterProvider
.getTextChapter(book, chapter, contents, chapterSize)
.getTextChapter(book, chapter, displayTitle, contents, chapterSize)
when (val offset = chapter.index - durChapterIndex) {
0 -> {
curTextChapter = textChapter

@ -21,7 +21,9 @@ import io.legado.app.utils.*
import splitties.init.appCtx
import java.util.*
/**
* 解析内容生成章节和页面
*/
@Suppress("DEPRECATION")
object ChapterProvider {
@JvmStatic
@ -81,6 +83,7 @@ object ChapterProvider {
fun getTextChapter(
book: Book,
bookChapter: BookChapter,
displayTitle: String,
contents: List<String>,
chapterSize: Int,
): TextChapter {
@ -154,12 +157,12 @@ object ChapterProvider {
item.pageSize = textPages.size
item.chapterIndex = bookChapter.index
item.chapterSize = chapterSize
item.title = bookChapter.getDisplayTitle()
item.title = displayTitle
item.upLinesPosition()
}
return TextChapter(
bookChapter.index, bookChapter.getDisplayTitle(),
bookChapter.index, displayTitle,
bookChapter.getAbsoluteURL().substringBefore(",{"), //getAbsoluteURL已经格式过
textPages, chapterSize
)

Loading…
Cancel
Save