feat: opt ui
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package com.lukouguoji.module_base.bean
|
||||
|
||||
import androidx.databinding.ObservableBoolean
|
||||
import com.lukouguoji.module_base.interfaces.ICheck
|
||||
import java.io.Serializable
|
||||
|
||||
/**
|
||||
@@ -41,6 +43,15 @@ data class GjcMove(
|
||||
var remark: String = "", // 备注
|
||||
var likeNo: String = "", // 部分运单号no(模糊查询)
|
||||
|
||||
// UI扩展字段
|
||||
var isSelected: Boolean = false // 是否被选中(用于多选)
|
||||
) : Serializable
|
||||
// UI扩展字段 - 使用ObservableBoolean实现自动UI更新
|
||||
val checked: ObservableBoolean = ObservableBoolean(false)
|
||||
) : Serializable, ICheck {
|
||||
|
||||
// 实现ICheck接口
|
||||
override fun getCheckObservable(): ObservableBoolean = checked
|
||||
|
||||
// 兼容现有代码的属性(如果其他地方使用isSelected)
|
||||
var isSelected: Boolean
|
||||
get() = checked.get()
|
||||
set(value) = checked.set(value)
|
||||
}
|
||||
|
||||
@@ -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中处理,此处不再需要
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,8 +83,8 @@
|
||||
android:layout_weight="1">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="36dp"
|
||||
android:layout_height="36dp"
|
||||
android:layout_width="32dp"
|
||||
android:layout_height="32dp"
|
||||
android:onClick="@{()-> viewModel.searchClick()}"
|
||||
android:src="@drawable/img_search" />
|
||||
|
||||
|
||||
@@ -89,17 +89,17 @@
|
||||
android:gravity="center">
|
||||
|
||||
<ImageView
|
||||
style="@style/iv_search_action"
|
||||
android:layout_width="32dp"
|
||||
android:layout_height="32dp"
|
||||
android:onClick="@{()-> viewModel.searchClick()}"
|
||||
android:src="@drawable/img_search" />
|
||||
|
||||
<!-- 添加按钮 -->
|
||||
<ImageView
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_width="28dp"
|
||||
android:layout_height="28dp"
|
||||
android:layout_marginLeft="15dp"
|
||||
android:onClick="@{()-> viewModel.addClick()}"
|
||||
android:padding="5dp"
|
||||
android:src="@drawable/img_add" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -128,7 +128,7 @@
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:background="@color/color_bottom_layout"
|
||||
android:background="@color/white"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingHorizontal="15dp">
|
||||
|
||||
@@ -144,7 +144,7 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text='@{"合计:"+viewModel.totalCount+"票"}'
|
||||
android:textColor="@color/white"
|
||||
android:textColor="@color/bottom_tool_tips_text_color"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold"
|
||||
tools:text="合计:1票" />
|
||||
@@ -154,7 +154,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:text='@{"总件数:"+viewModel.totalPc}'
|
||||
android:textColor="@color/white"
|
||||
android:textColor="@color/bottom_tool_tips_text_color"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold"
|
||||
tools:text="总件数:100" />
|
||||
@@ -164,7 +164,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:text='@{"总重量:"+viewModel.totalWeight}'
|
||||
android:textColor="@color/white"
|
||||
android:textColor="@color/bottom_tool_tips_text_color"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold"
|
||||
tools:text="总重量:100" />
|
||||
@@ -174,7 +174,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:text='@{"总货重:"+viewModel.cargoWeight}'
|
||||
android:textColor="@color/white"
|
||||
android:textColor="@color/bottom_tool_tips_text_color"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold"
|
||||
tools:text="总货重:150" />
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/bg_white_radius_8"
|
||||
android:orientation="vertical"
|
||||
android:padding="20dp">
|
||||
android:padding="15dp">
|
||||
|
||||
<!-- 第一部分:前2行表单(左侧2列)+ 地磅称重(右侧) -->
|
||||
<LinearLayout
|
||||
@@ -84,7 +84,7 @@
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="15dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<com.lukouguoji.module_base.ui.weight.data.layout.PadDataLayoutNew
|
||||
@@ -171,7 +171,7 @@
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="15dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<com.lukouguoji.module_base.ui.weight.data.layout.PadDataLayoutNew
|
||||
@@ -212,7 +212,7 @@
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="15dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<com.lukouguoji.module_base.ui.weight.data.layout.PadDataLayoutNew
|
||||
@@ -254,7 +254,7 @@
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="15dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<com.lukouguoji.module_base.ui.weight.data.layout.PadDataLayoutNew
|
||||
@@ -295,7 +295,7 @@
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="15dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<com.lukouguoji.module_base.ui.weight.data.layout.PadDataLayoutNew
|
||||
@@ -335,7 +335,7 @@
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="15dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<com.lukouguoji.module_base.ui.weight.data.layout.PadDataLayoutNew
|
||||
@@ -367,7 +367,7 @@
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="24dp"
|
||||
android:layout_marginTop="15dp"
|
||||
android:padding="15dp">
|
||||
|
||||
<Space
|
||||
|
||||
@@ -90,8 +90,8 @@
|
||||
|
||||
<!-- 搜索按钮 -->
|
||||
<ImageView
|
||||
android:layout_width="36dp"
|
||||
android:layout_height="36dp"
|
||||
android:layout_width="32dp"
|
||||
android:layout_height="32dp"
|
||||
android:onClick="@{()-> viewModel.searchClick()}"
|
||||
android:src="@drawable/img_search" />
|
||||
|
||||
|
||||
@@ -79,8 +79,8 @@
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="36dp"
|
||||
android:layout_height="36dp"
|
||||
android:layout_width="32dp"
|
||||
android:layout_height="32dp"
|
||||
android:background="@null"
|
||||
android:onClick="@{()-> viewModel.searchClick()}"
|
||||
android:src="@drawable/img_search" />
|
||||
|
||||
@@ -86,23 +86,26 @@
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
style="@style/iv_search_action"
|
||||
android:layout_width="32dp"
|
||||
android:layout_height="32dp"
|
||||
android:onClick="@{()-> viewModel.searchClick()}"
|
||||
android:src="@drawable/img_search" />
|
||||
|
||||
<!-- 加号按钮 -->
|
||||
<ImageView
|
||||
style="@style/iv_search_action"
|
||||
android:layout_width="28dp"
|
||||
android:layout_height="28dp"
|
||||
android:onClick="@{()-> viewModel.onAddClick()}"
|
||||
android:src="@drawable/img_add"
|
||||
android:layout_marginLeft="10dp" />
|
||||
android:layout_marginLeft="15dp" />
|
||||
|
||||
<!-- 删除按钮 -->
|
||||
<ImageView
|
||||
style="@style/iv_search_action"
|
||||
android:layout_width="28dp"
|
||||
android:layout_height="28dp"
|
||||
android:onClick="@{()-> viewModel.onDeleteClick()}"
|
||||
android:src="@drawable/img_delete"
|
||||
android:layout_marginLeft="10dp" />
|
||||
android:layout_marginLeft="15dp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
@@ -132,7 +135,7 @@
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:background="@color/color_bottom_layout"
|
||||
android:background="@color/white"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingHorizontal="15dp">
|
||||
|
||||
@@ -148,7 +151,7 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text='@{"合计:"+viewModel.totalCount+"票"}'
|
||||
android:textColor="@color/white"
|
||||
android:textColor="@color/bottom_tool_tips_text_color"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
@@ -157,7 +160,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:text='@{"总件数:"+viewModel.totalPieces}'
|
||||
android:textColor="@color/white"
|
||||
android:textColor="@color/bottom_tool_tips_text_color"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
@@ -166,7 +169,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:text='@{"总重量:"+viewModel.totalWeight}'
|
||||
android:textColor="@color/white"
|
||||
android:textColor="@color/bottom_tool_tips_text_color"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
|
||||
@@ -92,8 +92,8 @@
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="36dp"
|
||||
android:layout_height="36dp"
|
||||
android:layout_width="32dp"
|
||||
android:layout_height="32dp"
|
||||
android:onClick="@{()-> viewModel.searchClick()}"
|
||||
android:src="@drawable/img_search" />
|
||||
</LinearLayout>
|
||||
@@ -126,15 +126,27 @@
|
||||
android:gravity="center_vertical"
|
||||
android:paddingHorizontal="15dp">
|
||||
|
||||
<!-- 全选 -->
|
||||
<CheckBox
|
||||
android:id="@+id/cbSelectAll"
|
||||
<!-- 全选按钮区域 (图标+文字) -->
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="@{()-> viewModel.toggleSelectAll()}"
|
||||
android:text="全选"
|
||||
android:textColor="@color/c666666"
|
||||
android:textSize="16sp" />
|
||||
android:gravity="center_vertical"
|
||||
android:onClick="@{()-> viewModel.toggleSelectAll()}">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="全选"
|
||||
android:textColor="@color/c666666"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/checkIcon"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_marginLeft="5dp"
|
||||
android:src="@drawable/img_check_all" />
|
||||
</LinearLayout>
|
||||
|
||||
<!-- 统计信息 -->
|
||||
<LinearLayout
|
||||
|
||||
@@ -77,8 +77,8 @@
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="36dp"
|
||||
android:layout_height="36dp"
|
||||
android:layout_width="32dp"
|
||||
android:layout_height="32dp"
|
||||
android:onClick="@{()-> viewModel.searchClick()}"
|
||||
android:src="@drawable/img_search" />
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<data>
|
||||
<import type="android.view.View" />
|
||||
@@ -24,19 +25,14 @@
|
||||
android:padding="15dp"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<!-- 左侧:CheckBox -->
|
||||
<CheckBox
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:checked="@{bean.isSelected}"
|
||||
android:clickable="false"
|
||||
android:focusable="false" />
|
||||
|
||||
<!-- 中间:飞机图标 -->
|
||||
<!-- 飞机图标 - 作为选择指示器(根据checked状态切换图片) -->
|
||||
<ImageView
|
||||
android:id="@+id/iv_icon"
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="50dp"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_gravity="center"
|
||||
app:loadImage="@{bean.checked.get() ? @drawable/img_plane_s : @drawable/img_plane}"
|
||||
android:src="@drawable/img_plane"
|
||||
android:contentDescription="@string/app_name" />
|
||||
|
||||
|
||||
Reference in New Issue
Block a user