chore: 更新应用导航和配置

- 更新AppNavigation导航结构
- 更新MainActivity主活动
- 更新TokenManager令牌管理
- 更新AppIcons图标
This commit is contained in:
iammm0
2026-01-27 11:36:20 +08:00
parent c887bafde0
commit 57bcd72df2
4 changed files with 72 additions and 0 deletions

View File

@@ -155,6 +155,17 @@ fun LifeechoApp(initialLoggedIn: Boolean = false) {
androidx.compose.runtime.LaunchedEffect(TokenManager.isLoggedIn) { androidx.compose.runtime.LaunchedEffect(TokenManager.isLoggedIn) {
isLoggedIn = TokenManager.isLoggedIn isLoggedIn = TokenManager.isLoggedIn
} }
// 设置令牌刷新失败时的回调
androidx.compose.runtime.LaunchedEffect(Unit) {
TokenManager.setOnTokenRefreshFailedCallback {
// 令牌刷新失败,导航到登录页面
isLoggedIn = false
navController.navigate(Screen.Login.route) {
popUpTo(0) { inclusive = true }
}
}
}
// 同步currentDestination与当前路由 // 同步currentDestination与当前路由
androidx.compose.runtime.LaunchedEffect(currentRoute) { androidx.compose.runtime.LaunchedEffect(currentRoute) {

View File

@@ -22,9 +22,26 @@ object TokenManager {
private val _isLoggedIn = mutableStateOf(false) private val _isLoggedIn = mutableStateOf(false)
private val scope = CoroutineScope(Dispatchers.IO + SupervisorJob()) private val scope = CoroutineScope(Dispatchers.IO + SupervisorJob())
// 令牌刷新失败时的回调
private var onTokenRefreshFailedCallback: (() -> Unit)? = null
var isLoggedIn: Boolean var isLoggedIn: Boolean
get() = _isLoggedIn.value get() = _isLoggedIn.value
private set(value) { _isLoggedIn.value = value } private set(value) { _isLoggedIn.value = value }
/**
* 设置令牌刷新失败时的回调
*/
fun setOnTokenRefreshFailedCallback(callback: (() -> Unit)?) {
onTokenRefreshFailedCallback = callback
}
/**
* 通知令牌刷新失败
*/
fun notifyTokenRefreshFailed() {
onTokenRefreshFailedCallback?.invoke()
}
fun initialize(context: Context) { fun initialize(context: Context) {
if (tokenPreferences == null) { if (tokenPreferences == null) {

View File

@@ -18,6 +18,8 @@ sealed class Screen(val route: String) {
object Profile : Screen("profile") object Profile : Screen("profile")
object Login : Screen("login") object Login : Screen("login")
object Register : Screen("register") object Register : Screen("register")
object ResetPassword : Screen("reset_password")
object AccountManagement : Screen("account_management")
object UpgradePlan : Screen("upgrade_plan") object UpgradePlan : Screen("upgrade_plan")
object MyOrders : Screen("my_orders") object MyOrders : Screen("my_orders")
object ExportData : Screen("export_data") object ExportData : Screen("export_data")
@@ -164,6 +166,9 @@ fun AppNavigation(
}, },
onNavigateToRegister = { onNavigateToRegister = {
navController.navigate(Screen.Register.route) 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 }
}
}
)
}
} }
} }

View File

@@ -80,4 +80,11 @@ object AppIcons {
// 认证相关图标 // 认证相关图标
val Visibility = Icons.Default.Visibility val Visibility = Icons.Default.Visibility
val VisibilityOff = Icons.Default.VisibilityOff 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
} }