Skip to content
This repository has been archived by the owner on Feb 9, 2023. It is now read-only.

Commit

Permalink
Add an enabled attr to DateInputView and TimeInputView
Browse files Browse the repository at this point in the history
  • Loading branch information
eygraber committed Jan 26, 2022
1 parent 3b862e9 commit f6e6d5f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions xml/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<attr name="textInputExposedDropdownMenuStyle" format="reference" />

<declare-styleable name="DateInputView">
<attr name="android:enabled" format="boolean" />

<attr name="dateInputView_errorMarginStart" format="dimension" />

<attr name="dateInputView_monthNames" format="reference" />
Expand All @@ -29,6 +31,8 @@
</declare-styleable>

<declare-styleable name="TimeInputView">
<attr name="android:enabled" format="boolean" />

<attr name="timeInputView_secondVisibility" format="enum">
<enum name="visible" value="0"/>
<enum name="invisible" value="1"/>
Expand Down

0 comments on commit f6e6d5f

Please sign in to comment.