diff --git a/README.md b/README.md index 96d64581..3bf46400 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ View the sample app's source code [here](https://github.com/kizitonwose/Calendar #### Step 1 -The library uses `java.time` classes via [API desugaring](https://developer.android.com/studio/write/java8-support#library-desugaring) for backward compatibility since these classes were added in Java 8. +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. To setup 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. @@ -89,7 +89,7 @@ dependencies { } ``` -**You can find the latest version of `CalendarView` on the JitPack badge above the preview images.** +You can find the latest version of `CalendarView` on the JitPack badge above the preview images. ## Usage diff --git a/build.gradle b/build.gradle index 9e223540..bca2e771 100644 --- a/build.gradle +++ b/build.gradle @@ -1,36 +1,15 @@ buildscript { - ext.versions = [ - 'min_sdk_library' : 21, - 'min_sdk_sample' : 21, - 'target_sdk' : 28, - 'compile_sdk' : 28, - 'version_code' : 1, - 'version_name' : '0.3.1', - 'kotlin_lang' : '1.3.72', - 'desugar_jdk_libs' : '1.0.5', - 'material_library' : '1.2.0-beta01', - 'androidx_appcompat' : '1.2.0-rc01', - 'androidx_legacy' : '1.0.0', - 'androidx_core_ktx' : '1.3.0', - 'constraint_layout' : '2.0.0-beta6', - 'cardview' : '1.0.0', - 'recyclerview' : '1.2.0-alpha03', - 'junit' : '4.12', - 'espresso' : '3.2.0', - 'androidx_test_runner': '1.2.0', - 'androidx_test_rules' : '1.2.0', - 'androidx_test_junit' : '1.1.1' - ] + apply from: rootProject.file("dependencies.gradle") repositories { google() jcenter() gradlePluginPortal() } dependencies { - classpath 'com.android.tools.build:gradle:4.0.0' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$versions.kotlin_lang" - classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' - classpath 'org.jlleitschuh.gradle:ktlint-gradle:9.2.1' + classpath deps.gradle_plugins.android + classpath deps.gradle_plugins.kotlin + classpath deps.gradle_plugins.maven_release + classpath deps.gradle_plugins.ktlint } } diff --git a/dependencies.gradle b/dependencies.gradle new file mode 100644 index 00000000..4ffc8010 --- /dev/null +++ b/dependencies.gradle @@ -0,0 +1,45 @@ +ext.versions = [ + min_sdk_library: 15, + min_sdk_sample: 21, + target_sdk: 29, + compile_sdk: 29, + version_code: 1, + version_name: "0.4.0" +] + +def espresso_version = "3.2.0" + +ext.deps = [ + gradle_plugins: [ + android: "com.android.tools.build:gradle:4.0.0", + kotlin: "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.72", + maven_release: "com.github.dcendents:android-maven-gradle-plugin:2.1", + ktlint: "org.jlleitschuh.gradle:ktlint-gradle:9.2.1" + ], + + androidx: [ + legacy: "androidx.legacy:legacy-support-v4:1.0.0", + appcompat: "androidx.appcompat:appcompat:1.2.0-rc01", + core_ktx: "androidx.core:core-ktx:1.3.0", + constraint_layout: "androidx.constraintlayout:constraintlayout:2.0.0-beta8", + cardview: "androidx.cardview:cardview:1.0.0", + recyclerview: "androidx.recyclerview:recyclerview:1.2.0-alpha04" + ], + + material_library: "com.google.android.material:material:1.2.0-beta01", + + desugaring: "com.android.tools:desugar_jdk_libs:1.0.5", + + kotlin_stdlib8: "org.jetbrains.kotlin:kotlin-stdlib-jdk8", + + test: [ + junit: "junit:junit:4.12", + android: [ + espresso_core: "androidx.test.espresso:espresso-core:$espresso_version", + espresso_contrib: "androidx.test.espresso:espresso-contrib:$espresso_version", + runner: "androidx.test:runner:1.2.0", + rules: "androidx.test:rules:1.2.0", + ext_junit: "androidx.test.ext:junit:1.1.1", + ] + ] +] diff --git a/library/build.gradle b/library/build.gradle index d1518d20..f2b856b3 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: 'com.github.dcendents.android-maven' +apply from: rootProject.file("dependencies.gradle") group='com.github.kizitonwose' def artifact = 'CalendarView' @@ -12,7 +13,8 @@ android { targetSdkVersion versions.target_sdk versionCode versions.version_code versionName versions.version_name - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + multiDexEnabled true // Because library's minSdk < 21 } buildTypes { release { @@ -32,10 +34,9 @@ android { } dependencies { - implementation fileTree(dir: 'libs', include: ['*.jar']) - coreLibraryDesugaring "com.android.tools:desugar_jdk_libs:$versions.desugar_jdk_libs" - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$versions.kotlin_lang" - implementation "androidx.core:core-ktx:$versions.androidx_core_ktx" + coreLibraryDesugaring deps.desugaring + implementation deps.kotlin_stdlib8 + implementation deps.androidx.core_ktx // Expose RecyclerView which is CalendarView's superclass to // prevent a compile error when using the library in a project: @@ -47,8 +48,8 @@ dependencies { // Not exposing RecyclerView also means that calling findViewById // results in an error: Type argument is not within its bounds, Expected: View. // This is because CalendarView's superclass type cannot be determined. - api "androidx.recyclerview:recyclerview:$versions.recyclerview" + api deps.androidx.recyclerview - testImplementation "junit:junit:$versions.junit" + testImplementation deps.test.junit } diff --git a/library/src/main/java/com/kizitonwose/calendarview/ui/CalendarAdapter.kt b/library/src/main/java/com/kizitonwose/calendarview/ui/CalendarAdapter.kt index 5efb41f7..ffb77f61 100644 --- a/library/src/main/java/com/kizitonwose/calendarview/ui/CalendarAdapter.kt +++ b/library/src/main/java/com/kizitonwose/calendarview/ui/CalendarAdapter.kt @@ -118,14 +118,15 @@ internal class CalendarAdapter( } } - val userRoot = if (viewConfig.monthViewClass != null) { - (Class.forName(viewConfig.monthViewClass) + val userRoot = viewConfig.monthViewClass?.let { + val customLayout = (Class.forName(it) .getDeclaredConstructor(Context::class.java) - .newInstance(context) as ViewGroup).apply { + .newInstance(context) as ViewGroup) + customLayout.apply { setupRoot(this) addView(rootLayout) } - } else rootLayout.apply { setupRoot(this) } + } ?: rootLayout.apply { setupRoot(this) } @Suppress("UNCHECKED_CAST") return MonthViewHolder( diff --git a/sample/build.gradle b/sample/build.gradle index e0d894eb..988e6f13 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -1,5 +1,6 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' +apply from: rootProject.file("dependencies.gradle") android { compileSdkVersion versions.compile_sdk @@ -31,22 +32,21 @@ android { } dependencies { - implementation fileTree(dir: 'libs', include: ['*.jar']) implementation project(':library') - coreLibraryDesugaring "com.android.tools:desugar_jdk_libs:$versions.desugar_jdk_libs" - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$versions.kotlin_lang" - implementation "androidx.legacy:legacy-support-v4:$versions.androidx_legacy" - implementation "androidx.appcompat:appcompat:$versions.androidx_appcompat" - implementation "androidx.core:core-ktx:$versions.androidx_core_ktx" - implementation "androidx.constraintlayout:constraintlayout:$versions.constraint_layout" - implementation "androidx.cardview:cardview:$versions.cardview" - implementation "com.google.android.material:material:$versions.material_library" + coreLibraryDesugaring deps.desugaring + implementation deps.kotlin_stdlib8 + implementation deps.androidx.legacy + implementation deps.androidx.appcompat + implementation deps.androidx.core_ktx + implementation deps.androidx.constraint_layout + implementation deps.androidx.cardview + implementation deps.material_library - testImplementation "junit:junit:$versions.junit" + testImplementation deps.test.junit - androidTestImplementation "androidx.test.espresso:espresso-core:$versions.espresso" - androidTestImplementation "androidx.test.espresso:espresso-contrib:$versions.espresso" // RecyclerView actions. - androidTestImplementation "androidx.test:runner:$versions.androidx_test_runner" - androidTestImplementation "androidx.test:rules:$versions.androidx_test_rules" - androidTestImplementation "androidx.test.ext:junit:$versions.androidx_test_junit" + androidTestImplementation deps.test.android.espresso_core + androidTestImplementation deps.test.android.espresso_contrib // RecyclerView actions. + androidTestImplementation deps.test.android.runner + androidTestImplementation deps.test.android.rules + androidTestImplementation deps.test.android.ext_junit }