lmw
2023-06-13 adf8013576cbdd12e5ebea8ff7e32baf5d558b27
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package com.kuanzhai.user.ui.mine.adapter
 
import android.view.View
import android.widget.TextView
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import cn.sinata.xldutils.activity.ImagePagerActivity
import cn.sinata.xldutils.adapter.HFRecyclerAdapter
import cn.sinata.xldutils.adapter.util.ViewHolder
import cn.sinata.xldutils.gone
import cn.sinata.xldutils.invisible
import cn.sinata.xldutils.utils.parserTime
import cn.sinata.xldutils.visible
import com.kuanzhai.user.R
import com.kuanzhai.user.network.entity.Order
import com.kuanzhai.user.ui.logistics.adpter.GoodsImgAdapter
import org.jetbrains.anko.sdk27.coroutines.onClick
import org.jetbrains.anko.startActivity
import org.jetbrains.anko.textColorResource
import java.util.ArrayList
 
class LogisticsAdapter(datas: ArrayList<Order>,private val callback:ClickCallback) : HFRecyclerAdapter<Order>(datas, R.layout.item_logistics_order) {
    override fun onBind(holder: ViewHolder, position: Int, data: Order) {
        val pay = holder.bind<TextView>(R.id.tv_pay)
        val cancel = holder.bind<TextView>(R.id.tv_cancel)
        val line = holder.bind<View>(R.id.line)
        val rv_photo = holder.bind<RecyclerView>(R.id.rv_photo)
        val tv1 = holder.bind<View>(R.id.tv_1)
        val tv_thank = holder.bind<View>(R.id.tv_thank)
        val tv_thank_money = holder.bind<TextView>(R.id.tv_thank_money)
 
        holder.setText(R.id.tv_time,data.orderTime)
        holder.setText(R.id.tv_start,data.startAddress)
        holder.setText(R.id.tv_goods_typ,data.cargoType)
        holder.setText(R.id.tv_trip_time,data.time)
        holder.setText(R.id.tv_arrive_time,data.arriveTimeExpect)
        val realTime = holder.bind<TextView>(R.id.tv_real_time)
        val tv_title = holder.bind<TextView>(R.id.tv_title)
 
        holder.bind<View>(R.id.tv_arrive_time).visibility = if (data.arriveTimeExpect.isNullOrEmpty()) View.GONE else View.VISIBLE
        holder.bind<View>(R.id.tv_2).visibility = if (data.arriveTimeExpect.isNullOrEmpty()) View.GONE else View.VISIBLE
 
        if (data.endServiceTime.isNullOrEmpty()){
            realTime.gone()
            tv_title.invisible()
        }else{
            realTime.visible()
            tv_title.visible()
            val l = data.endServiceTime.parserTime("yyyy-MM-dd HH:mm") - data.arriveTimeExpect.parserTime("yyyy-MM-dd HH:mm")
            if (!data.arriveTimeExpect.isNullOrEmpty()&&l>0L){//超时
//                realTime.textColorResource = R.color.colorRed
                realTime.text = "${data.endServiceTime} 已超时"
            }else{
//                realTime.textColorResource = R.color.textColor
                realTime.text = data.endServiceTime
            }
        }
        holder.bind<TextView>(R.id.tv_code).apply {
            text = "收件码:${data.pickUpCode}"
            visibility = if (data.pickUpCode.isNullOrEmpty()) View.GONE else View.VISIBLE
        }
 
        holder.setText(R.id.tv_state,data.getLogisticsState())
        holder.bind<TextView>(R.id.tv_state).textColorResource = if (data.state == 10) R.color.textColor66 else R.color.colorOrange
        cancel.onClick {
            callback.onCancel(position)
        }
        if (data.userImg.isNullOrEmpty()){
            rv_photo.gone()
            tv1.gone()
        }else{
            rv_photo.visible()
            tv1.visible()
            rv_photo.layoutManager = GridLayoutManager(context,3)
            val arrayListOf = arrayListOf<String>()
            arrayListOf.addAll(data.userImg.split(","))
            val goodsImgAdapter = GoodsImgAdapter(arrayListOf,false)
            rv_photo.adapter = goodsImgAdapter
            goodsImgAdapter.setOnItemClickListener { view, position ->
                context.startActivity<ImagePagerActivity>(ImagePagerActivity.POSITION to position,ImagePagerActivity.URLS to arrayListOf)
            }
        }
        when(data.state){
            7->{
                pay.visible()
                pay.text = "立即支付(¥%.2f)".format(data.orderMoney)
                cancel.visible()
                line.visible()
                tv_thank.gone()
                tv_thank_money.gone()
                pay.onClick {
                    callback.onPay(position)
                }
            }
            8->{
                pay.visible()
                pay.text = "支付差价(¥%.2f)".format(data.differenceMoney)
                cancel.visible()
                line.visible()
                tv_thank.gone()
                tv_thank_money.gone()
                pay.onClick {
                    callback.onPay(position)
                }
            }
            6,9->{
                pay.visible()
                pay.text = "查看送货图"
                line.visible()
                cancel.gone()
                if (data.thankYouFee == 0.0){
                    tv_thank.visible()
                    tv_thank.onClick { callback.onThank(position) }
                    tv_thank_money.gone()
                }else{
                    tv_thank.gone()
                    tv_thank_money.visible()
                    tv_thank_money.text = "答谢%.2f元".format(data.thankYouFee)
                }
                pay.onClick {
                    val arrayListOf = arrayListOf<String>()
                    arrayListOf.addAll(data.driverImg.split(",").filter { it.isNotEmpty() })
                    context.startActivity<ImagePagerActivity>(ImagePagerActivity.POSITION to 0,ImagePagerActivity.URLS to arrayListOf)
                }
            }
            in (1..4),11->{
                pay.gone()
                tv_thank.gone()
                tv_thank_money.gone()
                cancel.visible()
                line.visible()
            }
            else->{
                pay.gone()
                cancel.gone()
                line.gone()
                tv_thank.gone()
                tv_thank_money.gone()
            }
        }
    }
 
    interface ClickCallback{
        fun onPay(index:Int)
        fun onThank(index:Int)
        fun onCancel(index:Int)
    }
}