auth to server-V92
This commit is contained in:
parent
fae89ee041
commit
3bdddba40e
4 changed files with 50 additions and 6 deletions
|
|
@ -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_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.detail_UI.setting_theme_page
|
||||||
import com.example.login_v3.home.setting.setting_detail_page.viewmodel.Theme_ViewModel
|
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
|
import com.example.login_v3.navigation.BottomBarViewModel
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
|
|
@ -50,7 +52,8 @@ fun SharedTransitionScope.setting_detail_Screen(
|
||||||
title: String,
|
title: String,
|
||||||
settingIcon: String,
|
settingIcon: String,
|
||||||
animatedVisibilityScope: AnimatedVisibilityScope,
|
animatedVisibilityScope: AnimatedVisibilityScope,
|
||||||
bottomBarViewModel: BottomBarViewModel = hiltViewModel()
|
bottomBarViewModel: BottomBarViewModel = hiltViewModel(),
|
||||||
|
appViewModel: AppViewModel = hiltViewModel()
|
||||||
){
|
){
|
||||||
//control bottom bar behavior
|
//control bottom bar behavior
|
||||||
DisposableEffect(Unit) {
|
DisposableEffect(Unit) {
|
||||||
|
|
@ -123,7 +126,11 @@ fun SharedTransitionScope.setting_detail_Screen(
|
||||||
startDestination = startRoute
|
startDestination = startRoute
|
||||||
) {
|
) {
|
||||||
|
|
||||||
composable("setting_Profile") { Setting_profile_page() }
|
composable("setting_Profile") { Setting_profile_page(
|
||||||
|
onNavigateToAccountSwitch = {
|
||||||
|
appViewModel.goTo(AppScreen.AccountSwitch)
|
||||||
|
}
|
||||||
|
) }
|
||||||
composable("setting_Theme") {
|
composable("setting_Theme") {
|
||||||
val activity = LocalActivity.current as ComponentActivity
|
val activity = LocalActivity.current as ComponentActivity
|
||||||
val vm: Theme_ViewModel = hiltViewModel(viewModelStoreOwner = activity)
|
val vm: Theme_ViewModel = hiltViewModel(viewModelStoreOwner = activity)
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,10 @@ import androidx.compose.foundation.shape.CircleShape
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.Edit
|
import androidx.compose.material.icons.filled.Edit
|
||||||
|
import androidx.compose.material.icons.filled.ManageAccounts
|
||||||
import androidx.compose.material3.AlertDialog
|
import androidx.compose.material3.AlertDialog
|
||||||
import androidx.compose.material3.Button
|
import androidx.compose.material3.Button
|
||||||
|
import androidx.compose.material3.ButtonDefaults
|
||||||
import androidx.compose.material3.CircularProgressIndicator
|
import androidx.compose.material3.CircularProgressIndicator
|
||||||
import androidx.compose.material3.Divider
|
import androidx.compose.material3.Divider
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
|
|
@ -64,7 +66,8 @@ import com.example.login_v3.ui.theme.main_orange
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun Setting_profile_page(
|
fun Setting_profile_page(
|
||||||
viewModel: PersonalProfileViewModel = hiltViewModel()
|
viewModel: PersonalProfileViewModel = hiltViewModel(),
|
||||||
|
onNavigateToAccountSwitch: () -> Unit
|
||||||
) {
|
) {
|
||||||
val uiState by viewModel.uiState.collectAsState()
|
val uiState by viewModel.uiState.collectAsState()
|
||||||
when (val state = uiState) {
|
when (val state = uiState) {
|
||||||
|
|
@ -73,7 +76,10 @@ fun Setting_profile_page(
|
||||||
}
|
}
|
||||||
is ProfileUiState.Success -> {
|
is ProfileUiState.Success -> {
|
||||||
// 顯示個人資料
|
// 顯示個人資料
|
||||||
Loaded_setting_profile_page(state.profile)
|
Loaded_setting_profile_page(
|
||||||
|
profile = state.profile,
|
||||||
|
onNavigateToAccountSwitch = onNavigateToAccountSwitch // 補上這行
|
||||||
|
)
|
||||||
}
|
}
|
||||||
is ProfileUiState.Error -> {
|
is ProfileUiState.Error -> {
|
||||||
// 顯示錯誤訊息與重試按鈕
|
// 顯示錯誤訊息與重試按鈕
|
||||||
|
|
@ -98,7 +104,8 @@ sealed class EditTarget(val title: String) {
|
||||||
@Composable
|
@Composable
|
||||||
fun Loaded_setting_profile_page(
|
fun Loaded_setting_profile_page(
|
||||||
profile: UserProfile,
|
profile: UserProfile,
|
||||||
viewModel: PersonalProfileViewModel = hiltViewModel()
|
viewModel: PersonalProfileViewModel = hiltViewModel(),
|
||||||
|
onNavigateToAccountSwitch: () -> Unit
|
||||||
){
|
){
|
||||||
|
|
||||||
//bia info
|
//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")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -31,7 +31,7 @@ class MainViewModel : ViewModel() {
|
||||||
|
|
||||||
//init navigation
|
//init navigation
|
||||||
enum class AppScreen {
|
enum class AppScreen {
|
||||||
PreReg, Login, Register, Home, ScreensTab, Loading
|
PreReg, Login, Register, Home, ScreensTab, Loading, AccountSwitch
|
||||||
}
|
}
|
||||||
|
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ import androidx.hilt.navigation.compose.hiltViewModel
|
||||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||||
import com.example.login_v3.auth.login.LoginScreen
|
import com.example.login_v3.auth.login.LoginScreen
|
||||||
import com.example.login_v3.auth.Login_or_Reg_page
|
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.RegisterScreen
|
||||||
import com.example.login_v3.auth.reg.Register_Screen
|
import com.example.login_v3.auth.reg.Register_Screen
|
||||||
import com.example.login_v3.home.HomeScreen
|
import com.example.login_v3.home.HomeScreen
|
||||||
|
|
@ -64,5 +65,14 @@ fun AppNavGraph(
|
||||||
)
|
)
|
||||||
|
|
||||||
AppScreen.ScreensTab -> MainScreen_tab()
|
AppScreen.ScreensTab -> MainScreen_tab()
|
||||||
|
|
||||||
|
AppScreen.AccountSwitch -> {
|
||||||
|
AccountSwitchScreen(
|
||||||
|
// 點擊「登入另一個帳號」就跳轉到 Login 頁面
|
||||||
|
onAddAccountClick = { appViewModel.goTo(AppScreen.Login) },
|
||||||
|
// 點擊返回則回到原本的主分頁 (ScreensTab)
|
||||||
|
onBack = { appViewModel.goTo(AppScreen.ScreensTab) }
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue