添加批量换源

pull/1751/head
kunfei 3 years ago
parent ea3fc5a076
commit 2b3e3b7618
  1. 10
      app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt
  2. 10
      app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookViewModel.kt
  3. 26
      app/src/main/java/io/legado/app/ui/book/arrange/ComposeView.kt

@ -112,7 +112,13 @@ class ArrangeBookActivity : VMBaseActivity<ActivityArrangeBookBinding, ArrangeBo
binding.selectActionBar.setCallBack(this) binding.selectActionBar.setCallBack(this)
binding.composeView.setContent { binding.composeView.setContent {
AppTheme { AppTheme {
BatchChangeSourceDialog(state = viewModel.batchChangeSourceState) BatchChangeSourceDialog(
state = viewModel.batchChangeSourceState,
size = viewModel.batchChangeSourceSize,
position = viewModel.batchChangeSourcePosition
) {
}
} }
} }
} }
@ -238,7 +244,7 @@ class ArrangeBookActivity : VMBaseActivity<ActivityArrangeBookBinding, ArrangeBo
} }
override fun sourceOnClick(source: BookSource) { override fun sourceOnClick(source: BookSource) {
//viewModel.changeSource(adapter.selectedBooks(), source) viewModel.changeSource(adapter.selectedBooks(), source)
viewModel.batchChangeSourceState.value = true viewModel.batchChangeSourceState.value = true
} }

@ -13,6 +13,8 @@ import io.legado.app.model.webBook.WebBook
class ArrangeBookViewModel(application: Application) : BaseViewModel(application) { class ArrangeBookViewModel(application: Application) : BaseViewModel(application) {
val batchChangeSourceState = mutableStateOf(false) val batchChangeSourceState = mutableStateOf(false)
val batchChangeSourceSize = mutableStateOf(0)
val batchChangeSourcePosition = mutableStateOf(0)
fun upCanUpdate(books: Array<Book>, canUpdate: Boolean) { fun upCanUpdate(books: Array<Book>, canUpdate: Boolean) {
execute { execute {
@ -37,13 +39,17 @@ class ArrangeBookViewModel(application: Application) : BaseViewModel(application
fun changeSource(books: Array<Book>, source: BookSource): Coroutine<Unit> { fun changeSource(books: Array<Book>, source: BookSource): Coroutine<Unit> {
return execute { 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 { WebBook.preciseSearchAwait(this, book.name, book.author, source)?.let {
} }
} }
}.onCancel {
batchChangeSourceState.value = false
}.onFinally { }.onFinally {
batchChangeSourceState.value = false
} }
} }

@ -1,36 +1,44 @@
package io.legado.app.ui.book.arrange package io.legado.app.ui.book.arrange
import androidx.compose.foundation.layout.Column
import androidx.compose.material.AlertDialog import androidx.compose.material.AlertDialog
import androidx.compose.material.LinearProgressIndicator
import androidx.compose.material.Text import androidx.compose.material.Text
import androidx.compose.material.TextButton import androidx.compose.material.TextButton
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf import androidx.compose.ui.Alignment
import androidx.compose.runtime.remember
import io.legado.app.R import io.legado.app.R
import splitties.init.appCtx import splitties.init.appCtx
@Composable @Composable
fun BatchChangeSourceDialog(state: MutableState<Boolean>) { fun BatchChangeSourceDialog(
val value = remember { state: MutableState<Boolean>,
mutableStateOf(0) size: MutableState<Int>,
} position: MutableState<Int>,
cancel: () -> Unit
) {
if (state.value) { if (state.value) {
AlertDialog( AlertDialog(
onDismissRequest = { }, onDismissRequest = { },
confirmButton = { confirmButton = {
TextButton(onClick = { TextButton(onClick = {
cancel.invoke()
state.value = false state.value = false
}, content = { }, content = {
Text(text = "取消") Text(text = "取消")
}) })
}, },
title = { title = {
Text(text = appCtx.getString(R.string.book_change_source)) Text(text = appCtx.getString(R.string.change_source_batch))
}, },
text = { text = {
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Text(text = "${position.value}/${size.value}")
LinearProgressIndicator(
progress = position.value / size.value.toFloat()
)
}
} }
) )
} }

Loading…
Cancel
Save