lmw
2024-06-18 1f45a54dc8e149548d3a61d1228741627aa4f23e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package com.dollearn.student.ui.welfare.adapter
 
import android.util.TypedValue
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import cn.sinata.xldutils.activity.BaseActivity
import cn.sinata.xldutils.adapter.HFRecyclerAdapter
import cn.sinata.xldutils.adapter.util.ViewHolder
import cn.sinata.xldutils.gone
import cn.sinata.xldutils.utils.SpanBuilder
import cn.sinata.xldutils.visible
import com.dollearn.student.R
import com.dollearn.student.dialog.LoginRuleDialog
import com.dollearn.student.network.entity.Coupon
import com.dollearn.student.utils.Const
import com.dollearn.student.utils.event.EmptyEvent
import com.dollearn.student.utils.extention.clickDelay
import com.dollearn.student.utils.interfaces.StringCallback
import org.greenrobot.eventbus.EventBus
import org.jetbrains.anko.backgroundResource
import java.util.ArrayList
 
class CouponDetailAdapter(list: ArrayList<Coupon>) :HFRecyclerAdapter<Coupon>(list, R.layout.item_coupon_detail){
    var callback:StringCallback? = null
    override fun onBind(holder: ViewHolder, position: Int, data: Coupon) {
        val clLeft = holder.bind<View>(R.id.tv_price)
        val clRight = holder.bind<View>(R.id.cl_right)
        val tvUse = holder.bind<View>(R.id.tv_use)
        val ivTag = holder.bind<ImageView>(R.id.iv_tag)
        val tvPrice = holder.bind<TextView>(R.id.tv_price)
 
        if (data.type == 3){ //体验券显示名字
            tvPrice.setTextSize(TypedValue.COMPLEX_UNIT_SP,12f)
            tvPrice.text = data.ruleModel?.experienceName
        }else{
            tvPrice.setTextSize(TypedValue.COMPLEX_UNIT_SP,20f)
            val money = "%s%s".format(data.ruleModel?.deductionAmount,if (data.ruleModel?.conditionalAmount.isNullOrEmpty()) "" else "\n${data.ruleModel?.conditionalAmount}")
            tvPrice.text = SpanBuilder(money).bold(0,data.ruleModel?.deductionAmount?.length?:0).size(data.ruleModel?.deductionAmount?.length?:0,money.length,12).build()
        }
 
        holder.setText(R.id.tv_name,data.name)
        holder.setText(R.id.tv_deadline,"有效期至${data.effectiveTime}")
        holder.bind<TextView>(R.id.tv_range).apply {
            text = if (data.useCondition == "3"||data.useCondition == "2") {
                val usage = "${data.available} 查看详情"
                SpanBuilder(usage).color(context,usage.length-4,usage.length,R.color.blue).build()
            } else data.available
            clickDelay {
                callback?.onResult(position.toString())
            }
        }
        holder.bind<View>(R.id.tv_describe).apply {
            isSelected = data.isOpenDescription
            setOnClickListener {
                data.isOpenDescription = !data.isOpenDescription
                notifyItemChanged(position)
            }
        }
        holder.setText(R.id.tv_detail,data.instructionsForUse)
        holder.bind<View>(R.id.ll_detail).visibility = if (data.isOpenDescription) View.VISIBLE else View.GONE
        when(data.useStatus){ //1未使用 2已使用 3已过期
            1->{
                clLeft.backgroundResource = R.mipmap.coupon_left
                clRight.backgroundResource = R.mipmap.coupon_right
                ivTag.gone()
                tvUse.visible()
                tvUse.clickDelay {
                    EventBus.getDefault().post(EmptyEvent(Const.EventCode.SWITCH_HOME))
                    (context as BaseActivity).finish()
                }
            }
            2->{
                clLeft.backgroundResource = R.mipmap.cl_left_disable
                clRight.backgroundResource = R.mipmap.cl_right_disable
                ivTag.visible()
                tvUse.gone()
                ivTag.setImageResource(R.mipmap.iv_used)
            }
            3->{
                clLeft.backgroundResource = R.mipmap.cl_left_disable
                clRight.backgroundResource = R.mipmap.cl_right_disable
                ivTag.visible()
                tvUse.gone()
                ivTag.setImageResource(R.mipmap.iv_disable)
            }
        }
    }
 
}