分组管理界面更新
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 :
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user