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")
|
}
|
}
|
}
|