mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user