lmw
21 小时以前 b6d14ec6c19cddb1c8caf1d024e77d250a203929
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
44
45
46
47
48
49
50
package com.dollearn.student.dialog
 
import android.view.Gravity
import androidx.core.os.bundleOf
import androidx.fragment.app.FragmentManager
import cn.sinata.xldutils.utils.myToast
import cn.sinata.xldutils.utils.showAllowingStateLoss
import com.dollearn.student.R
import com.dollearn.student.utils.interfaces.StringCallback
import kotlinx.android.synthetic.main.dialog_exchange_count.*
 
class ExchangeCountDialog:BaseDialogFragment() {
    override fun setContentView() = R.layout.dialog_exchange_count
 
    var callback:StringCallback? = null
    private val max by lazy { arguments?.getInt("max",0)?:0 }
    private var now = 0
 
    override fun setGravity() = Gravity.BOTTOM
 
    override fun initView() {
        now = arguments?.getInt("now",1)?:1
        tv_count.text = now.toString()
        iv_add.setOnClickListener {
            if (now<max){
                tv_count.text = (++now).toString()
            }else
                myToast("每人限领${max}份")
        }
        iv_del.setOnClickListener {
            if (now>1){
                tv_count.text = (--now).toString()
            }
        }
        tv_action.setOnClickListener {
            callback?.onResult(now.toString())
            dismissAllowingStateLoss()
        }
        tv_cancel.setOnClickListener { dismissAllowingStateLoss() }
    }
 
    companion object{
        fun show(fm:FragmentManager,max:Int,now:Int,callback:StringCallback){
            val exchangeCountDialog = ExchangeCountDialog()
            exchangeCountDialog.arguments = bundleOf("max" to max,"now" to now)
            exchangeCountDialog.callback = callback
            exchangeCountDialog.showAllowingStateLoss(fm,"count")
        }
    }
}