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 (internalAccountId == eventStatus.userId && !eventStatus.isAllGood && activity != null) {
|
||||
activity!!.runOnUiThread {
|
||||
// try {
|
||||
binding?.progressText?.text =
|
||||
"""
|
||||
${binding?.progressText?.text}
|
||||
${resources!!.getString(R.string.nc_push_disabled)}
|
||||
""".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()
|
||||
|
@ -25,12 +25,12 @@ import com.bluelinelabs.conductor.Controller
|
||||
import kotlin.properties.ReadOnlyProperty
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
fun <T : ViewBinding> Controller.viewBinding(bindingFactory: (View) -> T?) =
|
||||
fun <T : ViewBinding> Controller.viewBinding(bindingFactory: (View) -> T) =
|
||||
ControllerViewBindingDelegate(this, bindingFactory)
|
||||
|
||||
class ControllerViewBindingDelegate<T : ViewBinding>(
|
||||
controller: Controller,
|
||||
private val viewBinder: (View) -> T?
|
||||
private val viewBinder: (View) -> T
|
||||
) : ReadOnlyProperty<Controller, T?>, LifecycleObserver {
|
||||
|
||||
private var binding: T? = null
|
||||
@ -43,7 +43,10 @@ class ControllerViewBindingDelegate<T : ViewBinding>(
|
||||
})
|
||||
}
|
||||
|
||||
override fun getValue(thisRef: Controller, property: KProperty <*>): T? {
|
||||
return binding ?: thisRef.view?.let { viewBinder(it).also { binding = it } }
|
||||
override fun getValue(thisRef: Controller, property: KProperty<*>): T? {
|
||||
if (binding == null) {
|
||||
binding = thisRef.view?.let { viewBinder(it) }
|
||||
}
|
||||
return binding
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user