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 22, 2022
1 parent 46dc3cb commit 7d82421
Show file tree
Hide file tree
Showing 15 changed files with 111 additions and 63 deletions.
20 changes: 12 additions & 8 deletions DataBinding-ktx/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
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
namespace "com.wada811.databinding"
compileSdkVersion 32
defaultConfig {
minSdkVersion 16
targetSdkVersion 31
targetSdkVersion 32
}
buildFeatures {
dataBinding true
Expand All @@ -22,7 +26,7 @@ android {
}

dependencies {
implementation "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 @@ -34,7 +38,7 @@ afterEvaluate {
from components.release
groupId = "com.github.wada811"
artifactId = "DataBinding-ktx"
version = "6.0.0"
version = "7.0.0"
}
}
}
Expand Down
1 change: 0 additions & 1 deletion DataBinding-ktx/src/main/AndroidManifest.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.fragment.app.FragmentActivity

@Deprecated("Use withBinding", level = DeprecationLevel.WARNING)
fun <T : ViewDataBinding> FragmentActivity.dataBinding(): Lazy<T> = lazy(LazyThreadSafetyMode.NONE) {
bind<T>(getContentView()).also {
it.lifecycleOwner = this@dataBinding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.fragment.app.Fragment
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty

@Deprecated("Use withBinding", level = DeprecationLevel.WARNING)
fun <T : ViewDataBinding> Fragment.dataBinding(): ReadOnlyProperty<Fragment, T> {
return object : ReadOnlyProperty<Fragment, T> {
@Suppress("UNCHECKED_CAST")
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ DataBinding-ktx

- `DataBinding-ktx` is automatically calling `setLifecycleOwner`.
- `DataBinding-ktx` provides `withBinding` method accessing the `binding` variable by lambda.
- `DataBinding-ktx` provides `dataBinding` method accessing the `binding` variable by delegated property.
- [Deprecated] `DataBinding-ktx` provides `dataBinding` method accessing the `binding` variable by delegated property.

## Usage

Expand All @@ -21,7 +21,7 @@ withBinding<DataBindingActivityBinding> { binding ->
}
```

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

```kotlin
private val binding: DataBindingActivityBinding by dataBinding()
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
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sat Feb 27 23:00:16 JST 2021
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
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"
]
}
]
}
34 changes: 9 additions & 25 deletions sample/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
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.databindingktx"
minSdkVersion 16
targetSdkVersion 31
targetSdkVersion 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand All @@ -29,25 +31,7 @@ android {
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.0"
implementation 'androidx.appcompat:appcompat:1.4.2'
implementation project(':DataBinding-ktx')


// Core library
androidTestImplementation 'androidx.test:core:1.4.0'
// AndroidJUnitRunner and JUnit Rules
androidTestImplementation 'androidx.test:runner:1.4.0'
androidTestImplementation 'androidx.test:rules:1.4.0'
// Assertions
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.ext:truth:1.4.0'
androidTestImplementation 'com.google.truth:truth:1.1.3'
// Espresso dependencies
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.4.0'
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.4.0'
androidTestImplementation 'androidx.test.espresso:espresso-accessibility:3.4.0'
androidTestImplementation 'androidx.test.espresso:espresso-web:3.4.0'
androidTestImplementation 'androidx.test.espresso.idling:idling-concurrent:3.4.0'
}
6 changes: 4 additions & 2 deletions sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
package="com.wada811.databindingktx">

<application
android:allowBackup="false"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="true"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
tools:ignore="GoogleAppIndexingWarning,MissingApplicationIcon,UnusedAttribute">

<activity
android:name=".DataBindingActivity"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.wada811.databindingktx

import android.annotation.SuppressLint
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.wada811.databinding.withBinding
import com.wada811.databindingktx.databinding.DataBindingActivityBinding

class DataBindingActivity : AppCompatActivity(R.layout.data_binding_activity) {
@SuppressLint("SetTextI18n")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
withBinding<DataBindingActivityBinding> { binding ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.wada811.databindingktx

import android.annotation.SuppressLint
import android.os.Bundle
import android.view.View
import androidx.fragment.app.Fragment
import com.wada811.databinding.withBinding
import com.wada811.databindingktx.databinding.DataBindingFragmentBinding

class DataBindingFragment : Fragment(R.layout.data_binding_fragment) {
@SuppressLint("SetTextI18n")
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
withBinding<DataBindingFragmentBinding> { binding ->
Expand Down
36 changes: 36 additions & 0 deletions sample/src/main/res/xml/data_extraction_rules.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Sample data extraction rules file; uncomment and customize as necessary.
See https://developer.android.com/about/versions/12/backup-restore#xml-changes
for details.
-->
<data-extraction-rules>
<cloud-backup>
<!--
TODO: Use <include> and <exclude> to control what is backed up.
The domain can be file, database, sharedpref, external or root.
Examples:
<include domain="file" path="file_to_include"/>
<exclude domain="file" path="file_to_exclude"/>
<include domain="file" path="include_folder"/>
<exclude domain="file" path="include_folder/file_to_exclude"/>
<exclude domain="file" path="exclude_folder"/>
<include domain="file" path="exclude_folder/file_to_include"/>
<include domain="sharedpref" path="include_shared_pref1.xml"/>
<include domain="database" path="db_name/file_to_include"/>
<exclude domain="database" path="db_name/include_folder/file_to_exclude"/>
<include domain="external" path="file_to_include"/>
<exclude domain="external" path="file_to_exclude"/>
<include domain="root" path="file_to_include"/>
<exclude domain="root" path="file_to_exclude"/>
-->
</cloud-backup>
<!--
<device-transfer>
<include .../>
<exclude .../>
</device-transfer>
-->
</data-extraction-rules>
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 = "DataBinding-ktx"
include ':DataBinding-ktx'
include ':sample'

0 comments on commit 7d82421

Please sign in to comment.