pull/1814/head
kunfei 3 years ago
parent df2bf13d6d
commit 4fa4be52f7
  1. 9
      app/src/main/java/io/legado/app/data/entities/Book.kt
  2. 10
      app/src/main/java/io/legado/app/data/entities/BookChapter.kt
  3. 5
      app/src/main/java/io/legado/app/ui/book/toc/ChapterListAdapter.kt

@ -14,6 +14,7 @@ import io.legado.app.model.ReadBook
import io.legado.app.utils.GSON import io.legado.app.utils.GSON
import io.legado.app.utils.MD5Utils import io.legado.app.utils.MD5Utils
import io.legado.app.utils.fromJsonObject import io.legado.app.utils.fromJsonObject
import kotlinx.coroutines.runBlocking
import kotlinx.parcelize.IgnoredOnParcel import kotlinx.parcelize.IgnoredOnParcel
import kotlinx.parcelize.Parcelize import kotlinx.parcelize.Parcelize
import java.nio.charset.Charset import java.nio.charset.Charset
@ -283,9 +284,11 @@ data class Book(
fun changeTo(newBook: Book, toc: List<BookChapter>): Book { fun changeTo(newBook: Book, toc: List<BookChapter>): Book {
newBook.durChapterIndex = BookHelp newBook.durChapterIndex = BookHelp
.getDurChapter(durChapterIndex, durChapterTitle, toc, totalChapterNum) .getDurChapter(durChapterIndex, durChapterTitle, toc, totalChapterNum)
newBook.durChapterTitle = toc[newBook.durChapterIndex].getDisplayTitle( newBook.durChapterTitle = runBlocking {
ContentProcessor.get(newBook.name, newBook.origin).getTitleReplaceRules() toc[newBook.durChapterIndex].getDisplayTitle(
) ContentProcessor.get(newBook.name, newBook.origin).getTitleReplaceRules()
)
}
newBook.durChapterPos = durChapterPos newBook.durChapterPos = durChapterPos
newBook.group = group newBook.group = group
newBook.order = order newBook.order = order

@ -8,6 +8,8 @@ import androidx.room.Index
import com.github.liuyueyi.quick.transfer.ChineseUtils import com.github.liuyueyi.quick.transfer.ChineseUtils
import io.legado.app.R import io.legado.app.R
import io.legado.app.constant.AppPattern import io.legado.app.constant.AppPattern
import io.legado.app.data.appDb
import io.legado.app.exception.RegexTimeoutException
import io.legado.app.help.RuleBigDataHelp import io.legado.app.help.RuleBigDataHelp
import io.legado.app.help.config.AppConfig import io.legado.app.help.config.AppConfig
import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.model.analyzeRule.AnalyzeUrl
@ -79,8 +81,7 @@ data class BookChapter(
return false return false
} }
@Suppress("unused") suspend fun getDisplayTitle(
fun getDisplayTitle(
replaceRules: List<ReplaceRule>? = null, replaceRules: List<ReplaceRule>? = null,
useReplace: Boolean = true, useReplace: Boolean = true,
chineseConvert: Boolean = true, chineseConvert: Boolean = true,
@ -97,13 +98,16 @@ data class BookChapter(
if (item.pattern.isNotEmpty()) { if (item.pattern.isNotEmpty()) {
try { try {
val mDisplayTitle = if (item.isRegex) { val mDisplayTitle = if (item.isRegex) {
displayTitle.replace(item.pattern.toRegex(), item.replacement) displayTitle.replace(item.pattern.toRegex(), item.replacement, 100)
} else { } else {
displayTitle.replace(item.pattern, item.replacement) displayTitle.replace(item.pattern, item.replacement)
} }
if (mDisplayTitle.isNotBlank()) { if (mDisplayTitle.isNotBlank()) {
displayTitle = mDisplayTitle displayTitle = mDisplayTitle
} }
} catch (e: RegexTimeoutException) {
item.isEnabled = false
appDb.replaceRuleDao.update(item)
} catch (e: Exception) { } catch (e: Exception) {
appCtx.toastOnUi("${item.name}替换出错") appCtx.toastOnUi("${item.name}替换出错")
} }

@ -20,6 +20,7 @@ import io.legado.app.utils.longToastOnUi
import io.legado.app.utils.visible import io.legado.app.utils.visible
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.isActive import kotlinx.coroutines.isActive
import kotlinx.coroutines.runBlocking
import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.ConcurrentHashMap
class ChapterListAdapter(context: Context, val callback: Callback) : class ChapterListAdapter(context: Context, val callback: Callback) :
@ -97,7 +98,9 @@ class ChapterListAdapter(context: Context, val callback: Callback) :
if (displayTitle != null) { if (displayTitle != null) {
return displayTitle return displayTitle
} }
displayTitle = chapter.getDisplayTitle(replaceRules, useReplace) displayTitle = runBlocking {
chapter.getDisplayTitle(replaceRules, useReplace)
}
displayTitleMap[chapter.title] = displayTitle displayTitleMap[chapter.title] = displayTitle
return displayTitle return displayTitle
} }

Loading…
Cancel
Save