|
|
@ -25,11 +25,7 @@ class SearchViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
var isLoading = false |
|
|
|
var isLoading = false |
|
|
|
private var searchBooks = arrayListOf<SearchBook>() |
|
|
|
private var searchBooks = arrayListOf<SearchBook>() |
|
|
|
|
|
|
|
|
|
|
|
fun search( |
|
|
|
fun search(key: String) { |
|
|
|
key: String, |
|
|
|
|
|
|
|
start: (() -> Unit)? = null, |
|
|
|
|
|
|
|
finally: (() -> Unit)? = null |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
task?.cancel() |
|
|
|
task?.cancel() |
|
|
|
if (key.isEmpty()) { |
|
|
|
if (key.isEmpty()) { |
|
|
|
searchPage++ |
|
|
|
searchPage++ |
|
|
@ -39,7 +35,7 @@ class SearchViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
} |
|
|
|
} |
|
|
|
if (searchKey.isEmpty()) return |
|
|
|
if (searchKey.isEmpty()) return |
|
|
|
startTime = System.currentTimeMillis() |
|
|
|
startTime = System.currentTimeMillis() |
|
|
|
start?.invoke() |
|
|
|
callBack?.startSearch() |
|
|
|
task = execute { |
|
|
|
task = execute { |
|
|
|
isLoading = true |
|
|
|
isLoading = true |
|
|
|
val searchGroup = context.getPrefString("searchGroup") ?: "" |
|
|
|
val searchGroup = context.getPrefString("searchGroup") ?: "" |
|
|
@ -66,7 +62,7 @@ class SearchViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
task?.invokeOnCompletion { |
|
|
|
task?.invokeOnCompletion { |
|
|
|
finally?.invoke() |
|
|
|
callBack?.searchFinally() |
|
|
|
isLoading = false |
|
|
|
isLoading = false |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -176,5 +172,7 @@ class SearchViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
|
|
|
|
|
|
|
|
interface CallBack { |
|
|
|
interface CallBack { |
|
|
|
var adapter: SearchAdapter |
|
|
|
var adapter: SearchAdapter |
|
|
|
|
|
|
|
fun startSearch() |
|
|
|
|
|
|
|
fun searchFinally() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|