Skip to content

Commit

Permalink
FEAT: 기본 프로필 세팅 (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
arinming committed Feb 7, 2024
1 parent b49b764 commit 6067707
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -23,6 +25,7 @@ class MyProfileViewModel @Inject constructor(
var infoProfile: LoginMemberProfile = _infoProfile

val detailMemberInfo = getMemberInfoDetailUseCase().catch {

}.stateIn(
viewModelScope,
started = SharingStarted.Eagerly,
Expand All @@ -42,4 +45,6 @@ class MyProfileViewModel @Inject constructor(
}
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -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<MemberInfoDetailModel?>(null)
val detailMemberInfo: StateFlow<MemberInfoDetailModel?> = _detailMemberInfo.asStateFlow()


init {
getUserProfile()
getMemberInfoDetail()
}

private val _uiState = MutableStateFlow(ProfileEditUiState())
Expand Down Expand Up @@ -66,7 +65,7 @@ class ProfileEditViewModel @Inject constructor(
val phoneNum: StateFlow<String> = _phoneNum

private val _email = MutableStateFlow("")
val email: StateFlow<String> = _email
val email: MutableStateFlow<String> = _email

private val _emailError = MutableStateFlow<String?>(null)
val emailError: StateFlow<String?> = _emailError
Expand All @@ -85,7 +84,7 @@ class ProfileEditViewModel @Inject constructor(
val introduce: StateFlow<String> = _introduce

private val _signInStatus = MutableStateFlow(SignInStatus.DEFAULT)
val signInStatus : StateFlow<SignInStatus> = _signInStatus
val signInStatus: StateFlow<SignInStatus> = _signInStatus

private val _selectedPart = MutableStateFlow<String?>(null)
val selectedPart: StateFlow<String?> = _selectedPart
Expand Down Expand Up @@ -149,7 +148,6 @@ class ProfileEditViewModel @Inject constructor(
}



fun addLinkItem() {
val newLinkItem = LinkItem(LinkType.LINK, "") //기본 설정값
_linkItems.value = _linkItems.value + newLinkItem
Expand Down Expand Up @@ -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<MemberInfoDetailModel>(exception))
}
.single()

detailResult.onSuccess { detailInfo ->
_detailMemberInfo.value = detailInfo
_major.value = detailInfo.major
}.onFailure { exception ->
}
} catch (e: Exception) {
}
}
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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? ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 6067707

Please sign in to comment.