diff --git a/feature/navigator/src/main/java/com/susu/feature/navigator/MainNavigator.kt b/feature/navigator/src/main/java/com/susu/feature/navigator/MainNavigator.kt index c2701c25..f653eb21 100644 --- a/feature/navigator/src/main/java/com/susu/feature/navigator/MainNavigator.kt +++ b/feature/navigator/src/main/java/com/susu/feature/navigator/MainNavigator.kt @@ -11,6 +11,7 @@ import androidx.navigation.navOptions import com.susu.core.designsystem.theme.SusuTheme import com.susu.core.model.Envelope import com.susu.core.model.EnvelopeDetail +import com.susu.core.model.Friend import com.susu.core.model.Ledger import com.susu.core.model.Vote import com.susu.feature.community.navigation.CommunityRoute @@ -123,8 +124,8 @@ internal class MainNavigator( navController.navigateSentEnvelopeEdit(envelopeDetail) } - fun navigateSentEnvelopeAdd() { - navController.navigateSentEnvelopeAdd() + fun navigateSentEnvelopeAdd(friend: Friend? = null) { + navController.navigateSentEnvelopeAdd(friend) } fun navigateSentEnvelopeSearch() { 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 bdee2b79..515a78a4 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 @@ -1,11 +1,13 @@ package com.susu.feature.envelopeadd +import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.viewModelScope import com.susu.core.model.Category import com.susu.core.model.Relationship import com.susu.core.ui.MONEY_MAX_VALUE import com.susu.core.ui.base.BaseViewModel 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 @@ -15,7 +17,9 @@ import javax.inject.Inject @HiltViewModel class EnvelopeAddViewModel @Inject constructor( private val createSentEnvelopeUseCase: CreateSentEnvelopeUseCase, + savedStateHandle: SavedStateHandle, ) : BaseViewModel(EnvelopeAddState()) { + private val friendArgument = savedStateHandle.get(SentRoute.FRIEND_ARGUMENT_NAME) private var money: Long = 0 private var name: String = "" @@ -29,6 +33,10 @@ class EnvelopeAddViewModel @Inject constructor( private var phoneNumber: String? = null private var memo: String? = null + fun initData() { + println(friendArgument) + } + private fun createEnvelope() { viewModelScope.launch { createSentEnvelopeUseCase( 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 63be65cb..b7fd6043 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 @@ -8,6 +8,7 @@ import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.imePadding import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember @@ -67,6 +68,10 @@ fun SentEnvelopeAddRoute( mutableStateOf("") } + LaunchedEffect(key1 = Unit) { + viewModel.initData() + } + BackHandler { viewModel.goPrevStep() } diff --git a/feature/sent/src/main/java/com/susu/feature/sent/navigation/SentNavigation.kt b/feature/sent/src/main/java/com/susu/feature/sent/navigation/SentNavigation.kt index 64f5bcd6..06a1de0f 100644 --- a/feature/sent/src/main/java/com/susu/feature/sent/navigation/SentNavigation.kt +++ b/feature/sent/src/main/java/com/susu/feature/sent/navigation/SentNavigation.kt @@ -8,6 +8,7 @@ import androidx.navigation.NavType import androidx.navigation.compose.composable import androidx.navigation.navArgument import com.susu.core.model.EnvelopeDetail +import com.susu.core.model.Friend import com.susu.core.ui.DialogToken import com.susu.core.ui.SnackbarToken import com.susu.core.ui.extension.encodeToUri @@ -36,8 +37,8 @@ fun NavController.navigateSentEnvelopeEdit(envelopeDetail: EnvelopeDetail) { navigate(SentRoute.sentEnvelopeEditRoute(Json.encodeToUri(envelopeDetail))) } -fun NavController.navigateSentEnvelopeAdd() { - navigate(SentRoute.sentEnvelopeAddRoute) +fun NavController.navigateSentEnvelopeAdd(friend: Friend?) { + navigate(SentRoute.sentEnvelopeAddRoute(Json.encodeToUri(friend))) } fun NavController.navigateSentEnvelopeSearch() { @@ -134,7 +135,7 @@ fun NavGraphBuilder.sentNavGraph( ) } - composable(route = SentRoute.sentEnvelopeAddRoute) { + composable(route = SentRoute.sentEnvelopeAddRoute("{${SentRoute.FRIEND_ARGUMENT_NAME}}")) { SentEnvelopeAddRoute( popBackStack = popBackStack, popBackStackWithRefresh = popBackStackWithRefresh, @@ -163,8 +164,10 @@ fun NavGraphBuilder.sentNavGraph( object SentRoute { const val route = "sent" - const val sentEnvelopeAddRoute = "sent-envelope-add" const val SENT_REFRESH_ARGUMENT_NAME = "sent-refresh" + fun sentEnvelopeAddRoute(friend: String) = "sent-envelope-add/$friend" + const val FRIEND_ARGUMENT_NAME = "sent-friend" + fun sentEnvelopeRoute(id: String) = "sent-envelope/$id" const val FRIEND_ID_ARGUMENT_NAME = "sent-envelope-id" const val EDITED_FRIEND_ID_ARGUMENT_NAME = "edited-friend-id"