auth to server-V36
This commit is contained in:
parent
a9475e8c78
commit
95cbb63606
2 changed files with 38 additions and 5 deletions
|
|
@ -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.Image
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.border
|
import androidx.compose.foundation.border
|
||||||
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
|
|
@ -24,6 +25,9 @@ import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.collectAsState
|
import androidx.compose.runtime.collectAsState
|
||||||
import androidx.compose.runtime.getValue
|
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.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.blur
|
import androidx.compose.ui.draw.blur
|
||||||
|
|
@ -75,6 +79,9 @@ fun Setting_profile_page(
|
||||||
fun Loaded_setting_profile_page(
|
fun Loaded_setting_profile_page(
|
||||||
profile: UserProfile
|
profile: UserProfile
|
||||||
){
|
){
|
||||||
|
//bia info
|
||||||
|
var showDialog by remember { mutableStateOf(false) }
|
||||||
|
var tempBio by remember { mutableStateOf(profile.bio ?: "") }
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier.fillMaxSize()
|
modifier = Modifier.fillMaxSize()
|
||||||
|
|
@ -241,12 +248,25 @@ fun Loaded_setting_profile_page(
|
||||||
)
|
)
|
||||||
|
|
||||||
//intro
|
//intro
|
||||||
|
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(
|
||||||
text = "Founder of JFF studios,Software Dev Guy,3D Artist",
|
text = if (profile.bio.isNullOrBlank()) "Add a bio..." else profile.bio,
|
||||||
fontSize = 16.sp,
|
color = if (profile.bio.isNullOrBlank()) Color.Gray else Color.White
|
||||||
color = MaterialTheme.colorScheme.onBackground
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -3,6 +3,7 @@ package com.example.login_v3.home.setting.setting_detail_page.viewmodel
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import com.example.login_v3.data.api.api_class.UserProfile
|
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 com.example.login_v3.data.repository.basic.PersonalProfileRepository
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
|
@ -31,6 +32,7 @@ class PersonalProfileViewModel @Inject constructor(
|
||||||
fetchProfile()
|
fetchProfile()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//get profile
|
||||||
fun fetchProfile() {
|
fun fetchProfile() {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
_uiState.value = ProfileUiState.Loading
|
_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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue