|
|
@ -40,11 +40,10 @@ private val loggerTag = LoggerTag("Navigation") |
|
|
|
@SingleIn(AppScope::class) |
|
|
|
@SingleIn(AppScope::class) |
|
|
|
class DefaultAppNavigationStateService @Inject constructor() : AppNavigationStateService { |
|
|
|
class DefaultAppNavigationStateService @Inject constructor() : AppNavigationStateService { |
|
|
|
|
|
|
|
|
|
|
|
private val currentAppNavigationState = MutableStateFlow<AppNavigationState>(AppNavigationState.Root) |
|
|
|
private val currentAppNavigationState: MutableStateFlow<AppNavigationState> = MutableStateFlow(AppNavigationState.Root) |
|
|
|
|
|
|
|
|
|
|
|
override val appNavigationStateFlow: StateFlow<AppNavigationState> = currentAppNavigationState |
|
|
|
override val appNavigationStateFlow: StateFlow<AppNavigationState> = currentAppNavigationState |
|
|
|
|
|
|
|
|
|
|
|
override fun onNavigateToSession(sessionId: SessionId) { |
|
|
|
override fun onNavigateToSession(owner: String, sessionId: SessionId) { |
|
|
|
val currentValue = currentAppNavigationState.value |
|
|
|
val currentValue = currentAppNavigationState.value |
|
|
|
Timber.tag(loggerTag.value).d("Navigating to session $sessionId. Current state: $currentValue") |
|
|
|
Timber.tag(loggerTag.value).d("Navigating to session $sessionId. Current state: $currentValue") |
|
|
|
val newValue: AppNavigationState.Session = when (currentValue) { |
|
|
|
val newValue: AppNavigationState.Session = when (currentValue) { |
|
|
@ -52,53 +51,54 @@ class DefaultAppNavigationStateService @Inject constructor() : AppNavigationStat |
|
|
|
is AppNavigationState.Space, |
|
|
|
is AppNavigationState.Space, |
|
|
|
is AppNavigationState.Room, |
|
|
|
is AppNavigationState.Room, |
|
|
|
is AppNavigationState.Thread, |
|
|
|
is AppNavigationState.Thread, |
|
|
|
AppNavigationState.Root -> AppNavigationState.Session(sessionId) |
|
|
|
is AppNavigationState.Root -> AppNavigationState.Session(owner, sessionId) |
|
|
|
} |
|
|
|
} |
|
|
|
currentAppNavigationState.value = newValue |
|
|
|
currentAppNavigationState.value = newValue |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onNavigateToSpace(spaceId: SpaceId) { |
|
|
|
override fun onNavigateToSpace(owner: String, spaceId: SpaceId) { |
|
|
|
val currentValue = currentAppNavigationState.value |
|
|
|
val currentValue = currentAppNavigationState.value |
|
|
|
Timber.tag(loggerTag.value).d("Navigating to space $spaceId. Current state: $currentValue") |
|
|
|
Timber.tag(loggerTag.value).d("Navigating to space $spaceId. Current state: $currentValue") |
|
|
|
val newValue: AppNavigationState.Space = when (currentValue) { |
|
|
|
val newValue: AppNavigationState.Space = when (currentValue) { |
|
|
|
AppNavigationState.Root -> error("onNavigateToSession() must be called first") |
|
|
|
AppNavigationState.Root -> error("onNavigateToSession() must be called first") |
|
|
|
is AppNavigationState.Session -> AppNavigationState.Space(spaceId, currentValue) |
|
|
|
is AppNavigationState.Session -> AppNavigationState.Space(owner, spaceId, currentValue) |
|
|
|
is AppNavigationState.Space -> AppNavigationState.Space(spaceId, currentValue.parentSession) |
|
|
|
is AppNavigationState.Space -> AppNavigationState.Space(owner, spaceId, currentValue.parentSession) |
|
|
|
is AppNavigationState.Room -> AppNavigationState.Space(spaceId, currentValue.parentSpace.parentSession) |
|
|
|
is AppNavigationState.Room -> AppNavigationState.Space(owner, spaceId, currentValue.parentSpace.parentSession) |
|
|
|
is AppNavigationState.Thread -> AppNavigationState.Space(spaceId, currentValue.parentRoom.parentSpace.parentSession) |
|
|
|
is AppNavigationState.Thread -> AppNavigationState.Space(owner, spaceId, currentValue.parentRoom.parentSpace.parentSession) |
|
|
|
} |
|
|
|
} |
|
|
|
currentAppNavigationState.value = newValue |
|
|
|
currentAppNavigationState.value = newValue |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onNavigateToRoom(roomId: RoomId) { |
|
|
|
override fun onNavigateToRoom(owner: String, roomId: RoomId) { |
|
|
|
val currentValue = currentAppNavigationState.value |
|
|
|
val currentValue = currentAppNavigationState.value |
|
|
|
Timber.tag(loggerTag.value).d("Navigating to room $roomId. Current state: $currentValue") |
|
|
|
Timber.tag(loggerTag.value).d("Navigating to room $roomId. Current state: $currentValue") |
|
|
|
val newValue: AppNavigationState.Room = when (currentValue) { |
|
|
|
val newValue: AppNavigationState.Room = when (currentValue) { |
|
|
|
AppNavigationState.Root -> error("onNavigateToSession() must be called first") |
|
|
|
AppNavigationState.Root -> error("onNavigateToSession() must be called first") |
|
|
|
is AppNavigationState.Session -> error("onNavigateToSpace() must be called first") |
|
|
|
is AppNavigationState.Session -> error("onNavigateToSpace() must be called first") |
|
|
|
is AppNavigationState.Space -> AppNavigationState.Room(roomId, currentValue) |
|
|
|
is AppNavigationState.Space -> AppNavigationState.Room(owner, roomId, currentValue) |
|
|
|
is AppNavigationState.Room -> AppNavigationState.Room(roomId, currentValue.parentSpace) |
|
|
|
is AppNavigationState.Room -> AppNavigationState.Room(owner, roomId, currentValue.parentSpace) |
|
|
|
is AppNavigationState.Thread -> AppNavigationState.Room(roomId, currentValue.parentRoom.parentSpace) |
|
|
|
is AppNavigationState.Thread -> AppNavigationState.Room(owner, roomId, currentValue.parentRoom.parentSpace) |
|
|
|
} |
|
|
|
} |
|
|
|
currentAppNavigationState.value = newValue |
|
|
|
currentAppNavigationState.value = newValue |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onNavigateToThread(threadId: ThreadId) { |
|
|
|
override fun onNavigateToThread(owner: String, threadId: ThreadId) { |
|
|
|
val currentValue = currentAppNavigationState.value |
|
|
|
val currentValue = currentAppNavigationState.value |
|
|
|
Timber.tag(loggerTag.value).d("Navigating to thread $threadId. Current state: $currentValue") |
|
|
|
Timber.tag(loggerTag.value).d("Navigating to thread $threadId. Current state: $currentValue") |
|
|
|
val newValue: AppNavigationState.Thread = when (currentValue) { |
|
|
|
val newValue: AppNavigationState.Thread = when (currentValue) { |
|
|
|
AppNavigationState.Root -> error("onNavigateToSession() must be called first") |
|
|
|
AppNavigationState.Root -> error("onNavigateToSession() must be called first") |
|
|
|
is AppNavigationState.Session -> error("onNavigateToSpace() must be called first") |
|
|
|
is AppNavigationState.Session -> error("onNavigateToSpace() must be called first") |
|
|
|
is AppNavigationState.Space -> error("onNavigateToRoom() must be called first") |
|
|
|
is AppNavigationState.Space -> error("onNavigateToRoom() must be called first") |
|
|
|
is AppNavigationState.Room -> AppNavigationState.Thread(threadId, currentValue) |
|
|
|
is AppNavigationState.Room -> AppNavigationState.Thread(owner, threadId, currentValue) |
|
|
|
is AppNavigationState.Thread -> AppNavigationState.Thread(threadId, currentValue.parentRoom) |
|
|
|
is AppNavigationState.Thread -> AppNavigationState.Thread(owner, threadId, currentValue.parentRoom) |
|
|
|
} |
|
|
|
} |
|
|
|
currentAppNavigationState.value = newValue |
|
|
|
currentAppNavigationState.value = newValue |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onLeavingThread() { |
|
|
|
override fun onLeavingThread(owner: String) { |
|
|
|
val currentValue = currentAppNavigationState.value |
|
|
|
val currentValue = currentAppNavigationState.value |
|
|
|
Timber.tag(loggerTag.value).d("Leaving thread. Current state: $currentValue") |
|
|
|
Timber.tag(loggerTag.value).d("Leaving thread. Current state: $currentValue") |
|
|
|
|
|
|
|
if (!currentValue.assertOwner(owner)) return |
|
|
|
val newValue: AppNavigationState.Room = when (currentValue) { |
|
|
|
val newValue: AppNavigationState.Room = when (currentValue) { |
|
|
|
AppNavigationState.Root -> error("onNavigateToSession() must be called first") |
|
|
|
AppNavigationState.Root -> error("onNavigateToSession() must be called first") |
|
|
|
is AppNavigationState.Session -> error("onNavigateToSpace() must be called first") |
|
|
|
is AppNavigationState.Session -> error("onNavigateToSpace() must be called first") |
|
|
@ -109,9 +109,10 @@ class DefaultAppNavigationStateService @Inject constructor() : AppNavigationStat |
|
|
|
currentAppNavigationState.value = newValue |
|
|
|
currentAppNavigationState.value = newValue |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onLeavingRoom() { |
|
|
|
override fun onLeavingRoom(owner: String) { |
|
|
|
val currentValue = currentAppNavigationState.value |
|
|
|
val currentValue = currentAppNavigationState.value |
|
|
|
Timber.tag(loggerTag.value).d("Leaving room. Current state: $currentValue") |
|
|
|
Timber.tag(loggerTag.value).d("Leaving room. Current state: $currentValue") |
|
|
|
|
|
|
|
if (!currentValue.assertOwner(owner)) return |
|
|
|
val newValue: AppNavigationState.Space = when (currentValue) { |
|
|
|
val newValue: AppNavigationState.Space = when (currentValue) { |
|
|
|
AppNavigationState.Root -> error("onNavigateToSession() must be called first") |
|
|
|
AppNavigationState.Root -> error("onNavigateToSession() must be called first") |
|
|
|
is AppNavigationState.Session -> error("onNavigateToSpace() must be called first") |
|
|
|
is AppNavigationState.Session -> error("onNavigateToSpace() must be called first") |
|
|
@ -122,9 +123,10 @@ class DefaultAppNavigationStateService @Inject constructor() : AppNavigationStat |
|
|
|
currentAppNavigationState.value = newValue |
|
|
|
currentAppNavigationState.value = newValue |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onLeavingSpace() { |
|
|
|
override fun onLeavingSpace(owner: String) { |
|
|
|
val currentValue = currentAppNavigationState.value |
|
|
|
val currentValue = currentAppNavigationState.value |
|
|
|
Timber.tag(loggerTag.value).d("Leaving space. Current state: $currentValue") |
|
|
|
Timber.tag(loggerTag.value).d("Leaving space. Current state: $currentValue") |
|
|
|
|
|
|
|
if (!currentValue.assertOwner(owner)) return |
|
|
|
val newValue: AppNavigationState.Session = when (currentValue) { |
|
|
|
val newValue: AppNavigationState.Session = when (currentValue) { |
|
|
|
AppNavigationState.Root -> error("onNavigateToSession() must be called first") |
|
|
|
AppNavigationState.Root -> error("onNavigateToSession() must be called first") |
|
|
|
is AppNavigationState.Session -> error("onNavigateToSpace() must be called first") |
|
|
|
is AppNavigationState.Session -> error("onNavigateToSpace() must be called first") |
|
|
@ -135,9 +137,18 @@ class DefaultAppNavigationStateService @Inject constructor() : AppNavigationStat |
|
|
|
currentAppNavigationState.value = newValue |
|
|
|
currentAppNavigationState.value = newValue |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onLeavingSession() { |
|
|
|
override fun onLeavingSession(owner: String) { |
|
|
|
val currentValue = currentAppNavigationState.value |
|
|
|
val currentValue = currentAppNavigationState.value |
|
|
|
Timber.tag(loggerTag.value).d("Leaving session. Current state: $currentValue") |
|
|
|
Timber.tag(loggerTag.value).d("Leaving session. Current state: $currentValue") |
|
|
|
|
|
|
|
if (!currentValue.assertOwner(owner)) return |
|
|
|
currentAppNavigationState.value = AppNavigationState.Root |
|
|
|
currentAppNavigationState.value = AppNavigationState.Root |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun AppNavigationState.assertOwner(owner: String): Boolean { |
|
|
|
|
|
|
|
if (this.owner != owner) { |
|
|
|
|
|
|
|
Timber.tag(loggerTag.value).d("Can't leave current state as the owner is not the same (current = ${this.owner}, new = $owner)") |
|
|
|
|
|
|
|
return false |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return true |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|