Skip to content

Commit

Permalink
ViewBinding update
Browse files Browse the repository at this point in the history
  • Loading branch information
dkrivoruchko committed Mar 8, 2021
1 parent 57d99c6 commit 5c689bd
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ android {
applicationId = "info.dvkr.screenstream"
minSdkVersion(21)
targetSdkVersion(30)
versionCode = 30503
versionName = "3.5.3"
versionCode = 30504
versionName = "3.5.4"
resConfigs("en", "ru", "pt-rBR", "zh-rTW", "fr-rFR", "fa", "it", "pl", "hi", "de", "sk", "es", "ar", "ja", "gl", "ca")

vectorDrawables.useSupportLibrary = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,19 @@ abstract class ViewBindingProperty<in R, T : ViewBinding>(
) : ReadOnlyProperty<R, T> {

internal var viewBinding: T? = null
private val lifecycleObserver = BindingLifecycleObserver()
private val lifecycleObserver = ClearOnDestroyLifecycleObserver()

protected abstract fun getLifecycleOwner(thisRef: R): LifecycleOwner

@MainThread
override fun getValue(thisRef: R, property: KProperty<*>): T {
check(Looper.myLooper() == Looper.getMainLooper())
viewBinding?.let { return it }

getLifecycleOwner(thisRef).lifecycle.addObserver(lifecycleObserver)
return viewBinder(thisRef).also { viewBinding = it }
}

private inner class BindingLifecycleObserver : DefaultLifecycleObserver {
private inner class ClearOnDestroyLifecycleObserver : DefaultLifecycleObserver {
@MainThread
override fun onDestroy(owner: LifecycleOwner) {
owner.lifecycle.removeObserver(this)
Expand Down Expand Up @@ -60,7 +59,7 @@ internal class DialogFragmentViewBindingProperty<F : DialogFragment, T : ViewBin
) : ViewBindingProperty<F, T>(viewBinder) {

override fun getLifecycleOwner(thisRef: F): LifecycleOwner {
return if (thisRef.view == null) thisRef.viewLifecycleOwner else thisRef
return if (thisRef.showsDialog) thisRef else thisRef.viewLifecycleOwner
}
}

Expand Down
4 changes: 2 additions & 2 deletions data/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
defaultConfig {
minSdkVersion(21)
targetSdkVersion(30)
versionCode = 30503
versionName = "3.5.3"
versionCode = 30504
versionName = "3.5.4"
}

compileOptions {
Expand Down

0 comments on commit 5c689bd

Please sign in to comment.