Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: androidbroadcast/ViewBindingPropertyDelegate
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.4.0
Choose a base ref
...
head repository: androidbroadcast/ViewBindingPropertyDelegate
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Loading
Showing with 2,326 additions and 682 deletions.
  1. +5 −0 .github/FUNDING.yml
  2. +40 −0 .github/workflows/android.yml
  3. +48 −0 .github/workflows/build.yml
  4. +166 −0 CHANGELOG.md
  5. +2 −2 LICENSE.md
  6. +51 −34 README.md
  7. +0 −38 app/build.gradle
  8. +0 −12 app/src/main/AndroidManifest.xml
  9. +0 −16 app/src/main/java/by/kirich1409/viewbindingdelegate/sample/ProfileActivity.kt
  10. +0 −25 app/src/main/java/by/kirich1409/viewbindingdelegate/sample/ProfileDialogFragment1.kt
  11. +0 −28 app/src/main/java/by/kirich1409/viewbindingdelegate/sample/ProfileDialogFragment2.kt
  12. +0 −16 app/src/main/java/by/kirich1409/viewbindingdelegate/sample/ProfileFragment.kt
  13. +0 −27 app/src/main/res/layout/profile.xml
  14. +0 −3 app/src/main/res/values/strings.xml
  15. +0 −26 build.gradle
  16. +7 −0 build.gradle.kts
  17. +10 −2 gradle.properties
  18. +1 −0 gradle/convetions-plugins/.gitignore
  19. 0 gradle/convetions-plugins/build.gradle.kts
  20. +37 −0 gradle/convetions-plugins/settings.gradle.kts
  21. 0 {app → gradle/convetions-plugins/vbpd-library-base}/.gitignore
  22. +21 −0 gradle/convetions-plugins/vbpd-library-base/build.gradle.kts
  23. +40 −0 ...ions-plugins/vbpd-library-base/src/main/kotlin/dev/androidbroadcast/vbpd/gradle/BaseExtensions.kt
  24. +51 −0 gradle/convetions-plugins/vbpd-library-base/src/main/kotlin/vbpdconfig.gradle.kts
  25. +89 −0 gradle/convetions-plugins/vbpd-library-base/src/main/kotlin/vbpdpublish.gradle.kts
  26. +36 −0 gradle/libs.versions.toml
  27. BIN gradle/wrapper/gradle-wrapper.jar
  28. +3 −1 gradle/wrapper/gradle-wrapper.properties
  29. +175 −109 gradlew
  30. +23 −33 gradlew.bat
  31. +2 −0 jitpack.yml
  32. +0 −35 library/build.gradle
  33. +0 −3 library/proguard-rules.pro
  34. +0 −2 library/src/main/AndroidManifest.xml
  35. +0 −143 library/src/main/java/by/kirich1409/viewbindingdelegate/ViewBindingProperty.kt
  36. +0 −13 library/src/main/java/by/kirich1409/viewbindingdelegate/internal/ActivityUtils.kt
  37. +0 −30 library/src/main/java/by/kirich1409/viewbindingdelegate/internal/ActivityViewBinder.kt
  38. +0 −40 library/src/main/java/by/kirich1409/viewbindingdelegate/internal/DialogFragmentViewBinder.kt
  39. +0 −26 library/src/main/java/by/kirich1409/viewbindingdelegate/internal/FragmentViewBinder.kt
  40. +0 −11 library/src/main/java/by/kirich1409/viewbindingdelegate/internal/Utils.kt
  41. 0 {library → sample}/.gitignore
  42. +44 −0 sample/build.gradle.kts
  43. +2 −2 {app → sample}/proguard-rules.pro
  44. +26 −0 sample/src/main/AndroidManifest.xml
  45. +27 −0 sample/src/main/kotlin/dev/androidbroadcast/vbpd/sample/Fragments.kt
  46. +51 −0 sample/src/main/kotlin/dev/androidbroadcast/vbpd/sample/MainAcitivty.kt
  47. +34 −0 sample/src/main/kotlin/dev/androidbroadcast/vbpd/sample/Person.kt
  48. +44 −0 sample/src/main/kotlin/dev/androidbroadcast/vbpd/sample/PersonFragment.kt
  49. +95 −0 sample/src/main/kotlin/dev/androidbroadcast/vbpd/sample/PersonListFragment.kt
  50. 0 {app → sample}/src/main/res/drawable-v24/ic_launcher_foreground.xml
  51. 0 {app → sample}/src/main/res/drawable/ic_launcher_background.xml
  52. +25 −0 sample/src/main/res/layout/activity_main.xml
  53. +32 −0 sample/src/main/res/layout/fragment_person_detail.xml
  54. +13 −0 sample/src/main/res/layout/fragment_person_list.xml
  55. +16 −0 sample/src/main/res/layout/item_person.xml
  56. 0 {app → sample}/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
  57. 0 {app → sample}/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
  58. BIN {app → sample}/src/main/res/mipmap-hdpi/ic_launcher.png
  59. BIN {app → sample}/src/main/res/mipmap-hdpi/ic_launcher_round.png
  60. BIN {app → sample}/src/main/res/mipmap-mdpi/ic_launcher.png
  61. BIN {app → sample}/src/main/res/mipmap-mdpi/ic_launcher_round.png
  62. BIN {app → sample}/src/main/res/mipmap-xhdpi/ic_launcher.png
  63. BIN {app → sample}/src/main/res/mipmap-xhdpi/ic_launcher_round.png
  64. BIN {app → sample}/src/main/res/mipmap-xxhdpi/ic_launcher.png
  65. BIN {app → sample}/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
  66. BIN {app → sample}/src/main/res/mipmap-xxxhdpi/ic_launcher.png
  67. BIN {app → sample}/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
  68. 0 {app → sample}/src/main/res/values/colors.xml
  69. +4 −0 sample/src/main/res/values/strings.xml
  70. +2 −2 {app → sample}/src/main/res/values/styles.xml
  71. +0 −3 settings.gradle
  72. +39 −0 settings.gradle.kts
  73. +1 −0 vbpd-core/.gitignore
  74. +8 −0 vbpd-core/build.gradle.kts
  75. +57 −0 vbpd-core/src/main/kotlin/dev/androidbroadcast/vbpd/ViewBindingProperty.kt
  76. +1 −0 vbpd-reflection/.gitignore
  77. +21 −0 vbpd-reflection/build.gradle.kts
  78. +4 −0 vbpd-reflection/proguard-rules.pro
  79. +87 −0 vbpd-reflection/src/main/kotlin/dev/androidbroadcast/vbpd/ActivityViewBindings.kt
  80. +18 −0 vbpd-reflection/src/main/kotlin/dev/androidbroadcast/vbpd/CreateMethod.kt
  81. +103 −0 vbpd-reflection/src/main/kotlin/dev/androidbroadcast/vbpd/FragmentViewBindings.kt
  82. +185 −0 vbpd-reflection/src/main/kotlin/dev/androidbroadcast/vbpd/ViewBindingCache.kt
  83. +30 −0 vbpd-reflection/src/main/kotlin/dev/androidbroadcast/vbpd/ViewBindingPropertyDelegate.kt
  84. +77 −0 vbpd-reflection/src/main/kotlin/dev/androidbroadcast/vbpd/ViewGroupBindings.kt
  85. +32 −0 vbpd-reflection/src/main/kotlin/dev/androidbroadcast/vbpd/ViewHolderBindings.kt
  86. +1 −0 vbpd/.gitignore
  87. +12 −0 vbpd/build.gradle.kts
  88. +126 −0 vbpd/src/main/kotlin/dev/androidbroadcast/vbpd/ActivityViewBindings.kt
  89. +131 −0 vbpd/src/main/kotlin/dev/androidbroadcast/vbpd/FragmentViewBindings.kt
  90. +49 −0 vbpd/src/main/kotlin/dev/androidbroadcast/vbpd/ViewGroupBindings.kt
  91. +51 −0 vbpd/src/main/kotlin/dev/androidbroadcast/vbpd/ViewHolderBindings.kt
  92. +71 −0 vbpd/src/main/kotlin/dev/androidbroadcast/vbpd/internal/VbpdUtils.kt
5 changes: 5 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# These are supported funding model platforms

github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: android_broadcast
custom: https://www.donationalerts.com/r/androidbroadcast
40 changes: 40 additions & 0 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Android quality checks

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
check:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: set up JDK
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
cache: gradle

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Check build
run: ./gradlew check
continue-on-error: true

- name: Save Gradle cache
uses: actions/cache@v4
continue-on-error: true
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
48 changes: 48 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Build libs

on:
push:
branches: [ "develop" ]
workflow_dispatch:

jobs:
check:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: set up JDK
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
cache: gradle

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Check build
run: ./gradlew :vbpd-core:assembleRelease :vbpd:assembleRelease :vbpd-reflection:assembleRelease --no-configuration-cache --no-build-cache
continue-on-error: true

- name: Save Gradle cache
uses: actions/cache@v4
continue-on-error: true
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Save build artifacts
uses: actions/upload-artifact@v4
with:
name: vbpd-libs-builds
path:
vbpd/build/outputs/aar/vbpd-release.aar
vbpd-core/build/outputs/aar/vbpd-core-release.aar
vbpd-reflection/build/outputs/aar/vbpd-reflection-release.aar

166 changes: 166 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
## 2.0.4
- Fix memory leaks when using VBPD in Activities [#127](https://github.com/androidbroadcast/ViewBindingPropertyDelegate/issues/127)

## 2.0.2
- Removing checking access from the Main thread to correct work with [AsyncLayoutInflater](https://developer.android.com/jetpack/androidx/releases/asynclayoutinflater)

## 2.0.1
- VBPD-reflection: revert new generic param in 2.0.0 for Activity ViewBindings

## 2.0.0

- Changed under hood tracking of View lifecycle in ViewBindingPropertyDelegate
- Removed ViewBindingPropertyDelegate base on Lifecycle
- Removed Jetpack Lifecycle dependencies
- Remove Strict Modes checks
- Up Min sdk to API Level 21 Android 5.0 Lollipop
- Remove internal checking of possibility to access host's view
- Change artifact from `com.github.kirich1409:viewbindingpropertydelegate-*` to `dev.androidbroadcast.vbpd:vbpd-*`
- Change classes base package from `com.github.kirich1409.viewbindingpropertydelegate` to `dev.androidbroadcast.vbpd`. It allows to use 1.X and 2.X versions together
- Remove onViewDestroyCallback\(\) from ViewBindingPropertyDelegate
- Update Jetpack dependencies. All of them connected as compileOnly dependencies that's why you can use any version of them in project, but with required APIs
- All libraries artifacts distributes as AAR instead of JAR
- Fix bugs working during inter-Fragment's animations
- Upgrade JVM target from 8 to 11
- Minor improvements

### Changed under hood tracking of Fragment View lifecycle
- Fragment: Replace Jetpack Lifecycle with FragmentManager.FragmentLifecycleCallbacks
- Activity: Remove cleaning view after Activity.onDestroy()
- ViewGroup: Will be kept during View instance life
- RecyclerView.ViewHolder: Will be kept during ViewHolder instance life

## 1.5.10
- Bugs fixes

## 1.5.9
- Fix build-in ProGuard and R8 configuration for obfuscation

## 1.5.8
February 5, 2023

- Fix bugs
- All artifacts now will distributed as JAR instead of AAR
- Update Jetpack Dependencies
- Update Kotlin to 1.8.10
- Update AGP to 7.4.1

### Artifacts Renaming
viewbindingpropertydelegate-core - base API for ViewBindingPropertyDelegate
viewbindingpropertydelegate-noreflection - API to work with ViewBindingPropertyDelegate without reflection calls
viewbindingpropertydelegate -> viewbindingpropertydelegate-full - All possible ways to create ViewBindingPropertyDelegate

## 1.5.4
December 23, 2021

- Bug fixes
- Improve error messages

## 1.5.3
November 19, 2021

- Fix clearing of a Fragment when it is destroyed

## 1.5.2
November 13, 2021

### New feature "Strict mode"
New library mode to check correctness of ViewBinding usage. Enabled by default.
Call ViewBindingPropertyDelegate.strictMode = false to switch to old behavior

### Added a callback called when a ViewBinding inside ViewBindingProperty is destroyed
Callback is triggered when a ViewBinding in ViewBindingPropertyDelegate is destroyed
Instead of overriding Fragment.onDestroyView(), use

```kotlin
viewBinding(
...,
onViewDestroyed = { vb: ViewBinding ->
// reset views inside the ViewBinding
}
)
```

### ViewBindingProperty will throw an error if it is created before the host is ready
ViewBindingPropertyDelegate throws an exception if it is used before the host
(Fragment, Activity, etc.) is ready to create a ViewBinding. As an example, accessing
ViewBindingPropertyDelegate in a Fragment, before onViewCreated() has been called, will now throw
an Exception.

### Other
- Fix memory leaks
- Fix bugs

## 1.4.7

- Bugs fixing

## 1.4.6

- Bugs fixing

## 1.4.5

- Update built-in ProGuard rules

## 1.4.4

- Improve checking of a `Fragment`'s `ViewLifecycleOwner`

## 1.4.3

- Update ProGuard rules

## 1.4.2

- Migrate to Maven Central. This is the last release available via JCenter
- Artifacts group and id parameters were changed
- Support of [ViewTreeLifecycleOwner](https://d.android.com/reference/androidx/lifecycle/ViewTreeLifecycleOwner) for `ViewGroup` bindings
- `LifecycleViewBindingProperty` lifecycle management improvements
- Improvements in viewBinding implementation for `DialogFragment`
- Bugfixes

## 1.4.0

- Added support of `RecyclerView.ViewHolder`
- Added support of `ViewGroup`
- Added an option to use the `viewBinding` delegate without specifying rootView.
- Improved speed of `viewBinding` usage with reflection
- More ways of creating `ViewBinding` using `ViewBinding.inflate` instead of `ViewBinding.bind`
- *Breaking changes* `viewBinding()` in Activities uses `ViewBinding.bind` instead of `ViewBinding.inflate`. Use `viewBinding(CreateMethod.INFLATE)` to switch to old behavior
- Split implementation of lazy `viewBinding` delegate and implementation with lifecycle
- Minor improvements and bugfixes

## 1.3.1

- Bug fixes

## 1.3.0

- Added support of creating `ViewBinding` using `ViewBinding.inflate(LayoutInflater)`
- Added an option to create `ViewBindingProperty` using a `Class<ViewBinding>` instance
- Upgrade view binding library to 4.1.0
- Improved performance: removed the check working on the main thread within `ViewBindingProperty`
- Update the sample

## 1.2.2

- Bug fixing

## 1.2.1:

- Fix bugs

## 1.2.0:

- Add an artifact `vbpd-noreflection` without reflection when creating a `ViewBindingProperty`
- Fix a bug in Fragment

## 1.1.0:

- Simplify API

## 1.0.0:

- Add Android 4.0+ support
- Support Android View Binding inside `Fragment`, `ComponentActivity` and `DialogFragment`
4 changes: 2 additions & 2 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2020 Kirill Rozov
Copyright 2020-2025 Kirill Rozov

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -198,4 +198,4 @@
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
85 changes: 51 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,61 +1,78 @@
# ViewBindingPropertyDelegate
[![](https://jitpack.io/v/kirich1409/ViewBindingPropertyDelegate.svg)](https://jitpack.io/#kirich1409/ViewBindingPropertyDelegate)

Make work with [Android View Binding](https://developer.android.com/topic/libraries/view-binding) simpler
Make work with [Android View Binding](https://d.android.com/topic/libraries/view-binding) simpler. The library:
- manages ViewBinding lifecycle and clears the reference to it to prevent memory leaks
- eliminates the need to keep nullable references to Views or ViewBindings
- creates ViewBinding lazily

## Add library to a project
The library comes in two variants: with and without reflection. The artifacts are respectively: `vbpd` and `vbpd-reflection`. **Prefer to use the one without reflection for better performance**

```groovy
## IMPORTANT: Enable ViewBinding before using the library
Each Gradle module in your project where you need to use ViewBinding must be properly configured. Refer to the [official guide](https://d.android.com/topic/libraries/view-binding) on how to do that

## Add the library to a project

```kotlin
allprojects {
repositories {
maven { url 'https://jitpack.io' }
mavenCentral()
}
}

dependencies {
implementation 'com.github.kirich1409:ViewBindingPropertyDelegate:0.4.1'
// recommended
implementation("dev.androidbroadcast.vbpd:vbpd:2.0.4")

// additional factories that use reflection under hood
implementation("dev.androidbroadcast.vbpd:vbpd-reflection:2.0.4")
}
```

## Samples

```kotlin
class ProfileFragment : Fragment(R.layout.profile) {
import javax.swing.text.View

private val viewBinding: ProfileBinding by viewBinding()
class ProfileFragment : Fragment(R.layout.profile) {
// RECOMMENDED
// no reflection API is used under the hood
private val profileBinding: ProfileBinding by viewBinding(ProfileBinding::bind)

override fun onViewCreated(view: View) {
super.onViewCreate(view)
with(profileBinding) {
firstName.text = person.name
lastName.text = person.surname
email.text = person.email
}
}

override fun onViewDestroyed() {
super.onViewDestroyed()
// profileBinding will be cleared after onViewDestroyed()
}
}
```

```kotlin
class ProfileActivity : AppCompatActivity(R.layout.profile) {
## Migration from 1.0

private val viewBinding: ProfileBinding by viewBinding(R.id.container)
}
```
You can use 1.X and 2.X in the same project without replacing code

```kotlin
class ProfileDialogFragment : DialogFragment() {
- Replace packages `com.github.kirich1409.viewbindingpropertydelegate` -> `dev.androidbroadcast.vbpd`
- Replace `onViewDestroyed` with moving code to proper lifecycle callback (Fragment.onViewDestroyed(), Activity.onDestroy(), etc.)

private val viewBinding: ProfileBinding by dialogViewBinding(R.id.container)
# License

// Creating via default way will work too for that case
// private val viewBinding: ProfileBinding by viewBinding()
Copyright 2020-2025 Kirill Rozov

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
return AlertDialog.Builder(requireContext())
.setView(R.layout.profile)
.create()
}
}
```
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

```kotlin
class ProfileDialogFragment : DialogFragment() {
http://www.apache.org/licenses/LICENSE-2.0

private val viewBinding: ProfileBinding by dialogViewBinding(R.id.container)

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.profile, container, false)
}
}
```
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Loading