chore: 更新应用导航和配置
- 更新AppNavigation导航结构 - 更新MainActivity主活动 - 更新TokenManager令牌管理 - 更新AppIcons图标
This commit is contained in:
@@ -156,6 +156,17 @@ fun LifeechoApp(initialLoggedIn: Boolean = false) {
|
||||
isLoggedIn = TokenManager.isLoggedIn
|
||||
}
|
||||
|
||||
// 设置令牌刷新失败时的回调
|
||||
androidx.compose.runtime.LaunchedEffect(Unit) {
|
||||
TokenManager.setOnTokenRefreshFailedCallback {
|
||||
// 令牌刷新失败,导航到登录页面
|
||||
isLoggedIn = false
|
||||
navController.navigate(Screen.Login.route) {
|
||||
popUpTo(0) { inclusive = true }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 同步currentDestination与当前路由
|
||||
androidx.compose.runtime.LaunchedEffect(currentRoute) {
|
||||
when (currentRoute) {
|
||||
|
||||
@@ -22,10 +22,27 @@ object TokenManager {
|
||||
private val _isLoggedIn = mutableStateOf(false)
|
||||
private val scope = CoroutineScope(Dispatchers.IO + SupervisorJob())
|
||||
|
||||
// 令牌刷新失败时的回调
|
||||
private var onTokenRefreshFailedCallback: (() -> Unit)? = null
|
||||
|
||||
var isLoggedIn: Boolean
|
||||
get() = _isLoggedIn.value
|
||||
private set(value) { _isLoggedIn.value = value }
|
||||
|
||||
/**
|
||||
* 设置令牌刷新失败时的回调
|
||||
*/
|
||||
fun setOnTokenRefreshFailedCallback(callback: (() -> Unit)?) {
|
||||
onTokenRefreshFailedCallback = callback
|
||||
}
|
||||
|
||||
/**
|
||||
* 通知令牌刷新失败
|
||||
*/
|
||||
fun notifyTokenRefreshFailed() {
|
||||
onTokenRefreshFailedCallback?.invoke()
|
||||
}
|
||||
|
||||
fun initialize(context: Context) {
|
||||
if (tokenPreferences == null) {
|
||||
tokenPreferences = TokenPreferences(context)
|
||||
|
||||
@@ -18,6 +18,8 @@ sealed class Screen(val route: String) {
|
||||
object Profile : Screen("profile")
|
||||
object Login : Screen("login")
|
||||
object Register : Screen("register")
|
||||
object ResetPassword : Screen("reset_password")
|
||||
object AccountManagement : Screen("account_management")
|
||||
object UpgradePlan : Screen("upgrade_plan")
|
||||
object MyOrders : Screen("my_orders")
|
||||
object ExportData : Screen("export_data")
|
||||
@@ -164,6 +166,9 @@ fun AppNavigation(
|
||||
},
|
||||
onNavigateToRegister = {
|
||||
navController.navigate(Screen.Register.route)
|
||||
},
|
||||
onNavigateToResetPassword = {
|
||||
navController.navigate(Screen.ResetPassword.route)
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -180,6 +185,38 @@ fun AppNavigation(
|
||||
}
|
||||
)
|
||||
}
|
||||
composable(
|
||||
route = Screen.ResetPassword.route,
|
||||
enterTransition = { slideInHorizontally() },
|
||||
exitTransition = { slideOutHorizontally() },
|
||||
popEnterTransition = { slideInHorizontallyFromLeft() },
|
||||
popExitTransition = { slideOutHorizontallyToRight() }
|
||||
) {
|
||||
ResetPasswordScreen(
|
||||
onResetSuccess = {
|
||||
navController.navigate(Screen.Login.route) {
|
||||
popUpTo(Screen.ResetPassword.route) { inclusive = true }
|
||||
}
|
||||
},
|
||||
onBackToLogin = { navController.popBackStack() }
|
||||
)
|
||||
}
|
||||
composable(
|
||||
route = Screen.AccountManagement.route,
|
||||
enterTransition = { slideInHorizontally() },
|
||||
exitTransition = { slideOutHorizontally() },
|
||||
popEnterTransition = { slideInHorizontallyFromLeft() },
|
||||
popExitTransition = { slideOutHorizontallyToRight() }
|
||||
) {
|
||||
AccountManagementScreen(
|
||||
onNavigateBack = { navController.popBackStack() },
|
||||
onLogoutSuccess = {
|
||||
navController.navigate(Screen.Login.route) {
|
||||
popUpTo(0) { inclusive = true }
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -80,4 +80,11 @@ object AppIcons {
|
||||
// 认证相关图标
|
||||
val Visibility = Icons.Default.Visibility
|
||||
val VisibilityOff = Icons.Default.VisibilityOff
|
||||
|
||||
// 账户管理图标
|
||||
val ManageAccounts = Icons.Default.ManageAccounts
|
||||
val Lock = Icons.Default.Lock
|
||||
val Phone = Icons.Default.Phone
|
||||
val ExitToApp = Icons.Default.ExitToApp
|
||||
val DevicesOther = Icons.Default.DevicesOther
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user