Skip to content

Commit

Permalink
Merge branch 'main' into develop
Browse files Browse the repository at this point in the history
# Conflicts:
#	composecalendar/src/main/java/com/squaredem/composecalendar/composable/CalendarContent.kt
#	composecalendar/src/main/java/com/squaredem/composecalendar/composable/CalendarMonthYearSelector.kt
  • Loading branch information
lampione committed Oct 18, 2022
2 parents 30c4529 + bc0fc47 commit 0c42807
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ then add the latest ComposeCalendar version to your `app/build.gradle` file depe

```groovy
dependencies {
implementation 'com.squaredem:composecalendar:1.0.3'
implementation 'com.squaredem:composecalendar:1.0.4'
}
```

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
compose_version = '1.3.0-alpha01'
material3_version = '1.0.0-alpha14'
corektx_version = '1.8.0'
accompanist_version = '0.23.1'
accompanist_version = '0.25.1'
}
}

Expand Down
2 changes: 1 addition & 1 deletion composecalendar/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ dependencies {
ext {
PUBLISH_GROUP_ID = 'com.squaredem'
PUBLISH_ARTIFACT_ID = 'composecalendar'
PUBLISH_VERSION = '1.0.3'
PUBLISH_VERSION = '1.0.4'
}

apply from: "${rootProject.projectDir}/scripts/publish-module.gradle"
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.squaredem.composecalendar.composable

import android.util.Log
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
Expand Down Expand Up @@ -86,7 +85,7 @@ internal fun CalendarContent(

if (!LocalInspectionMode.current) {
LaunchedEffect(pagerState) {
snapshotFlow { pagerState.targetPage }.collect { page ->
snapshotFlow { pagerState.currentPage }.collect { page ->
val currentDate = getDateFromCurrentPage(page, dateRange)
currentPagerDate.value = currentDate
}
Expand All @@ -105,7 +104,8 @@ internal fun CalendarContent(
onNextMonth = {
coroutineScope.launch {
try {
pagerState.animateScrollToPage(pagerState.currentPage + 1)
val newPage = pagerState.currentPage + 1
pagerState.animateScrollToPage(newPage)
} catch (e: Exception) {
// avoid IndexOutOfBounds and animation crashes
}
Expand All @@ -114,7 +114,8 @@ internal fun CalendarContent(
onPreviousMonth = {
coroutineScope.launch {
try {
pagerState.animateScrollToPage(pagerState.currentPage - 1)
val newPage = pagerState.currentPage - 1
pagerState.animateScrollToPage(newPage)
} catch (e: Exception) {
// avoid IndexOutOfBounds and animation crashes
}
Expand All @@ -129,12 +130,8 @@ internal fun CalendarContent(
) {
DayOfWeek.values().forEach {
Text(
modifier = Modifier
.weight(1f),
text = it.getDisplayName(
TextStyle.NARROW,
Locale.getDefault()
),
modifier = Modifier.weight(1f),
text = it.getDisplayName(TextStyle.NARROW, Locale.getDefault()),
textAlign = TextAlign.Center,
fontWeight = FontWeight.SemiBold
)
Expand All @@ -146,7 +143,6 @@ internal fun CalendarContent(
state = pagerState
) { page ->
val currentDate = getDateFromCurrentPage(page, dateRange)

currentDate?.let {
// grid
CalendarGrid(
Expand Down Expand Up @@ -193,7 +189,9 @@ private fun getStartPage(
if (startDate >= dateRange.endInclusive) {
return pageCount
}
val indexOfRange = dateRange.indexOf(startDate.withDayOfMonth(1))
val indexOfRange = dateRange.indexOfFirst {
it.year == startDate.year && it.monthValue == startDate.monthValue
}
return if (indexOfRange != -1) indexOfRange else pageCount / 2
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import com.google.accompanist.pager.ExperimentalPagerApi
import com.google.accompanist.pager.PagerState
import com.squaredem.composecalendar.utils.LogCompositions
import kotlinx.coroutines.CoroutineScope
import java.text.SimpleDateFormat
import java.time.LocalDate
import java.time.OffsetTime
Expand All @@ -46,7 +43,7 @@ internal fun CalendarMonthYearSelector(
pagerDate: LocalDate,
onChipClicked: () -> Unit,
onNextMonth: () -> Unit,
onPreviousMonth: () -> Unit
onPreviousMonth: () -> Unit,
) {
LogCompositions("CalendarMonthYearSelector")

Expand Down

0 comments on commit 0c42807

Please sign in to comment.