Skip to content

Commit b8f2007

Browse files
committed
🐛 Supporting auto set ViewDataBinding.lifecycleOwner
1 parent 07b1586 commit b8f2007

4 files changed

Lines changed: 47 additions & 1 deletion

File tree

binding-ktx/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
#
44
PUBLISH_GROUP_ID=com.sorrowblue.jetpack
55
PUBLISH_ARTIFACT_ID=binding-ktx
6-
PUBLISH_VERSION=3.0.0
6+
PUBLISH_VERSION=3.0.1

binding-ktx/src/main/java/com/sorrowblue/jetpack/binding/AndroidLifecycleProperty.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import android.os.Looper
99
import androidx.annotation.MainThread
1010
import androidx.annotation.RestrictTo
1111
import androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP
12+
import androidx.databinding.ViewDataBinding
1213
import androidx.lifecycle.DefaultLifecycleObserver
1314
import androidx.lifecycle.Lifecycle
1415
import androidx.lifecycle.LifecycleOwner
@@ -29,6 +30,9 @@ abstract class AndroidLifecycleViewBindingProperty<T, V : ViewBinding> : ReadOnl
2930
lifecycle.addObserver(object : DefaultLifecycleObserver {
3031
override fun onDestroy(owner: LifecycleOwner) = clear()
3132
})
33+
if (binding is ViewDataBinding) {
34+
binding.lifecycleOwner = getLifecycleOwner(thisRef)
35+
}
3236
this.binding = binding
3337
}
3438
return binding
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="utf-8"?><!--
2+
~ (c) 2020-2021 SorrowBlue.
3+
-->
4+
5+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
6+
xmlns:aapt="http://schemas.android.com/aapt"
7+
android:width="108dp"
8+
android:height="108dp"
9+
android:viewportWidth="108"
10+
android:viewportHeight="108">
11+
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
12+
<aapt:attr name="android:fillColor">
13+
<gradient
14+
android:endX="85.84757"
15+
android:endY="92.4963"
16+
android:startX="42.9492"
17+
android:startY="49.59793"
18+
android:type="linear">
19+
<item
20+
android:color="#44000000"
21+
android:offset="0.0" />
22+
<item
23+
android:color="#00000000"
24+
android:offset="1.0" />
25+
</gradient>
26+
</aapt:attr>
27+
</path>
28+
<path
29+
android:fillColor="#FFFFFF"
30+
android:fillType="nonZero"
31+
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
32+
android:strokeWidth="1"
33+
android:strokeColor="#00000000" />
34+
</vector>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?><!--
2+
~ (c) 2020-2021 SorrowBlue.
3+
-->
4+
5+
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
6+
<background android:drawable="@drawable/ic_launcher_background" />
7+
<foreground android:drawable="@drawable/ic_launcher_foreground" />
8+
</adaptive-icon>

0 commit comments

Comments
 (0)