From dc4d6734a42f49f3cc90608bfdddfaa097d92a58 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 15 Feb 2022 14:07:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/data/entities/BookSource.kt | 44 +++++++++++-------- .../io/legado/app/data/entities/RssSource.kt | 8 ++++ .../book/source/manage/BookSourceAdapter.kt | 37 +++++++++++++--- .../ui/rss/source/manage/RssSourceAdapter.kt | 42 ++++++++---------- 4 files changed, 83 insertions(+), 48 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 c22d5a345..5c095d467 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 @@ -118,6 +118,14 @@ data class BookSource( fun getContentRule() = ruleContent ?: ContentRule() + fun getDisPlayNameGroup(): String { + return if (bookSourceGroup.isNullOrBlank()) { + bookSourceName + } else { + String.format("%s (%s)", bookSourceName, bookSourceGroup) + } + } + fun addGroup(groups: String): BookSource { bookSourceGroup?.splitNotBlank(AppPattern.splitGroupRegex)?.toHashSet()?.let { it.addAll(groups.splitNotBlank(AppPattern.splitGroupRegex)) @@ -137,7 +145,7 @@ data class BookSource( fun hasGroup(group: String): Boolean { bookSourceGroup?.splitNotBlank(AppPattern.splitGroupRegex)?.toHashSet()?.let { - return it.indexOf(group) != -1 + return it.indexOf(group) != -1 } return false } @@ -148,28 +156,28 @@ data class BookSource( fun getInvalidGroupNames(): String { return bookSourceGroup?.splitNotBlank(AppPattern.splitGroupRegex)?.toHashSet()?.filter { - "失效" in it + "失效" in it }?.joinToString() ?: "" } fun equal(source: BookSource) = equal(bookSourceName, source.bookSourceName) - && equal(bookSourceUrl, source.bookSourceUrl) - && equal(bookSourceGroup, source.bookSourceGroup) - && bookSourceType == source.bookSourceType - && equal(bookUrlPattern, source.bookUrlPattern) - && equal(bookSourceComment, source.bookSourceComment) - && enabled == source.enabled - && enabledExplore == source.enabledExplore - && equal(header, source.header) - && 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() + && equal(bookSourceUrl, source.bookSourceUrl) + && equal(bookSourceGroup, source.bookSourceGroup) + && bookSourceType == source.bookSourceType + && equal(bookUrlPattern, source.bookUrlPattern) + && equal(bookSourceComment, source.bookSourceComment) + && enabled == source.enabled + && enabledExplore == source.enabledExplore + && equal(header, source.header) + && 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?) = a == b || (a.isNullOrEmpty() && b.isNullOrEmpty()) 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 bafa5139d..4d7d9ca54 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 @@ -85,6 +85,14 @@ data class RssSource( return a == b || (a.isNullOrEmpty() && b.isNullOrEmpty()) } + fun getDisplayNameGroup(): String { + return if (sourceGroup.isNullOrBlank()) { + sourceName + } else { + String.format("%s (%s)", sourceName, sourceGroup) + } + } + fun sortUrls(): List> = arrayListOf>().apply { kotlin.runCatching { var a = sortUrl diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt index 48caf74ff..876bd816d 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt @@ -51,7 +51,32 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) : } override fun areContentsTheSame(oldItem: BookSource, newItem: BookSource): Boolean { - return false + return oldItem.bookSourceName == newItem.bookSourceName + && oldItem.bookSourceGroup == newItem.bookSourceGroup + && oldItem.enabled == newItem.enabled + && oldItem.enabledExplore == newItem.enabledExplore + && oldItem.exploreUrl == newItem.exploreUrl + } + + override fun getChangePayload(oldItem: BookSource, newItem: BookSource): Any? { + val payload = Bundle() + if (oldItem.bookSourceName != newItem.bookSourceName + || oldItem.bookSourceGroup != newItem.bookSourceGroup + ) { + payload.putBoolean("upName", true) + } + if (oldItem.enabled != newItem.enabled) { + payload.putBoolean("enabled", newItem.enabled) + } + if (oldItem.enabledExplore != newItem.enabledExplore || + oldItem.exploreUrl != newItem.exploreUrl + ) { + payload.putBoolean("upExplore", true) + } + if (payload.isEmpty) { + return null + } + return payload } } @@ -70,12 +95,7 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) : val payload = payloads.getOrNull(0) as? Bundle if (payload == null) { root.setBackgroundColor(ColorUtils.withAlpha(context.backgroundColor, 0.5f)) - if (item.bookSourceGroup.isNullOrEmpty()) { - cbBookSource.text = item.bookSourceName - } else { - cbBookSource.text = - String.format("%s (%s)", item.bookSourceName, item.bookSourceGroup) - } + cbBookSource.text = item.getDisPlayNameGroup() swtEnabled.isChecked = item.enabled cbBookSource.isChecked = selected.contains(item) ivDebugText.text = Debug.debugMessageMap[item.bookSourceUrl] ?: "" @@ -85,6 +105,9 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) : } else { payload.keySet().map { when (it) { + "enabled" -> swtEnabled.isChecked = payload.getBoolean("enabled") + "upName" -> cbBookSource.text = item.getDisPlayNameGroup() + "upExplore" -> upShowExplore(ivExplore, item) "selected" -> cbBookSource.isChecked = selected.contains(item) "checkSourceMessage" -> { ivDebugText.text = Debug.debugMessageMap[item.bookSourceUrl] ?: "" diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt index 34147a14c..9300d0e4a 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt @@ -44,27 +44,26 @@ class RssSourceAdapter(context: Context, val callBack: CallBack) : override fun areContentsTheSame(oldItem: RssSource, newItem: RssSource): Boolean { return oldItem.sourceName == newItem.sourceName - && oldItem.sourceGroup == newItem.sourceGroup - && oldItem.enabled == newItem.enabled + && oldItem.sourceGroup == newItem.sourceGroup + && oldItem.enabled == newItem.enabled } - override fun getChangePayload(oldItem: RssSource, newItem: RssSource): Any? { - val payload = Bundle() - if (oldItem.sourceName != newItem.sourceName) { - payload.putString("name", newItem.sourceName) - } - if (oldItem.sourceGroup != newItem.sourceGroup) { - payload.putString("group", newItem.sourceGroup) - } - if (oldItem.enabled != newItem.enabled) { - payload.putBoolean("enabled", newItem.enabled) - } - if (payload.isEmpty) { - return null - } - return payload + override fun getChangePayload(oldItem: RssSource, newItem: RssSource): Any? { + val payload = Bundle() + if (oldItem.sourceName != newItem.sourceName + || oldItem.sourceGroup != newItem.sourceGroup + ) { + payload.putBoolean("upName", true) } + if (oldItem.enabled != newItem.enabled) { + payload.putBoolean("enabled", newItem.enabled) + } + if (payload.isEmpty) { + return null + } + return payload } + } override fun getViewBinding(parent: ViewGroup): ItemRssSourceBinding { return ItemRssSourceBinding.inflate(inflater, parent, false) @@ -80,17 +79,14 @@ class RssSourceAdapter(context: Context, val callBack: CallBack) : val bundle = payloads.getOrNull(0) as? Bundle if (bundle == null) { root.setBackgroundColor(ColorUtils.withAlpha(context.backgroundColor, 0.5f)) - if (item.sourceGroup.isNullOrEmpty()) { - cbSource.text = item.sourceName - } else { - cbSource.text = - String.format("%s (%s)", item.sourceName, item.sourceGroup) - } + cbSource.text = item.getDisplayNameGroup() swtEnabled.isChecked = item.enabled cbSource.isChecked = selected.contains(item) } else { bundle.keySet().map { when (it) { + "upName" -> cbSource.text = item.getDisplayNameGroup() + "enabled" -> swtEnabled.isChecked = bundle.getBoolean("enabled") "selected" -> cbSource.isChecked = selected.contains(item) } }