lmw
2024-07-16 c303346ae803dc2a89ec0f025192773211861915
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
package com.dollearn.student.dialog
 
import android.view.Gravity
import cn.sinata.xldutils.utils.toTime
import com.dollearn.student.R
import com.dollearn.student.utils.interfaces.StringCallback
import kotlinx.android.synthetic.main.dialog_choose_city.*
 
class ChooseRecordTimeDialog:BaseDialogFragment() {
    override fun setContentView() = R.layout.dialog_choose_city
 
    override fun setGravity() = Gravity.BOTTOM
 
    var callback:StringCallback? = null
 
    override fun initView() {
        tv_title.text = "查询时间"
        val years = arrayListOf<String>()
        val currentYear = System.currentTimeMillis().toTime("yyyy").toInt()
        years.addAll((currentYear-3..currentYear).map { it.toString() })
        wv_1.setItems(years)
        wv_1.setSeletion(years.lastIndex)
 
        setMonth()
 
        wv_1.setOnWheelViewListener { selectedIndex, item ->
            setMonth()
        }
 
        iv_close.setOnClickListener { dismissAllowingStateLoss() }
        tv_action.setOnClickListener {
            callback?.onResult("${wv_1.seletedItem}-${wv_2.seletedItem}")
            dismissAllowingStateLoss()
        }
    }
 
    private fun setMonth(){
        val month = arrayListOf<String>()
        val currentMonth = System.currentTimeMillis().toTime("MM").toInt()
        month.addAll((1..(if (wv_1.seletedIndex == 3) currentMonth else 12)).map { "%02d".format(it) })
        wv_2.setItems(month)
        wv_2.setSeletion(0)
    }
 
}