Dagger: makes sure to not remove an active component when navigating
This commit is contained in:
parent
e3d939726c
commit
f57a2a694d
4 changed files with 16 additions and 13 deletions
|
|
@ -68,13 +68,13 @@ class MainNode(
|
||||||
}
|
}
|
||||||
|
|
||||||
private val roomFlowNodeCallback = object : RoomFlowNode.LifecycleCallback {
|
private val roomFlowNodeCallback = object : RoomFlowNode.LifecycleCallback {
|
||||||
override fun onFlowCreated(room: MatrixRoom) {
|
override fun onFlowCreated(owner: String, room: MatrixRoom) {
|
||||||
val component = bindings<RoomComponent.ParentBindings>().roomComponentBuilder().room(room).build()
|
val component = bindings<RoomComponent.ParentBindings>().roomComponentBuilder().room(room).build()
|
||||||
mainDaggerComponentOwner.addComponent(room.roomId.value, component)
|
mainDaggerComponentOwner.addComponent(owner, component)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onFlowReleased(room: MatrixRoom) {
|
override fun onFlowReleased(owner: String, room: MatrixRoom) {
|
||||||
mainDaggerComponentOwner.removeComponent(room.roomId.value)
|
mainDaggerComponentOwner.removeComponent(owner)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,10 @@ class MainDaggerComponentsOwner @Inject constructor(@ApplicationContext context:
|
||||||
daggerComponents.remove(identifier)
|
daggerComponents.remove(identifier)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We expose the dagger components in the opposite order they arrived.
|
||||||
|
* So we pick the most recent component when searching with the [io.element.android.libraries.architecture.bindings] methods.
|
||||||
|
*/
|
||||||
override val daggerComponent: Any
|
override val daggerComponent: Any
|
||||||
get() = daggerComponents.values.reversed()
|
get() = daggerComponents.values.reversed()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,6 @@ import io.element.android.services.analytics.api.AnalyticsService
|
||||||
import io.element.android.services.appnavstate.api.AppNavigationStateService
|
import io.element.android.services.appnavstate.api.AppNavigationStateService
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||||
import kotlinx.coroutines.flow.flowOf
|
|
||||||
import kotlinx.coroutines.flow.launchIn
|
import kotlinx.coroutines.flow.launchIn
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
import kotlinx.parcelize.Parcelize
|
import kotlinx.parcelize.Parcelize
|
||||||
|
|
@ -118,9 +117,9 @@ class LoggedInFlowNode @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
interface LifecycleCallback : NodeLifecycleCallback {
|
interface LifecycleCallback : NodeLifecycleCallback {
|
||||||
fun onFlowCreated(client: MatrixClient) = Unit
|
fun onFlowCreated(identifier: String, client: MatrixClient) = Unit
|
||||||
|
|
||||||
fun onFlowReleased(client: MatrixClient) = Unit
|
fun onFlowReleased(identifier: String, client: MatrixClient) = Unit
|
||||||
}
|
}
|
||||||
|
|
||||||
data class Inputs(
|
data class Inputs(
|
||||||
|
|
@ -139,7 +138,7 @@ class LoggedInFlowNode @AssistedInject constructor(
|
||||||
observeAnalyticsState()
|
observeAnalyticsState()
|
||||||
lifecycle.subscribe(
|
lifecycle.subscribe(
|
||||||
onCreate = {
|
onCreate = {
|
||||||
plugins<LifecycleCallback>().forEach { it.onFlowCreated(inputs.matrixClient) }
|
plugins<LifecycleCallback>().forEach { it.onFlowCreated(id, inputs.matrixClient) }
|
||||||
val imageLoaderFactory = bindings<MatrixUIBindings>().loggedInImageLoaderFactory()
|
val imageLoaderFactory = bindings<MatrixUIBindings>().loggedInImageLoaderFactory()
|
||||||
Coil.setImageLoader(imageLoaderFactory)
|
Coil.setImageLoader(imageLoaderFactory)
|
||||||
inputs.matrixClient.startSync()
|
inputs.matrixClient.startSync()
|
||||||
|
|
@ -151,7 +150,7 @@ class LoggedInFlowNode @AssistedInject constructor(
|
||||||
onDestroy = {
|
onDestroy = {
|
||||||
val imageLoaderFactory = bindings<MatrixUIBindings>().notLoggedInImageLoaderFactory()
|
val imageLoaderFactory = bindings<MatrixUIBindings>().notLoggedInImageLoaderFactory()
|
||||||
Coil.setImageLoader(imageLoaderFactory)
|
Coil.setImageLoader(imageLoaderFactory)
|
||||||
plugins<LifecycleCallback>().forEach { it.onFlowReleased(inputs.matrixClient) }
|
plugins<LifecycleCallback>().forEach { it.onFlowReleased(id, inputs.matrixClient) }
|
||||||
appNavigationStateService.onLeavingSpace(id)
|
appNavigationStateService.onLeavingSpace(id)
|
||||||
appNavigationStateService.onLeavingSession(id)
|
appNavigationStateService.onLeavingSession(id)
|
||||||
loggedInFlowProcessor.stopObserving()
|
loggedInFlowProcessor.stopObserving()
|
||||||
|
|
|
||||||
|
|
@ -68,8 +68,8 @@ class RoomFlowNode @AssistedInject constructor(
|
||||||
) {
|
) {
|
||||||
|
|
||||||
interface LifecycleCallback : NodeLifecycleCallback {
|
interface LifecycleCallback : NodeLifecycleCallback {
|
||||||
fun onFlowCreated(room: MatrixRoom) = Unit
|
fun onFlowCreated(owner: String, room: MatrixRoom) = Unit
|
||||||
fun onFlowReleased(room: MatrixRoom) = Unit
|
fun onFlowReleased(owner: String, room: MatrixRoom) = Unit
|
||||||
}
|
}
|
||||||
|
|
||||||
data class Inputs(
|
data class Inputs(
|
||||||
|
|
@ -83,14 +83,14 @@ class RoomFlowNode @AssistedInject constructor(
|
||||||
lifecycle.subscribe(
|
lifecycle.subscribe(
|
||||||
onCreate = {
|
onCreate = {
|
||||||
Timber.v("OnCreate")
|
Timber.v("OnCreate")
|
||||||
plugins<LifecycleCallback>().forEach { it.onFlowCreated(inputs.room) }
|
plugins<LifecycleCallback>().forEach { it.onFlowCreated(id, inputs.room) }
|
||||||
appNavigationStateService.onNavigateToRoom(id, inputs.room.roomId)
|
appNavigationStateService.onNavigateToRoom(id, inputs.room.roomId)
|
||||||
fetchRoomMembers()
|
fetchRoomMembers()
|
||||||
},
|
},
|
||||||
onDestroy = {
|
onDestroy = {
|
||||||
Timber.v("OnDestroy")
|
Timber.v("OnDestroy")
|
||||||
inputs.room.close()
|
inputs.room.close()
|
||||||
plugins<LifecycleCallback>().forEach { it.onFlowReleased(inputs.room) }
|
plugins<LifecycleCallback>().forEach { it.onFlowReleased(id, inputs.room) }
|
||||||
appNavigationStateService.onLeavingRoom(id)
|
appNavigationStateService.onLeavingRoom(id)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue