Glimpse: Cleanup getViewProperty delegate
Change-Id: I2f3cf5df7ddcbc3353b2733c289fd8d155c99385
diff --git a/app/src/main/java/org/lineageos/glimpse/ext/Fragment.kt b/app/src/main/java/org/lineageos/glimpse/ext/Fragment.kt
index 6c8d8c1..0e5e834 100644
--- a/app/src/main/java/org/lineageos/glimpse/ext/Fragment.kt
+++ b/app/src/main/java/org/lineageos/glimpse/ext/Fragment.kt
@@ -8,15 +8,9 @@
import android.view.View
import androidx.annotation.IdRes
import androidx.fragment.app.Fragment
-import kotlin.reflect.KProperty
+import kotlin.properties.ReadOnlyProperty
-class FragmentViewProperty<T : View?>(
- private val fragment: Fragment, @IdRes private val viewId: Int
-) {
- operator fun getValue(thisRef: Any?, property: KProperty<*>): T {
- return fragment.requireView().findViewById<T>(viewId)
+inline fun <reified T : View?> getViewProperty(@IdRes viewId: Int) =
+ ReadOnlyProperty<Fragment, T> { thisRef, _ ->
+ thisRef.requireView().findViewById<T>(viewId)
}
-}
-
-fun <T : View?> Fragment.getViewProperty(@IdRes viewId: Int) =
- FragmentViewProperty<T>(this, viewId)