添加批量换源
This commit is contained in:
@@ -112,7 +112,13 @@ class ArrangeBookActivity : VMBaseActivity<ActivityArrangeBookBinding, ArrangeBo
|
||||
binding.selectActionBar.setCallBack(this)
|
||||
binding.composeView.setContent {
|
||||
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) {
|
||||
//viewModel.changeSource(adapter.selectedBooks(), source)
|
||||
viewModel.changeSource(adapter.selectedBooks(), source)
|
||||
viewModel.batchChangeSourceState.value = true
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,8 @@ import io.legado.app.model.webBook.WebBook
|
||||
class ArrangeBookViewModel(application: Application) : BaseViewModel(application) {
|
||||
|
||||
val batchChangeSourceState = mutableStateOf(false)
|
||||
val batchChangeSourceSize = mutableStateOf(0)
|
||||
val batchChangeSourcePosition = mutableStateOf(0)
|
||||
|
||||
fun upCanUpdate(books: Array<Book>, canUpdate: Boolean) {
|
||||
execute {
|
||||
@@ -37,13 +39,17 @@ class ArrangeBookViewModel(application: Application) : BaseViewModel(application
|
||||
|
||||
fun changeSource(books: Array<Book>, source: BookSource): Coroutine<Unit> {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<Boolean>) {
|
||||
val value = remember {
|
||||
mutableStateOf(0)
|
||||
}
|
||||
fun BatchChangeSourceDialog(
|
||||
state: MutableState<Boolean>,
|
||||
size: MutableState<Int>,
|
||||
position: MutableState<Int>,
|
||||
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()
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user