lmw
2024-09-25 92778728b83ce1a34ba21bcdb061afdeca16cce5
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
package com.sinata.xqmuse.dialog
 
import android.view.Gravity
import androidx.core.os.bundleOf
import androidx.fragment.app.FragmentManager
import com.sinata.xqmuse.R
import com.sinata.xqmuse.utils.interfaces.StringCallback
import kotlinx.android.synthetic.main.dialog_choose_weight.*
import kotlin.math.max
 
class ChooseWeightDialog:BaseDialogFragment() {
    override fun setContentView() = R.layout.dialog_choose_weight
 
    private var current = ""
    private val unit by lazy { arguments?.getString("unit")?:"斤" }
    private val ok by lazy { arguments?.getString("ok")?:"确认" }
    private var max = 300
    var callback:StringCallback? = null
 
    override fun setGravity() = Gravity.BOTTOM
 
    override fun initView() {
        current = arguments?.getString("current")?:"40.0"
        if (current.toDouble() == 0.0){
            current = if (unit!="公斤") "120.0" else "60.0"
        }
        if (unit != "公斤")
            max = 600
        tv_title.text = arguments?.getString("title")
        tv_action.text = ok
        val lefts = arrayListOf<String>()
        lefts.addAll((0..max).map { "%d".format(it) })
        wv_1.setItems(lefts)
        val position = lefts.indexOf(current.substring(0, current.indexOf(".")))
        wv_1.setSeletion(max(position,0))
 
        val rights = arrayListOf<String>()
        rights.addAll((0..99).map { "%02d".format(it) })
        wv_2.setItems(rights)
        val position1 = rights.indexOf("%02d".format(current.substring(current.indexOf(".") + 1).toInt()))
        wv_2.setSeletion(max(position1,0))
 
        iv_close.setOnClickListener { dismissAllowingStateLoss() }
 
        tv_action.setOnClickListener {
            val rsl = "%d.%s".format(wv_1.seletedItem.toInt(), wv_2.seletedItem)
            callback?.onResult(rsl)
            dismissAllowingStateLoss()
        }
    }
 
    companion object{
        fun show(fm:FragmentManager,title:String,unit:String,current:String?,callback:StringCallback,ok:String?=null){
            val chooseWeightDialog = ChooseWeightDialog()
            chooseWeightDialog.arguments = bundleOf("title" to title,"current" to current,"unit" to unit,"ok" to ok)
            chooseWeightDialog.callback = callback
            chooseWeightDialog.show(fm,"weight")
        }
    }
}