|
|
@ -15,6 +15,7 @@ class ArrangeBookViewModel(application: Application) : BaseViewModel(application |
|
|
|
val batchChangeSourceState = mutableStateOf(false) |
|
|
|
val batchChangeSourceState = mutableStateOf(false) |
|
|
|
val batchChangeSourceSize = mutableStateOf(0) |
|
|
|
val batchChangeSourceSize = mutableStateOf(0) |
|
|
|
val batchChangeSourcePosition = mutableStateOf(0) |
|
|
|
val batchChangeSourcePosition = mutableStateOf(0) |
|
|
|
|
|
|
|
var batchChangeSourceCoroutine: Coroutine<Unit>? = null |
|
|
|
|
|
|
|
|
|
|
|
fun upCanUpdate(books: Array<Book>, canUpdate: Boolean) { |
|
|
|
fun upCanUpdate(books: Array<Book>, canUpdate: Boolean) { |
|
|
|
execute { |
|
|
|
execute { |
|
|
@ -37,17 +38,16 @@ class ArrangeBookViewModel(application: Application) : BaseViewModel(application |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun changeSource(books: Array<Book>, source: BookSource): Coroutine<Unit> { |
|
|
|
fun changeSource(books: Array<Book>, source: BookSource) { |
|
|
|
return execute { |
|
|
|
batchChangeSourceCoroutine?.cancel() |
|
|
|
|
|
|
|
batchChangeSourceCoroutine = execute { |
|
|
|
batchChangeSourceSize.value = books.size |
|
|
|
batchChangeSourceSize.value = books.size |
|
|
|
books.forEachIndexed { index, book -> |
|
|
|
books.forEachIndexed { index, book -> |
|
|
|
batchChangeSourcePosition.value = index + 1 |
|
|
|
batchChangeSourcePosition.value = index + 1 |
|
|
|
WebBook.preciseSearchAwait(this, book.name, book.author, source)?.let { |
|
|
|
WebBook.preciseSearchAwait(this, book.name, book.author, source)?.let { |
|
|
|
|
|
|
|
book.changeTo(it.second) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}.onCancel { |
|
|
|
|
|
|
|
batchChangeSourceState.value = false |
|
|
|
|
|
|
|
}.onFinally { |
|
|
|
}.onFinally { |
|
|
|
batchChangeSourceState.value = false |
|
|
|
batchChangeSourceState.value = false |
|
|
|
} |
|
|
|
} |
|
|
|