Merge pull request #2437 from 821938089/little-fix

优化分组搜索范围
pull/2436/head
Horis 2 years ago committed by GitHub
commit e1820be375
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt
  2. 3
      app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt
  3. 21
      app/src/main/java/io/legado/app/ui/book/search/SearchScope.kt
  4. 2
      app/src/main/java/io/legado/app/ui/book/search/SearchScopeDialog.kt

@ -134,6 +134,9 @@ interface BookSourceDao {
@get:Query("select distinct bookSourceGroup from book_sources where trim(bookSourceGroup) <> ''")
val allGroupsUnProcessed: List<String>
@get:Query("select distinct bookSourceGroup from book_sources where enabled = 1 and trim(bookSourceGroup) <> ''")
val allEnabledGroupsUnProcessed: List<String>
@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<String>
get() {
return dealGroups(allEnabledGroupsUnProcessed)
}
fun flowGroups(): Flow<List<String>> {
return flowGroupsUnProcessed().map { list ->
dealGroups(list)

@ -221,6 +221,9 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
private fun initData() {
searchScopeAdapter.setItems(viewModel.searchScope.displayNames)
viewModel.searchScope.stateLiveData.observe(this) {
searchScopeAdapter.setItems(viewModel.searchScope.displayNames)
}
viewModel.isSearchLiveData.observe(this) {
if (it) {
startSearch()

@ -1,5 +1,6 @@
package io.legado.app.ui.book.search
import androidx.lifecycle.MutableLiveData
import io.legado.app.data.appDb
import io.legado.app.data.entities.BookSource
import io.legado.app.help.config.AppConfig
@ -13,12 +14,18 @@ data class SearchScope(private var scope: String) {
constructor(groups: List<String>) : 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 }

@ -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

Loading…
Cancel
Save