package com.dollearn.student.dialog
|
|
import android.view.Gravity
|
import androidx.recyclerview.widget.LinearLayoutManager
|
import cn.sinata.xldutils.utils.myToast
|
import com.dollearn.student.R
|
import com.dollearn.student.network.entity.Coupon
|
import com.dollearn.student.ui.home.adapter.CouponAdapter
|
import com.dollearn.student.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?.getLong("checked") }
|
var callback:StringCallback? = null
|
|
override fun initView() {
|
list.addAll(arguments?.getParcelableArrayList("list")?: arrayListOf())
|
adapter.checked = checked?: 0L
|
rv_coupon.layoutManager = LinearLayoutManager(requireContext())
|
rv_coupon.adapter = adapter
|
adapter.setOnItemClickListener { view, position ->
|
adapter.checked = list[position].id
|
adapter.notifyDataSetChanged()
|
}
|
tv_action.setOnClickListener {
|
if (adapter.checked==0L)
|
myToast("请选择优惠券")
|
else{
|
callback?.onResult(adapter.checked.toString())
|
dismissAllowingStateLoss()
|
}
|
}
|
tv_cancel.setOnClickListener { dismissAllowingStateLoss() }
|
}
|
|
}
|