From 022c60af38557af8213b9558dd04a240706c62a0 Mon Sep 17 00:00:00 2001 From: Horis <821938089@qq.com> Date: Sun, 16 Oct 2022 13:09:30 +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/dao/BookSourceDao.kt | 8 +++++++ .../app/ui/book/search/SearchActivity.kt | 3 +++ .../legado/app/ui/book/search/SearchScope.kt | 21 ++++++++++++++++--- .../app/ui/book/search/SearchScopeDialog.kt | 2 +- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt index 9e0ec4dbc..f0a689843 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt @@ -134,6 +134,9 @@ interface BookSourceDao { @get:Query("select distinct bookSourceGroup from book_sources where trim(bookSourceGroup) <> ''") val allGroupsUnProcessed: List + @get:Query("select distinct bookSourceGroup from book_sources where enabled = 1 and trim(bookSourceGroup) <> ''") + val allEnabledGroupsUnProcessed: List + @Query("select * from book_sources where bookSourceUrl = :key") fun getBookSource(key: String): BookSource? @@ -175,6 +178,11 @@ interface BookSourceDao { return dealGroups(allGroupsUnProcessed) } + val allEnabledGroups: List + get() { + return dealGroups(allEnabledGroupsUnProcessed) + } + fun flowGroups(): Flow> { return flowGroupsUnProcessed().map { list -> dealGroups(list) diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt index 948aac28b..fc94136ff 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt @@ -221,6 +221,9 @@ class SearchActivity : VMBaseActivity) : this(groups.joinToString(",")) - constructor(source: BookSource) : this("${source.bookSourceName}::${source.bookSourceUrl}") + constructor(source: BookSource) : this( + "${ + source.bookSourceName.replace("::", "") + }::${source.bookSourceUrl}" + ) override fun toString(): String { return scope } + val stateLiveData = MutableLiveData("") + fun update(scope: String) { this.scope = scope } @@ -70,12 +77,20 @@ data class SearchScope(private var scope: String) { } } } else { - scope.splitNotBlank(",").forEach { - list.addAll(appDb.bookSourceDao.getEnabledByGroup(it)) + val oldScope = scope.splitNotBlank(",") + val newScope = oldScope.filter { + val bookSources = appDb.bookSourceDao.getEnabledByGroup(it) + list.addAll(bookSources) + bookSources.isNotEmpty() + } + if (oldScope.size != newScope.size) { + update(newScope) + stateLiveData.postValue("") } } if (list.isEmpty()) { scope = "" + stateLiveData.postValue("") return appDb.bookSourceDao.allEnabled } return list.sortedBy { it.customOrder } diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchScopeDialog.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchScopeDialog.kt index 8d7ff9fab..b478d6957 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchScopeDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchScopeDialog.kt @@ -102,7 +102,7 @@ class SearchScopeDialog : BaseDialogFragment(R.layout.dialog_search_scope) { private fun initData() { launch { groups = withContext(IO) { - appDb.bookSourceDao.allGroups + appDb.bookSourceDao.allEnabledGroups } sources = withContext(IO) { appDb.bookSourceDao.allEnabled