mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-22 13:09:46 +01:00
simplify ControllerViewBindingDelegate
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
parent
b45794b0ca
commit
b95399750d
@ -378,17 +378,11 @@ class AccountVerificationController(args: Bundle? = null) :
|
|||||||
if (eventStatus.eventType == EventStatus.EventType.PUSH_REGISTRATION) {
|
if (eventStatus.eventType == EventStatus.EventType.PUSH_REGISTRATION) {
|
||||||
if (internalAccountId == eventStatus.userId && !eventStatus.isAllGood && activity != null) {
|
if (internalAccountId == eventStatus.userId && !eventStatus.isAllGood && activity != null) {
|
||||||
activity!!.runOnUiThread {
|
activity!!.runOnUiThread {
|
||||||
// try {
|
|
||||||
binding?.progressText?.text =
|
binding?.progressText?.text =
|
||||||
"""
|
"""
|
||||||
${binding?.progressText?.text}
|
${binding?.progressText?.text}
|
||||||
${resources!!.getString(R.string.nc_push_disabled)}
|
${resources!!.getString(R.string.nc_push_disabled)}
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
// } catch (npe: NullPointerException) {
|
|
||||||
// // view binding can be null
|
|
||||||
// // since this is called asynchronously and UI might have been destroyed in the meantime
|
|
||||||
// Log.i(TAG, "UI destroyed - view binding already gone")
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fetchAndStoreCapabilities()
|
fetchAndStoreCapabilities()
|
||||||
|
@ -25,12 +25,12 @@ import com.bluelinelabs.conductor.Controller
|
|||||||
import kotlin.properties.ReadOnlyProperty
|
import kotlin.properties.ReadOnlyProperty
|
||||||
import kotlin.reflect.KProperty
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
fun <T : ViewBinding> Controller.viewBinding(bindingFactory: (View) -> T?) =
|
fun <T : ViewBinding> Controller.viewBinding(bindingFactory: (View) -> T) =
|
||||||
ControllerViewBindingDelegate(this, bindingFactory)
|
ControllerViewBindingDelegate(this, bindingFactory)
|
||||||
|
|
||||||
class ControllerViewBindingDelegate<T : ViewBinding>(
|
class ControllerViewBindingDelegate<T : ViewBinding>(
|
||||||
controller: Controller,
|
controller: Controller,
|
||||||
private val viewBinder: (View) -> T?
|
private val viewBinder: (View) -> T
|
||||||
) : ReadOnlyProperty<Controller, T?>, LifecycleObserver {
|
) : ReadOnlyProperty<Controller, T?>, LifecycleObserver {
|
||||||
|
|
||||||
private var binding: T? = null
|
private var binding: T? = null
|
||||||
@ -43,7 +43,10 @@ class ControllerViewBindingDelegate<T : ViewBinding>(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getValue(thisRef: Controller, property: KProperty <*>): T? {
|
override fun getValue(thisRef: Controller, property: KProperty<*>): T? {
|
||||||
return binding ?: thisRef.view?.let { viewBinder(it).also { binding = it } }
|
if (binding == null) {
|
||||||
|
binding = thisRef.view?.let { viewBinder(it) }
|
||||||
|
}
|
||||||
|
return binding
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user