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 68a506d commit b49b764
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,45 @@ package com.kusitms.presentation.model.profile.edit

import android.net.Uri
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.signIn.InterestItem
import com.kusitms.presentation.model.signIn.LinkItem
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.launch
import javax.inject.Inject

@HiltViewModel
class ProfileEditViewModel @Inject constructor(

private val getInfoMemberUseCase: GetLoginMemberProfileUseCase,
getMemberInfoDetailUseCase: GetMemberInfoDetailUseCase,
) : ViewModel() {

private var _infoProfile: LoginMemberProfile = LoginMemberProfile("", "", "", "", false)
var infoProfile: LoginMemberProfile = _infoProfile

val detailMemberInfo = getMemberInfoDetailUseCase().catch {
}.stateIn(
viewModelScope,
started = SharingStarted.Eagerly,
initialValue = MemberInfoDetailModel()
)

init {
getUserProfile()
}

private val _uiState = MutableStateFlow(ProfileEditUiState())
val uiState: StateFlow<ProfileEditUiState> = _uiState.asStateFlow()

Expand Down Expand Up @@ -167,4 +192,17 @@ class ProfileEditViewModel @Inject constructor(
return phoneNumber.matches(phoneRegex)
}


private fun getUserProfile() {
viewModelScope.launch {
val profileResult = getInfoMemberUseCase.fetchLoginMemberProfile()
if (profileResult.isSuccess) {
_infoProfile = profileResult.getOrNull()!!
_name.value = _infoProfile.name
_email.value = infoProfile.email
_phoneNum.value = infoProfile.phoneNumber
infoProfile = _infoProfile
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import com.kusitms.presentation.common.ui.theme.KusitmsColorPalette
import com.kusitms.presentation.common.ui.theme.KusitmsTypo
import com.kusitms.presentation.model.login.LoginStatus
import com.kusitms.presentation.model.login.LoginViewModel
import com.kusitms.presentation.model.signIn.InputState
import com.kusitms.presentation.ui.signIn.KusitmsInputField

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ private fun ProfileFilterButton(
viewModel: ProfileEditViewModel,
) {
val uiState by viewModel.uiState.collectAsState()
val infoUser = viewModel.infoProfile
val detailMemberInfo by viewModel.detailMemberInfo.collectAsStateWithLifecycle()


Row(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,15 @@ import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.ScaffoldState
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
import androidx.navigation.NavHostController
import androidx.navigation.compose.rememberNavController
import com.kusitms.presentation.R
import com.kusitms.presentation.common.theme.KusitmsScaffoldNonScroll
import com.kusitms.presentation.common.ui.KusitmsMarginVerticalSpacer
Expand All @@ -33,7 +30,6 @@ import com.kusitms.presentation.ui.signIn.KusitmsInputField
import com.kusitms.presentation.ui.signIn.PartBottomSheet
import com.kusitms.presentation.ui.signIn.SignInFixedInput
import com.kusitms.presentation.ui.signIn.component.LikeCatergoryBottomSheet
import kotlinx.coroutines.launch


@Composable
Expand Down
1 change: 1 addition & 0 deletions presentation/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@
<string name="profile_edit_filter">프로필 선택 필터</string>
<string name="profile_edit_basic">기본 프로필</string>
<string name="profile_edit_add">추가 프로필</string>
<string name="profile_edit_major_hint">%s</string>



Expand Down

0 comments on commit b49b764

Please sign in to comment.