From b1eb411ad4f5f7199c7c7c4ed915a821dcbd4cc8 Mon Sep 17 00:00:00 2001 From: AbronStudio Date: Sun, 7 Sep 2025 10:41:00 +0330 Subject: [PATCH] ChatRouter: Remember last selected channel This change ensures that the last selected channel remains highlighted in the channel list even when navigating to other screens like server settings. The `lastSelectedChannelId` is updated whenever a channel destination is navigated to. This stored ID is then used to determine the `selectedChannelId` for the `ServerChannels` composable, ensuring the correct channel remains visually selected. --- .../main/java/chat/peptide/screens/chat/ChatRouterScreen.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/chat/peptide/screens/chat/ChatRouterScreen.kt b/app/src/main/java/chat/peptide/screens/chat/ChatRouterScreen.kt index 3965de66..53b0ba39 100644 --- a/app/src/main/java/chat/peptide/screens/chat/ChatRouterScreen.kt +++ b/app/src/main/java/chat/peptide/screens/chat/ChatRouterScreen.kt @@ -164,6 +164,7 @@ class ChatRouterViewModel @Inject constructor( var currentDestination by mutableStateOf(ChatRouterDestination.default) var previousDestination by mutableStateOf(null) var lastNonChannelDestination by mutableStateOf(null) + var lastSelectedChannelId by mutableStateOf(null) var latestChangelogRead by mutableStateOf(true) var latestChangelog by mutableStateOf("") var latestChangelogBody by mutableStateOf("") @@ -226,6 +227,8 @@ class ChatRouterViewModel @Inject constructor( currentDestination = destination if (destination !is ChatRouterDestination.Channel) { lastNonChannelDestination = destination + } else { + lastSelectedChannelId = destination.channelId } } } @@ -1105,7 +1108,7 @@ fun ChannelNavigator( is ChatRouterDestination.Channel -> currentServer else -> null }, - selectedChannelId = (if (dest is ChatRouterDestination.Channel) dest.channelId else null), + selectedChannelId = viewModel.lastSelectedChannelId, navigateToServer = viewModel::navigateToServer, onShowServerContextSheet = onShowServerContextSheet, showSettingsIcon = isTouchExplorationEnabled,