|
@@ -9,47 +9,45 @@ import android.widget.TextView
|
|
|
import androidx.recyclerview.widget.RecyclerView
|
|
import androidx.recyclerview.widget.RecyclerView
|
|
|
import cn.muchinfo.rma.R
|
|
import cn.muchinfo.rma.R
|
|
|
import cn.muchinfo.rma.view.base.BaseViewModel
|
|
import cn.muchinfo.rma.view.base.BaseViewModel
|
|
|
|
|
+import cn.muchinfo.rma.view.base.future.interfaces.OnItemClickListener
|
|
|
|
|
+import org.jetbrains.anko.backgroundColor
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 今日委托和今日可撤model
|
|
* 今日委托和今日可撤model
|
|
|
*/
|
|
*/
|
|
|
class EntrustChildViewModel : BaseViewModel() {
|
|
class EntrustChildViewModel : BaseViewModel() {
|
|
|
|
|
|
|
|
- var list: ArrayList<EntrustData>? = null
|
|
|
|
|
-
|
|
|
|
|
|
|
+ var list: ArrayList<EntrustData>? = null // 数据
|
|
|
|
|
+ var onItemClickListener: OnItemClickListener? = null // item点击事件
|
|
|
|
|
+ var currentEntrustData: EntrustData? = null // 当前选择的item对应的数据
|
|
|
/**
|
|
/**
|
|
|
* 获取配置器。
|
|
* 获取配置器。
|
|
|
*/
|
|
*/
|
|
|
fun getAdapter(): RecyclerView.Adapter<HoldAdapter.EntrustHolder> {
|
|
fun getAdapter(): RecyclerView.Adapter<HoldAdapter.EntrustHolder> {
|
|
|
return HoldAdapter(context, list)
|
|
return HoldAdapter(context, list)
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 通用的适配器。
|
|
* 通用的适配器。
|
|
|
*/
|
|
*/
|
|
|
- class HoldAdapter(context: Context?, list: ArrayList<EntrustData>?) : RecyclerView.Adapter<HoldAdapter.EntrustHolder>() {
|
|
|
|
|
|
|
+ inner class HoldAdapter(context: Context?, list: ArrayList<EntrustData>?) : RecyclerView.Adapter<HoldAdapter.EntrustHolder>() {
|
|
|
private var list: ArrayList<EntrustData>? = null
|
|
private var list: ArrayList<EntrustData>? = null
|
|
|
private var inflater: LayoutInflater? = null
|
|
private var inflater: LayoutInflater? = null
|
|
|
private var context: Context? = null
|
|
private var context: Context? = null
|
|
|
- private var pink: Drawable? = null
|
|
|
|
|
- private var green: Drawable? = null
|
|
|
|
|
- private var priceRed: Int = 0
|
|
|
|
|
- private var priceGreen: Int = 0
|
|
|
|
|
|
|
+ private var selectColor: Int = 0
|
|
|
|
|
+
|
|
|
init {
|
|
init {
|
|
|
this.list = list
|
|
this.list = list
|
|
|
this.inflater = LayoutInflater.from(context)
|
|
this.inflater = LayoutInflater.from(context)
|
|
|
this.context = context
|
|
this.context = context
|
|
|
-
|
|
|
|
|
- pink = context?.getDrawable(R.drawable.rma_red)
|
|
|
|
|
- green = context?.getDrawable(R.drawable.rma_green)
|
|
|
|
|
- priceGreen = context?.getColor(R.color.p_price_green)!!
|
|
|
|
|
- priceRed = context.getColor(R.color.p_price_red)
|
|
|
|
|
|
|
+ selectColor = context?.getColor(R.color.p_select_bg_color)!!
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
override fun getItemCount(): Int {
|
|
override fun getItemCount(): Int {
|
|
|
return list?.size ?: 0
|
|
return list?.size ?: 0
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- class EntrustHolder(itemView: View?) : RecyclerView.ViewHolder(itemView!!) {
|
|
|
|
|
|
|
+ inner class EntrustHolder(itemView: View?) : RecyclerView.ViewHolder(itemView!!) {
|
|
|
var idGoodsName = itemView?.findViewById<TextView>(R.id.id_goods_name)
|
|
var idGoodsName = itemView?.findViewById<TextView>(R.id.id_goods_name)
|
|
|
var idStatus = itemView?.findViewById<TextView>(R.id.id_status)
|
|
var idStatus = itemView?.findViewById<TextView>(R.id.id_status)
|
|
|
var idDate = itemView?.findViewById<TextView>(R.id.id_date)
|
|
var idDate = itemView?.findViewById<TextView>(R.id.id_date)
|
|
@@ -57,9 +55,15 @@ class EntrustChildViewModel : BaseViewModel() {
|
|
|
var idEntrustNum = itemView?.findViewById<TextView>(R.id.id_entrust_num)
|
|
var idEntrustNum = itemView?.findViewById<TextView>(R.id.id_entrust_num)
|
|
|
var idEntrustPrice = itemView?.findViewById<TextView>(R.id.id_entrust_price)
|
|
var idEntrustPrice = itemView?.findViewById<TextView>(R.id.id_entrust_price)
|
|
|
var idEntrustPl = itemView?.findViewById<TextView>(R.id.id_entrust_pl)
|
|
var idEntrustPl = itemView?.findViewById<TextView>(R.id.id_entrust_pl)
|
|
|
|
|
+
|
|
|
|
|
+ var idChart = itemView?.findViewById<TextView>(R.id.id_chart)
|
|
|
|
|
+ var idEntrustDetail = itemView?.findViewById<TextView>(R.id.id_entrust_detail)
|
|
|
|
|
+ var idCancel = itemView?.findViewById<TextView>(R.id.id_cancel)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
override fun onBindViewHolder(entrust: EntrustHolder, position: Int) {
|
|
override fun onBindViewHolder(entrust: EntrustHolder, position: Int) {
|
|
|
|
|
+ entrust.itemView.tag = list?.get(position)
|
|
|
|
|
+
|
|
|
entrust.idGoodsName?.text = list?.get(position)?.goodsName
|
|
entrust.idGoodsName?.text = list?.get(position)?.goodsName
|
|
|
entrust.idStatus?.text = list?.get(position)?.status
|
|
entrust.idStatus?.text = list?.get(position)?.status
|
|
|
entrust.idEntrustType?.text = list?.get(position)?.entrustType
|
|
entrust.idEntrustType?.text = list?.get(position)?.entrustType
|
|
@@ -67,11 +71,59 @@ class EntrustChildViewModel : BaseViewModel() {
|
|
|
entrust.idEntrustPrice?.text = list?.get(position)?.entrustPrice.toString()
|
|
entrust.idEntrustPrice?.text = list?.get(position)?.entrustPrice.toString()
|
|
|
entrust.idEntrustNum?.text = list?.get(position)?.entrustNum.toString()
|
|
entrust.idEntrustNum?.text = list?.get(position)?.entrustNum.toString()
|
|
|
entrust.idEntrustPl?.text = list?.get(position)?.pl.toString()
|
|
entrust.idEntrustPl?.text = list?.get(position)?.pl.toString()
|
|
|
|
|
+
|
|
|
|
|
+ // 下面三个按钮的点击事件
|
|
|
|
|
+ entrust.idChart?.tag = list?.get(position)
|
|
|
|
|
+ entrust.idEntrustDetail?.tag = list?.get(position)
|
|
|
|
|
+ entrust.idCancel?.tag = list?.get(position)
|
|
|
|
|
+ entrust.idChart?.setOnClickListener {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ entrust.idEntrustDetail?.setOnClickListener {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ entrust.idCancel?.setOnClickListener {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (list?.get(position)?.select == true) {
|
|
|
|
|
+ entrust.idChart?.visibility = View.VISIBLE
|
|
|
|
|
+ entrust.idEntrustDetail?.visibility = View.VISIBLE
|
|
|
|
|
+ entrust.idCancel?.visibility = View.VISIBLE
|
|
|
|
|
+ entrust.itemView.backgroundColor = selectColor
|
|
|
|
|
+ } else if(list?.get(position)?.select == false) {
|
|
|
|
|
+ entrust.idChart?.visibility = View.GONE
|
|
|
|
|
+ entrust.idEntrustDetail?.visibility = View.GONE
|
|
|
|
|
+ entrust.idCancel?.visibility = View.GONE
|
|
|
|
|
+ entrust.itemView.backgroundColor = 0
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 点击item事件
|
|
|
|
|
+ entrust.itemView.setOnClickListener {
|
|
|
|
|
+ clickItem(it)
|
|
|
|
|
+ onItemClickListener?.onClick(it)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): EntrustHolder {
|
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): EntrustHolder {
|
|
|
return EntrustHolder(inflater?.inflate(R.layout.entrust_item, parent, false))
|
|
return EntrustHolder(inflater?.inflate(R.layout.entrust_item, parent, false))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private fun clickItem(view: View) {
|
|
|
|
|
+ currentEntrustData = view.tag as EntrustData? // 临时存储当前点击item
|
|
|
|
|
+
|
|
|
|
|
+ // 选择
|
|
|
|
|
+ list?.forEach { itemValue ->
|
|
|
|
|
+ if (itemValue.goodsId == currentEntrustData?.goodsId) {
|
|
|
|
|
+ itemValue.select = !itemValue.select
|
|
|
|
|
+ } else {
|
|
|
|
|
+ itemValue.select = false
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 刷新数据
|
|
|
|
|
+ notifyDataSetChanged()
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|