Improve InputWeekDay (easy check with timestamp and external access to WeekdayPicker view)
This commit is contained in:
parent
7fac5a87f3
commit
72d4feffc4
|
@ -49,7 +49,7 @@ class InputWeekDay : Element() {
|
|||
}
|
||||
|
||||
val weekdays = BooleanArray(DayOfWeek.values().size)
|
||||
|
||||
var view: WeekdayPicker? = null
|
||||
init {
|
||||
for (day in DayOfWeek.values()) set(day, false)
|
||||
}
|
||||
|
@ -65,6 +65,11 @@ class InputWeekDay : Element() {
|
|||
|
||||
fun isSet(day: DayOfWeek): Boolean = weekdays[day.ordinal]
|
||||
|
||||
fun isSet(timestamp: Long): Boolean {
|
||||
val scheduledDayOfWeek = Calendar.getInstance().also { it.time = Date(timestamp) }
|
||||
return isSet(Objects.requireNonNull(DayOfWeek.fromCalendarInt(scheduledDayOfWeek[Calendar.DAY_OF_WEEK])))
|
||||
}
|
||||
|
||||
fun getSelectedDays(): List<Int> {
|
||||
val selectedDays: MutableList<Int> = ArrayList()
|
||||
for (i in weekdays.indices) {
|
||||
|
@ -76,11 +81,12 @@ class InputWeekDay : Element() {
|
|||
}
|
||||
|
||||
override fun addToLayout(root: LinearLayout) {
|
||||
view = WeekdayPicker(root.context).apply {
|
||||
setSelectedDays(getSelectedDays())
|
||||
setOnWeekdaysChangeListener { i: Int, selected: Boolean -> set(DayOfWeek.fromCalendarInt(i), selected) }
|
||||
}
|
||||
root.addView(
|
||||
WeekdayPicker(root.context).apply {
|
||||
setSelectedDays(getSelectedDays())
|
||||
setOnWeekdaysChangeListener { i: Int, selected: Boolean -> set(DayOfWeek.fromCalendarInt(i), selected) }
|
||||
}
|
||||
view
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue