feat: Improve logout handling and back navigation in AuthFlow for better user experience
This commit is contained in:
@@ -164,10 +164,11 @@ class MainActivity : ComponentActivity() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
onLogout = {
|
onLogout = {
|
||||||
|
// Set currentAccount to null immediately to prevent UI lag
|
||||||
|
currentAccount = null
|
||||||
scope.launch {
|
scope.launch {
|
||||||
com.rosetta.messenger.network.ProtocolManager.disconnect()
|
com.rosetta.messenger.network.ProtocolManager.disconnect()
|
||||||
accountManager.logout()
|
accountManager.logout()
|
||||||
currentAccount = null
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -182,10 +183,11 @@ class MainActivity : ComponentActivity() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
onLogout = {
|
onLogout = {
|
||||||
|
// Set currentAccount to null immediately to prevent UI lag
|
||||||
|
currentAccount = null
|
||||||
scope.launch {
|
scope.launch {
|
||||||
com.rosetta.messenger.network.ProtocolManager.disconnect()
|
com.rosetta.messenger.network.ProtocolManager.disconnect()
|
||||||
accountManager.logout()
|
accountManager.logout()
|
||||||
currentAccount = null
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.rosetta.messenger.ui.auth
|
package com.rosetta.messenger.ui.auth
|
||||||
|
|
||||||
|
import androidx.activity.compose.BackHandler
|
||||||
import androidx.compose.animation.*
|
import androidx.compose.animation.*
|
||||||
import androidx.compose.animation.core.tween
|
import androidx.compose.animation.core.tween
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.*
|
||||||
@@ -35,6 +36,19 @@ fun AuthFlow(
|
|||||||
var selectedAccountId by remember { mutableStateOf<String?>(accounts.firstOrNull()?.id) }
|
var selectedAccountId by remember { mutableStateOf<String?>(accounts.firstOrNull()?.id) }
|
||||||
var showCreateModal by remember { mutableStateOf(false) }
|
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(
|
AnimatedContent(
|
||||||
targetState = currentScreen,
|
targetState = currentScreen,
|
||||||
transitionSpec = {
|
transitionSpec = {
|
||||||
@@ -99,7 +113,14 @@ fun AuthFlow(
|
|||||||
SetPasswordScreen(
|
SetPasswordScreen(
|
||||||
seedPhrase = seedPhrase,
|
seedPhrase = seedPhrase,
|
||||||
isDarkTheme = isDarkTheme,
|
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) }
|
onAccountCreated = { onAuthComplete(null) }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -122,8 +143,8 @@ fun AuthFlow(
|
|||||||
onUnlocked = { account -> onAuthComplete(account) },
|
onUnlocked = { account -> onAuthComplete(account) },
|
||||||
onSwitchAccount = {
|
onSwitchAccount = {
|
||||||
// Navigate to create new account screen
|
// Navigate to create new account screen
|
||||||
|
// Don't reset selectedAccountId so last logged account is remembered
|
||||||
currentScreen = AuthScreen.WELCOME
|
currentScreen = AuthScreen.WELCOME
|
||||||
selectedAccountId = null
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user