feat: 出港组装 list

This commit is contained in:
2025-11-27 13:11:33 +08:00
parent bea8a8c8c8
commit 29b1875fa5
16 changed files with 1058 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
package com.lukouguoji.gjc.holder
import android.view.View
import com.lukouguoji.gjc.databinding.ItemAssembleWaybillDetailBinding
import com.lukouguoji.module_base.base.BaseViewHolder
import com.lukouguoji.module_base.bean.GjcWarehouse
/**
* 国际出港组装-运单明细ViewHolder
*/
class AssembleWaybillDetailViewHolder(view: View) :
BaseViewHolder<GjcWarehouse, ItemAssembleWaybillDetailBinding>(view) {
override fun onBind(item: Any?, position: Int) {
val bean = getItemBean(item) ?: return
binding.bean = bean
binding.position = position // 用于显示序号
binding.executePendingBindings()
}
}

View File

@@ -0,0 +1,137 @@
package com.lukouguoji.gjc.holder
import android.view.View
import android.view.ViewGroup
import android.view.animation.Animation
import android.view.animation.Transformation
import androidx.recyclerview.widget.LinearLayoutManager
import com.lukouguoji.gjc.R
import com.lukouguoji.gjc.databinding.ItemIntExpAssembleUldBinding
import com.lukouguoji.module_base.base.BaseViewHolder
import com.lukouguoji.module_base.base.CommonAdapter
import com.lukouguoji.module_base.bean.GjcUldUseBean
import com.lukouguoji.module_base.bean.GjcWarehouse
/**
* 国际出港组装-ULD列表ViewHolder
* 支持展开/收起运单明细
*/
class IntExpAssembleViewHolder(view: View) :
BaseViewHolder<GjcUldUseBean, ItemIntExpAssembleUldBinding>(view) {
private var waybillAdapter: CommonAdapter? = null
override fun onBind(item: Any?, position: Int) {
val bean = getItemBean(item) ?: return
binding.bean = bean
binding.position = position
// 初始化运单明细子列表
setupWaybillRecyclerView(bean)
// 更新展开状态(初次绑定不需要动画)
updateExpandState(bean, animate = false)
// 展开按钮点击事件
binding.btnExpand.setOnClickListener {
clickListener?.onItemClick(position, 1000) // type=1000表示展开操作
}
binding.executePendingBindings()
}
/**
* 初始化运单明细RecyclerView
*/
private fun setupWaybillRecyclerView(bean: GjcUldUseBean) {
if (binding.rvWaybillDetails.adapter == null) {
binding.rvWaybillDetails.layoutManager = LinearLayoutManager(itemView.context)
waybillAdapter = CommonAdapter(
itemView.context,
R.layout.item_assemble_waybill_detail,
AssembleWaybillDetailViewHolder::class.java
)
binding.rvWaybillDetails.adapter = waybillAdapter
}
// 刷新运单明细数据
waybillAdapter?.refresh(bean.waybillDetails ?: mutableListOf())
}
/**
* 更新展开状态
* @param bean ULD数据
* @param animate 是否显示动画
*/
private fun updateExpandState(bean: GjcUldUseBean, animate: Boolean = true) {
if (bean.isExpanded) {
// 展开
if (animate) {
expand(binding.llWaybillDetails)
} else {
binding.llWaybillDetails.visibility = View.VISIBLE
}
binding.btnExpand.text = "收起"
} else {
// 收起
if (animate) {
collapse(binding.llWaybillDetails)
} else {
binding.llWaybillDetails.visibility = View.GONE
}
binding.btnExpand.text = "展开"
}
}
/**
* 展开动画高度从0到wrap_content
*/
private fun expand(view: View) {
// 测量目标高度
view.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED)
val targetHeight = view.measuredHeight
// 初始高度设为0
view.layoutParams.height = 0
view.visibility = View.VISIBLE
val animation = object : Animation() {
override fun applyTransformation(interpolatedTime: Float, t: Transformation?) {
view.layoutParams.height = if (interpolatedTime == 1f) {
ViewGroup.LayoutParams.WRAP_CONTENT
} else {
(targetHeight * interpolatedTime).toInt()
}
view.requestLayout()
}
override fun willChangeBounds() = true
}
animation.duration = 300 // 动画时长300ms
view.startAnimation(animation)
}
/**
* 收起动画高度从当前到0
*/
private fun collapse(view: View) {
val initialHeight = view.measuredHeight
val animation = object : Animation() {
override fun applyTransformation(interpolatedTime: Float, t: Transformation?) {
if (interpolatedTime == 1f) {
view.visibility = View.GONE
} else {
view.layoutParams.height = initialHeight - (initialHeight * interpolatedTime).toInt()
view.requestLayout()
}
}
override fun willChangeBounds() = true
}
animation.duration = 300 // 动画时长300ms
view.startAnimation(animation)
}
}