Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

프로필 생성 완료 다이얼로그 구현 #49

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class MainActivity : ComponentActivity() {
if (user == null) {
"RouteModel.Profile.Create"
} else {
"RouteModel.Onboarding"
"RouteModel.Onboarding?isAfterProfileCreate={isAfterProfileCreate}"
}
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ internal fun MainNavHost(
}
)
profileNavGraph(
onSaveSuccess = { navigator.navigationToOnboarding() },
onSaveSuccess = { navigator.navigationToOnboarding(isAfterProfileCreate = true) },
onBackClick = { navigator.popBackStack() }
)
settingNavGraph(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ class MainNavigator(
navController.navigateToProfileSetting()
}

fun navigationToOnboarding() {
navController.navigateToOnboarding()
fun navigationToOnboarding(isAfterProfileCreate: Boolean = false) {
navController.navigateToOnboarding(isAfterProfileCreate)
}

fun navigationToBoardSetup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,48 @@ package com.goalpanzi.mission_mate.feature.onboarding
import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavOptions
import androidx.navigation.NavType
import androidx.navigation.compose.composable
import com.goalpanzi.mission_mate.core.navigation.OnboardingRouteModel
import com.goalpanzi.mission_mate.core.navigation.RouteModel
import androidx.navigation.navArgument
import com.goalpanzi.mission_mate.feature.onboarding.screen.OnboardingRoute
import com.goalpanzi.mission_mate.feature.onboarding.screen.boardsetup.BoardSetupRoute
import com.goalpanzi.mission_mate.feature.onboarding.screen.boardsetup.BoardSetupSuccessScreen
import com.goalpanzi.mission_mate.feature.onboarding.screen.invitation.InvitationCodeRoute

internal const val isAfterProfileCreateArg = "isAfterProfileCreate"

fun NavController.navigateToOnboarding(
isAfterProfileCreate: Boolean = false,
navOptions: NavOptions? = androidx.navigation.navOptions {
popUpTo([email protected]){
popUpTo([email protected]) {
inclusive = true
}
}
) {
this.navigate("RouteModel.Onboarding",navOptions = navOptions)
this.navigate("RouteModel.Onboarding" + "?isAfterProfileCreate=${isAfterProfileCreate}", navOptions = navOptions)
}

fun NavGraphBuilder.onboardingNavGraph(
onClickBoardSetup: () -> Unit,
onClickInvitationCode: () -> Unit,
onClickSetting: () -> Unit,
onNavigateMissionBoard: (Long) -> Unit
) {
composable(
"RouteModel.Onboarding?${isAfterProfileCreateArg}={$isAfterProfileCreateArg}",
arguments = listOf(
navArgument(isAfterProfileCreateArg) {
type = NavType.BoolType
}
)
) {
OnboardingRoute(
onClickBoardSetup = onClickBoardSetup,
onClickInvitationCode = onClickInvitationCode,
onClickSetting = onClickSetting,
onNavigateMissionBoard = onNavigateMissionBoard
)
}
}

fun NavController.navigateToBoardSetup() {
Expand All @@ -27,34 +53,18 @@ fun NavController.navigateToBoardSetup() {

fun NavController.navigateToBoardSetupSuccess(
navOptions: NavOptions? = androidx.navigation.navOptions {
popUpTo([email protected]){
popUpTo([email protected]) {
inclusive = true
}
}
) {
this.navigate("OnboardingRouteModel.BoardSetupSuccess",navOptions = navOptions)
this.navigate("OnboardingRouteModel.BoardSetupSuccess", navOptions = navOptions)
}

fun NavController.navigateToInvitationCode() {
this.navigate("OnboardingRouteModel.InvitationCode")
}

fun NavGraphBuilder.onboardingNavGraph(
onClickBoardSetup: () -> Unit,
onClickInvitationCode: () -> Unit,
onClickSetting: () -> Unit,
onNavigateMissionBoard : (Long) -> Unit
) {
composable("RouteModel.Onboarding") {
OnboardingRoute(
onClickBoardSetup = onClickBoardSetup,
onClickInvitationCode = onClickInvitationCode,
onClickSetting = onClickSetting,
onNavigateMissionBoard = onNavigateMissionBoard
)
}
}

fun NavGraphBuilder.boardSetupNavGraph(
onSuccess: () -> Unit,
onBackClick: () -> Unit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ import androidx.compose.material3.Text
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
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.paint
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.layout.ContentScale
Expand All @@ -34,7 +38,12 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.goalpanzi.core.model.CharacterType
import com.goalpanzi.core.model.UserProfile
import com.goalpanzi.core.model.response.ProfileResponse
import com.goalpanzi.mission_mate.core.designsystem.component.MissionMateDialog
import com.goalpanzi.mission_mate.core.designsystem.theme.ColorGray1_FF404249
import com.goalpanzi.mission_mate.core.designsystem.theme.ColorGray2_FF4F505C
import com.goalpanzi.mission_mate.core.designsystem.theme.ColorWhite_FFFFFFFF
import com.goalpanzi.mission_mate.core.designsystem.theme.MissionMateTypography
import com.goalpanzi.mission_mate.core.designsystem.theme.component.MissionMateTopAppBar
Expand All @@ -45,7 +54,7 @@ import com.goalpanzi.mission_mate.feature.onboarding.component.OutlinedTextBox
import com.goalpanzi.mission_mate.feature.onboarding.component.StableImage
import com.goalpanzi.mission_mate.feature.onboarding.model.OnboardingResultEvent
import com.goalpanzi.mission_mate.feature.onboarding.model.OnboardingUiModel
import com.goalpanzi.core.model.response.ProfileResponse
import kotlinx.coroutines.flow.collectLatest
import com.goalpanzi.mission_mate.core.designsystem.R as designSystemResource

@Composable
Expand All @@ -54,33 +63,51 @@ fun OnboardingRoute(
onClickBoardSetup: () -> Unit,
onClickInvitationCode: () -> Unit,
onClickSetting: () -> Unit,
onNavigateMissionBoard : (Long) -> Unit,
onNavigateMissionBoard: (Long) -> Unit,
viewModel: OnboardingViewModel = hiltViewModel()
) {
val onboardingUiModel by viewModel.onboardingUiModel.collectAsStateWithLifecycle()
var profileCreateSuccessData by remember { mutableStateOf<UserProfile?>(null) }

LaunchedEffect(key1 = Unit) {
viewModel.getJoinedMissions()

viewModel.onboardingResultEvent.collect { result ->
when(result){
when (result) {
is OnboardingResultEvent.SuccessWithJoinedMissions -> {
onNavigateMissionBoard(result.mission.missionId)
}

is OnboardingResultEvent.Error -> {
// 에러
}
}
}
}

LaunchedEffect(key1 = Unit) {
viewModel.profileCreateSuccessEvent.collectLatest {
it?.let { profileCreateSuccessData = it }
}
}

OnboardingScreen(
onboardingUiModel = onboardingUiModel,
modifier = modifier.fillMaxSize(),
onClickBoardSetup = onClickBoardSetup,
onClickInvitationCode = onClickInvitationCode,
onClickSetting = onClickSetting
)

profileCreateSuccessData?.let {
ProfileCreateSuccessDialog(
nickname = it.nickname,
character = it.characterType,
onClickOk = {
profileCreateSuccessData = null
}
)
}
}

@Composable
Expand All @@ -102,7 +129,7 @@ fun OnboardingScreen(
contentDescription = null,
contentScale = ContentScale.FillWidth
)
when(onboardingUiModel){
when (onboardingUiModel) {
is OnboardingUiModel.Success -> {
Column(
modifier = modifier
Expand Down Expand Up @@ -149,7 +176,7 @@ fun OnboardingScreen(
modifier = Modifier
.fillMaxWidth(0.564f)
.wrapContentHeight(),
drawableResId = when(onboardingUiModel.profileResponse.characterType){
drawableResId = when (onboardingUiModel.profileResponse.characterType) {
"CAT" -> designSystemResource.drawable.img_cat_selected
"DOG" -> designSystemResource.drawable.img_dog_selected
"RABBIT" -> designSystemResource.drawable.img_rabbit_selected
Expand All @@ -173,9 +200,11 @@ fun OnboardingScreen(
imageId = designSystemResource.drawable.ic_creating_board,
onClick = onClickBoardSetup
)
Spacer(modifier = Modifier
.height(1.dp)
.weight(24f / 324f))
Spacer(
modifier = Modifier
.height(1.dp)
.weight(24f / 324f)
)
OnboardingNavigationButton(
modifier = Modifier.weight(162f / 324f),
titleId = R.string.onboarding_code_title,
Expand All @@ -186,6 +215,7 @@ fun OnboardingScreen(
}
}
}

is OnboardingUiModel.Loading -> {
CircularProgressIndicator(
modifier = Modifier.align(Alignment.Center)
Expand All @@ -205,13 +235,77 @@ fun TopBarSetting(
modifier = Modifier.wrapContentSize()
) {
Icon(
imageVector = ImageVector.vectorResource(id = com.goalpanzi.mission_mate.core.designsystem.R.drawable.ic_setting),
imageVector = ImageVector.vectorResource(id = designSystemResource.drawable.ic_setting),
contentDescription = "",
tint = ColorGray1_FF404249
)
}
}

@Composable
fun ProfileCreateSuccessDialog(
nickname: String,
character: CharacterType,
onClickOk: () -> Unit
) {
MissionMateDialog(
onDismissRequest = {},
onClickOk = onClickOk,
okTextId = R.string.confirm
) {
Column(
modifier = Modifier
.wrapContentHeight(),
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(
text = stringResource(
id = R.string.onboarding_profile_create_dialog_title,
nickname
),
style = MissionMateTypography.title_xl_bold,
textAlign = TextAlign.Center,
color = ColorGray1_FF404249
)
Text(
modifier = Modifier.padding(top = 12.dp),
text = stringResource(id = R.string.onboarding_profile_create_dialog_description),
style = MissionMateTypography.body_lg_regular,
textAlign = TextAlign.Center,
color = ColorGray2_FF4F505C
)
Image(
painter = painterResource(
id = when (character) {
CharacterType.RABBIT -> designSystemResource.drawable.img_rabbit_selected
CharacterType.CAT -> designSystemResource.drawable.img_cat_selected
CharacterType.DOG -> designSystemResource.drawable.img_dog_selected
CharacterType.PANDA -> designSystemResource.drawable.img_panda_selected
CharacterType.BEAR -> designSystemResource.drawable.img_bear_selected
CharacterType.BIRD -> designSystemResource.drawable.img_bird_selected
}
),
contentDescription = null,
modifier = Modifier
.padding(vertical = 32.dp)
.paint(
painter = painterResource(
when (character) {
CharacterType.RABBIT -> designSystemResource.drawable.background_rabbit
CharacterType.CAT -> designSystemResource.drawable.background_cat
CharacterType.DOG -> designSystemResource.drawable.background_dog
CharacterType.PANDA -> designSystemResource.drawable.background_panda
CharacterType.BEAR -> designSystemResource.drawable.background_bear
CharacterType.BIRD -> designSystemResource.drawable.background_bird
}
),
contentScale = ContentScale.FillWidth,
)
)
}
}
}

@Preview
@Composable
fun OnboardingScreenPreview() {
Expand All @@ -227,3 +321,13 @@ fun OnboardingScreenPreview() {
onClickSetting = {}
)
}

@Preview
@Composable
fun ProfileCreateSuccessDialogPreview() {
ProfileCreateSuccessDialog(
nickname = "Test",
character = CharacterType.CAT,
onClickOk = {}
)
}
Loading
Loading