Skip to content

Commit

Permalink
little refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
epicarchitect committed Apr 24, 2023
1 parent 80d7117 commit ace2078
Showing 1 changed file with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,23 @@ object EpicDatePicker {
private var _selectionMode by mutableStateOf(selectionMode)
override var selectionMode
get() = _selectionMode
set(value) {
val takeLastAmount = when (value) {
is SelectionMode.Range -> 2
is SelectionMode.Single -> value.maxSize
set(mode) {
_selectionMode = mode
val dates = selectedDates
selectedDates = if (dates.isEmpty()) {
emptyList()
} else {
when (mode) {
is SelectionMode.Range -> {
if (dates.size == 1) listOf(dates.first())
else listOf(dates.min(), dates.max())
}

is SelectionMode.Single -> {
dates.takeLast(mode.maxSize)
}
}
}
selectedDates = selectedDates.takeLast(takeLastAmount)
_selectionMode = value
}

override var displayDaysOfAdjacentMonths
Expand Down

0 comments on commit ace2078

Please sign in to comment.