feat: Improve logout handling and back navigation in AuthFlow for better user experience

This commit is contained in:
k1ngsterr1
2026-01-09 23:32:57 +05:00
parent 2d7dbe88a5
commit 1b860e1c3e
2 changed files with 27 additions and 4 deletions

View File

@@ -164,10 +164,11 @@ class MainActivity : ComponentActivity() {
}
},
onLogout = {
// Set currentAccount to null immediately to prevent UI lag
currentAccount = null
scope.launch {
com.rosetta.messenger.network.ProtocolManager.disconnect()
accountManager.logout()
currentAccount = null
}
}
)
@@ -182,10 +183,11 @@ class MainActivity : ComponentActivity() {
}
},
onLogout = {
// Set currentAccount to null immediately to prevent UI lag
currentAccount = null
scope.launch {
com.rosetta.messenger.network.ProtocolManager.disconnect()
accountManager.logout()
currentAccount = null
}
}
)

View File

@@ -1,5 +1,6 @@
package com.rosetta.messenger.ui.auth
import androidx.activity.compose.BackHandler
import androidx.compose.animation.*
import androidx.compose.animation.core.tween
import androidx.compose.runtime.*
@@ -35,6 +36,19 @@ fun AuthFlow(
var selectedAccountId by remember { mutableStateOf<String?>(accounts.firstOrNull()?.id) }
var showCreateModal by remember { mutableStateOf(false) }
// Handle system back button
BackHandler(enabled = currentScreen != AuthScreen.UNLOCK && currentScreen != AuthScreen.WELCOME) {
when (currentScreen) {
AuthScreen.SEED_PHRASE -> currentScreen = AuthScreen.WELCOME
AuthScreen.CONFIRM_SEED -> currentScreen = AuthScreen.SEED_PHRASE
AuthScreen.SET_PASSWORD -> {
currentScreen = if (hasExistingAccount) AuthScreen.UNLOCK else AuthScreen.CONFIRM_SEED
}
AuthScreen.IMPORT_SEED -> currentScreen = AuthScreen.WELCOME
else -> {} // UNLOCK and WELCOME don't have back navigation
}
}
AnimatedContent(
targetState = currentScreen,
transitionSpec = {
@@ -99,7 +113,14 @@ fun AuthFlow(
SetPasswordScreen(
seedPhrase = seedPhrase,
isDarkTheme = isDarkTheme,
onBack = { currentScreen = AuthScreen.CONFIRM_SEED },
onBack = {
// If there are existing accounts, allow going back to unlock screen
if (hasExistingAccount) {
currentScreen = AuthScreen.UNLOCK
} else {
currentScreen = AuthScreen.CONFIRM_SEED
}
},
onAccountCreated = { onAuthComplete(null) }
)
}
@@ -122,8 +143,8 @@ fun AuthFlow(
onUnlocked = { account -> onAuthComplete(account) },
onSwitchAccount = {
// Navigate to create new account screen
// Don't reset selectedAccountId so last logged account is remembered
currentScreen = AuthScreen.WELCOME
selectedAccountId = null
}
)
}