package com.sinata.xqmuse.dialog
|
|
import android.view.Gravity
|
import androidx.recyclerview.widget.LinearLayoutManager
|
import cn.sinata.xldutils.utils.myToast
|
import com.sinata.xqmuse.R
|
import com.sinata.xqmuse.network.entity.Coupon
|
import com.sinata.xqmuse.ui.home.adapter.CouponAdapter
|
import com.sinata.xqmuse.utils.interfaces.StringCallback
|
import kotlinx.android.synthetic.main.dialog_choose_coupon.*
|
|
class ChooseCouponDialog:BaseDialogFragment() {
|
override fun setContentView() = R.layout.dialog_choose_coupon
|
|
override fun setGravity() = Gravity.BOTTOM
|
|
private val list = arrayListOf<Coupon>()
|
private val adapter = CouponAdapter(list)
|
|
private val checked by lazy { arguments?.getString("checked") }
|
private val money by lazy { arguments?.getDouble("money",0.0)?:0.0 }
|
|
var callback:StringCallback? = null
|
|
override fun initView() {
|
list.addAll(arguments?.getParcelableArrayList("list")?: arrayListOf())
|
adapter.checked = checked?:""
|
list.forEach {
|
it.useful = money >= it.money.toDouble()
|
}
|
rv_coupon.layoutManager = LinearLayoutManager(requireContext())
|
rv_coupon.adapter = adapter
|
adapter.setOnItemClickListener { view, position ->
|
if (list[position].useful){
|
adapter.checked = list[position].id
|
adapter.notifyDataSetChanged()
|
}
|
}
|
tv_action.setOnClickListener {
|
if (adapter.checked=="")
|
myToast("请选择优惠券")
|
else{
|
callback?.onResult(adapter.checked)
|
dismissAllowingStateLoss()
|
}
|
}
|
iv_close.setOnClickListener { dismissAllowingStateLoss() }
|
}
|
|
}
|