From 2b3e3b761856cb239c516bf1146cc6c36832a97d Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 3 Apr 2022 22:54:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=89=B9=E9=87=8F=E6=8D=A2?= =?UTF-8?q?=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/book/arrange/ArrangeBookActivity.kt | 10 +++++-- .../ui/book/arrange/ArrangeBookViewModel.kt | 10 +++++-- .../legado/app/ui/book/arrange/ComposeView.kt | 26 ++++++++++++------- 3 files changed, 33 insertions(+), 13 deletions(-) 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() + ) + } } ) }