替换净化添加正文多行标题

pull/1616/head
Xwite 3 years ago
parent c35f208e49
commit 3a15b3ca37
  1. 2
      app/src/main/java/io/legado/app/data/AppDatabase.kt
  2. 7
      app/src/main/java/io/legado/app/data/dao/ReplaceRuleDao.kt
  3. 3
      app/src/main/java/io/legado/app/data/entities/ReplaceRule.kt
  4. 29
      app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt
  5. 2
      app/src/main/java/io/legado/app/ui/replace/edit/ReplaceEditActivity.kt
  6. 7
      app/src/main/res/layout/activity_replace_edit.xml
  7. 4
      app/src/main/res/values-es-rES/strings.xml
  8. 4
      app/src/main/res/values-ja-rJP/strings.xml
  9. 4
      app/src/main/res/values-zh-rHK/strings.xml
  10. 4
      app/src/main/res/values-zh-rTW/strings.xml
  11. 4
      app/src/main/res/values-zh/strings.xml
  12. 4
      app/src/main/res/values/strings.xml

@ -17,7 +17,7 @@ val appDb by lazy {
}
@Database(
version = 44,
version = 45,
exportSchema = true,
entities = [Book::class, BookGroup::class, BookSource::class, BookChapter::class,
ReplaceRule::class, SearchBook::class, SearchKeyword::class, Cookie::class,

@ -55,6 +55,13 @@ interface ReplaceRuleDao {
)
fun findEnabledByTitleScope(name: String, origin: String): List<ReplaceRule>
@Query(
"""SELECT * FROM replace_rules WHERE isEnabled = 1 and scopeMultilineTitle = 1
AND (scope LIKE '%' || :name || '%' or scope LIKE '%' || :origin || '%' or scope is null or scope = '')
order by sortOrder"""
)
fun findEnabledByMultilineTitleScope(name: String, origin: String): List<ReplaceRule>
@Query("select * from replace_rules where `group` like '%' || :group || '%'")
fun getByGroup(group: String): List<ReplaceRule>

@ -34,6 +34,9 @@ data class ReplaceRule(
//作用于标题
@ColumnInfo(defaultValue = "0")
var scopeTitle: Boolean = false,
//作用于多行标题
@ColumnInfo(defaultValue = "0")
var scopeMultilineTitle: Boolean = false,
//作用于正文
@ColumnInfo(defaultValue = "1")
var scopeContent: Boolean = true,

@ -8,6 +8,7 @@ import android.text.StaticLayout
import android.text.TextPaint
import io.legado.app.constant.AppPattern
import io.legado.app.constant.EventBus
import io.legado.app.data.appDb
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter
import io.legado.app.help.AppConfig
@ -133,6 +134,7 @@ object ChapterProvider {
matcher.appendTail(sb)
text = sb.toString()
if (!(isTitle && ReadBookConfig.titleMode == 2)) {
if (isTitle) text = replaceMultilineTitle(text, book)
setTypeText(
absStartX, durY, text, textPages, stringBuilder,
isTitle, isTitleWithNoContent, isVolumeTitle, textPaint, srcList
@ -145,9 +147,10 @@ object ChapterProvider {
val matcher = AppPattern.imgPattern.matcher(content)
var start = 0
while (matcher.find()) {
val text = content.substring(start, matcher.start())
var text = content.substring(start, matcher.start())
if (text.isNotBlank()) {
if (!(isTitle && ReadBookConfig.titleMode == 2)) {
if (isTitle) text = replaceMultilineTitle(text, book)
setTypeText(
absStartX, durY, text, textPages, stringBuilder,
isTitle, isTitleWithNoContent, isVolumeTitle, textPaint
@ -164,9 +167,10 @@ object ChapterProvider {
start = matcher.end()
}
if (start < content.length) {
val text = content.substring(start, content.length)
var text = content.substring(start, content.length)
if (text.isNotBlank()) {
if (!(isTitle && ReadBookConfig.titleMode == 2)) {
if (isTitle) text = replaceMultilineTitle(text, book)
setTypeText(
absStartX, durY, text, textPages, stringBuilder,
isTitle, isTitleWithNoContent, isVolumeTitle, textPaint
@ -621,4 +625,25 @@ object ChapterProvider {
}
}
/**
* 单独替换正文的标题可用于多行标题
*/
private fun replaceMultilineTitle(title: String, book: Book): String {
var mTitle = title
appDb.replaceRuleDao.findEnabledByMultilineTitleScope(book.name, book.origin).forEach { item ->
if (item.pattern.isNotEmpty()) {
try {
mTitle = if (item.isRegex) {
mTitle.replace(item.pattern.toRegex(), item.replacement)
} else {
mTitle.replace(item.pattern, item.replacement)
}
} catch (e: Exception) {
appCtx.toastOnUi("${item.name}替换出错")
}
}
}
return mTitle
}
}

@ -98,6 +98,7 @@ class ReplaceEditActivity :
cbUseRegex.isChecked = replaceRule.isRegex
etReplaceTo.setText(replaceRule.replacement)
cbScopeTitle.isChecked = replaceRule.scopeTitle
cbScopeMultilineTitle.isChecked = replaceRule.scopeMultilineTitle
cbScopeContent.isChecked = replaceRule.scopeContent
etScope.setText(replaceRule.scope)
}
@ -110,6 +111,7 @@ class ReplaceEditActivity :
replaceRule.isRegex = cbUseRegex.isChecked
replaceRule.replacement = etReplaceTo.text.toString()
replaceRule.scopeTitle = cbScopeTitle.isChecked
replaceRule.scopeMultilineTitle = cbScopeMultilineTitle.isChecked
replaceRule.scopeContent = cbScopeContent.isChecked
replaceRule.scope = etScope.text.toString()
return replaceRule

@ -114,6 +114,13 @@
android:text="@string/scope_title"
android:checked="false" />
<io.legado.app.lib.theme.view.ThemeCheckBox
android:id="@+id/cb_scope_multiline_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/scope_multiline_title"
android:checked="false" />
<io.legado.app.lib.theme.view.ThemeCheckBox
android:id="@+id/cb_scope_content"
android:layout_width="wrap_content"

@ -917,8 +917,6 @@
<string name="select_book_folder">选择保存书籍的文件夹</string>
<string name="user_agent">用户代理</string>
<string name="bg_alpha">背景透明度</string>
<!-- check source config string -->
<string name="check_source_config">校验设置</string>
<string name="check_source_item">校验项目</string>
<string name="check_source_timeout">单个书源校验超时(秒)</string>
@ -932,5 +930,5 @@
<string name="use_replace">使用替换</string>
<string name="scope_title">作用于标题</string>
<string name="scope_content">作用于正文</string>
<!-- string end -->
<string name="scope_multiline_title">Multiline title</string>
</resources>

@ -920,8 +920,6 @@
<string name="select_book_folder">选择保存书籍的文件夹</string>
<string name="user_agent">用户代理</string>
<string name="bg_alpha">背景透明度</string>
<!-- check source config string -->
<string name="check_source_config">校验设置</string>
<string name="check_source_item">校验项目</string>
<string name="check_source_timeout">单个书源校验超时(秒)</string>
@ -935,5 +933,5 @@
<string name="use_replace">使用替换</string>
<string name="scope_title">作用于标题</string>
<string name="scope_content">作用于正文</string>
<!-- string end -->
<string name="scope_multiline_title">Multiline title</string>
</resources>

@ -917,8 +917,6 @@
<string name="select_book_folder">选择保存书籍的文件夹</string>
<string name="user_agent">用户代理</string>
<string name="bg_alpha">背景透明度</string>
<!-- check source config string -->
<string name="check_source_config">校验设置</string>
<string name="check_source_item">校验项目</string>
<string name="check_source_timeout">单个书源校验超时(秒)</string>
@ -932,5 +930,5 @@
<string name="use_replace">使用替换</string>
<string name="scope_title">作用于标题</string>
<string name="scope_content">作用于正文</string>
<!-- string end -->
<string name="scope_multiline_title">多行标题</string>
</resources>

@ -919,8 +919,6 @@
<string name="select_book_folder">选择保存书籍的文件夹</string>
<string name="user_agent">用户代理</string>
<string name="bg_alpha">背景透明度</string>
<!-- check source config string -->
<string name="check_source_config">校验设置</string>
<string name="check_source_item">校验项目</string>
<string name="check_source_timeout">单个书源校验超时(秒)</string>
@ -934,5 +932,5 @@
<string name="use_replace">使用替换</string>
<string name="scope_title">作用于标题</string>
<string name="scope_content">作用于正文</string>
<!-- string end -->
<string name="scope_multiline_title">多行标题</string>
</resources>

@ -919,8 +919,6 @@
<string name="select_book_folder">选择保存书籍的文件夹</string>
<string name="user_agent">用户代理</string>
<string name="bg_alpha">背景透明度</string>
<!-- check source config string -->
<string name="check_source_config">校验设置</string>
<string name="check_source_item">校验项目</string>
<string name="check_source_timeout">单个书源校验超时(秒)</string>
@ -934,5 +932,5 @@
<string name="use_replace">使用替换</string>
<string name="scope_title">作用于标题</string>
<string name="scope_content">作用于正文</string>
<!-- string end -->
<string name="scope_multiline_title">多行标题</string>
</resources>

@ -920,8 +920,6 @@
<string name="select_book_folder">选择保存书籍的文件夹</string>
<string name="user_agent">User agent</string>
<string name="bg_alpha">Background alpha</string>
<!-- check source config string -->
<string name="check_source_config">校验设置</string>
<string name="check_source_item">校验项目</string>
<string name="check_source_timeout">单个书源校验超时(秒)</string>
@ -935,5 +933,5 @@
<string name="use_replace">Use replace</string>
<string name="scope_title">作用于标题</string>
<string name="scope_content">作用于正文</string>
<!-- string end -->
<string name="scope_multiline_title">Multiline title</string>
</resources>

Loading…
Cancel
Save