lmw
2024-10-25 314b67e56f24f7bce040ae2b5d57c7eac7b197a9
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package com.sinata.xqmuse.dialog
 
import android.view.Gravity
import com.sinata.xqmuse.R
import com.sinata.xqmuse.utils.interfaces.StringCallback
import kotlinx.android.synthetic.main.dialog_time_setting.*
import org.jetbrains.anko.textColorResource
import kotlin.math.max
 
class TimeSettingDialog:BaseDialogFragment() {
    override fun setContentView() = R.layout.dialog_time_setting
 
    override fun setGravity() = Gravity.BOTTOM
    var time = 10
 
    var callback:StringCallback? = null
 
    override fun initView() {
        rg_time.setOnCheckedChangeListener { group, checkedId ->
            time = when(checkedId){
                R.id.rb_5->5
                R.id.rb_10->10
                R.id.rb_15->15
                R.id.rb_30->30
                R.id.rb_60->60
                R.id.rb_90->90
                R.id.rb_0->0
                else->-1
            }
            if (time!=-1){
                tv_custom.textColorResource = R.color.textColor66
                tv_min.textColorResource = R.color.textColor66
            }else{
                tv_custom.textColorResource = R.color.colorPrimary
                tv_min.textColorResource = R.color.colorPrimary
            }
        }
 
        tv_jia.setOnClickListener {
            rg_time.check(-1)
            val s = et_time.text.toString()
            time = (if (s.isNullOrEmpty()) 0 else s.toInt())+1
            et_time.setText(time.toString())
        }
 
        tv_jian.setOnClickListener {
            rg_time.check(-1)
            val s = et_time.text.toString()
            time = (if (s.isNullOrEmpty()) 0 else s.toInt())
            time = max(0,time)
            et_time.setText(time.toString())
        }
 
        tv_action.setOnClickListener {
            if (rg_time.checkedRadioButtonId != -1){
                callback?.onResult(time.toString())
            }else{
                val s = et_time.text.toString()
                time = (if (s.isNullOrEmpty()) 0 else s.toInt())
                callback?.onResult(time.toString())
            }
            dismissAllowingStateLoss()
        }
    }
 
}