diff --git a/README.md b/README.md index 393cee27..0dac6550 100644 --- a/README.md +++ b/README.md @@ -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 { diff --git a/build.gradle b/build.gradle deleted file mode 100644 index f60bcc51..00000000 --- a/build.gradle +++ /dev/null @@ -1,31 +0,0 @@ -import com.kizitonwose.calendar.buildsrc.Plugins - -apply plugin: 'com.github.ben-manes.versions' - -buildscript { - repositories { - google() - gradlePluginPortal() - mavenCentral() - } - dependencies { - classpath Plugins.android - classpath Plugins.kotlin - classpath Plugins.kotlinter - classpath Plugins.versions - classpath Plugins.mavenPublish - } -} - -allprojects { - repositories { - google() - mavenCentral() - } - - apply plugin: 'org.jmailen.kotlinter' -} - -task clean(type: Delete) { - delete rootProject.buildDir -} diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 00000000..3574324b --- /dev/null +++ b/build.gradle.kts @@ -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("clean").configure { + delete(rootProject.layout.buildDirectory) +} diff --git a/buildSrc/src/main/java/com/kizitonwose/calendar/buildsrc/Dependencies.kt b/buildSrc/src/main/java/com/kizitonwose/calendar/buildsrc/Dependencies.kt index 0f5417d4..bc1092b6 100644 --- a/buildSrc/src/main/java/com/kizitonwose/calendar/buildsrc/Dependencies.kt +++ b/buildSrc/src/main/java/com/kizitonwose/calendar/buildsrc/Dependencies.kt @@ -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" } @@ -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" @@ -70,7 +84,7 @@ object Libs { 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 { diff --git a/compose/build.gradle b/compose/build.gradle deleted file mode 100644 index 28ae5cb9..00000000 --- a/compose/build.gradle +++ /dev/null @@ -1,44 +0,0 @@ -import com.kizitonwose.calendar.buildsrc.Android -import com.kizitonwose.calendar.buildsrc.Config -import com.kizitonwose.calendar.buildsrc.Kotlin -import com.kizitonwose.calendar.buildsrc.Libs - -apply plugin: 'com.android.library' -apply plugin: 'kotlin-android' -apply plugin: 'com.vanniktech.maven.publish' - -android { - compileSdk Android.compileSdk - namespace 'com.kizitonwose.calendar.compose' - defaultConfig { - minSdkVersion Android.minSdkLibraryCompose - targetSdkVersion Android.targetSdk - } - compileOptions { - coreLibraryDesugaringEnabled true - sourceCompatibility = Config.compatibleJavaVersion - targetCompatibility = Config.compatibleJavaVersion - } - kotlinOptions { - jvmTarget = Config.compatibleJavaVersion - } - buildFeatures { - compose true - } - composeOptions { - kotlinCompilerExtensionVersion Android.composeCompiler - } -} - -dependencies { - api project(':core') - implementation project(':data') - coreLibraryDesugaring Libs.Core.deSugar - implementation Kotlin.stdLib - - implementation Libs.Compose.ui - implementation Libs.Compose.tooling - implementation Libs.Compose.foundation - - testImplementation Libs.Core.Test.junit -} diff --git a/compose/build.gradle.kts b/compose/build.gradle.kts new file mode 100644 index 00000000..d69ad895 --- /dev/null +++ b/compose/build.gradle.kts @@ -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) +} diff --git a/core/build.gradle b/core/build.gradle deleted file mode 100644 index 59845487..00000000 --- a/core/build.gradle +++ /dev/null @@ -1,30 +0,0 @@ -import com.kizitonwose.calendar.buildsrc.Android -import com.kizitonwose.calendar.buildsrc.Config -import com.kizitonwose.calendar.buildsrc.Libs - -apply plugin: 'com.android.library' -apply plugin: 'kotlin-android' -apply plugin: 'com.vanniktech.maven.publish' - -android { - compileSdk Android.compileSdk - namespace 'com.kizitonwose.calendar.core' - defaultConfig { - minSdkVersion Android.minSdkLibraryCore - targetSdkVersion Android.targetSdk - multiDexEnabled true // Needed for desugar because minSdk < 21 - } - compileOptions { - coreLibraryDesugaringEnabled true - sourceCompatibility = Config.compatibleJavaVersion - targetCompatibility = Config.compatibleJavaVersion - } - kotlinOptions { - jvmTarget = Config.compatibleJavaVersion - } -} - -dependencies { - coreLibraryDesugaring Libs.Core.deSugar - implementation Libs.Compose.runtime // Only needed for @Immutable annotation. -} diff --git a/core/build.gradle.kts b/core/build.gradle.kts new file mode 100644 index 00000000..daf1333c --- /dev/null +++ b/core/build.gradle.kts @@ -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. +} diff --git a/core/src/main/java/com/kizitonwose/calendar/core/Extensions.kt b/core/src/main/java/com/kizitonwose/calendar/core/Extensions.kt index f63f5ee1..8ee5e512 100644 --- a/core/src/main/java/com/kizitonwose/calendar/core/Extensions.kt +++ b/core/src/main/java/com/kizitonwose/calendar/core/Extensions.kt @@ -21,9 +21,10 @@ fun daysOfWeek(firstDayOfWeek: DayOfWeek = firstDayOfWeekFromLocale()): List Unit) { Icon( tint = Color.White, modifier = Modifier.align(Alignment.Center), - imageVector = Icons.Default.ArrowBack, + imageVector = Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Back", ) } diff --git a/sample/src/main/java/com/kizitonwose/calendar/sample/shared/StatusBarColorLifecycleObserver.kt b/sample/src/main/java/com/kizitonwose/calendar/sample/shared/StatusBarColorLifecycleObserver.kt index 9668ce0e..18c1324a 100644 --- a/sample/src/main/java/com/kizitonwose/calendar/sample/shared/StatusBarColorLifecycleObserver.kt +++ b/sample/src/main/java/com/kizitonwose/calendar/sample/shared/StatusBarColorLifecycleObserver.kt @@ -11,6 +11,7 @@ import com.kizitonwose.calendar.sample.R import com.kizitonwose.calendar.sample.view.getColorCompat import java.lang.ref.WeakReference +@Suppress("DEPRECATION") class StatusBarColorLifecycleObserver( activity: Activity, @ColorInt private val color: Int, diff --git a/sample/src/main/java/com/kizitonwose/calendar/sample/view/Example3Fragment.kt b/sample/src/main/java/com/kizitonwose/calendar/sample/view/Example3Fragment.kt index 2c70aead..69b04004 100644 --- a/sample/src/main/java/com/kizitonwose/calendar/sample/view/Example3Fragment.kt +++ b/sample/src/main/java/com/kizitonwose/calendar/sample/view/Example3Fragment.kt @@ -1,5 +1,6 @@ package com.kizitonwose.calendar.sample.view +import android.annotation.SuppressLint import android.os.Bundle import android.view.View import android.view.ViewGroup @@ -96,7 +97,7 @@ class Example3Fragment : BaseFragment(R.layout.example_3_fragment), HasBackButto } .setNegativeButton(R.string.close, null) .create() - .apply { + .apply @Suppress("DEPRECATION") { setOnShowListener { // Show the keyboard editText.requestFocus() @@ -189,6 +190,7 @@ class Example3Fragment : BaseFragment(R.layout.example_3_fragment), HasBackButto updateAdapterForDate(date) } + @SuppressLint("NotifyDataSetChanged") private fun updateAdapterForDate(date: LocalDate) { eventsAdapter.apply { events.clear() @@ -242,11 +244,13 @@ class Example3Fragment : BaseFragment(R.layout.example_3_fragment), HasBackButto textView.setBackgroundResource(R.drawable.example_3_today_bg) dotView.makeInVisible() } + selectedDate -> { textView.setTextColorRes(R.color.example_3_blue) textView.setBackgroundResource(R.drawable.example_3_selected_bg) dotView.makeInVisible() } + else -> { textView.setTextColorRes(R.color.example_3_black) textView.background = null diff --git a/settings.gradle b/settings.gradle deleted file mode 100644 index edb9d0b3..00000000 --- a/settings.gradle +++ /dev/null @@ -1 +0,0 @@ -include ':core', ':data', ':view', ':compose', ':sample' diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 00000000..eb300931 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,20 @@ +pluginManagement { + repositories { + google() + gradlePluginPortal() + mavenCentral() + } +} +@Suppress("UnstableApiUsage") +dependencyResolutionManagement { + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) + repositories { + google() + mavenCentral() + } +} +include(":core") +include(":data") +include(":view") +include(":compose") +include(":sample") diff --git a/view/build.gradle b/view/build.gradle deleted file mode 100644 index d4c8caad..00000000 --- a/view/build.gradle +++ /dev/null @@ -1,37 +0,0 @@ -import com.kizitonwose.calendar.buildsrc.Android -import com.kizitonwose.calendar.buildsrc.Config -import com.kizitonwose.calendar.buildsrc.Kotlin -import com.kizitonwose.calendar.buildsrc.Libs - -apply plugin: 'com.android.library' -apply plugin: 'kotlin-android' -apply plugin: 'com.vanniktech.maven.publish' - -android { - compileSdk Android.compileSdk - namespace 'com.kizitonwose.calendar.view' - defaultConfig { - minSdkVersion Android.minSdkLibraryView - targetSdkVersion Android.targetSdk - multiDexEnabled true // Needed for desugar because minSdk < 21 - } - compileOptions { - coreLibraryDesugaringEnabled true - sourceCompatibility = Config.compatibleJavaVersion - targetCompatibility = Config.compatibleJavaVersion - } - kotlinOptions { - jvmTarget = Config.compatibleJavaVersion - } -} - -dependencies { - api project(':core') - implementation project(':data') - coreLibraryDesugaring Libs.Core.deSugar - implementation Kotlin.stdLib - implementation Libs.View.coreKtx - - // Expose RecyclerView which is CalendarView's superclass. - api Libs.View.recyclerView -} diff --git a/view/build.gradle.kts b/view/build.gradle.kts new file mode 100644 index 00000000..67d51511 --- /dev/null +++ b/view/build.gradle.kts @@ -0,0 +1,40 @@ +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.view" + defaultConfig { + minSdk = Android.minSdkViewLibrary + } + java { + toolchain { + languageVersion.set(Config.compatibleJavaLanguageVersion) + } + } + kotlin { + jvmToolchain { + languageVersion.set(Config.compatibleJavaLanguageVersion) + } + } +} + +dependencies { + api(project(":core")) + implementation(project(":data")) + implementation(Kotlin.stdLib) + implementation(Libs.View.coreKtx) + + // Expose RecyclerView which is CalendarView"s superclass. + api(Libs.View.recyclerView) +}