添加批量换源

pull/1751/head
kunfei 3 years ago
parent 364466e358
commit bd797476b3
  1. 9
      app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt
  2. 3
      app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookViewModel.kt
  3. 37
      app/src/main/java/io/legado/app/ui/book/arrange/ComposeView.kt
  4. 13
      app/src/main/java/io/legado/app/ui/book/arrange/SourcePickerDialog.kt
  5. 8
      app/src/main/java/io/legado/app/ui/book/audio/ComposeView.kt
  6. 16
      app/src/main/java/io/legado/app/ui/theme/AppTheme.kt
  7. 19
      app/src/main/res/layout/activity_arrange_book.xml
  8. 1
      app/src/main/res/layout/item_1line_text_and_del.xml

@ -21,6 +21,7 @@ import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.theme.primaryColor
import io.legado.app.ui.book.group.GroupManageDialog
import io.legado.app.ui.book.group.GroupSelectDialog
import io.legado.app.ui.theme.AppTheme
import io.legado.app.ui.widget.SelectActionBar
import io.legado.app.ui.widget.recycler.DragSelectTouchHelper
import io.legado.app.ui.widget.recycler.ItemTouchCallback
@ -109,6 +110,11 @@ class ArrangeBookActivity : VMBaseActivity<ActivityArrangeBookBinding, ArrangeBo
binding.selectActionBar.inflateMenu(R.menu.arrange_book_sel)
binding.selectActionBar.setOnMenuItemClickListener(this)
binding.selectActionBar.setCallBack(this)
binding.composeView.setContent {
AppTheme {
BatchChangeSourceDialog(state = viewModel.batchChangeSourceState)
}
}
}
@SuppressLint("NotifyDataSetChanged")
@ -232,7 +238,8 @@ class ArrangeBookActivity : VMBaseActivity<ActivityArrangeBookBinding, ArrangeBo
}
override fun sourceOnClick(source: BookSource) {
viewModel.changeSource(adapter.selectedBooks(), source)
//viewModel.changeSource(adapter.selectedBooks(), source)
viewModel.batchChangeSourceState.value = true
}
}

@ -1,6 +1,7 @@
package io.legado.app.ui.book.arrange
import android.app.Application
import androidx.compose.runtime.mutableStateOf
import io.legado.app.base.BaseViewModel
import io.legado.app.data.appDb
import io.legado.app.data.entities.Book
@ -11,6 +12,8 @@ import io.legado.app.model.webBook.WebBook
class ArrangeBookViewModel(application: Application) : BaseViewModel(application) {
val batchChangeSourceState = mutableStateOf(false)
fun upCanUpdate(books: Array<Book>, canUpdate: Boolean) {
execute {
books.forEach {

@ -0,0 +1,37 @@
package io.legado.app.ui.book.arrange
import androidx.compose.material.AlertDialog
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 io.legado.app.R
import splitties.init.appCtx
@Composable
fun BatchChangeSourceDialog(state: MutableState<Boolean>) {
val value = remember {
mutableStateOf(0)
}
if (state.value) {
AlertDialog(
onDismissRequest = { },
confirmButton = {
TextButton(onClick = {
state.value = false
}, content = {
Text(text = "取消")
})
},
title = {
Text(text = appCtx.getString(R.string.book_change_source))
},
text = {
}
)
}
}

@ -14,7 +14,7 @@ import io.legado.app.base.adapter.RecyclerAdapter
import io.legado.app.data.appDb
import io.legado.app.data.entities.BookSource
import io.legado.app.databinding.DialogSourcePickerBinding
import io.legado.app.databinding.ItemTextBinding
import io.legado.app.databinding.Item1lineTextAndDelBinding
import io.legado.app.lib.theme.primaryColor
import io.legado.app.lib.theme.primaryTextColor
import io.legado.app.utils.applyTint
@ -81,27 +81,28 @@ class SourcePickerDialog : BaseDialogFragment(R.layout.dialog_source_picker) {
}
inner class SourceAdapter(context: Context) :
RecyclerAdapter<BookSource, ItemTextBinding>(context) {
RecyclerAdapter<BookSource, Item1lineTextAndDelBinding>(context) {
override fun getViewBinding(parent: ViewGroup): ItemTextBinding {
return ItemTextBinding.inflate(inflater, parent, false).apply {
override fun getViewBinding(parent: ViewGroup): Item1lineTextAndDelBinding {
return Item1lineTextAndDelBinding.inflate(inflater, parent, false).apply {
root.setPadding(16.dpToPx())
}
}
override fun convert(
holder: ItemViewHolder,
binding: ItemTextBinding,
binding: Item1lineTextAndDelBinding,
item: BookSource,
payloads: MutableList<Any>
) {
binding.textView.text = item.getDisPlayNameGroup()
}
override fun registerListener(holder: ItemViewHolder, binding: ItemTextBinding) {
override fun registerListener(holder: ItemViewHolder, binding: Item1lineTextAndDelBinding) {
binding.root.onClick {
getItemByLayoutPosition(holder.layoutPosition)?.let {
callback?.sourceOnClick(it)
dismissAllowingStateLoss()
}
}
}

@ -5,19 +5,15 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Card
import androidx.compose.material.Slider
import androidx.compose.material.SliderDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
import io.legado.app.lib.theme.accentColor
import io.legado.app.model.AudioPlay
import io.legado.app.service.AudioPlayService
import splitties.init.appCtx
@Composable
@ -37,10 +33,6 @@ fun TimerDialog(state: MutableState<Boolean>, parent: View) {
AudioPlay.setTimer(it.toInt())
},
valueRange = 0f..180f,
colors = SliderDefaults.colors(
thumbColor = Color(appCtx.accentColor),
activeTrackColor = Color(appCtx.accentColor)
)
)
}
}

@ -16,17 +16,17 @@ object AppTheme {
val colors
get() = if (ThemeConfig.isDarkTheme()) {
darkColors(
primary = Color(appCtx.primaryColor),
primaryVariant = Color(ColorUtils.darkenColor(appCtx.primaryColor)),
secondary = Color(appCtx.accentColor),
secondaryVariant = Color(appCtx.accentColor)
primary = Color(appCtx.accentColor),
primaryVariant = Color(ColorUtils.darkenColor(appCtx.accentColor)),
secondary = Color(appCtx.primaryColor),
secondaryVariant = Color(appCtx.primaryColor)
)
} else {
lightColors(
primary = Color(appCtx.primaryColor),
primaryVariant = Color(ColorUtils.darkenColor(appCtx.primaryColor)),
secondary = Color(appCtx.accentColor),
secondaryVariant = Color(appCtx.accentColor)
primary = Color(appCtx.accentColor),
primaryVariant = Color(ColorUtils.darkenColor(appCtx.accentColor)),
secondary = Color(appCtx.primaryColor),
secondaryVariant = Color(appCtx.primaryColor)
)
}

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
@ -9,17 +9,26 @@
android:id="@+id/title_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:title="@string/arrange_bookshelf" />
app:title="@string/arrange_bookshelf"
app:layout_constraintTop_toTopOf="parent" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
app:layout_constraintTop_toBottomOf="@id/title_bar"
app:layout_constraintBottom_toTopOf="@id/select_action_bar" />
<io.legado.app.ui.widget.SelectActionBar
android:id="@+id/select_action_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent" />
<androidx.compose.ui.platform.ComposeView
android:id="@+id/compose_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

@ -6,6 +6,7 @@
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:background="?attr/selectableItemBackground"
android:padding="6dp"
tools:ignore="UseCompoundDrawables">

Loading…
Cancel
Save