pull/898/head
gedoor 4 years ago
parent c6dcd01fc3
commit 19869854ba
  1. 9
      app/src/main/java/io/legado/app/help/ContentProcessor.kt

@ -5,8 +5,6 @@ import io.legado.app.data.appDb
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.ReplaceRule
import io.legado.app.utils.toastOnUi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import splitties.init.appCtx
class ContentProcessor(private val bookName: String, private val bookOrigin: String) {
@ -23,7 +21,8 @@ class ContentProcessor(private val bookName: String, private val bookOrigin: Str
replaceRules.addAll(appDb.replaceRuleDao.findEnabledByScope(bookName, bookOrigin))
}
suspend fun getContent(
@Synchronized
fun getContent(
book: Book,
title: String, //已经经过简繁转换
content: String,
@ -41,13 +40,11 @@ class ContentProcessor(private val bookName: String, private val bookOrigin: Str
content1.replace(item.pattern, item.replacement)
}
} catch (e: Exception) {
withContext(Dispatchers.Main) {
appCtx.toastOnUi("${item.name}替换出错")
}
}
}
}
}
if (isRead) {
if (book.getReSegment()) {
content1 = ContentHelp.reSegment(content1, title)
@ -58,11 +55,9 @@ class ContentProcessor(private val bookName: String, private val bookOrigin: Str
2 -> content1 = HanLP.convertToTraditionalChinese(content1)
}
} catch (e: Exception) {
withContext(Dispatchers.Main) {
appCtx.toastOnUi("简繁转换出错")
}
}
}
val contents = arrayListOf<String>()
content1.split("\n").forEach {
val str = it.replace("^[\\n\\r]+".toRegex(), "").trim()

Loading…
Cancel
Save