This commit is contained in:
kunfei
2022-10-20 20:30:24 +08:00
parent 678e6125dd
commit 710adb58ee
@@ -100,30 +100,32 @@ data class SearchScope(private var scope: String) {
val list = hashSetOf<BookSource>() val list = hashSetOf<BookSource>()
if (scope.isEmpty()) { if (scope.isEmpty()) {
list.addAll(appDb.bookSourceDao.allEnabled) list.addAll(appDb.bookSourceDao.allEnabled)
} else if (scope.contains("::")) { } else {
scope.substringAfter("::").let { if (scope.contains("::")) {
appDb.bookSourceDao.getBookSource(it)?.let { source -> scope.substringAfter("::").let {
list.add(source) appDb.bookSourceDao.getBookSource(it)?.let { source ->
list.add(source)
}
}
} else {
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(scope)
} }
} }
} else { if (list.isEmpty()) {
val oldScope = scope.splitNotBlank(",") scope = ""
val newScope = oldScope.filter { appDb.bookSourceDao.allEnabled.let {
val bookSources = appDb.bookSourceDao.getEnabledByGroup(it) if (it.isNotEmpty()) {
list.addAll(bookSources) stateLiveData.postValue(scope)
bookSources.isNotEmpty() list.addAll(it)
} }
if (oldScope.size != newScope.size) {
update(newScope)
stateLiveData.postValue(scope)
}
}
if (list.isEmpty()) {
scope = ""
appDb.bookSourceDao.allEnabled.let {
if (it.isNotEmpty()) {
stateLiveData.postValue(scope)
list.addAll(it)
} }
} }
} }