feat: 优化代码

pull/133/head
kunfei 5 years ago
parent 36683d5734
commit 6678e9a939
  1. 14
      app/src/main/java/io/legado/app/data/dao/ReplaceRuleDao.kt
  2. 17
      app/src/main/java/io/legado/app/help/BookHelp.kt

@ -33,14 +33,20 @@ interface ReplaceRuleDao {
fun findByIds(vararg ids: Long): List<ReplaceRule>
@Query(
"""SELECT * FROM replace_rules WHERE isEnabled = 1
AND (scope LIKE '%' || :scope || '%' or scope is null or scope = '')"""
"""
SELECT * FROM replace_rules WHERE isEnabled = 1
AND (scope LIKE '%' || :scope || '%' or scope is null or scope = '')
order by sortOrder
"""
)
fun findEnabledByScope(scope: String): List<ReplaceRule>
@Query(
"""SELECT * FROM replace_rules WHERE isEnabled = 1
AND (scope LIKE '%' || :name || '%' or scope LIKE '%' || :origin || '%' or scope is null or scope = '')"""
"""
SELECT * FROM replace_rules WHERE isEnabled = 1
AND (scope LIKE '%' || :name || '%' or scope LIKE '%' || :origin || '%' or scope is null or scope = '')
order by sortOrder
"""
)
fun findEnabledByScope(name: String, origin: String): List<ReplaceRule>

@ -11,7 +11,10 @@ import io.legado.app.data.entities.BookChapter
import io.legado.app.data.entities.ReplaceRule
import io.legado.app.model.localBook.AnalyzeTxtFile
import io.legado.app.utils.*
import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.withContext
import org.apache.commons.text.similarity.JaccardSimilarity
import org.jetbrains.anko.toast
import java.io.File
import kotlin.math.min
@ -262,7 +265,7 @@ object BookHelp {
}
}
fun disposeContent(
suspend fun disposeContent(
title: String,
name: String,
origin: String?,
@ -272,15 +275,19 @@ object BookHelp {
var c = content
if (enableReplace) {
upReplaceRules(name, origin)
kotlin.runCatching {
replaceRules.forEach { item ->
item.pattern.let {
if (it.isNotEmpty()) {
replaceRules.forEach { item ->
item.pattern.let {
if (it.isNotEmpty()) {
try {
c = if (item.isRegex) {
c.replace(it.toRegex(), item.replacement)
} else {
c.replace(it, item.replacement)
}
} catch (e: Exception) {
withContext(Main) {
App.INSTANCE.toast("${item.name}替换出错")
}
}
}
}

Loading…
Cancel
Save