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

Loading…
Cancel
Save