|
|
@ -27,17 +27,20 @@ class SearchViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
|
|
|
|
|
|
|
|
fun search(key: String) { |
|
|
|
fun search(key: String) { |
|
|
|
task?.cancel() |
|
|
|
task?.cancel() |
|
|
|
if (key.isEmpty()) { |
|
|
|
if (key.isEmpty() && searchKey.isEmpty()) { |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} else if (key.isEmpty()) { |
|
|
|
|
|
|
|
isLoading = true |
|
|
|
searchPage++ |
|
|
|
searchPage++ |
|
|
|
} else { |
|
|
|
} else if (key.isNotEmpty()) { |
|
|
|
|
|
|
|
isLoading = true |
|
|
|
|
|
|
|
searchPage = 0 |
|
|
|
searchKey = key |
|
|
|
searchKey = key |
|
|
|
searchBooks.clear() |
|
|
|
searchBooks.clear() |
|
|
|
} |
|
|
|
} |
|
|
|
if (searchKey.isEmpty()) return |
|
|
|
|
|
|
|
startTime = System.currentTimeMillis() |
|
|
|
startTime = System.currentTimeMillis() |
|
|
|
callBack?.startSearch() |
|
|
|
callBack?.startSearch() |
|
|
|
task = execute { |
|
|
|
task = execute { |
|
|
|
isLoading = true |
|
|
|
|
|
|
|
val searchGroup = context.getPrefString("searchGroup") ?: "" |
|
|
|
val searchGroup = context.getPrefString("searchGroup") ?: "" |
|
|
|
val bookSourceList = if (searchGroup.isBlank()) { |
|
|
|
val bookSourceList = if (searchGroup.isBlank()) { |
|
|
|
App.db.bookSourceDao().allEnabled |
|
|
|
App.db.bookSourceDao().allEnabled |
|
|
|