|
@@ -37,7 +37,8 @@ class ContentProcessor private constructor(
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private val replaceRules = arrayListOf<ReplaceRule>()
|
|
|
|
|
|
|
+ private val titleReplaceRules = arrayListOf<ReplaceRule>()
|
|
|
|
|
+ private val contentReplaceRules = arrayListOf<ReplaceRule>()
|
|
|
|
|
|
|
|
init {
|
|
init {
|
|
|
upReplaceRules()
|
|
upReplaceRules()
|
|
@@ -45,13 +46,25 @@ class ContentProcessor private constructor(
|
|
|
|
|
|
|
|
@Synchronized
|
|
@Synchronized
|
|
|
fun upReplaceRules() {
|
|
fun upReplaceRules() {
|
|
|
- replaceRules.clear()
|
|
|
|
|
- replaceRules.addAll(appDb.replaceRuleDao.findEnabledByScope(bookName, bookOrigin))
|
|
|
|
|
|
|
+ titleReplaceRules.clear()
|
|
|
|
|
+ contentReplaceRules.clear()
|
|
|
|
|
+ titleReplaceRules.addAll(appDb.replaceRuleDao.findEnabledByTitleScope(bookName, bookOrigin))
|
|
|
|
|
+ contentReplaceRules.addAll(
|
|
|
|
|
+ appDb.replaceRuleDao.findEnabledByContentScope(
|
|
|
|
|
+ bookName,
|
|
|
|
|
+ bookOrigin
|
|
|
|
|
+ )
|
|
|
|
|
+ )
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Synchronized
|
|
@Synchronized
|
|
|
- fun getReplaceRules(): Array<ReplaceRule> {
|
|
|
|
|
- return replaceRules.toTypedArray()
|
|
|
|
|
|
|
+ fun getTitleReplaceRules(): List<ReplaceRule> {
|
|
|
|
|
+ return titleReplaceRules
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Synchronized
|
|
|
|
|
+ fun getContentReplaceRules(): List<ReplaceRule> {
|
|
|
|
|
+ return contentReplaceRules
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
fun getContent(
|
|
fun getContent(
|
|
@@ -94,7 +107,7 @@ class ContentProcessor private constructor(
|
|
|
}
|
|
}
|
|
|
if (includeTitle) {
|
|
if (includeTitle) {
|
|
|
//重新添加标题
|
|
//重新添加标题
|
|
|
- mContent = chapter.getDisplayTitle(getReplaceRules()) + "\n" + mContent
|
|
|
|
|
|
|
+ mContent = chapter.getDisplayTitle(getTitleReplaceRules()) + "\n" + mContent
|
|
|
}
|
|
}
|
|
|
val contents = arrayListOf<String>()
|
|
val contents = arrayListOf<String>()
|
|
|
mContent.split("\n").forEach { str ->
|
|
mContent.split("\n").forEach { str ->
|
|
@@ -114,7 +127,7 @@ class ContentProcessor private constructor(
|
|
|
|
|
|
|
|
fun replaceContent(content: String): String {
|
|
fun replaceContent(content: String): String {
|
|
|
var mContent = content
|
|
var mContent = content
|
|
|
- getReplaceRules().forEach { item ->
|
|
|
|
|
|
|
+ getContentReplaceRules().forEach { item ->
|
|
|
if (item.pattern.isNotEmpty()) {
|
|
if (item.pattern.isNotEmpty()) {
|
|
|
try {
|
|
try {
|
|
|
mContent = if (item.isRegex) {
|
|
mContent = if (item.isRegex) {
|