From 95cbb63606140ef4fafa3b17a88bfb2e3a58611d Mon Sep 17 00:00:00 2001 From: Eric85710 Date: Sat, 2 May 2026 17:12:26 +0800 Subject: [PATCH] auth to server-V36 --- .../detail_UI/setting_Profile_Page.kt | 30 +++++++++++++++---- .../viewmodel/Profile_Viewmodel.kt | 13 ++++++++ 2 files changed, 38 insertions(+), 5 deletions(-) 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 099fbc2..6e9fcbf 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 @@ -3,6 +3,7 @@ package com.example.login_v3.home.setting.setting_detail_page.detail_UI import androidx.compose.foundation.Image import androidx.compose.foundation.background import androidx.compose.foundation.border +import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row @@ -24,6 +25,9 @@ import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.blur @@ -75,6 +79,9 @@ fun Setting_profile_page( fun Loaded_setting_profile_page( profile: UserProfile ){ + //bia info + var showDialog by remember { mutableStateOf(false) } + var tempBio by remember { mutableStateOf(profile.bio ?: "") } Column( modifier = Modifier.fillMaxSize() @@ -241,11 +248,24 @@ fun Loaded_setting_profile_page( ) //intro - Text( - text = "Founder of JFF studios,Software Dev Guy,3D Artist", - fontSize = 16.sp, - color = MaterialTheme.colorScheme.onBackground - ) + Box( + modifier = Modifier + .fillMaxWidth() + .padding(top = 8.dp) + .clickable { + tempBio = profile.bio ?: "" // 開啟時同步目前的 bio + showDialog = true + } + .border(1.dp, Color.White.copy(alpha = 0.3f), RoundedCornerShape(8.dp)) + .padding(16.dp) + ) { + // 這裡改用 profile.bio + Text( + text = if (profile.bio.isNullOrBlank()) "Add a bio..." else profile.bio, + color = if (profile.bio.isNullOrBlank()) Color.Gray else Color.White + ) + } + } } } diff --git a/app/src/main/java/com/example/login_v3/home/setting/setting_detail_page/viewmodel/Profile_Viewmodel.kt b/app/src/main/java/com/example/login_v3/home/setting/setting_detail_page/viewmodel/Profile_Viewmodel.kt index 1edce9a..856ad70 100644 --- a/app/src/main/java/com/example/login_v3/home/setting/setting_detail_page/viewmodel/Profile_Viewmodel.kt +++ b/app/src/main/java/com/example/login_v3/home/setting/setting_detail_page/viewmodel/Profile_Viewmodel.kt @@ -3,6 +3,7 @@ package com.example.login_v3.home.setting.setting_detail_page.viewmodel import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.example.login_v3.data.api.api_class.UserProfile +import com.example.login_v3.data.api.api_class.UserProfileUpdateRequest import com.example.login_v3.data.repository.basic.PersonalProfileRepository import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableStateFlow @@ -31,6 +32,7 @@ class PersonalProfileViewModel @Inject constructor( fetchProfile() } + //get profile fun fetchProfile() { viewModelScope.launch { _uiState.value = ProfileUiState.Loading @@ -47,4 +49,15 @@ class PersonalProfileViewModel @Inject constructor( } } } + + //update profile + fun updateBio(newBio: String) { + viewModelScope.launch { + val request = UserProfileUpdateRequest(bio = newBio) + repository.patchUserProfile(request).onSuccess { + // 更新成功後,可以重新 loadProfile() 或更新本地狀態 + fetchProfile() + } + } + } } \ No newline at end of file