mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
优化
This commit is contained in:
@@ -14,6 +14,7 @@ import io.legado.app.model.ReadBook
|
||||
import io.legado.app.utils.GSON
|
||||
import io.legado.app.utils.MD5Utils
|
||||
import io.legado.app.utils.fromJsonObject
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.parcelize.IgnoredOnParcel
|
||||
import kotlinx.parcelize.Parcelize
|
||||
import java.nio.charset.Charset
|
||||
@@ -283,9 +284,11 @@ data class Book(
|
||||
fun changeTo(newBook: Book, toc: List<BookChapter>): Book {
|
||||
newBook.durChapterIndex = BookHelp
|
||||
.getDurChapter(durChapterIndex, durChapterTitle, toc, totalChapterNum)
|
||||
newBook.durChapterTitle = toc[newBook.durChapterIndex].getDisplayTitle(
|
||||
ContentProcessor.get(newBook.name, newBook.origin).getTitleReplaceRules()
|
||||
)
|
||||
newBook.durChapterTitle = runBlocking {
|
||||
toc[newBook.durChapterIndex].getDisplayTitle(
|
||||
ContentProcessor.get(newBook.name, newBook.origin).getTitleReplaceRules()
|
||||
)
|
||||
}
|
||||
newBook.durChapterPos = durChapterPos
|
||||
newBook.group = group
|
||||
newBook.order = order
|
||||
|
||||
@@ -8,6 +8,8 @@ import androidx.room.Index
|
||||
import com.github.liuyueyi.quick.transfer.ChineseUtils
|
||||
import io.legado.app.R
|
||||
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.config.AppConfig
|
||||
import io.legado.app.model.analyzeRule.AnalyzeUrl
|
||||
@@ -79,8 +81,7 @@ data class BookChapter(
|
||||
return false
|
||||
}
|
||||
|
||||
@Suppress("unused")
|
||||
fun getDisplayTitle(
|
||||
suspend fun getDisplayTitle(
|
||||
replaceRules: List<ReplaceRule>? = null,
|
||||
useReplace: Boolean = true,
|
||||
chineseConvert: Boolean = true,
|
||||
@@ -97,13 +98,16 @@ data class BookChapter(
|
||||
if (item.pattern.isNotEmpty()) {
|
||||
try {
|
||||
val mDisplayTitle = if (item.isRegex) {
|
||||
displayTitle.replace(item.pattern.toRegex(), item.replacement)
|
||||
displayTitle.replace(item.pattern.toRegex(), item.replacement, 100)
|
||||
} else {
|
||||
displayTitle.replace(item.pattern, item.replacement)
|
||||
}
|
||||
if (mDisplayTitle.isNotBlank()) {
|
||||
displayTitle = mDisplayTitle
|
||||
}
|
||||
} catch (e: RegexTimeoutException) {
|
||||
item.isEnabled = false
|
||||
appDb.replaceRuleDao.update(item)
|
||||
} catch (e: Exception) {
|
||||
appCtx.toastOnUi("${item.name}替换出错")
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import io.legado.app.utils.longToastOnUi
|
||||
import io.legado.app.utils.visible
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.isActive
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
class ChapterListAdapter(context: Context, val callback: Callback) :
|
||||
@@ -97,7 +98,9 @@ class ChapterListAdapter(context: Context, val callback: Callback) :
|
||||
if (displayTitle != null) {
|
||||
return displayTitle
|
||||
}
|
||||
displayTitle = chapter.getDisplayTitle(replaceRules, useReplace)
|
||||
displayTitle = runBlocking {
|
||||
chapter.getDisplayTitle(replaceRules, useReplace)
|
||||
}
|
||||
displayTitleMap[chapter.title] = displayTitle
|
||||
return displayTitle
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user