From 7f443158cf0f725924ba79642dcb26f8c207100c Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 7 Nov 2019 09:57:24 +0800 Subject: [PATCH] up --- .../io/legado/app/data/entities/BookSource.kt | 36 ++++++++--------- .../io/legado/app/data/entities/RssSource.kt | 40 +++++++++---------- .../source/edit/BookSourceEditActivity.kt | 17 +++----- .../rss/source/edit/RssSourceEditActivity.kt | 17 +++----- app/src/main/res/values/strings.xml | 2 +- 5 files changed, 50 insertions(+), 62 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/entities/BookSource.kt b/app/src/main/java/io/legado/app/data/entities/BookSource.kt index aada00709..8dc3ee71b 100644 --- a/app/src/main/java/io/legado/app/data/entities/BookSource.kt +++ b/app/src/main/java/io/legado/app/data/entities/BookSource.kt @@ -169,27 +169,27 @@ data class BookSource( return AppConst.SCRIPT_ENGINE.eval(jsStr, bindings) } - fun equal(source: BookSource?): Boolean { - if (source == null) { - return false - } - return bookSourceName == source.bookSourceName - && bookSourceUrl == source.bookSourceUrl - && bookSourceGroup == source.bookSourceGroup + fun equal(source: BookSource): Boolean { + return equal(bookSourceName, source.bookSourceName) + && equal(bookSourceUrl, source.bookSourceUrl) + && equal(bookSourceGroup, source.bookSourceGroup) && bookSourceType == source.bookSourceType - && bookUrlPattern == source.bookUrlPattern + && equal(bookUrlPattern, source.bookUrlPattern) && enabled == source.enabled && enabledExplore == source.enabledExplore - && header == source.header - && loginUrl == source.loginUrl - && lastUpdateTime == source.lastUpdateTime - && exploreUrl == source.exploreUrl - && searchUrl == source.searchUrl - && ruleSearch == source.ruleSearch - && ruleExplore == source.ruleExplore - && ruleBookInfo == source.ruleBookInfo - && ruleToc == source.ruleToc - && ruleContent == source.ruleContent + && equal(header, source.header) + && equal(loginUrl, source.loginUrl) + && equal(exploreUrl, source.exploreUrl) + && equal(searchUrl, source.searchUrl) + && getSearchRule() == source.getSearchRule() + && getExploreRule() == source.getExploreRule() + && getBookInfoRule() == source.getBookInfoRule() + && getTocRule() == source.getTocRule() + && getContentRule() == source.getContentRule() + } + + private fun equal(a: String?, b: String?): Boolean { + return a == b || (a.isNullOrEmpty() && b.isNullOrEmpty()) } data class ExploreKind( diff --git a/app/src/main/java/io/legado/app/data/entities/RssSource.kt b/app/src/main/java/io/legado/app/data/entities/RssSource.kt index 128410f99..e35ac8bdf 100644 --- a/app/src/main/java/io/legado/app/data/entities/RssSource.kt +++ b/app/src/main/java/io/legado/app/data/entities/RssSource.kt @@ -32,27 +32,25 @@ data class RssSource( var customOrder: Int = 0 ) : Parcelable { - fun equal(source: RssSource?): Boolean { - if (source == null) { - return false - } else { - return sourceUrl == source.sourceUrl - && sourceName == source.sourceName - && sourceIcon == source.sourceIcon - && enabled == source.enabled - && sourceGroup == source.sourceGroup - && ruleArticles == source.ruleArticles - && ruleNextPage == source.ruleNextPage - && ruleTitle == source.ruleTitle - && rulePubDate == source.rulePubDate - && ruleCategories == source.ruleCategories - && ruleDescription == source.ruleDescription - && ruleLink == source.ruleLink - && ruleContent == source.ruleContent - && enableJs == source.enableJs - && loadWithBaseUrl == source.loadWithBaseUrl - && customOrder == source.customOrder - } + fun equal(source: RssSource): Boolean { + return equal(sourceUrl, source.sourceUrl) + && equal(sourceIcon, source.sourceIcon) + && enabled == source.enabled + && equal(sourceGroup, source.sourceGroup) + && equal(ruleArticles, source.ruleArticles) + && equal(ruleNextPage, source.ruleNextPage) + && equal(ruleTitle, source.ruleTitle) + && equal(rulePubDate, source.rulePubDate) + && equal(ruleCategories, source.ruleCategories) + && equal(ruleDescription, source.ruleDescription) + && equal(ruleLink, source.ruleLink) + && equal(ruleContent, source.ruleContent) + && enableJs == source.enableJs + && loadWithBaseUrl == source.loadWithBaseUrl + } + + private fun equal(a: String?, b: String?): Boolean { + return a == b || (a.isNullOrEmpty() && b.isNullOrEmpty()) } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt index 75eee99c3..033d7f57d 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt @@ -21,8 +21,6 @@ import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.EditEntity import io.legado.app.data.entities.rule.* import io.legado.app.lib.dialogs.alert -import io.legado.app.lib.dialogs.noButton -import io.legado.app.lib.dialogs.yesButton import io.legado.app.lib.theme.ATH import io.legado.app.ui.book.source.debug.BookSourceDebugActivity import io.legado.app.ui.widget.KeyboardToolPop @@ -114,16 +112,13 @@ class BookSourceEditActivity : override fun finish() { val source = getSource() - if (!source.equal(viewModel.bookSource)) { - alert(R.string.exit_no_save) { - yesButton { - if (checkSource(source)) { - viewModel.save(source) { - super.finish() - } - } + if (!source.equal(viewModel.bookSource ?: BookSource())) { + alert(R.string.exit) { + messageResource = R.string.exit_no_save + positiveButton(R.string.yes) + negativeButton(R.string.no) { + super.finish() } - noButton { } }.show().applyTint() } else { super.finish() diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt index 9d415e860..c7b561b2a 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt @@ -19,8 +19,6 @@ import io.legado.app.constant.AppConst import io.legado.app.data.entities.EditEntity import io.legado.app.data.entities.RssSource import io.legado.app.lib.dialogs.alert -import io.legado.app.lib.dialogs.noButton -import io.legado.app.lib.dialogs.yesButton import io.legado.app.lib.theme.ATH import io.legado.app.ui.rss.source.debug.RssSourceDebugActivity import io.legado.app.ui.widget.KeyboardToolPop @@ -56,16 +54,13 @@ class RssSourceEditActivity : override fun finish() { val source = getRssSource() - if (!source.equal(viewModel.rssSource)) { - alert(R.string.exit_no_save) { - yesButton { - if (checkSource(source)) { - viewModel.save(source) { - super.finish() - } - } + if (!source.equal(viewModel.rssSource ?: RssSource())) { + alert(R.string.exit) { + messageResource = R.string.exit_no_save + positiveButton(R.string.yes) + negativeButton(R.string.no) { + super.finish() } - noButton { } }.show().applyTint() } else { super.finish() diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5e6c96226..d606691e4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -59,7 +59,7 @@ 关于 捐赠 退出 - 是否保存 + 尚未保存,是否继续编辑 阅读样式设置 版本 本地