From f6e6d5fe9bdc7288adf9c6dabc7f712ca8435a7d Mon Sep 17 00:00:00 2001 From: Eliezer Graber Date: Tue, 25 Jan 2022 23:11:25 -0500 Subject: [PATCH] Add an enabled attr to DateInputView and TimeInputView --- .../eygraber/date_time_input/xml/DateInputView.kt | 10 ++++++++++ .../eygraber/date_time_input/xml/TimeInputView.kt | 13 +++++++++++++ xml/src/main/res/values/attrs.xml | 4 ++++ 3 files changed, 27 insertions(+) diff --git a/xml/src/main/kotlin/com/eygraber/date_time_input/xml/DateInputView.kt b/xml/src/main/kotlin/com/eygraber/date_time_input/xml/DateInputView.kt index f3cb708..f66325b 100644 --- a/xml/src/main/kotlin/com/eygraber/date_time_input/xml/DateInputView.kt +++ b/xml/src/main/kotlin/com/eygraber/date_time_input/xml/DateInputView.kt @@ -56,6 +56,13 @@ class DateInputView @JvmOverloads constructor( private var selectedMonth = INVALID_MONTH + override fun setEnabled(enabled: Boolean) { + super.setEnabled(enabled) + monthContainerView.isEnabled = enabled + dayContainerView.isEnabled = enabled + yearContainerView.isEnabled = enabled + } + val selectedDateResult: DateResult get() = DateResult.calculateResult( minDate = minDate, @@ -161,6 +168,9 @@ class DateInputView @JvmOverloads constructor( errorView = findViewById(R.id.error) styledAttr(attrs, R.styleable.DateInputView, R.attr.dateInputViewStyle) { + val enabled = getBoolean(R.styleable.DateInputView_android_enabled, true) + isEnabled = enabled + val horizontalGap = getDimensionPixelSize( R.styleable.DateInputView_dateInputView_horizontalGap, -1 diff --git a/xml/src/main/kotlin/com/eygraber/date_time_input/xml/TimeInputView.kt b/xml/src/main/kotlin/com/eygraber/date_time_input/xml/TimeInputView.kt index e954d57..35f0e2c 100644 --- a/xml/src/main/kotlin/com/eygraber/date_time_input/xml/TimeInputView.kt +++ b/xml/src/main/kotlin/com/eygraber/date_time_input/xml/TimeInputView.kt @@ -16,6 +16,7 @@ import android.widget.TextView import androidx.constraintlayout.helper.widget.Flow import androidx.constraintlayout.widget.ConstraintLayout import androidx.constraintlayout.widget.Group +import androidx.core.view.children import androidx.core.view.isVisible import androidx.core.view.updateLayoutParams import androidx.core.widget.doAfterTextChanged @@ -69,6 +70,15 @@ class TimeInputView @JvmOverloads constructor( private var padLeadingZero = true + override fun setEnabled(enabled: Boolean) { + super.setEnabled(enabled) + hourContainerView.isEnabled = enabled + minuteContainerView.isEnabled = enabled + secondContainerView.isEnabled = enabled + amPmContainerView.isEnabled = enabled + amPmContainerView.children.forEach { it.isEnabled = enabled } + } + val selectedTimeResult: TimeResult get() = TimeResult.calculateResult( minTime = minTime, @@ -218,6 +228,9 @@ class TimeInputView @JvmOverloads constructor( errorView = findViewById(R.id.error) styledAttr(attrs, R.styleable.TimeInputView, R.attr.timeInputViewStyle) { + val enabled = getBoolean(R.styleable.DateInputView_android_enabled, true) + isEnabled = enabled + val horizontalGap = getDimensionPixelSize( R.styleable.TimeInputView_timeInputView_horizontalGap, -1 diff --git a/xml/src/main/res/values/attrs.xml b/xml/src/main/res/values/attrs.xml index d577b41..99034f5 100644 --- a/xml/src/main/res/values/attrs.xml +++ b/xml/src/main/res/values/attrs.xml @@ -5,6 +5,8 @@ + + @@ -29,6 +31,8 @@ + +