分组管理界面更新
This commit is contained in:
@@ -36,15 +36,20 @@ data class BookGroup(
|
||||
const val IdError = -11L
|
||||
}
|
||||
|
||||
fun getManageName(context: Context): String {
|
||||
data class GroupNameInfo(
|
||||
val groupName: String,
|
||||
val suffix: String? = null
|
||||
)
|
||||
|
||||
fun getManageName(context: Context): GroupNameInfo {
|
||||
return when (groupId) {
|
||||
IdAll -> "$groupName(${context.getString(R.string.all)})"
|
||||
IdAudio -> "$groupName(${context.getString(R.string.audio)})"
|
||||
IdLocal -> "$groupName(${context.getString(R.string.local)})"
|
||||
IdNetNone -> "$groupName(${context.getString(R.string.net_no_group)})"
|
||||
IdLocalNone -> "$groupName(${context.getString(R.string.local_no_group)})"
|
||||
IdError -> "$groupName(${context.getString(R.string.update_book_fail)})"
|
||||
else -> groupName
|
||||
IdAll -> GroupNameInfo(groupName, context.getString(R.string.all))
|
||||
IdAudio -> GroupNameInfo(groupName, context.getString(R.string.audio))
|
||||
IdLocal -> GroupNameInfo(groupName, context.getString(R.string.local))
|
||||
IdNetNone -> GroupNameInfo(groupName, context.getString(R.string.net_no_group))
|
||||
IdLocalNone -> GroupNameInfo(groupName, context.getString(R.string.local_no_group))
|
||||
IdError -> GroupNameInfo(groupName, context.getString(R.string.update_book_fail))
|
||||
else -> GroupNameInfo(groupName)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ import io.legato.kazusa.databinding.ItemBookGroupManageBinding
|
||||
import io.legato.kazusa.ui.widget.recycler.ItemTouchCallback
|
||||
import io.legato.kazusa.ui.widget.recycler.VerticalDivider
|
||||
import io.legato.kazusa.utils.applyTint
|
||||
import io.legato.kazusa.utils.gone
|
||||
import io.legato.kazusa.utils.showDialogFragment
|
||||
import io.legato.kazusa.utils.toastOnUi
|
||||
import io.legato.kazusa.utils.viewbindingdelegate.viewBinding
|
||||
@@ -61,7 +62,6 @@ class GroupManageDialog : BaseBottomSheetDialogFragment(R.layout.dialog_recycler
|
||||
|
||||
private fun initView() {
|
||||
binding.recyclerView.layoutManager = LinearLayoutManager(requireContext())
|
||||
binding.recyclerView.addItemDecoration(VerticalDivider(requireContext()))
|
||||
binding.recyclerView.adapter = adapter
|
||||
val itemTouchCallback = ItemTouchCallback(adapter)
|
||||
itemTouchCallback.isCanDrag = true
|
||||
@@ -119,8 +119,16 @@ class GroupManageDialog : BaseBottomSheetDialogFragment(R.layout.dialog_recycler
|
||||
payloads: MutableList<Any>
|
||||
) {
|
||||
binding.run {
|
||||
//root.setBackgroundColor(context.backgroundColor)
|
||||
tvGroup.text = item.getManageName(context)
|
||||
val nameInfo = item.getManageName(context)
|
||||
tvGroup.text = nameInfo.groupName
|
||||
|
||||
if (nameInfo.suffix != null) {
|
||||
tvSuffix.visible()
|
||||
tvSuffix.text = nameInfo.suffix
|
||||
} else {
|
||||
tvSuffix.gone()
|
||||
}
|
||||
|
||||
swShow.isChecked = item.show
|
||||
}
|
||||
}
|
||||
@@ -158,6 +166,10 @@ class GroupManageDialog : BaseBottomSheetDialogFragment(R.layout.dialog_recycler
|
||||
viewModel.upGroup(*getItems().toTypedArray())
|
||||
}
|
||||
isMoved = false
|
||||
val position = viewHolder.layoutPosition
|
||||
if (position != RecyclerView.NO_POSITION) {
|
||||
notifyItemChanged(position)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.widget.ArrayAdapter
|
||||
import androidx.activity.viewModels
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import io.legato.kazusa.R
|
||||
@@ -46,6 +47,9 @@ class BookInfoEditActivity :
|
||||
override val binding by viewBinding(ActivityBookInfoEditBinding::inflate)
|
||||
override val viewModel by viewModels<BookInfoEditViewModel>()
|
||||
|
||||
// 从资源获取书籍类型数组
|
||||
private val bookTypes = arrayOf("文本", "音频", "图片")
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
viewModel.bookData.observe(this) { upView(it) }
|
||||
@@ -77,6 +81,24 @@ class BookInfoEditActivity :
|
||||
view.bottomPadding = insets.bottom
|
||||
windowInsets
|
||||
}
|
||||
initAutoCompleteTextView()
|
||||
}
|
||||
|
||||
private fun initAutoCompleteTextView() = binding.run {
|
||||
// 创建适配器
|
||||
val adapter = ArrayAdapter(
|
||||
this@BookInfoEditActivity,
|
||||
android.R.layout.simple_dropdown_item_1line, bookTypes
|
||||
)
|
||||
actvType.setAdapter(adapter)
|
||||
actvType.setOnClickListener {
|
||||
actvType.showDropDown()
|
||||
}
|
||||
actvType.setOnFocusChangeListener { _, hasFocus ->
|
||||
if (hasFocus) {
|
||||
actvType.showDropDown()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun initEvent() = binding.run {
|
||||
@@ -99,13 +121,12 @@ class BookInfoEditActivity :
|
||||
private fun upView(book: Book) = binding.run {
|
||||
tieBookName.setText(book.name)
|
||||
tieBookAuthor.setText(book.author)
|
||||
spType.setSelection(
|
||||
when {
|
||||
book.isImage -> 2
|
||||
book.isAudio -> 1
|
||||
else -> 0
|
||||
}
|
||||
)
|
||||
val selectedType = when {
|
||||
book.isImage -> 2
|
||||
book.isAudio -> 1
|
||||
else -> 0
|
||||
}
|
||||
actvType.setText(bookTypes.getOrNull(selectedType) ?: bookTypes[0], false)
|
||||
tieCoverUrl.setText(book.getDisplayCover())
|
||||
tieBookIntro.setText(book.getDisplayIntro())
|
||||
upCover()
|
||||
@@ -123,9 +144,10 @@ class BookInfoEditActivity :
|
||||
book.name = tieBookName.text?.toString() ?: ""
|
||||
book.author = tieBookAuthor.text?.toString() ?: ""
|
||||
val local = if (book.isLocal) BookType.local else 0
|
||||
val bookType = when (spType.selectedItemPosition) {
|
||||
2 -> BookType.image or local
|
||||
1 -> BookType.audio or local
|
||||
val selectedType = actvType.text.toString()
|
||||
val bookType = when (selectedType) {
|
||||
bookTypes[2] -> BookType.image or local
|
||||
bookTypes[1] -> BookType.audio or local
|
||||
else -> BookType.text or local
|
||||
}
|
||||
book.removeType(BookType.local, BookType.image, BookType.audio, BookType.text)
|
||||
@@ -167,5 +189,4 @@ class BookInfoEditActivity :
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,33 +1,72 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:padding="16dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_group"
|
||||
android:layout_width="0dp"
|
||||
android:layout_margin="8dp"
|
||||
app:strokeWidth="0dp">
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
tools:text="group" />
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:background="?attr/colorSurface"
|
||||
android:foreground="?attr/selectableItemBackground"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:padding="8dp">
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/tv_edit"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
style="@style/Widget.Material3Expressive.Button.IconButton.Tonal"
|
||||
app:icon="@drawable/ic_edit" />
|
||||
<TextView
|
||||
android:id="@+id/tv_group"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:textStyle="bold"
|
||||
android:textSize="14sp"
|
||||
tools:text="group" />
|
||||
|
||||
<io.legato.kazusa.lib.theme.view.ThemeSwitch
|
||||
android:id="@+id/sw_show"
|
||||
android:minWidth="48dp"
|
||||
android:minHeight="48dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
android:id="@+id/cd_group"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:cardCornerRadius="8dp"
|
||||
app:strokeColor="?attr/colorSurfaceContainerHigh"
|
||||
app:cardBackgroundColor="?attr/colorSurfaceContainerHigh"
|
||||
android:layout_marginStart="8dp">
|
||||
<TextView
|
||||
android:id="@+id/tv_suffix"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginVertical="4dp"
|
||||
android:layout_marginHorizontal="8dp"
|
||||
android:textStyle="bold"
|
||||
android:textSize="12sp"
|
||||
tools:text="group" />
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
||||
</LinearLayout>
|
||||
<View
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/tv_edit"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
app:iconSize="20dp"
|
||||
app:iconPadding="0dp"
|
||||
app:iconGravity="textStart"
|
||||
android:layout_marginEnd="8dp"
|
||||
style="@style/Widget.Material3Expressive.Button.IconButton.Tonal"
|
||||
app:icon="@drawable/ic_edit" />
|
||||
|
||||
<io.legato.kazusa.lib.theme.view.ThemeSwitch
|
||||
android:id="@+id/sw_show"
|
||||
android:minWidth="48dp"
|
||||
android:minHeight="48dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</LinearLayout>
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
Reference in New Issue
Block a user