Skip to content

Commit

Permalink
Merge branch 'compose_1.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
kizitonwose committed Jun 15, 2024
2 parents d41601f + 7fcadfa commit 33ccd90
Show file tree
Hide file tree
Showing 24 changed files with 327 additions and 297 deletions.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,13 @@ View the sample app's source code [here](https://github.com/kizitonwose/Calendar

## Setup

The library uses `java.time` classes via [Java 8+ API desugaring](https://developer.android.com/studio/write/java8-support#library-desugaring) for backward compatibility since these classes were added in Java 8.

#### Step 1

This step is required ONLY if your app's `minSdkVersion` is below 26. Jump to [step 2](#step-2) if this does not apply to you.
**This step is required ONLY if your app's `minSdkVersion` is below 26. Jump to [step 2](#step-2) if this does not apply to you.**

To set up your project for desugaring, you need to first ensure that you are using [Android Gradle plugin](https://developer.android.com/studio/releases/gradle-plugin#updating-plugin) 4.0.0 or higher.
Apps with `minSdkVersion` below 26 have to enable [Java 8+ API desugaring](https://developer.android.com/studio/write/java8-support#library-desugaring) for backward compatibility since `java.time` classes were added in Java 8 which is supported natively starting from Android SDK 26. To set up your project for desugaring, you need to first ensure that you are using [Android Gradle plugin](https://developer.android.com/studio/releases/gradle-plugin#updating-plugin) 4.0.0 or higher.

Then include the following in your app's build.gradle file:
Then include the following in your app's `build.gradle` file:

```groovy
android {
Expand Down
31 changes: 0 additions & 31 deletions build.gradle

This file was deleted.

15 changes: 15 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import com.kizitonwose.calendar.buildsrc.Plugins

plugins {
with(com.kizitonwose.calendar.buildsrc.Plugins) {
applyRootPlugins()
}
}

allprojects {
apply(plugin = Plugins.kotlinter)
}

tasks.register<Delete>("clean").configure {
delete(rootProject.layout.buildDirectory)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,49 @@
package com.kizitonwose.calendar.buildsrc

import org.gradle.api.JavaVersion
import org.gradle.jvm.toolchain.JavaLanguageVersion
import org.gradle.kotlin.dsl.PluginDependenciesSpecScope
import kotlin.math.max

object Config {
val compatibleJavaVersion = JavaVersion.VERSION_17
val compatibleJavaLanguageVersion = JavaLanguageVersion.of(compatibleJavaVersion.majorVersion.toInt())
}

object Android {
const val minSdkLibraryCore = 4
const val minSdkLibraryView = 15
const val minSdkLibraryCompose = 21
const val minSdkSample = 21
const val targetSdk = 33
const val minSdkViewLibrary = 15
const val minSdkComposeLibrary = 21
val minSdkSampleApp = max(minSdkViewLibrary, minSdkComposeLibrary)
const val targetSdk = 34
const val compileSdk = 34

// See compose/kotlin version mapping
// https://developer.android.com/jetpack/androidx/releases/compose-kotlin
const val composeCompiler = "1.5.9"
const val composeCompiler = "1.5.14"
}

object Plugins {
const val android = "com.android.tools.build:gradle:8.2.2"
const val kotlin = Kotlin.gradlePlugin
const val kotlinter = "org.jmailen.gradle:kotlinter-gradle:4.2.0"
const val versions = "com.github.ben-manes:gradle-versions-plugin:0.51.0"
const val mavenPublish = "com.vanniktech:gradle-maven-publish-plugin:0.27.0"
private const val agpVersion = "8.4.0"
const val androidApp = "com.android.application"
const val androidLibrary = "com.android.library"
const val kotlinJvm = "org.jetbrains.kotlin.jvm"
const val kotlinAndroid = "org.jetbrains.kotlin.android"
const val kotlinter = "org.jmailen.kotlinter"
const val mavenPublish = "com.vanniktech.maven.publish"
const val versionCheck = "com.github.ben-manes.versions"

fun PluginDependenciesSpecScope.applyRootPlugins() {
id(androidApp).version(agpVersion).apply(false)
id(androidLibrary).version(agpVersion).apply(false)
id(kotlinAndroid).version(Kotlin.version).apply(false)
id(kotlinter).version("4.3.0").apply(false)
id(mavenPublish).version("0.28.0").apply(false)
id(versionCheck).version("0.51.0").apply(true)
}
}

object Kotlin {
private const val version = "1.9.22"
const val gradlePlugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:$version"
internal const val version = "1.9.24"
const val stdLib = "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$version"
}

Expand All @@ -47,11 +61,11 @@ object Libs {
object View {
const val legacySupport = "androidx.legacy:legacy-support-v4:1.0.0"
const val appCompat = "androidx.appcompat:appcompat:1.6.1"
const val coreKtx = "androidx.core:core-ktx:1.12.0"
const val coreKtx = "androidx.core:core-ktx:1.13.1"
const val constraintLayout = "androidx.constraintlayout:constraintlayout:2.1.4"
const val cardView = "androidx.cardview:cardview:1.0.0"
const val recyclerView = "androidx.recyclerview:recyclerview:1.3.2"
const val material = "com.google.android.material:material:1.9.0"
const val material = "com.google.android.material:material:1.12.0"

object Test {
private const val espressoVersion = "3.5.1"
Expand All @@ -64,13 +78,13 @@ object Libs {
}

object Compose {
private const val composeVersion = "1.6.1"
private const val composeVersion = "1.7.0-beta01"
const val ui = "androidx.compose.ui:ui:$composeVersion"
const val foundation = "androidx.compose.foundation:foundation:$composeVersion"
const val tooling = "androidx.compose.ui:ui-tooling:$composeVersion"
const val runtime = "androidx.compose.runtime:runtime:$composeVersion"
const val material = "androidx.compose.material:material:$composeVersion"
const val activity = "androidx.activity:activity-compose:1.8.2"
const val activity = "androidx.activity:activity-compose:1.9.0"
const val navigation = "androidx.navigation:navigation-compose:2.7.7"

object Test {
Expand Down
44 changes: 0 additions & 44 deletions compose/build.gradle

This file was deleted.

48 changes: 48 additions & 0 deletions compose/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import com.kizitonwose.calendar.buildsrc.Android
import com.kizitonwose.calendar.buildsrc.Config
import com.kizitonwose.calendar.buildsrc.Kotlin
import com.kizitonwose.calendar.buildsrc.Libs

plugins {
with(com.kizitonwose.calendar.buildsrc.Plugins) {
id(androidLibrary)
id(kotlinAndroid)
id(mavenPublish)
}
}

android {
compileSdk = Android.compileSdk
namespace = "com.kizitonwose.calendar.compose"
defaultConfig {
minSdk = Android.minSdkComposeLibrary
}
java {
toolchain {
languageVersion.set(Config.compatibleJavaLanguageVersion)
}
}
kotlin {
jvmToolchain {
languageVersion.set(Config.compatibleJavaLanguageVersion)
}
}
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = Android.composeCompiler
}
}

dependencies {
api(project(":core"))
implementation(project(":data"))
implementation(Kotlin.stdLib)

implementation(Libs.Compose.ui)
implementation(Libs.Compose.tooling)
implementation(Libs.Compose.foundation)

testImplementation(Libs.Core.Test.junit)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.gestures.FlingBehavior
import androidx.compose.foundation.gestures.ScrollableDefaults
import androidx.compose.foundation.gestures.snapping.SnapLayoutInfoProvider
import androidx.compose.foundation.gestures.snapping.SnapPositionInLayout
import androidx.compose.foundation.gestures.snapping.SnapPosition
import androidx.compose.foundation.gestures.snapping.rememberSnapFlingBehavior
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.runtime.Composable
Expand All @@ -22,7 +22,7 @@ internal object CalendarDefaults {
@Composable
private fun pagedFlingBehavior(state: LazyListState): FlingBehavior {
val snappingLayout = remember(state) {
val provider = SnapLayoutInfoProvider(state, CalendarSnapPositionInLayout())
val provider = SnapLayoutInfoProvider(state, SnapPosition.Start)
CalendarSnapLayoutInfoProvider(provider)
}
return rememberSnapFlingBehavior(snappingLayout)
Expand All @@ -46,9 +46,5 @@ private fun CalendarSnapLayoutInfoProvider(
* In compose 1.3, the default was single page snapping (zero), but this changed
* in compose 1.4 to decayed page snapping which is not great for calendar usage.
*/
override fun calculateApproachOffset(initialVelocity: Float): Float = 0f
override fun calculateApproachOffset(velocity: Float, decayOffset: Float): Float = 0f
}

@OptIn(ExperimentalFoundationApi::class)
@Suppress("FunctionName")
private fun CalendarSnapPositionInLayout() = SnapPositionInLayout { _, _, _, _, _ -> 0 }
30 changes: 0 additions & 30 deletions core/build.gradle

This file was deleted.

25 changes: 25 additions & 0 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import com.kizitonwose.calendar.buildsrc.Config
import com.kizitonwose.calendar.buildsrc.Libs

plugins {
with(com.kizitonwose.calendar.buildsrc.Plugins) {
id(kotlinJvm)
id(mavenPublish)
}
}

java {
toolchain {
languageVersion.set(Config.compatibleJavaLanguageVersion)
}
}

kotlin {
jvmToolchain {
languageVersion.set(Config.compatibleJavaLanguageVersion)
}
}

dependencies {
implementation(Libs.Compose.runtime) // Only needed for @Immutable annotation.
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ fun daysOfWeek(firstDayOfWeek: DayOfWeek = firstDayOfWeekFromLocale()): List<Day
}

/**
* Returns the first day of the week from the default locale.
* Returns the first day of the week from the provided locale.
*/
fun firstDayOfWeekFromLocale(): DayOfWeek = WeekFields.of(Locale.getDefault()).firstDayOfWeek
@JvmOverloads
fun firstDayOfWeekFromLocale(locale: Locale = Locale.getDefault()): DayOfWeek = WeekFields.of(locale).firstDayOfWeek

/**
* Returns a [LocalDate] at the start of the month.
Expand Down
34 changes: 0 additions & 34 deletions data/build.gradle

This file was deleted.

Loading

0 comments on commit 33ccd90

Please sign in to comment.