Skip to content

Commit

Permalink
Refactor dependencies.
Browse files Browse the repository at this point in the history
  • Loading branch information
kizitonwose committed Jul 11, 2020
1 parent 6bb40d5 commit 69af16f
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 54 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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

Expand Down
31 changes: 5 additions & 26 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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
}
}

Expand Down
45 changes: 45 additions & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
@@ -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",
]
]
]
15 changes: 8 additions & 7 deletions library/build.gradle
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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 {
Expand All @@ -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:
Expand All @@ -47,8 +48,8 @@ dependencies {
// Not exposing RecyclerView also means that calling findViewById<CalendarView>
// 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
}

Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
30 changes: 15 additions & 15 deletions sample/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: rootProject.file("dependencies.gradle")

android {
compileSdkVersion versions.compile_sdk
Expand Down Expand Up @@ -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
}

0 comments on commit 69af16f

Please sign in to comment.