From 72d4feffc49dbb1b6d035845e38e746bf21dda58 Mon Sep 17 00:00:00 2001 From: Philoul Date: Sun, 5 Jun 2022 20:29:04 +0200 Subject: [PATCH] Improve InputWeekDay (easy check with timestamp and external access to WeekdayPicker view) --- .../general/automation/elements/InputWeekDay.kt | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputWeekDay.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputWeekDay.kt index c34a53444c..0f9ec5c159 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputWeekDay.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputWeekDay.kt @@ -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 { val selectedDays: MutableList = 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 ) } }