Skip to content

Commit

Permalink
Deprecated delegated property
Browse files Browse the repository at this point in the history
  • Loading branch information
wada811 committed Jun 26, 2022
1 parent bdcc93c commit e34f76b
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 54 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ViewBinding-ktx
## Overview

- `ViewBinding-ktx` provides `withBinding` method accessing the `binding` variable by lambda.
- `ViewBinding-ktx` provides `viewBinding` method accessing the `binding` variable by delegated property.
- [Deprecated] `ViewBinding-ktx` provides `viewBinding` method accessing the `binding` variable by delegated property.

## Usage

Expand All @@ -25,7 +25,7 @@ withBinding<ViewBindingActivityBinding> { binding ->
}
```

### Delegated Property
### [Deprecated] Delegated Property

```kotlin
private val binding by viewBinding(ViewBindingActivityBinding::bind) // no reflection
Expand Down
19 changes: 11 additions & 8 deletions ViewBinding-ktx/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'maven-publish'
plugins {
id 'com.android.library'
id 'com.diffplug.spotless'
id 'org.jetbrains.kotlin.android'
id 'org.jetbrains.kotlin.kapt'
id 'maven-publish'
}

android {
compileSdkVersion 31
compileSdkVersion 32
defaultConfig {
minSdkVersion 16
targetSdkVersion 31
targetSdkVersion 32
}
buildFeatures {
viewBinding true
Expand All @@ -21,7 +25,7 @@ android {
}

dependencies {
compileOnly "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.0"
//noinspection GradleDependency
implementation 'androidx.fragment:fragment-ktx:1.1.0'
}
Expand All @@ -33,9 +37,8 @@ afterEvaluate {
from components.release
groupId = "com.github.wada811"
artifactId = "ViewBinding-ktx"
version = "2.1.0"
version = "2.2.0"
}
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import android.view.ViewGroup
import androidx.fragment.app.FragmentActivity
import androidx.viewbinding.ViewBinding

@Deprecated("Use withBinding", level = DeprecationLevel.WARNING)
inline fun <reified T : ViewBinding> FragmentActivity.viewBinding(): Lazy<T> {
return viewBinding {
T::class.java.getMethod("bind", View::class.java).invoke(null, it) as T
}
}

@Deprecated("Use withBinding", level = DeprecationLevel.WARNING)
fun <T : ViewBinding> FragmentActivity.viewBinding(bind: (View) -> T): Lazy<T> {
return lazy(LazyThreadSafetyMode.NONE) {
val getContentView: FragmentActivity.() -> View = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import androidx.viewbinding.ViewBinding
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty

@Deprecated("Use withBinding", level = DeprecationLevel.WARNING)
inline fun <reified T : ViewBinding> Fragment.viewBinding(): ReadOnlyProperty<Fragment, T> {
return viewBinding {
T::class.java.getMethod("bind", View::class.java).invoke(null, it) as T
}
}

@Deprecated("Use withBinding", level = DeprecationLevel.WARNING)
fun <T : ViewBinding> Fragment.viewBinding(bind: (View) -> T): ReadOnlyProperty<Fragment, T> {
return object : ReadOnlyProperty<Fragment, T> {
@Suppress("UNCHECKED_CAST")
Expand Down
26 changes: 5 additions & 21 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
buildscript {
ext.kotlin_version = '1.5.31'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

allprojects {
repositories {
google()
mavenCentral()
}
}

task clean(type: Delete) {
delete rootProject.buildDir
plugins {
id 'com.android.application' version '7.2.1' apply false
id 'com.android.library' version '7.2.1' apply false
id "com.diffplug.spotless" version "6.7.2" apply false
id 'org.jetbrains.kotlin.android' version '1.7.0' apply false
}
3 changes: 0 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ org.gradle.caching=true
org.gradle.configureondemand=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official
# Kapt improvements
# https://blog.jetbrains.com/kotlin/2018/08/kotlin-1-2-60-is-out/
kapt.use.worker.api=true
# Compile avoidance for kapt
kapt.include.compile.classpath=false
# Incremental annotation processing in KAPT
Expand Down
6 changes: 3 additions & 3 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Oct 26 09:43:16 JST 2020
#Sun Jun 26 23:10:53 JST 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip
zipStoreBase=GRADLE_USER_HOME
21 changes: 21 additions & 0 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"extends": [
"config:base"
],
"dependencyDashboard": true,
"packageRules": [
{
"groupName": "Android Gradle Plugin",
"matchPackagePatterns": [
"com\\.android\\.application",
"com\\.android\\.library"
]
},
{
"groupName": "Kotlin",
"matchPackagePatterns": [
"^org\\.jetbrains\\.kotlin"
]
}
]
}
27 changes: 10 additions & 17 deletions sample/build.gradle
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'org.jetbrains.kotlin.kapt'
}

android {
compileSdkVersion 31
compileSdkVersion 32
defaultConfig {
applicationId "com.wada811.viewbindingktx"
minSdkVersion 16
targetSdkVersion 31
targetSdkVersion 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArgument "listener", "leakcanary.FailTestOnLeakRunListener"
}
buildTypes {
debug {
debuggable true
minifyEnabled true
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
release {
Expand All @@ -27,18 +28,10 @@ android {
buildFeatures {
viewBinding true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_11.toString()
}
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.fragment:fragment-ktx:1.3.6'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.0"
implementation 'androidx.appcompat:appcompat:1.4.2'
implementation project(':ViewBinding-ktx')
}
15 changes: 15 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
}
}
rootProject.name = "ViewBinding-ktx"
include ':ViewBinding-ktx'
include ':sample'

0 comments on commit e34f76b

Please sign in to comment.