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