diff --git a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt index 56e7a7151..d151c84e1 100644 --- a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt @@ -112,7 +112,13 @@ class ArrangeBookActivity : VMBaseActivity, canUpdate: Boolean) { execute { @@ -37,13 +39,17 @@ class ArrangeBookViewModel(application: Application) : BaseViewModel(application fun changeSource(books: Array, source: BookSource): Coroutine { return execute { - books.forEach { book -> + batchChangeSourceSize.value = books.size + books.forEachIndexed { index, book -> + batchChangeSourcePosition.value = index + 1 WebBook.preciseSearchAwait(this, book.name, book.author, source)?.let { } } + }.onCancel { + batchChangeSourceState.value = false }.onFinally { - + batchChangeSourceState.value = false } } diff --git a/app/src/main/java/io/legado/app/ui/book/arrange/ComposeView.kt b/app/src/main/java/io/legado/app/ui/book/arrange/ComposeView.kt index a36dde904..bfb86ed15 100644 --- a/app/src/main/java/io/legado/app/ui/book/arrange/ComposeView.kt +++ b/app/src/main/java/io/legado/app/ui/book/arrange/ComposeView.kt @@ -1,36 +1,44 @@ package io.legado.app.ui.book.arrange +import androidx.compose.foundation.layout.Column import androidx.compose.material.AlertDialog +import androidx.compose.material.LinearProgressIndicator import androidx.compose.material.Text import androidx.compose.material.TextButton import androidx.compose.runtime.Composable import androidx.compose.runtime.MutableState -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember +import androidx.compose.ui.Alignment import io.legado.app.R import splitties.init.appCtx - @Composable -fun BatchChangeSourceDialog(state: MutableState) { - val value = remember { - mutableStateOf(0) - } +fun BatchChangeSourceDialog( + state: MutableState, + size: MutableState, + position: MutableState, + cancel: () -> Unit +) { if (state.value) { AlertDialog( onDismissRequest = { }, confirmButton = { TextButton(onClick = { + cancel.invoke() state.value = false }, content = { Text(text = "取消") }) }, title = { - Text(text = appCtx.getString(R.string.book_change_source)) + Text(text = appCtx.getString(R.string.change_source_batch)) }, text = { - + Column(horizontalAlignment = Alignment.CenterHorizontally) { + Text(text = "${position.value}/${size.value}") + LinearProgressIndicator( + progress = position.value / size.value.toFloat() + ) + } } ) }