Skip to content

Commit

Permalink
Merge pull request #10 from bmoliveira/fix/calendar-selection
Browse files Browse the repository at this point in the history
Fix calendar selection + update dependencies
  • Loading branch information
bmoliveira committed Mar 22, 2024
2 parents 504220f + 8190eac commit b2469f9
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 30 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ android {
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = '1.8'
jvmTarget = "17"
}
buildFeatures {
compose true
Expand Down
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
buildscript {
ext {
compose_bom_version = '2024.02.01'
compose_compiler_version = '1.5.8'
compose_bom_version = '2024.03.00'
compose_compiler_version = '1.5.11'
corektx_version = '1.12.0'
accompanist_version = '0.34.0'
}
Expand All @@ -10,12 +10,12 @@ buildscript {
plugins {
id 'com.android.application' version '8.3.1' apply false
id 'com.android.library' version '8.3.1' apply false
id 'org.jetbrains.kotlin.android' version '1.9.22' apply false
id 'org.jetbrains.kotlin.android' version '1.9.23' apply false
id 'io.github.gradle-nexus.publish-plugin' version "1.1.0"
}

task clean(type: Delete) {
delete rootProject.buildDir
tasks.register('clean', Delete) {
delete rootProject.layout.buildDirectory
}

apply from: "${rootDir}/scripts/publish-root.gradle"
8 changes: 4 additions & 4 deletions composecalendar/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ android {
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = '1.8'
jvmTarget = "17"
}
buildFeatures {
compose true
Expand Down Expand Up @@ -82,7 +82,7 @@ afterEvaluate {
from components.release
groupId = 'com.squaredem.composecalendar'
artifactId = 'composecalendar'
version = '2.5.3'
version = '2.5.4'
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ sealed class CalendarMode {
) : CalendarMode()
}

internal fun CalendarMode.Range.hasEndDate(): Boolean =
internal fun CalendarMode.Range.rangeSelected(): Boolean =
selection?.endDate != null && selection.endDate != selection.startDate

internal fun CalendarMode.Range.onDayClicked(day: LocalDate): CalendarMode.Range = when {
Expand All @@ -69,32 +69,44 @@ internal fun CalendarMode.Range.onDayClicked(day: LocalDate): CalendarMode.Range

selectionMode == ForcedSelectMode.StartDate -> {
when {
!hasEndDate() && day.isAfter(selection.startDate) -> copy(
// BO: Single date selected, and the new date is after selected start ->
// Continue single selection on the selected day.
!rangeSelected() && day.isAfter(selection.startDate) -> copy(
selection = DateRangeSelection(day),
selectionMode = ForcedSelectMode.EndDate
)

!hasEndDate() && day.isBefore(selection.startDate) -> copy(
// BO: Single date selected, and the new date is before selected start ->
// Date range from the selected date to the previous start date.
!rangeSelected() && day.isBefore(selection.startDate) -> copy(
selection = DateRangeSelection(day, startDate),
selectionMode = ForcedSelectMode.EndDate
)

!hasEndDate() && day == selection.startDate -> copy(
// BO: Single date selected, and the new date is the same as start ->
// Clear selection.
!rangeSelected() && day == selection.startDate -> copy(
selection = null,
selectionMode = ForcedSelectMode.StartDate
)

!hasEndDate() && day.isBefore(selection.endDate) -> copy(
selection = selection.copy(startDate = day),
// BO: Range selected, and the date selected is the start date ->
// Deselect start date.
rangeSelected() && day == selection.startDate -> copy(
selection = selection.endDate?.let { DateRangeSelection(it) },
selectionMode = ForcedSelectMode.EndDate
)

day == selection.startDate -> copy(
selection = selection.endDate?.let { DateRangeSelection(it) },
// BO: Range selected, and the date selected is before end date ->
// Make a range from selection to end date.
rangeSelected() && day.isBefore(selection.endDate) -> copy(
selection = selection.copy(startDate = day),
selectionMode = ForcedSelectMode.EndDate
)

day == selection.endDate -> copy(
// BO: Range selected, and the new date is the end date ->
// Deselect end date.
rangeSelected() && day == selection.endDate -> copy(
selection = selection.copy(startDate = day, endDate = null),
selectionMode = ForcedSelectMode.EndDate
)
Expand All @@ -108,31 +120,37 @@ internal fun CalendarMode.Range.onDayClicked(day: LocalDate): CalendarMode.Range

selectionMode == ForcedSelectMode.EndDate -> {
when {
// BO: Date selected is before the start date ->
// Make single selection with the selected day.
day.isBefore(selection.startDate) -> copy(
selection = selection.copy(
startDate = day,
endDate = selection.endDate ?: selection.startDate,
)
)

!hasEndDate() && day.isAfter(selection.startDate) -> copy(
// BO: Single selection, and the new date is after start date ->
// Make range from old start to selected day.
!rangeSelected() && day.isAfter(selection.startDate) -> copy(
selection = selection.copy(endDate = day)
)

!hasEndDate() && day == selection.startDate -> copy(
// BO: Single selection, and the new date is the same as start ->
// Clear selection.
!rangeSelected() && day == selection.startDate -> copy(
selection = null,
selectionMode = ForcedSelectMode.StartDate,
)

day == selection.startDate -> copy(
selection = DateRangeSelection(startDate = day),
)

hasEndDate() && day.isBefore(selection.endDate) -> copy(
selection = selection.copy(endDate = day),
// BO: Range selection, and the new date is the start date ->
// Clear start selection.
rangeSelected() && day == selection.startDate -> copy(
selection = selection.endDate?.let { DateRangeSelection(it) }
)

hasEndDate() && day == selection.endDate -> copy(
// BO: Range selection, and the new date is the end date ->
// Clear end selection.
rangeSelected() && day == selection.endDate -> copy(
selection = selection.copy(endDate = null),
)

Expand Down

0 comments on commit b2469f9

Please sign in to comment.