diff --git a/feature/sent/src/main/java/com/susu/feature/envelopeadd/EnvelopeAddContract.kt b/feature/sent/src/main/java/com/susu/feature/envelopeadd/EnvelopeAddContract.kt index 52705939..598e2072 100644 --- a/feature/sent/src/main/java/com/susu/feature/envelopeadd/EnvelopeAddContract.kt +++ b/feature/sent/src/main/java/com/susu/feature/envelopeadd/EnvelopeAddContract.kt @@ -9,11 +9,16 @@ sealed interface EnvelopeAddEffect : SideEffect { data class HandleException(val throwable: Throwable, val retry: () -> Unit) : EnvelopeAddEffect } +/** + * @param fromEnvelope 보내요 봉투 화면에서 추가 화면으로 진입할 시 true. MORE STEP에서 전화번호를 감추기 위함. + * */ data class EnvelopeAddState( val isLoading: Boolean = false, val buttonEnabled: Boolean = false, val currentStep: EnvelopeAddStep = EnvelopeAddStep.MONEY, val lastPage: Boolean = false, + val friendName: String = "", + val fromEnvelope: Boolean = false, ) : UiState { val buttonResId = if (lastPage) { com.susu.core.ui.R.string.word_done diff --git a/feature/sent/src/main/java/com/susu/feature/envelopeadd/EnvelopeAddViewModel.kt b/feature/sent/src/main/java/com/susu/feature/envelopeadd/EnvelopeAddViewModel.kt index 515a78a4..ee0d323b 100644 --- a/feature/sent/src/main/java/com/susu/feature/envelopeadd/EnvelopeAddViewModel.kt +++ b/feature/sent/src/main/java/com/susu/feature/envelopeadd/EnvelopeAddViewModel.kt @@ -3,14 +3,17 @@ package com.susu.feature.envelopeadd import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.viewModelScope import com.susu.core.model.Category +import com.susu.core.model.Friend import com.susu.core.model.Relationship import com.susu.core.ui.MONEY_MAX_VALUE import com.susu.core.ui.base.BaseViewModel +import com.susu.core.ui.extension.decodeFromUri import com.susu.domain.usecase.envelope.CreateSentEnvelopeUseCase import com.susu.feature.sent.navigation.SentRoute import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.launch import kotlinx.datetime.toKotlinLocalDateTime +import kotlinx.serialization.json.Json import java.time.LocalDateTime import javax.inject.Inject @@ -19,10 +22,13 @@ class EnvelopeAddViewModel @Inject constructor( private val createSentEnvelopeUseCase: CreateSentEnvelopeUseCase, savedStateHandle: SavedStateHandle, ) : BaseViewModel(EnvelopeAddState()) { - private val friendArgument = savedStateHandle.get(SentRoute.FRIEND_ARGUMENT_NAME) + private val friendArgument = runCatching { + savedStateHandle.get(SentRoute.FRIEND_ARGUMENT_NAME)?.let { + Json.decodeFromUri(it) + } + }.getOrNull() private var money: Long = 0 - private var name: String = "" private var friendId: Long? = null private var relationShip: Relationship? = null private var category: Category? = null @@ -34,7 +40,12 @@ class EnvelopeAddViewModel @Inject constructor( private var memo: String? = null fun initData() { - println(friendArgument) + friendArgument?.let { + updateFriendId(it.id) + updateName(it.name) + updatePhoneNumber(it.phoneNumber.ifEmpty { null }) + intent { copy(fromEnvelope = true) } + } ?: intent { copy(fromEnvelope = false) } } private fun createEnvelope() { @@ -42,7 +53,7 @@ class EnvelopeAddViewModel @Inject constructor( createSentEnvelopeUseCase( param = CreateSentEnvelopeUseCase.Param( friendId = friendId, - friendName = name, + friendName = currentState.friendName, phoneNumber = phoneNumber, relationshipId = relationShip?.id, customRelation = relationShip?.customRelation, @@ -63,7 +74,14 @@ class EnvelopeAddViewModel @Inject constructor( fun goNextStep() { when (uiState.value.currentStep) { - EnvelopeAddStep.MONEY -> intent { copy(currentStep = EnvelopeAddStep.NAME) } + EnvelopeAddStep.MONEY -> { + if (friendArgument == null) { + intent { copy(currentStep = EnvelopeAddStep.NAME) } + } else { + intent { copy(currentStep = EnvelopeAddStep.EVENT) } + } + } + EnvelopeAddStep.NAME -> { intent { if (friendId == null) { @@ -97,13 +115,12 @@ class EnvelopeAddViewModel @Inject constructor( EnvelopeAddStep.NAME -> intent { copy(currentStep = EnvelopeAddStep.MONEY) } EnvelopeAddStep.RELATIONSHIP -> intent { copy(currentStep = EnvelopeAddStep.NAME) } EnvelopeAddStep.EVENT -> { - intent { - if (friendId == null) { - copy(currentStep = EnvelopeAddStep.RELATIONSHIP) - } else { - copy(currentStep = EnvelopeAddStep.NAME) - } + val prevStep = when { + friendId == null -> EnvelopeAddStep.RELATIONSHIP + friendArgument != null -> EnvelopeAddStep.MONEY + else -> EnvelopeAddStep.NAME } + intent { copy(currentStep = prevStep) } } EnvelopeAddStep.DATE -> intent { copy(currentStep = EnvelopeAddStep.EVENT) } @@ -133,8 +150,7 @@ class EnvelopeAddViewModel @Inject constructor( } fun updateName(name: String) = intent { - this@EnvelopeAddViewModel.name = name - copy(buttonEnabled = name.isNotEmpty()) + copy(friendName = name, buttonEnabled = name.isNotEmpty()) } fun updateFriendId(friendId: Long?) { diff --git a/feature/sent/src/main/java/com/susu/feature/envelopeadd/SentEnvelopeAddScreen.kt b/feature/sent/src/main/java/com/susu/feature/envelopeadd/SentEnvelopeAddScreen.kt index b7fd6043..0739bdcf 100644 --- a/feature/sent/src/main/java/com/susu/feature/envelopeadd/SentEnvelopeAddScreen.kt +++ b/feature/sent/src/main/java/com/susu/feature/envelopeadd/SentEnvelopeAddScreen.kt @@ -60,10 +60,6 @@ fun SentEnvelopeAddRoute( } } - var friendName by remember { - mutableStateOf("") - } - var categoryName by remember { mutableStateOf("") } @@ -78,15 +74,11 @@ fun SentEnvelopeAddRoute( SentEnvelopeAddScreen( uiState = uiState, - friendName = friendName, categoryName = categoryName, onClickBack = viewModel::goPrevStep, onClickNext = viewModel::goNextStep, updateParentMoney = viewModel::updateMoney, - updateParentName = { name -> - viewModel.updateName(name) - friendName = name - }, + updateParentName = viewModel::updateName, updateParentFriendId = viewModel::updateFriendId, updateParentSelectedRelation = viewModel::updateSelectedRelationShip, updateParentCategory = { category -> @@ -106,7 +98,6 @@ fun SentEnvelopeAddRoute( @Composable fun SentEnvelopeAddScreen( uiState: EnvelopeAddState = EnvelopeAddState(), - friendName: String = "", onClickBack: () -> Unit = {}, onClickNext: () -> Unit = {}, updateParentMoney: (Long) -> Unit = {}, @@ -170,11 +161,12 @@ fun SentEnvelopeAddScreen( ) EnvelopeAddStep.DATE -> DateContentRoute( - friendName = friendName, + friendName = uiState.friendName, updateParentDate = updateParentDate, ) EnvelopeAddStep.MORE -> MoreContentRoute( + fromEnvelope = uiState.fromEnvelope, updateParentMoreStep = updateParentMoreStep, ) @@ -189,7 +181,7 @@ fun SentEnvelopeAddScreen( ) EnvelopeAddStep.PHONE -> PhoneContentRoute( - friendName = friendName, + friendName = uiState.friendName, updateParentPhone = updateParentPhoneNumber, onShowSnackbar = onShowSnackbar, ) diff --git a/feature/sent/src/main/java/com/susu/feature/envelopeadd/content/more/MoreContent.kt b/feature/sent/src/main/java/com/susu/feature/envelopeadd/content/more/MoreContent.kt index e49d815a..bd447079 100644 --- a/feature/sent/src/main/java/com/susu/feature/envelopeadd/content/more/MoreContent.kt +++ b/feature/sent/src/main/java/com/susu/feature/envelopeadd/content/more/MoreContent.kt @@ -34,6 +34,7 @@ import com.susu.feature.sent.R @Composable fun MoreContentRoute( viewModel: MoreViewModel = hiltViewModel(), + fromEnvelope: Boolean, updateParentMoreStep: (List) -> Unit, ) { val uiState = viewModel.uiState.collectAsStateWithLifecycle().value @@ -45,6 +46,7 @@ fun MoreContentRoute( MoreContent( uiState = uiState, + fromEnvelope = fromEnvelope, onClickStepButton = viewModel::toggleStep, ) } @@ -57,6 +59,7 @@ fun MoreContent( vertical = SusuTheme.spacing.spacing_xl, ), uiState: MoreState = MoreState(), + fromEnvelope: Boolean = false, onClickStepButton: (EnvelopeAddStep) -> Unit = {}, ) { val scrollState = rememberScrollState() @@ -88,7 +91,9 @@ fun MoreContent( Column( verticalArrangement = Arrangement.spacedBy(SusuTheme.spacing.spacing_xxs), ) { - moreStep.forEach { (step, stringRes) -> + for ((step, stringRes) in moreStep) { + if (fromEnvelope && step == EnvelopeAddStep.PHONE) continue + if (step in uiState.selectedMoreStop) { SusuFilledButton( color = FilledButtonColor.Orange,