Skip to content

Commit

Permalink
(Clock) Add config setup check
Browse files Browse the repository at this point in the history
  • Loading branch information
maxkeppeler committed Apr 19, 2023
1 parent 6a00aec commit 5c420c5
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions clock/src/main/java/com/maxkeppeler/sheets/clock/ClockState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ internal class ClockState(
var disabledKeys by mutableStateOf(getCurrentDisabledKeys())
var valid by mutableStateOf(isValid())

init {
checkSetup()
}

private fun checkSetup() {
if (config.defaultTime != null && config.boundary != null && (config.defaultTime !in config.boundary))
throw IllegalStateException("Please correct your setup. The default time must be in the boundary.")
if(config.boundary != null && config.boundary.start > config.boundary.endInclusive)
throw IllegalStateException("Please correct your setup. The start time must be before the end time.")
}

private val debouncer = Debouncer(Constants.DEBOUNCE_KEY_CLICK_DURATION)

private fun isValid(): Boolean = config.boundary?.let { time in it } ?: true
Expand Down

0 comments on commit 5c420c5

Please sign in to comment.