feat: opt ui
This commit is contained in:
@@ -4,6 +4,10 @@ import android.view.View
|
||||
import com.lukouguoji.gjc.databinding.ItemIntExpMoveBinding
|
||||
import com.lukouguoji.module_base.base.BaseViewHolder
|
||||
import com.lukouguoji.module_base.bean.GjcMove
|
||||
import com.lukouguoji.module_base.common.ConstantEvent
|
||||
import com.lukouguoji.module_base.impl.FlowBus
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
/**
|
||||
* 国际出港移库列表项ViewHolder
|
||||
@@ -16,10 +20,15 @@ class IntExpMoveViewHolder(view: View) :
|
||||
binding.bean = bean
|
||||
binding.position = position
|
||||
|
||||
// 点击整个item切换选中状态
|
||||
binding.root.setOnClickListener {
|
||||
bean.isSelected = !bean.isSelected
|
||||
binding.bean = bean // 触发DataBinding更新
|
||||
// 添加图标点击事件 - 切换选择状态
|
||||
binding.ivIcon.setOnClickListener {
|
||||
bean.checked.set(!bean.checked.get()) // 反转选择状态
|
||||
binding.executePendingBindings() // 立即刷新UI
|
||||
|
||||
// 发送事件通知Activity更新全选状态
|
||||
GlobalScope.launch {
|
||||
FlowBus.with<String>(ConstantEvent.EVENT_CHECK_CHANGED).emit("check_changed")
|
||||
}
|
||||
}
|
||||
|
||||
binding.executePendingBindings()
|
||||
|
||||
@@ -11,6 +11,9 @@ import com.lukouguoji.gjc.databinding.ActivityIntExpMoveBinding
|
||||
import com.lukouguoji.gjc.viewModel.IntExpMoveViewModel
|
||||
import com.lukouguoji.module_base.base.BaseBindingActivity
|
||||
import com.lukouguoji.module_base.common.Constant
|
||||
import com.lukouguoji.module_base.common.ConstantEvent
|
||||
import com.lukouguoji.module_base.impl.FlowBus
|
||||
import com.lukouguoji.module_base.impl.observe
|
||||
import com.lukouguoji.module_base.ktx.addOnItemClickListener
|
||||
import com.lukouguoji.module_base.ktx.showToast
|
||||
import com.lukouguoji.module_base.model.ScanModel
|
||||
@@ -32,6 +35,7 @@ class IntExpMoveActivity : BaseBindingActivity<ActivityIntExpMoveBinding, IntExp
|
||||
|
||||
initRecyclerView()
|
||||
initListeners()
|
||||
observeData()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -57,6 +61,26 @@ class IntExpMoveActivity : BaseBindingActivity<ActivityIntExpMoveBinding, IntExp
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 观察数据变化
|
||||
*/
|
||||
private fun observeData() {
|
||||
// 观察全选状态,更新图标透明度
|
||||
viewModel.isAllChecked.observe(this) { isAllChecked ->
|
||||
binding.checkIcon.alpha = if (isAllChecked) 1.0f else 0.5f
|
||||
}
|
||||
|
||||
// 监听item选择变化事件,更新全选状态
|
||||
FlowBus.with<String>(ConstantEvent.EVENT_CHECK_CHANGED).observe(this) {
|
||||
viewModel.onItemCheckChanged()
|
||||
}
|
||||
|
||||
// 监听刷新事件
|
||||
FlowBus.with<String>(ConstantEvent.EVENT_REFRESH).observe(this) {
|
||||
viewModel.refresh()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 扫码运单号
|
||||
*/
|
||||
|
||||
@@ -13,6 +13,7 @@ import com.lukouguoji.module_base.ktx.launchLoadingCollect
|
||||
import com.lukouguoji.module_base.ktx.noNull
|
||||
import com.lukouguoji.module_base.ktx.showToast
|
||||
import com.lukouguoji.module_base.ktx.toRequestBody
|
||||
import com.lukouguoji.module_base.util.CheckUtil
|
||||
import dev.utils.app.info.KeyValue
|
||||
|
||||
/**
|
||||
@@ -50,6 +51,9 @@ class IntExpMoveViewModel : BasePageViewModel(), IOnItemClickListener {
|
||||
val totalPieces = MutableLiveData("0") // 总件数
|
||||
val totalWeight = MutableLiveData("0") // 总重量
|
||||
|
||||
// ========== 全选状态 ==========
|
||||
val isAllChecked = MutableLiveData(false)
|
||||
|
||||
// ========== 适配器配置 ==========
|
||||
val itemViewHolder = IntExpMoveViewHolder::class.java
|
||||
val itemLayoutId = R.layout.item_int_exp_move
|
||||
@@ -74,18 +78,44 @@ class IntExpMoveViewModel : BasePageViewModel(), IOnItemClickListener {
|
||||
fun toggleSelectAll() {
|
||||
val adapter = pageModel.rv?.commonAdapter() ?: return
|
||||
val list = adapter.items.filterIsInstance<GjcMove>()
|
||||
val allSelected = list.all { it.isSelected }
|
||||
|
||||
list.forEach { it.isSelected = !allSelected }
|
||||
// 使用CheckUtil处理全选逻辑
|
||||
CheckUtil.handleAllCheck(list)
|
||||
|
||||
// 更新全选状态
|
||||
updateCheckAllStatus()
|
||||
|
||||
// 刷新UI
|
||||
adapter.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新全选状态
|
||||
*/
|
||||
fun updateCheckAllStatus() {
|
||||
val adapter = pageModel.rv?.commonAdapter() ?: return
|
||||
val list = adapter.items.filterIsInstance<GjcMove>()
|
||||
|
||||
if (list.isNotEmpty()) {
|
||||
isAllChecked.value = list.all { it.checked.get() }
|
||||
} else {
|
||||
isAllChecked.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 单个item选择变化时调用(从Activity接收事件)
|
||||
*/
|
||||
fun onItemCheckChanged() {
|
||||
updateCheckAllStatus()
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取选中的运单
|
||||
*/
|
||||
fun getSelectedItems(): List<GjcMove> {
|
||||
val adapter = pageModel.rv?.commonAdapter() ?: return emptyList()
|
||||
return adapter.items.filterIsInstance<GjcMove>().filter { it.isSelected }
|
||||
return adapter.items.filterIsInstance<GjcMove>().filter { it.checked.get() }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -158,11 +188,9 @@ class IntExpMoveViewModel : BasePageViewModel(), IOnItemClickListener {
|
||||
}
|
||||
|
||||
/**
|
||||
* Item点击事件处理(用于单选CheckBox)
|
||||
* Item点击事件处理(现已改为图标点击,此方法暂时保留兼容)
|
||||
*/
|
||||
override fun onItemClick(position: Int, type: Int) {
|
||||
val bean = pageModel.rv?.commonAdapter()?.getItem(position) as? GjcMove ?: return
|
||||
bean.isSelected = !bean.isSelected
|
||||
pageModel.rv?.commonAdapter()?.notifyItemChanged(position)
|
||||
// 图标点击已在ViewHolder中处理,此处不再需要
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user