Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
gedoor committed Oct 20, 2022
1 parent 678e612 commit 710adb5
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions app/src/main/java/io/legado/app/ui/book/search/SearchScope.kt
Original file line number Diff line number Diff line change
Expand Up @@ -100,30 +100,32 @@ data class SearchScope(private var scope: String) {
val list = hashSetOf<BookSource>()
if (scope.isEmpty()) {
list.addAll(appDb.bookSourceDao.allEnabled)
} else if (scope.contains("::")) {
scope.substringAfter("::").let {
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)
}
}
if (list.isEmpty()) {
scope = ""
appDb.bookSourceDao.allEnabled.let {
if (it.isNotEmpty()) {
if (scope.contains("::")) {
scope.substringAfter("::").let {
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)
list.addAll(it)
}
}
if (list.isEmpty()) {
scope = ""
appDb.bookSourceDao.allEnabled.let {
if (it.isNotEmpty()) {
stateLiveData.postValue(scope)
list.addAll(it)
}
}
}
}
Expand Down

0 comments on commit 710adb5

Please sign in to comment.