罗明文
2024-06-18 c9f6a2283ee7e5595c91c6d721726a89a3ab9ecd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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() }
    }
 
}