122 lines
3.7 KiB
Kotlin
122 lines
3.7 KiB
Kotlin
package com.dahe.mylibrary.utils
|
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
|
import com.dahe.mylibrary.base.SingletonNoPHolder
|
|
import com.dahe.mylibrary.callback.OnMyDatePickedListener
|
|
import com.github.gzuliyujiang.wheelpicker.BirthdayPicker
|
|
import com.github.gzuliyujiang.wheelpicker.DatePicker
|
|
import com.github.gzuliyujiang.wheelpicker.OptionPicker
|
|
import com.github.gzuliyujiang.wheelpicker.annotation.DateMode
|
|
import com.github.gzuliyujiang.wheelpicker.contract.OnDatePickedListener
|
|
import com.github.gzuliyujiang.wheelpicker.contract.OnOptionPickedListener
|
|
import com.github.gzuliyujiang.wheelpicker.entity.DateEntity
|
|
import com.github.gzuliyujiang.wheelview.contract.TextProvider
|
|
import java.util.ArrayList
|
|
|
|
/**
|
|
* @ClassName PickUtils
|
|
* @Author john
|
|
* @Date 2024/2/5 14:48
|
|
* @Description 选择器工具类
|
|
*/
|
|
class PickerUtils private constructor() {
|
|
companion object : SingletonNoPHolder<PickerUtils>(::PickerUtils)
|
|
|
|
|
|
/**
|
|
* TODO
|
|
* 底部弹出生日日期选择
|
|
* @param activity
|
|
* @param title 日期选择title
|
|
* @param dateEntity 默认参数:默认当天
|
|
* @param listener
|
|
*/
|
|
fun showDate(
|
|
activity: AppCompatActivity,
|
|
title: String = "",
|
|
dateEntity: DateEntity = DateEntity.today(),
|
|
listener: OnMyDatePickedListener
|
|
) {
|
|
val picker = BirthdayPicker(activity)
|
|
picker.setTitle(title)
|
|
picker.setDefaultValue(1991, 11, 11)
|
|
picker.setDefaultValue(dateEntity.year, dateEntity.month, dateEntity.day)
|
|
picker.setOnDatePickedListener { year, month, day ->
|
|
if (listener != null)
|
|
listener.onDatePicked("$year-${if (month <= 9) "0${month}" else month}-${if (day <= 9) "0${day}" else day}")
|
|
}
|
|
picker.wheelLayout.setResetWhenLinkage(false)
|
|
picker.show()
|
|
}
|
|
|
|
|
|
/**
|
|
* TODO
|
|
* 底部弹出日期选择
|
|
* @param activity
|
|
* @param title 日期选择title
|
|
* @param listener
|
|
*/
|
|
fun showDateSim(
|
|
activity: AppCompatActivity,
|
|
title: String = "日期选择",
|
|
listener: OnMyDatePickedListener
|
|
) {
|
|
val picker = DatePicker(activity)
|
|
picker.setTitle(title)
|
|
val wheelLayout = picker.wheelLayout
|
|
wheelLayout.setDateMode(DateMode.YEAR_MONTH_DAY)
|
|
wheelLayout.setDateLabel("年", "月", "日")
|
|
picker.setOnDatePickedListener { year, month, day ->
|
|
listener.onDatePicked("$year-${if (month <= 9) "0${month}" else month}-${if (day <= 9) "0${day}" else day}")
|
|
|
|
}
|
|
picker.show()
|
|
}
|
|
|
|
|
|
/**
|
|
* 选择驾驶证类型
|
|
* @param activity
|
|
* @param title
|
|
* @param listener
|
|
*/
|
|
fun showSelectCarType(
|
|
activity: AppCompatActivity,
|
|
title: String = "",
|
|
listener: OnOptionPickedListener
|
|
) {
|
|
OptionPicker(activity)
|
|
.run {
|
|
setData("A1", "A2", "A3", "B1", "B2", "B3", "C1", "C2")
|
|
setDefaultValue("B1")
|
|
setTitle(title)
|
|
setOnOptionPickedListener(listener)
|
|
show()
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 底部弹框-单选
|
|
* @param activity AppCompatActivity
|
|
* @param title String
|
|
* @param listener OnOptionPickedListener
|
|
*/
|
|
fun <T:TextProvider> showSelectCarColor(
|
|
activity: AppCompatActivity,
|
|
title: String = "",
|
|
default: String = "",
|
|
datas: MutableList<T>,
|
|
listener: OnOptionPickedListener
|
|
) {
|
|
OptionPicker(activity)
|
|
.run {
|
|
setData(datas)
|
|
setDefaultValue(default)
|
|
setTitle(title)
|
|
setOnOptionPickedListener(listener)
|
|
show()
|
|
}
|
|
}
|
|
|
|
} |