package com.kuanzhai.user.ui.mine.adapter
|
|
import android.view.LayoutInflater
|
import android.view.View
|
import android.widget.LinearLayout
|
import android.widget.TextView
|
import cn.sinata.xldutils.adapter.HFRecyclerAdapter
|
import cn.sinata.xldutils.adapter.util.ViewHolder
|
import cn.sinata.xldutils.clickDelay
|
import cn.sinata.xldutils.gone
|
import cn.sinata.xldutils.utils.SpanBuilder
|
import cn.sinata.xldutils.utils.interval
|
import cn.sinata.xldutils.utils.parserTime
|
import cn.sinata.xldutils.visible
|
import com.facebook.drawee.view.SimpleDraweeView
|
import com.google.gson.Gson
|
import com.kuanzhai.user.R
|
import com.kuanzhai.user.interfaces.StringCallback
|
import com.kuanzhai.user.network.entity.CommentBean
|
import com.kuanzhai.user.network.entity.RentBean
|
import com.kuanzhai.user.network.entity.SaleBean
|
import com.kuanzhai.user.network.entity.WantedBean
|
import com.kuanzhai.user.views.FlowLayout
|
import org.jetbrains.anko.backgroundResource
|
import java.util.ArrayList
|
|
class MyCommentAdapter(list: ArrayList<CommentBean>,private val isReply:Boolean,val callback:StringCallback):HFRecyclerAdapter<CommentBean>(list, R.layout.item_my_comment) {
|
private val gson = Gson()
|
override fun onBind(holder: ViewHolder, position: Int, data: CommentBean) {
|
val ivDel = holder.bind<View>(R.id.iv_del)
|
val ivImg = holder.bind<SimpleDraweeView>(R.id.iv_img)
|
val tvReply = holder.bind<TextView>(R.id.tv_reply)
|
val tvTitle = holder.bind<TextView>(R.id.tv_title)
|
val tvType = holder.bind<TextView>(R.id.tv_type)
|
val tvSaleInfo = holder.bind<TextView>(R.id.tv_sale_info)
|
val tvAddress = holder.bind<TextView>(R.id.tv_address)
|
val llTag = holder.bind<FlowLayout>(R.id.ll_tag)
|
holder.setText(R.id.tv_time,data.createTime.parserTime().interval())
|
when(data.type){ //类型(1=租车,2=卖车,3=招聘)
|
1->{
|
val rentBean = gson.fromJson<RentBean>(data.orderInfo, RentBean::class.java)
|
ivImg.visible()
|
tvType.visible()
|
ivImg.setImageURI(rentBean.imgUrl.split(",").firstOrNull())
|
tvType.backgroundResource = R.drawable.bg_type_tag
|
tvType.text = if (rentBean.userType == 3) "企业车辆" else "个人车辆"
|
tvTitle.text = rentBean.title
|
holder.setText(R.id.tv_money,rentBean.rentMoney+"元/天")
|
llTag.gone()
|
tvSaleInfo.gone()
|
tvAddress.visible()
|
tvAddress.text = rentBean.provinceName+rentBean.cityName+rentBean.addres
|
}
|
2->{
|
val saleBean = gson.fromJson<SaleBean>(data.orderInfo, SaleBean::class.java)
|
ivImg.visible()
|
tvType.visible()
|
ivImg.setImageURI(saleBean.imgUrl.split(",").firstOrNull())
|
tvType.backgroundResource = R.drawable.bg_type_tag_green
|
tvType.text = if (saleBean.userType == 3) "企业车辆" else "个人车辆"
|
tvTitle.text = saleBean.title
|
holder.setText(R.id.tv_money,saleBean.getMoney())
|
llTag.gone()
|
tvSaleInfo.visible()
|
tvAddress.gone()
|
tvSaleInfo.text = "${saleBean.mileage}万公里/${saleBean.licensingTime.replace("-","/")}/${saleBean.cityName}"
|
}
|
3->{
|
val wantedBean = gson.fromJson<WantedBean>(data.orderInfo, WantedBean::class.java)
|
ivImg.gone()
|
tvType.gone()
|
tvAddress.gone()
|
tvSaleInfo.gone()
|
tvTitle.text = wantedBean.title
|
holder.setText(R.id.tv_money,"${wantedBean.startSalary}-${wantedBean.endSalary}元/月")
|
llTag.visible()
|
llTag.removeAllViews()
|
wantedBean.welfare.split(",").filter { it.isNotEmpty() }?.forEach {
|
val inflate = LayoutInflater.from(context).inflate(R.layout.item_tag, null) as TextView
|
inflate.text = it
|
llTag.addView(inflate)
|
}
|
}
|
}
|
if (isReply){
|
tvReply.visible()
|
tvReply.text = SpanBuilder("${data.userName}回复${data.replyUserName}:${data.content}")
|
.color(context,0,data.userName.length,R.color.colorPrimary)
|
.color(context,data.userName.length+2,data.replyUserName.length+data.userName.length+3,R.color.colorPrimary).build()
|
holder.setText(R.id.tv_content,SpanBuilder("${data.replyUserName}:${data.replyUserContent}").color(context,0,data.replyUserName.length+1,R.color.colorPrimary).build())
|
ivDel.gone()
|
}else{
|
holder.setText(R.id.tv_content,data.content)
|
ivDel.clickDelay {
|
callback.onRlt(position.toString())
|
}
|
}
|
}
|
|
}
|