diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputWeekDay.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputWeekDay.kt index dda616de14..53733acfc8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputWeekDay.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputWeekDay.kt @@ -20,7 +20,6 @@ class InputWeekDay(injector: HasAndroidInjector) : Element(injector) { get() = shortNames[ordinal] companion object { - private val calendarInts = intArrayOf( Calendar.MONDAY, Calendar.TUESDAY, @@ -82,6 +81,5 @@ class InputWeekDay(injector: HasAndroidInjector) : Element(injector) { setOnWeekdaysChangeListener { i: Int, selected: Boolean -> set(DayOfWeek.fromCalendarInt(i), selected) } root.addView(this) } - // TODO: remove library and dependency statement } } diff --git a/core/src/main/java/info/nightscout/androidaps/utils/ui/WeekdayPicker.kt b/core/src/main/java/info/nightscout/androidaps/utils/ui/WeekdayPicker.kt index 07af86879f..e3352ec94d 100644 --- a/core/src/main/java/info/nightscout/androidaps/utils/ui/WeekdayPicker.kt +++ b/core/src/main/java/info/nightscout/androidaps/utils/ui/WeekdayPicker.kt @@ -4,7 +4,6 @@ import android.content.Context import android.util.AttributeSet import android.view.LayoutInflater import android.widget.Checkable -import android.widget.LinearLayout import androidx.appcompat.widget.AppCompatCheckedTextView import androidx.constraintlayout.widget.ConstraintLayout import info.nightscout.androidaps.core.databinding.WeekdayPickerBinding @@ -33,33 +32,33 @@ class WeekdayPicker @JvmOverloads constructor( } } - fun setSelectedDays(list: List) { - binding.weekdayPickerSundayStart.isChecked = list.contains(Calendar.SUNDAY) - binding.weekdayPickerSundayEnd.isChecked = list.contains(Calendar.SUNDAY) - binding.weekdayPickerMonday.isChecked = list.contains(Calendar.MONDAY) - binding.weekdayPickerTuesday.isChecked = list.contains(Calendar.TUESDAY) - binding.weekdayPickerWednesday.isChecked = list.contains(Calendar.WEDNESDAY) - binding.weekdayPickerThursday.isChecked = list.contains(Calendar.THURSDAY) - binding.weekdayPickerFriday.isChecked = list.contains(Calendar.FRIDAY) - binding.weekdayPickerSaturday.isChecked = list.contains(Calendar.SATURDAY) + fun setSelectedDays(list: List) = with(binding) { + weekdayPickerSundayStart.isChecked = list.contains(Calendar.SUNDAY) + weekdayPickerSundayEnd.isChecked = list.contains(Calendar.SUNDAY) + weekdayPickerMonday.isChecked = list.contains(Calendar.MONDAY) + weekdayPickerTuesday.isChecked = list.contains(Calendar.TUESDAY) + weekdayPickerWednesday.isChecked = list.contains(Calendar.WEDNESDAY) + weekdayPickerThursday.isChecked = list.contains(Calendar.THURSDAY) + weekdayPickerFriday.isChecked = list.contains(Calendar.FRIDAY) + weekdayPickerSaturday.isChecked = list.contains(Calendar.SATURDAY) } - private fun setupClickListeners() { - binding.weekdayPickerSundayStart.setupCallbackFor(Calendar.SUNDAY) - binding.weekdayPickerSundayEnd.setupCallbackFor(Calendar.SUNDAY) - binding.weekdayPickerMonday.setupCallbackFor(Calendar.MONDAY) - binding.weekdayPickerTuesday.setupCallbackFor(Calendar.TUESDAY) - binding.weekdayPickerWednesday.setupCallbackFor(Calendar.WEDNESDAY) - binding.weekdayPickerThursday.setupCallbackFor(Calendar.THURSDAY) - binding.weekdayPickerFriday.setupCallbackFor(Calendar.FRIDAY) - binding.weekdayPickerSaturday.setupCallbackFor(Calendar.SATURDAY) + private fun setupClickListeners() = with(binding) { + weekdayPickerSundayStart.setupCallbackFor(Calendar.SUNDAY) + weekdayPickerSundayEnd.setupCallbackFor(Calendar.SUNDAY) + weekdayPickerMonday.setupCallbackFor(Calendar.MONDAY) + weekdayPickerTuesday.setupCallbackFor(Calendar.TUESDAY) + weekdayPickerWednesday.setupCallbackFor(Calendar.WEDNESDAY) + weekdayPickerThursday.setupCallbackFor(Calendar.THURSDAY) + weekdayPickerFriday.setupCallbackFor(Calendar.FRIDAY) + weekdayPickerSaturday.setupCallbackFor(Calendar.SATURDAY) } fun setOnWeekdaysChangeListener(changeListener: (Int, Boolean) -> Unit) { this.changeListener = changeListener } - private fun AppCompatCheckedTextView.setupCallbackFor(day: Int) = setOnClickListener{ + private fun AppCompatCheckedTextView.setupCallbackFor(day: Int) = setOnClickListener { val checkable = it as Checkable val checked = checkable.isChecked checkable.isChecked = !checked diff --git a/core/src/main/res/layout/weekday_picker.xml b/core/src/main/res/layout/weekday_picker.xml index db8219f583..f20fec423d 100644 --- a/core/src/main/res/layout/weekday_picker.xml +++ b/core/src/main/res/layout/weekday_picker.xml @@ -1,40 +1,39 @@ + android:layout_height="wrap_content" + android:padding="2dp"> + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" /> @@ -43,15 +42,15 @@ android:id="@+id/weekdayPickerTuesday" android:layout_width="0dp" android:layout_height="0dp" + android:layout_margin="2dp" android:background="@drawable/weekday_circle_brackground" android:gravity="center" - android:textAlignment="gravity" android:padding="8dp" - android:layout_margin="2dp" - app:layout_constraintDimensionRatio="H,1:1" - app:autoSizeTextType="uniform" android:text="@string/tuesday_short" + android:textAlignment="gravity" + app:autoSizeTextType="uniform" app:layout_constraintBaseline_toBaselineOf="@+id/weekdayPickerWednesday" + app:layout_constraintDimensionRatio="H,1:1" app:layout_constraintEnd_toStartOf="@+id/weekdayPickerWednesday" app:layout_constraintStart_toEndOf="@+id/weekdayPickerMonday" /> @@ -59,14 +58,14 @@ android:id="@+id/weekdayPickerWednesday" android:layout_width="0dp" android:layout_height="0dp" + android:layout_margin="2dp" android:background="@drawable/weekday_circle_brackground" android:gravity="center" - android:textAlignment="gravity" android:padding="8dp" - android:layout_margin="2dp" - app:layout_constraintDimensionRatio="H,1:1" - app:autoSizeTextType="uniform" android:text="@string/wednesday_short" + android:textAlignment="gravity" + app:autoSizeTextType="uniform" + app:layout_constraintDimensionRatio="H,1:1" app:layout_constraintEnd_toStartOf="@+id/weekdayPickerThursday" app:layout_constraintStart_toEndOf="@+id/weekdayPickerTuesday" app:layout_constraintTop_toTopOf="parent" /> @@ -75,30 +74,30 @@ android:id="@+id/weekdayPickerThursday" android:layout_width="0dp" android:layout_height="0dp" + android:layout_margin="2dp" android:background="@drawable/weekday_circle_brackground" android:gravity="center" - android:textAlignment="gravity" android:padding="8dp" - android:layout_margin="2dp" - app:layout_constraintDimensionRatio="H,1:1" - app:autoSizeTextType="uniform" android:text="@string/thursday_short" - app:layout_constraintTop_toTopOf="parent" + android:textAlignment="gravity" + app:autoSizeTextType="uniform" + app:layout_constraintDimensionRatio="H,1:1" app:layout_constraintEnd_toStartOf="@+id/weekdayPickerFriday" - app:layout_constraintStart_toEndOf="@+id/weekdayPickerWednesday" /> + app:layout_constraintStart_toEndOf="@+id/weekdayPickerWednesday" + app:layout_constraintTop_toTopOf="parent" /> @@ -107,30 +106,30 @@ android:id="@+id/weekdayPickerSaturday" android:layout_width="0dp" android:layout_height="0dp" + android:layout_margin="2dp" android:background="@drawable/weekend_circle_brackground" android:gravity="center" - android:textAlignment="gravity" android:padding="8dp" - android:layout_margin="2dp" - app:layout_constraintDimensionRatio="H,1:1" - app:autoSizeTextType="uniform" android:text="@string/saturday_short" - app:layout_constraintTop_toTopOf="parent" + android:textAlignment="gravity" + app:autoSizeTextType="uniform" + app:layout_constraintDimensionRatio="H,1:1" app:layout_constraintEnd_toStartOf="@+id/weekdayPickerSundayEnd" - app:layout_constraintStart_toEndOf="@+id/weekdayPickerFriday" /> + app:layout_constraintStart_toEndOf="@+id/weekdayPickerFriday" + app:layout_constraintTop_toTopOf="parent" />