From 27a2785be40959515b5f1946501f49045b291570 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 2 Sep 2019 17:14:20 +0800 Subject: [PATCH] up --- .../java/io/legado/app/data/entities/ReplaceRule.kt | 6 +++--- app/src/main/java/io/legado/app/help/BookHelp.kt | 13 ++++++++----- .../app/ui/replacerule/ReplaceEditActivity.kt | 1 + 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/entities/ReplaceRule.kt b/app/src/main/java/io/legado/app/data/entities/ReplaceRule.kt index 9235543aa..dcab47e66 100644 --- a/app/src/main/java/io/legado/app/data/entities/ReplaceRule.kt +++ b/app/src/main/java/io/legado/app/data/entities/ReplaceRule.kt @@ -15,10 +15,10 @@ import kotlinx.android.parcel.Parcelize data class ReplaceRule( @PrimaryKey(autoGenerate = true) var id: Int = 0, - var name: String? = null, + var name: String = "", var group: String? = null, - var pattern: String? = null, - var replacement: String? = null, + var pattern: String = "", + var replacement: String = "", var scope: String? = null, var isEnabled: Boolean = true, var isRegex: Boolean = true, diff --git a/app/src/main/java/io/legado/app/help/BookHelp.kt b/app/src/main/java/io/legado/app/help/BookHelp.kt index 15e2b5c81..b3ae92f19 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -124,8 +124,11 @@ object BookHelp { var bookOrigin: String? = null var replaceRules: List = arrayListOf() - fun disposeContent(name: String, origin: String?, content: String, enableReplace: Boolean) - : String { + fun disposeContent( + name: String, origin: String?, + content: String, + enableReplace: Boolean + ): String { var c = content synchronized(this) { if (enableReplace && (bookName != name || bookOrigin != origin)) { @@ -137,12 +140,12 @@ object BookHelp { } } for (item in replaceRules) { - item.pattern?.let { + item.pattern.let { if (it.isNotEmpty()) { c = if (item.isRegex) { - c.replace(it.toRegex(), item.replacement ?: "") + c.replace(it.toRegex(), item.replacement) } else { - c.replace(it, item.replacement ?: "") + c.replace(it, item.replacement) } } } diff --git a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceEditActivity.kt b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceEditActivity.kt index 81ed2b297..464fcf9a9 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceEditActivity.kt @@ -29,4 +29,5 @@ class ReplaceEditActivity : return super.onCompatOptionsItemSelected(item) } + }