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