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)
|
}
|
}
|