diff --git a/app/src/main/java/com/example/login_v3/home/setting/Setting_detail_Screen.kt b/app/src/main/java/com/example/login_v3/home/setting/Setting_detail_Screen.kt index b893e17..b620f7d 100644 --- a/app/src/main/java/com/example/login_v3/home/setting/Setting_detail_Screen.kt +++ b/app/src/main/java/com/example/login_v3/home/setting/Setting_detail_Screen.kt @@ -43,6 +43,8 @@ import com.example.login_v3.home.setting.setting_detail_page.detail_UI.setting_d import com.example.login_v3.home.setting.setting_detail_page.detail_UI.setting_subscription_page import com.example.login_v3.home.setting.setting_detail_page.detail_UI.setting_theme_page import com.example.login_v3.home.setting.setting_detail_page.viewmodel.Theme_ViewModel +import com.example.login_v3.navigation.AppScreen +import com.example.login_v3.navigation.AppViewModel import com.example.login_v3.navigation.BottomBarViewModel @Composable @@ -50,7 +52,8 @@ fun SharedTransitionScope.setting_detail_Screen( title: String, settingIcon: String, animatedVisibilityScope: AnimatedVisibilityScope, - bottomBarViewModel: BottomBarViewModel = hiltViewModel() + bottomBarViewModel: BottomBarViewModel = hiltViewModel(), + appViewModel: AppViewModel = hiltViewModel() ){ //control bottom bar behavior DisposableEffect(Unit) { @@ -123,7 +126,11 @@ fun SharedTransitionScope.setting_detail_Screen( startDestination = startRoute ) { - composable("setting_Profile") { Setting_profile_page() } + composable("setting_Profile") { Setting_profile_page( + onNavigateToAccountSwitch = { + appViewModel.goTo(AppScreen.AccountSwitch) + } + ) } composable("setting_Theme") { val activity = LocalActivity.current as ComponentActivity val vm: Theme_ViewModel = hiltViewModel(viewModelStoreOwner = activity) diff --git a/app/src/main/java/com/example/login_v3/home/setting/setting_detail_page/detail_UI/setting_Profile_Page.kt b/app/src/main/java/com/example/login_v3/home/setting/setting_detail_page/detail_UI/setting_Profile_Page.kt index a6ee4de..6e2a4b0 100644 --- a/app/src/main/java/com/example/login_v3/home/setting/setting_detail_page/detail_UI/setting_Profile_Page.kt +++ b/app/src/main/java/com/example/login_v3/home/setting/setting_detail_page/detail_UI/setting_Profile_Page.kt @@ -24,8 +24,10 @@ import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Edit +import androidx.compose.material.icons.filled.ManageAccounts import androidx.compose.material3.AlertDialog import androidx.compose.material3.Button +import androidx.compose.material3.ButtonDefaults import androidx.compose.material3.CircularProgressIndicator import androidx.compose.material3.Divider import androidx.compose.material3.Icon @@ -64,7 +66,8 @@ import com.example.login_v3.ui.theme.main_orange @Composable fun Setting_profile_page( - viewModel: PersonalProfileViewModel = hiltViewModel() + viewModel: PersonalProfileViewModel = hiltViewModel(), + onNavigateToAccountSwitch: () -> Unit ) { val uiState by viewModel.uiState.collectAsState() when (val state = uiState) { @@ -73,7 +76,10 @@ fun Setting_profile_page( } is ProfileUiState.Success -> { // 顯示個人資料 - Loaded_setting_profile_page(state.profile) + Loaded_setting_profile_page( + profile = state.profile, + onNavigateToAccountSwitch = onNavigateToAccountSwitch // 補上這行 + ) } is ProfileUiState.Error -> { // 顯示錯誤訊息與重試按鈕 @@ -98,7 +104,8 @@ sealed class EditTarget(val title: String) { @Composable fun Loaded_setting_profile_page( profile: UserProfile, - viewModel: PersonalProfileViewModel = hiltViewModel() + viewModel: PersonalProfileViewModel = hiltViewModel(), + onNavigateToAccountSwitch: () -> Unit ){ //bia info @@ -383,5 +390,25 @@ fun Loaded_setting_profile_page( } } + + + //switch account button + Spacer(modifier = Modifier.height(20.dp)) // 將按鈕推到底部 + + Button( + onClick = onNavigateToAccountSwitch, + modifier = Modifier + .fillMaxWidth() + .padding(10.dp), + colors = ButtonDefaults.buttonColors( + containerColor = MaterialTheme.colorScheme.secondaryContainer, + contentColor = MaterialTheme.colorScheme.onSecondaryContainer + ), + shape = RoundedCornerShape(12.dp) + ) { + Icon(Icons.Default.ManageAccounts, contentDescription = null) + Spacer(modifier = Modifier.width(8.dp)) + Text("Manage & Switch Accounts") + } } } \ No newline at end of file diff --git a/app/src/main/java/com/example/login_v3/navigation/MainViewModel.kt b/app/src/main/java/com/example/login_v3/navigation/MainViewModel.kt index 3b4dd6b..f39fb4e 100644 --- a/app/src/main/java/com/example/login_v3/navigation/MainViewModel.kt +++ b/app/src/main/java/com/example/login_v3/navigation/MainViewModel.kt @@ -31,7 +31,7 @@ class MainViewModel : ViewModel() { //init navigation enum class AppScreen { - PreReg, Login, Register, Home, ScreensTab, Loading + PreReg, Login, Register, Home, ScreensTab, Loading, AccountSwitch } @HiltViewModel diff --git a/app/src/main/java/com/example/login_v3/navigation/nav_controller.kt b/app/src/main/java/com/example/login_v3/navigation/nav_controller.kt index fbe9537..bc85de8 100644 --- a/app/src/main/java/com/example/login_v3/navigation/nav_controller.kt +++ b/app/src/main/java/com/example/login_v3/navigation/nav_controller.kt @@ -14,6 +14,7 @@ import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.viewmodel.compose.viewModel import com.example.login_v3.auth.login.LoginScreen import com.example.login_v3.auth.Login_or_Reg_page +import com.example.login_v3.auth.SwitchAccount.AccountSwitchScreen import com.example.login_v3.auth.reg.RegisterScreen import com.example.login_v3.auth.reg.Register_Screen import com.example.login_v3.home.HomeScreen @@ -64,5 +65,14 @@ fun AppNavGraph( ) AppScreen.ScreensTab -> MainScreen_tab() + + AppScreen.AccountSwitch -> { + AccountSwitchScreen( + // 點擊「登入另一個帳號」就跳轉到 Login 頁面 + onAddAccountClick = { appViewModel.goTo(AppScreen.Login) }, + // 點擊返回則回到原本的主分頁 (ScreensTab) + onBack = { appViewModel.goTo(AppScreen.ScreensTab) } + ) + } } } \ No newline at end of file