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