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

pull/1343/head
gedoor 4 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.ForeignKey
import androidx.room.Ignore import androidx.room.Ignore
import androidx.room.Index import androidx.room.Index
import com.github.liuyueyi.quick.transfer.ChineseUtils
import io.legado.app.R import io.legado.app.R
import io.legado.app.help.AppConfig
import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.model.analyzeRule.AnalyzeUrl
import io.legado.app.model.analyzeRule.RuleDataInterface import io.legado.app.model.analyzeRule.RuleDataInterface
import io.legado.app.utils.* import io.legado.app.utils.*
@ -71,8 +73,9 @@ data class BookChapter(
@Suppress("unused") @Suppress("unused")
fun getDisplayTitle( fun getDisplayTitle(
replaceRules: List<ReplaceRule>? = null, replaceRules: Array<ReplaceRule>? = null,
useReplace: Boolean = true useReplace: Boolean = true,
chineseConvert: Boolean = true,
): String { ): String {
var displayTitle = title var displayTitle = title
if (useReplace && replaceRules != null) { 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 { return when {
!isVip -> displayTitle !isVip -> displayTitle
isPay -> appCtx.getString(R.string.payed_title, displayTitle) isPay -> appCtx.getString(R.string.payed_title, displayTitle)

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

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

Loading…
Cancel
Save