diff --git a/presentation/src/main/java/com/kusitms/presentation/model/home/profile/MyProfileViewModel.kt b/presentation/src/main/java/com/kusitms/presentation/model/home/profile/MyProfileViewModel.kt index 372b0f8..bce1564 100644 --- a/presentation/src/main/java/com/kusitms/presentation/model/home/profile/MyProfileViewModel.kt +++ b/presentation/src/main/java/com/kusitms/presentation/model/home/profile/MyProfileViewModel.kt @@ -1,11 +1,13 @@ package com.kusitms.presentation.model.home.profile +import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.kusitms.domain.model.home.MemberInfoDetailModel import com.kusitms.domain.model.login.LoginMemberProfile import com.kusitms.domain.usecase.home.GetMemberInfoDetailUseCase import com.kusitms.domain.usecase.signin.GetLoginMemberProfileUseCase +import com.kusitms.presentation.model.profile.detail.ProfileDetailViewModel import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.catch @@ -23,6 +25,7 @@ class MyProfileViewModel @Inject constructor( var infoProfile: LoginMemberProfile = _infoProfile val detailMemberInfo = getMemberInfoDetailUseCase().catch { + }.stateIn( viewModelScope, started = SharingStarted.Eagerly, @@ -42,4 +45,6 @@ class MyProfileViewModel @Inject constructor( } } } + + } \ No newline at end of file diff --git a/presentation/src/main/java/com/kusitms/presentation/model/profile/edit/ProfileEditViewModel.kt b/presentation/src/main/java/com/kusitms/presentation/model/profile/edit/ProfileEditViewModel.kt index 1c72ff4..dd57461 100644 --- a/presentation/src/main/java/com/kusitms/presentation/model/profile/edit/ProfileEditViewModel.kt +++ b/presentation/src/main/java/com/kusitms/presentation/model/profile/edit/ProfileEditViewModel.kt @@ -13,32 +13,31 @@ import com.kusitms.presentation.model.signIn.LinkType import com.kusitms.presentation.model.signIn.SignInStatus import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.catch -import kotlinx.coroutines.flow.stateIn +import kotlinx.coroutines.flow.map +import kotlinx.coroutines.flow.single import kotlinx.coroutines.launch import javax.inject.Inject @HiltViewModel class ProfileEditViewModel @Inject constructor( private val getInfoMemberUseCase: GetLoginMemberProfileUseCase, - getMemberInfoDetailUseCase: GetMemberInfoDetailUseCase, + private val getMemberInfoDetailUseCase: GetMemberInfoDetailUseCase, ) : ViewModel() { + private var _infoProfile: LoginMemberProfile = LoginMemberProfile("", "", "", "", false) var infoProfile: LoginMemberProfile = _infoProfile - val detailMemberInfo = getMemberInfoDetailUseCase().catch { - }.stateIn( - viewModelScope, - started = SharingStarted.Eagerly, - initialValue = MemberInfoDetailModel() - ) + private val _detailMemberInfo = MutableStateFlow(null) + val detailMemberInfo: StateFlow = _detailMemberInfo.asStateFlow() + init { getUserProfile() + getMemberInfoDetail() } private val _uiState = MutableStateFlow(ProfileEditUiState()) @@ -66,7 +65,7 @@ class ProfileEditViewModel @Inject constructor( val phoneNum: StateFlow = _phoneNum private val _email = MutableStateFlow("") - val email: StateFlow = _email + val email: MutableStateFlow = _email private val _emailError = MutableStateFlow(null) val emailError: StateFlow = _emailError @@ -85,7 +84,7 @@ class ProfileEditViewModel @Inject constructor( val introduce: StateFlow = _introduce private val _signInStatus = MutableStateFlow(SignInStatus.DEFAULT) - val signInStatus : StateFlow = _signInStatus + val signInStatus: StateFlow = _signInStatus private val _selectedPart = MutableStateFlow(null) val selectedPart: StateFlow = _selectedPart @@ -149,7 +148,6 @@ class ProfileEditViewModel @Inject constructor( } - fun addLinkItem() { val newLinkItem = LinkItem(LinkType.LINK, "") //기본 설정값 _linkItems.value = _linkItems.value + newLinkItem @@ -199,10 +197,33 @@ class ProfileEditViewModel @Inject constructor( if (profileResult.isSuccess) { _infoProfile = profileResult.getOrNull()!! _name.value = _infoProfile.name - _email.value = infoProfile.email - _phoneNum.value = infoProfile.phoneNumber + _email.value = _infoProfile.email + _phoneNum.value = _infoProfile.phoneNumber infoProfile = _infoProfile } } } + + private fun getMemberInfoDetail() { + viewModelScope.launch { + try { + val detailResult = getMemberInfoDetailUseCase() + .map { Result.success(it) } + .catch { exception -> + emit(Result.failure(exception)) + } + .single() + + detailResult.onSuccess { detailInfo -> + _detailMemberInfo.value = detailInfo + _major.value = detailInfo.major + }.onFailure { exception -> + } + } catch (e: Exception) { + } + } + } + + + } \ No newline at end of file diff --git a/presentation/src/main/java/com/kusitms/presentation/ui/home/profile/MyProfileScreen.kt b/presentation/src/main/java/com/kusitms/presentation/ui/home/profile/MyProfileScreen.kt index 1ba7b6e..6b5e71e 100644 --- a/presentation/src/main/java/com/kusitms/presentation/ui/home/profile/MyProfileScreen.kt +++ b/presentation/src/main/java/com/kusitms/presentation/ui/home/profile/MyProfileScreen.kt @@ -9,6 +9,7 @@ import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource diff --git a/presentation/src/main/java/com/kusitms/presentation/ui/profile/edit/ProfileAdd.kt b/presentation/src/main/java/com/kusitms/presentation/ui/profile/edit/ProfileAdd.kt index e7766d4..8a9efdd 100644 --- a/presentation/src/main/java/com/kusitms/presentation/ui/profile/edit/ProfileAdd.kt +++ b/presentation/src/main/java/com/kusitms/presentation/ui/profile/edit/ProfileAdd.kt @@ -97,7 +97,7 @@ fun ProfileAdd( @OptIn(ExperimentalCoroutinesApi::class) @Composable fun PhotoColumn(viewModel: ProfileEditViewModel) { - val imageUri by viewModel.selectedImage.collectAsState() // This should be a Uri? in your ViewModel + val imageUri by viewModel.selectedImage.collectAsState() val imagePickerLauncher = rememberLauncherForActivityResult(ActivityResultContracts.GetContent()) { uri: Uri? -> diff --git a/presentation/src/main/java/com/kusitms/presentation/ui/profile/edit/ProfileBasic.kt b/presentation/src/main/java/com/kusitms/presentation/ui/profile/edit/ProfileBasic.kt index 5851b23..5a52422 100644 --- a/presentation/src/main/java/com/kusitms/presentation/ui/profile/edit/ProfileBasic.kt +++ b/presentation/src/main/java/com/kusitms/presentation/ui/profile/edit/ProfileBasic.kt @@ -38,6 +38,7 @@ import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import androidx.hilt.navigation.compose.hiltViewModel +import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.kusitms.presentation.R import com.kusitms.presentation.common.ui.KusitmsMarginHorizontalSpacer import com.kusitms.presentation.common.ui.KusitmsMarginVerticalSpacer diff --git a/presentation/src/main/java/com/kusitms/presentation/ui/profile/edit/ProfileEditScreen.kt b/presentation/src/main/java/com/kusitms/presentation/ui/profile/edit/ProfileEditScreen.kt index 02b1e8a..faa4c2b 100644 --- a/presentation/src/main/java/com/kusitms/presentation/ui/profile/edit/ProfileEditScreen.kt +++ b/presentation/src/main/java/com/kusitms/presentation/ui/profile/edit/ProfileEditScreen.kt @@ -47,6 +47,8 @@ fun ProfileEditScreen( ) { val scrollState = rememberScrollState() + val infoUser = viewModel.infoProfile + val detailMemberInfo = viewModel.detailMemberInfo val expanded by viewModel.expended.collectAsStateWithLifecycle() val uiState by viewModel.uiState.collectAsState() @@ -118,8 +120,6 @@ private fun ProfileFilterButton( viewModel: ProfileEditViewModel, ) { val uiState by viewModel.uiState.collectAsState() - val infoUser = viewModel.infoProfile - val detailMemberInfo by viewModel.detailMemberInfo.collectAsStateWithLifecycle() Row(