添加批量换源

This commit is contained in:
kunfei
2022-04-03 23:08:47 +08:00
parent 2163747fe9
commit 94a81eae14
2 changed files with 6 additions and 6 deletions
@@ -117,7 +117,7 @@ class ArrangeBookActivity : VMBaseActivity<ActivityArrangeBookBinding, ArrangeBo
size = viewModel.batchChangeSourceSize,
position = viewModel.batchChangeSourcePosition
) {
viewModel.batchChangeSourceCoroutine?.cancel()
}
}
}
@@ -15,6 +15,7 @@ class ArrangeBookViewModel(application: Application) : BaseViewModel(application
val batchChangeSourceState = mutableStateOf(false)
val batchChangeSourceSize = mutableStateOf(0)
val batchChangeSourcePosition = mutableStateOf(0)
var batchChangeSourceCoroutine: Coroutine<Unit>? = null
fun upCanUpdate(books: Array<Book>, canUpdate: Boolean) {
execute {
@@ -37,17 +38,16 @@ class ArrangeBookViewModel(application: Application) : BaseViewModel(application
}
}
fun changeSource(books: Array<Book>, source: BookSource): Coroutine<Unit> {
return execute {
fun changeSource(books: Array<Book>, source: BookSource) {
batchChangeSourceCoroutine?.cancel()
batchChangeSourceCoroutine = execute {
batchChangeSourceSize.value = books.size
books.forEachIndexed { index, book ->
batchChangeSourcePosition.value = index + 1
WebBook.preciseSearchAwait(this, book.name, book.author, source)?.let {
book.changeTo(it.second)
}
}
}.onCancel {
batchChangeSourceState.value = false
}.onFinally {
batchChangeSourceState.value = false
}