Skip to content

Commit cfb1118

Browse files
Remove core library desugaring in library (#120)
1 parent b345a86 commit cfb1118

File tree

23 files changed

+81
-17
lines changed

23 files changed

+81
-17
lines changed

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,23 @@ Library is available on Maven Central repository.
2020
```
2121
Snapshots are available on [Sonatype’s snapshots repository](https://s01.oss.sonatype.org/content/repositories/snapshots/io/github/boguszpawlowski/composecalendar/).
2222

23+
### 1.3.0 Changes
24+
From version 1.3.0 library no longer uses `coreLibraryDesugaring` itself. If you are using it in project supporting min SDK < 26, you need to add it to prevent runtime crashes.
25+
```kotlin
26+
// app-level build.gradle
27+
android {
28+
compileOptions {
29+
coreLibraryDesugaringEnabled true
30+
}
31+
kotlinOptions {
32+
jvmTarget = "1.8"
33+
}
34+
}
35+
dependencies {
36+
coreLibraryDesugaring "com.android.tools:desugar_jdk_libs:2.0.4"
37+
}
38+
```
39+
2340
## Supported features
2441
- Selection (single, multiple or a range of days)
2542
- Chose day as first day of week
@@ -213,7 +230,7 @@ This implementation of SelectionState also allows for handling side-effects and
213230
Apart from the default calendar, there is also a week calendar, which shows a single week at a time. It can be used in the same way as the default calendar, and has the same customization options.
214231

215232
## KotlinX DateTime
216-
As the core of the library is built on `java.time` library, on Android it requires to use [core libary desugaring](https://developer.android.com/studio/write/java8-support) to be able to access it's API.
233+
As the core of the library is built on `java.time` library, on Android SDK < 26 it requires to use [core libary desugaring](https://developer.android.com/studio/write/java8-support) to access it's API.
217234
As a result it's features may be unavailable to some project built around different date-time libraries (e.g. kotlinx-datetime). Although the project wont be migrating from `java.time`, as it's the best suited for it, there is a separate `kotlinx-datetime` artifact for those who need to use the library from a codebase based on it. It doesn't consist of a separate version of `ComposeCalendar` features, but offers a small bunch of utilities, that will enable you to create your own wrapper, as briefly presented in `KotlinDateTimeSample`. If the provided functionality, doesn't match your use-case, please submit an issue.
218235

219236
## License

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ allprojects {
3434
mavenCentral()
3535
gradlePluginPortal()
3636
google()
37+
mavenLocal()
3738
}
3839

3940
tasks.withType<KotlinCompile> {

buildSrc/src/main/kotlin/CommonAndroidPlugin.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,13 @@ class CommonAndroidPlugin : Plugin<Project> {
2020
compileOptions {
2121
sourceCompatibility = VERSION_17
2222
targetCompatibility = VERSION_17
23-
isCoreLibraryDesugaringEnabled = true
2423
}
2524

2625
buildFeatures.compose = true
2726

2827
composeOptions {
2928
kotlinCompilerExtensionVersion = Compose.CompilerVersion
3029
}
31-
32-
target.dependencies.add("coreLibraryDesugaring", Kotlin.DesugarJdkLibs)
3330
}
3431
}
3532
}

buildSrc/src/main/kotlin/Dependencies.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ object Kotlin {
2727
const val CompatibilityPlugin = "org.jetbrains.kotlinx.binary-compatibility-validator"
2828
const val CompatibilityPluginId = "binary-compatibility-validator"
2929

30-
const val DesugarJdkLibs = "com.android.tools:desugar_jdk_libs:1.1.5"
30+
const val DesugarJdkLibs = "com.android.tools:desugar_jdk_libs:2.0.4"
3131
const val DateTime = "org.jetbrains.kotlinx:kotlinx-datetime:0.4.0"
3232
}
3333

library/src/main/java/io/github/boguszpawlowski/composecalendar/Calendar.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
package io.github.boguszpawlowski.composecalendar
44

5+
import android.annotation.SuppressLint
56
import androidx.compose.foundation.layout.Box
67
import androidx.compose.foundation.layout.BoxScope
78
import androidx.compose.foundation.layout.Column
@@ -68,6 +69,7 @@ public class CalendarState<T : SelectionState>(
6869
* @param monthContainer container composable for all the days in current month
6970
*/
7071
@Composable
72+
@SuppressLint("NewApi")
7173
public fun SelectableCalendar(
7274
modifier: Modifier = Modifier,
7375
firstDayOfWeek: DayOfWeek = WeekFields.of(Locale.getDefault()).firstDayOfWeek,
@@ -122,6 +124,7 @@ public fun SelectableCalendar(
122124
* @param monthContainer container composable for all the days in current month
123125
*/
124126
@Composable
127+
@SuppressLint("NewApi")
125128
public fun StaticCalendar(
126129
modifier: Modifier = Modifier,
127130
firstDayOfWeek: DayOfWeek = WeekFields.of(Locale.getDefault()).firstDayOfWeek,
@@ -170,6 +173,7 @@ public fun StaticCalendar(
170173
* @param monthContainer container composable for all the days in current month
171174
*/
172175
@Composable
176+
@SuppressLint("NewApi")
173177
public fun <T : SelectionState> Calendar(
174178
calendarState: CalendarState<T>,
175179
modifier: Modifier = Modifier,
@@ -235,6 +239,7 @@ public fun <T : SelectionState> Calendar(
235239
* @param maxMonth last month that can be shown
236240
*/
237241
@Composable
242+
@SuppressLint("NewApi")
238243
public fun rememberSelectableCalendarState(
239244
initialMonth: YearMonth = YearMonth.now(),
240245
minMonth: YearMonth = initialMonth.minusMonths(DefaultCalendarPagerRange),
@@ -264,6 +269,7 @@ public fun rememberSelectableCalendarState(
264269
* @param maxMonth last month that can be shown
265270
*/
266271
@Composable
272+
@SuppressLint("NewApi")
267273
public fun rememberCalendarState(
268274
initialMonth: YearMonth = YearMonth.now(),
269275
minMonth: YearMonth = initialMonth.minusMonths(DefaultCalendarPagerRange),

library/src/main/java/io/github/boguszpawlowski/composecalendar/WeekCalendar.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
package io.github.boguszpawlowski.composecalendar
44

5+
import android.annotation.SuppressLint
56
import androidx.compose.foundation.layout.BoxScope
67
import androidx.compose.foundation.layout.Column
78
import androidx.compose.foundation.layout.ColumnScope
@@ -111,6 +112,7 @@ public fun SelectableWeekCalendar(
111112
* @param daysOfWeekHeader header for showing captions for each day of week
112113
*/
113114
@Composable
115+
@SuppressLint("NewApi")
114116
public fun StaticWeekCalendar(
115117
modifier: Modifier = Modifier,
116118
firstDayOfWeek: DayOfWeek = WeekFields.of(Locale.getDefault()).firstDayOfWeek,
@@ -153,6 +155,7 @@ public fun StaticWeekCalendar(
153155
* @param daysOfWeekHeader header for showing captions for each day of week
154156
*/
155157
@Composable
158+
@SuppressLint("NewApi")
156159
public fun <T : SelectionState> WeekCalendar(
157160
calendarState: WeekCalendarState<T>,
158161
modifier: Modifier = Modifier,
@@ -211,6 +214,7 @@ public fun <T : SelectionState> WeekCalendar(
211214
* @param maxWeek last week that can be shown
212215
*/
213216
@Composable
217+
@SuppressLint("NewApi")
214218
public fun rememberSelectableWeekCalendarState(
215219
firstDayOfWeek: DayOfWeek = WeekFields.of(Locale.getDefault()).firstDayOfWeek,
216220
initialWeek: Week = Week.now(firstDayOfWeek),
@@ -243,6 +247,7 @@ public fun rememberSelectableWeekCalendarState(
243247
* @param maxWeek last week that can be shown
244248
*/
245249
@Composable
250+
@SuppressLint("NewApi")
246251
public fun rememberWeekCalendarState(
247252
firstDayOfWeek: DayOfWeek = WeekFields.of(Locale.getDefault()).firstDayOfWeek,
248253
initialWeek: Week = Week.now(firstDayOfWeek),

library/src/main/java/io/github/boguszpawlowski/composecalendar/day/DefaultDay.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.github.boguszpawlowski.composecalendar.day
22

3+
import android.annotation.SuppressLint
34
import androidx.compose.foundation.BorderStroke
45
import androidx.compose.foundation.clickable
56
import androidx.compose.foundation.layout.Box
@@ -26,6 +27,7 @@ import java.time.LocalDate
2627
* @param onClick callback for interacting with day clicks
2728
*/
2829
@Composable
30+
@SuppressLint("NewApi")
2931
public fun <T : SelectionState> DefaultDay(
3032
state: DayState<T>,
3133
modifier: Modifier = Modifier,

library/src/main/java/io/github/boguszpawlowski/composecalendar/header/DefaultMonthHeader.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.github.boguszpawlowski.composecalendar.header
22

3+
import android.annotation.SuppressLint
34
import androidx.compose.foundation.Image
45
import androidx.compose.foundation.layout.Arrangement
56
import androidx.compose.foundation.layout.Row
@@ -26,6 +27,7 @@ import java.util.Locale
2627
* 2 arrows for changing currently showed month
2728
*/
2829
@Composable
30+
@SuppressLint("NewApi")
2931
public fun DefaultMonthHeader(
3032
monthState: MonthState,
3133
modifier: Modifier = Modifier,

library/src/main/java/io/github/boguszpawlowski/composecalendar/header/DefaultWeekHeader.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.github.boguszpawlowski.composecalendar.header
22

3+
import android.annotation.SuppressLint
34
import androidx.compose.foundation.Image
45
import androidx.compose.foundation.layout.Arrangement
56
import androidx.compose.foundation.layout.Row
@@ -27,6 +28,7 @@ import java.util.Locale
2728
*/
2829
@Composable
2930
@Suppress("LongMethod")
31+
@SuppressLint("NewApi")
3032
public fun DefaultWeekHeader(
3133
weekState: WeekState,
3234
modifier: Modifier = Modifier,

library/src/main/java/io/github/boguszpawlowski/composecalendar/header/MonthState.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.github.boguszpawlowski.composecalendar.header
22

3+
import android.annotation.SuppressLint
34
import androidx.compose.runtime.Stable
45
import androidx.compose.runtime.getValue
56
import androidx.compose.runtime.mutableStateOf
@@ -42,6 +43,7 @@ public interface MonthState {
4243
}
4344

4445
@Stable
46+
@SuppressLint("NewApi")
4547
private class MonthStateImpl(
4648
initialMonth: YearMonth,
4749
minMonth: YearMonth,

library/src/main/java/io/github/boguszpawlowski/composecalendar/header/WeekState.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.github.boguszpawlowski.composecalendar.header
22

3+
import android.annotation.SuppressLint
34
import androidx.compose.runtime.Stable
45
import androidx.compose.runtime.getValue
56
import androidx.compose.runtime.mutableStateOf
@@ -21,6 +22,7 @@ public fun WeekState(
2122
)
2223

2324
@Stable
25+
@SuppressLint("NewApi")
2426
public interface WeekState {
2527
public var currentWeek: Week
2628
public var minWeek: Week

library/src/main/java/io/github/boguszpawlowski/composecalendar/month/MonthContent.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import java.time.temporal.ChronoUnit
3333

3434
@OptIn(ExperimentalSnapperApi::class)
3535
@Composable
36-
@Suppress("LongMethod")
36+
@Suppress("LongMethod", "NewApi")
3737
internal fun <T : SelectionState> MonthPager(
3838
initialMonth: YearMonth,
3939
showAdjacentMonths: Boolean,

library/src/main/java/io/github/boguszpawlowski/composecalendar/month/MonthListState.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.github.boguszpawlowski.composecalendar.month
22

3+
import android.annotation.SuppressLint
34
import androidx.compose.foundation.lazy.LazyListState
45
import androidx.compose.runtime.Stable
56
import androidx.compose.runtime.derivedStateOf
@@ -15,6 +16,7 @@ import java.time.YearMonth
1516
import java.time.temporal.ChronoUnit
1617

1718
@Stable
19+
@SuppressLint("NewApi")
1820
internal class MonthListState(
1921
private val coroutineScope: CoroutineScope,
2022
private val monthState: MonthState,

library/src/main/java/io/github/boguszpawlowski/composecalendar/selection/DynamicSelectionHandler.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.github.boguszpawlowski.composecalendar.selection
22

3+
import android.annotation.SuppressLint
34
import io.github.boguszpawlowski.composecalendar.util.addOrRemoveIfExists
45
import java.time.LocalDate
56

@@ -10,6 +11,7 @@ import java.time.LocalDate
1011
* @param selectionMode current selection mode
1112
* @returns new selection in a form of a list of local dates.
1213
*/
14+
@SuppressLint("NewApi")
1315
public object DynamicSelectionHandler {
1416
public fun calculateNewSelection(
1517
date: LocalDate,

library/src/main/java/io/github/boguszpawlowski/composecalendar/selection/SelectionExtensions.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package io.github.boguszpawlowski.composecalendar.selection
22

3+
import android.annotation.SuppressLint
34
import java.time.LocalDate
45

6+
@SuppressLint("NewApi")
57
internal fun Collection<LocalDate>.startOrMax() = firstOrNull() ?: LocalDate.MAX
68

79
internal fun Collection<LocalDate>.endOrNull() = drop(1).lastOrNull()
810

11+
@SuppressLint("NewApi")
912
internal fun Collection<LocalDate>.fillUpTo(date: LocalDate) =
1013
(0..date.toEpochDay() - first().toEpochDay()).map {
1114
first().plusDays(it)

library/src/main/java/io/github/boguszpawlowski/composecalendar/selection/SelectionState.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.github.boguszpawlowski.composecalendar.selection
22

3+
import android.annotation.SuppressLint
34
import androidx.compose.runtime.Immutable
45
import androidx.compose.runtime.Stable
56
import androidx.compose.runtime.getValue
@@ -21,6 +22,7 @@ public interface SelectionState {
2122
* @param confirmSelectionChange return false from this callback to veto the selection change
2223
*/
2324
@Stable
25+
@SuppressLint("NewApi")
2426
public class DynamicSelectionState(
2527
private val confirmSelectionChange: (newValue: List<LocalDate>) -> Boolean = { true },
2628
selection: List<LocalDate>,

library/src/main/java/io/github/boguszpawlowski/composecalendar/week/DefaultWeekHeader.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.github.boguszpawlowski.composecalendar.week
22

3+
import android.annotation.SuppressLint
34
import androidx.compose.foundation.layout.Row
45
import androidx.compose.foundation.layout.wrapContentHeight
56
import androidx.compose.material.Text
@@ -20,6 +21,7 @@ import kotlin.DeprecationLevel.WARNING
2021
),
2122
message = "Replace with DefaultDaysOfWeekHeader, DefaultWeekHeader will be removed in future versions"
2223
)
24+
@SuppressLint("NewApi")
2325
public fun DefaultWeekHeader(
2426
daysOfWeek: List<DayOfWeek>,
2527
modifier: Modifier = Modifier,
@@ -38,6 +40,7 @@ public fun DefaultWeekHeader(
3840
}
3941

4042
@Composable
43+
@SuppressLint("NewApi")
4144
public fun DefaultDaysOfWeekHeader(
4245
daysOfWeek: List<DayOfWeek>,
4346
modifier: Modifier = Modifier,

library/src/main/java/io/github/boguszpawlowski/composecalendar/week/Week.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.github.boguszpawlowski.composecalendar.week
22

3+
import android.annotation.SuppressLint
34
import io.github.boguszpawlowski.composecalendar.selection.fillUpTo
45
import io.github.boguszpawlowski.composecalendar.util.daysUntil
56
import java.time.DayOfWeek
@@ -9,6 +10,7 @@ import java.time.temporal.ChronoUnit
910
import java.time.temporal.WeekFields
1011
import java.util.Locale
1112

13+
@SuppressLint("NewApi")
1214
public data class Week(
1315
val days: List<LocalDate>,
1416
) {
@@ -48,5 +50,6 @@ public data class Week(
4850
}
4951
}
5052

53+
@SuppressLint("NewApi")
5154
public fun ChronoUnit.between(first: Week, other: Week): Int =
5255
between(first.start, other.start).toInt()

library/src/main/java/io/github/boguszpawlowski/composecalendar/week/WeekListState.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.github.boguszpawlowski.composecalendar.week
22

3+
import android.annotation.SuppressLint
34
import androidx.compose.foundation.lazy.LazyListState
45
import androidx.compose.runtime.Stable
56
import androidx.compose.runtime.derivedStateOf
@@ -14,6 +15,7 @@ import kotlinx.coroutines.launch
1415
import java.time.temporal.ChronoUnit
1516

1617
@Stable
18+
@SuppressLint("NewApi")
1719
internal class WeekListState(
1820
private val coroutineScope: CoroutineScope,
1921
private val weekState: WeekState,

library/src/main/java/io/github/boguszpawlowski/composecalendar/week/WeekPager.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.github.boguszpawlowski.composecalendar.week
22

3+
import android.annotation.SuppressLint
34
import androidx.compose.animation.rememberSplineBasedDecay
45
import androidx.compose.foundation.layout.Box
56
import androidx.compose.foundation.layout.BoxScope
@@ -30,6 +31,7 @@ import java.time.temporal.ChronoUnit
3031
@OptIn(ExperimentalSnapperApi::class)
3132
@Composable
3233
@Suppress("LongMethod")
34+
@SuppressLint("NewApi")
3335
internal fun <T : SelectionState> WeekPager(
3436
initialWeek: Week,
3537
selectionState: T,

library/src/main/java/io/github/boguszpawlowski/composecalendar/week/WeekUtil.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.github.boguszpawlowski.composecalendar.week
22

3+
import android.annotation.SuppressLint
34
import io.github.boguszpawlowski.composecalendar.day.WeekDay
45
import io.github.boguszpawlowski.composecalendar.util.daysUntil
56
import java.time.DayOfWeek
@@ -8,10 +9,11 @@ import java.time.YearMonth
89

910
internal const val DaysInAWeek = 7
1011

12+
@SuppressLint("NewApi")
1113
internal fun YearMonth.getWeeks(
1214
includeAdjacentMonths: Boolean,
1315
firstDayOfTheWeek: DayOfWeek,
14-
today: LocalDate = LocalDate.now(),
16+
today: LocalDate,
1517
): List<WeekDays> {
1618
val daysLength = lengthOfMonth()
1719

0 commit comments

Comments
 (0)