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

Feature/tgyuu/#130 #132

Merged
merged 6 commits into from
Feb 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
2 changes: 1 addition & 1 deletion app/src/main/java/com/wap/wapp/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private fun handleBottomBarState(
eventEditNavigationRoute -> setBottomBarState(false)
SurveyRoute.answerRoute("{id}") -> setBottomBarState(false)
surveyCheckRoute -> setBottomBarState(false)
SurveyCheckRoute.surveyDetailRoute("{id}") -> setBottomBarState(false)
SurveyCheckRoute.surveyDetailRoute("{id}", "{backStack}") -> setBottomBarState(false)
else -> setBottomBarState(true)
}

Expand Down
17 changes: 10 additions & 7 deletions app/src/main/java/com/wap/wapp/navigation/WappNavHost.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import com.wap.wapp.feature.profile.profilesetting.navigation.profileSettingScre
import com.wap.wapp.feature.splash.navigation.splashNavigationRoute
import com.wap.wapp.feature.splash.navigation.splashScreen
import com.wap.wapp.feature.survey.check.navigation.SurveyCheckRoute.surveyCheckRoute
import com.wap.wapp.feature.survey.check.navigation.SurveyDetailBackStack
import com.wap.wapp.feature.survey.check.navigation.navigateToSurveyCheck
import com.wap.wapp.feature.survey.check.navigation.navigateToSurveyDetail
import com.wap.wapp.feature.survey.check.navigation.surveyCheckNavGraph
Expand Down Expand Up @@ -98,6 +99,7 @@ fun WappNavHost(
navOptions { popUpTo(surveyCheckRoute) { inclusive = true } },
)
},
navigateToProfile = navController::navigateToProfile,
)
managementSurveyNavGraph(
navigateToManagement = navController::navigateToManagement,
Expand All @@ -111,16 +113,17 @@ fun WappNavHost(
navigateToSignIn = {
navController.navigateToSignIn(navOptions { popUpTo(profileNavigationRoute) })
},
navigateToSurveyDetail = { surveyId ->
navController.navigateToSurveyDetail(
surveyId = surveyId,
backStack = SurveyDetailBackStack.PROFILE,
navOptions = navOptions { popUpTo(profileNavigationRoute) },
)
},
Comment on lines +116 to +122
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

νƒœκ·œμƒ Compose Navigationμ—μ„œ μ›λž˜ λ°±μŠ€νƒ 관리λ₯Ό 인자둜 μ „λ‹¬ν•΄μ„œ κ΅¬ν˜„ν•΄μ•Ό ν•˜λ‚˜μš”?

κΈ°μ‘΄ Xmlμ—μ„œλŠ” popBackStack()μ΄λΌλŠ” λ©”μ†Œλ“œκ°€ μžˆμ–΄μ„œ, 이전 ν”„λ‘œμ νŠΈμ—μ„œ ν•΄λ‹Ή λ©”μ†Œλ“œλ₯Ό μ‚¬μš©ν–ˆμ—ˆμ–΄μš”

μ•„λ§ˆ μ„€λ¬Έ μ‘λ‹΅μ˜ 경우 말고도 λ°±μŠ€νƒκ΄€λ¦¬λ₯Ό ν•΄μ€˜μ•Όν•˜λŠ” 상황이 λ°˜λ“œμ‹œ μ°Ύμ•„μ˜¬ν…λ°,
그럴 λ•Œλ§ˆλ‹€ 이전 컴포저블을 인자둜 μ „λ‹¬ν•˜κ³  -> ν˜„μž¬ μ»΄ν¬μ €λΈ”μ—μ„œ λ°±μŠ€νƒμ„ μ €μž₯ν•˜κ³  -> 이전 λ²„νŠΌμ„ λˆ„λ₯Όλ–„ λ°±μŠ€νƒμ„ κΊΌλ‚΄μ„œ λ‹€μŒ μ „ν™˜ 인자둜 λ„˜κ²¨μ£ΌλŠ”κ²Œ 번거둜운 과정이 될 μˆ˜λ„ μžˆμ„ 것 κ°™μ•„μ„œμš” 😭

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeongjaino

ν—‰ μƒκ°ν•΄λ³΄λ‹ˆ κ·ΈλŸ¬λ„€μš”.

μ°Ύμ•„λ³΄λ‹ˆ μ•„λž˜ 처럼 popBackStack이 있긴 ν•˜λ„€μš”.

image

근데 μ–΄μ§œν”Ό main NavHostμ—μ„œ λžŒλ‹€ νŒŒλΌλ―Έν„°λ‘œ ν•˜λ‚˜ ν•˜λ‚˜ μ”© λ‹€ λ„£μ–΄μ€˜μ•Ό ν•΄μ„œ

κΈ°λŠ₯μ΄λ‚˜ κ΅¬ν˜„ν•˜λŠ” λ°μ—λŠ” λΉ„μŠ·ν•  것 κ°™μ•„μš”.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이전 Xmlμ—μ„œλŠ” λ”°λ‘œ 인자 없이 λ°”λ‘œ κ°€μž₯ μœ„μ—μžˆλŠ” μŠ€νƒ λ½‘μ•„μ€¬λŠ”λ°

ComposeλŠ” λ”°λ‘œ 라우트λ₯Ό λ„˜κ²¨μ•Ό λ˜λ„€μš”

그럼 κ²°κ΅­ 같은 λ‘œμ§μ΄κ² λ„€μš” μ’‹μŠ΅λ‹ˆλ‹€

)
attendanceScreen(
navigateToSignIn = {
navController.navigateToSignIn(
navOptions {
popUpTo(
attendanceNavigationRoute,
)
},
)
navController.navigateToSignIn(navOptions { popUpTo(attendanceNavigationRoute) })
},
navigateToAttendanceManagement = navController::navigateToAttendanceManagement,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ internal fun ProfileRoute(
navigateToProfileSetting: (String) -> Unit,
navigateToAttendance: () -> Unit,
navigateToSignIn: () -> Unit,
navigateToSurveyDetail: (String) -> Unit,
) {
val todayEventsState by viewModel.todayEvents.collectAsStateWithLifecycle()
val recentEventsState by viewModel.recentEvents.collectAsStateWithLifecycle()
Expand All @@ -67,6 +68,7 @@ internal fun ProfileRoute(
navigateToProfileSetting = navigateToProfileSetting,
navigateToAttendance = navigateToAttendance,
navigateToSignIn = navigateToSignIn,
navigateToSurveyDetail = navigateToSurveyDetail,
)
}

Expand All @@ -81,6 +83,7 @@ internal fun ProfileScreen(
navigateToProfileSetting: (String) -> Unit,
navigateToAttendance: () -> Unit,
navigateToSignIn: () -> Unit,
navigateToSurveyDetail: (String) -> Unit,
) {
val scrollState = rememberScrollState()

Expand Down Expand Up @@ -137,6 +140,7 @@ internal fun ProfileScreen(
userRespondedSurveysState = userRespondedSurveysState,
attendanceCardBoardColor = WappTheme.colors.blue4FF,
navigateToAttendance = navigateToAttendance,
navigateToSurveyDetail = navigateToSurveyDetail,
)
}

Expand All @@ -161,6 +165,7 @@ internal fun ProfileScreen(
userRespondedSurveysState = userRespondedSurveysState,
attendanceCardBoardColor = WappTheme.colors.yellow34,
navigateToAttendance = navigateToAttendance,
navigateToSurveyDetail = navigateToSurveyDetail,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ import com.wap.wapp.core.model.survey.Survey
internal fun WappSurveyHistoryRow(
survey: Survey,
modifier: Modifier = Modifier,
onClick: () -> Unit = {},
onClick: (String) -> Unit,
) {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = modifier
.padding(horizontal = 10.dp)
.clickable { onClick() },
.clickable { onClick(survey.surveyId) },
) {
Row(
verticalAlignment = Alignment.CenterVertically,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ fun NavGraphBuilder.profileScreen(
navigateToProfileSetting: (String) -> Unit,
navigateToAttendance: () -> Unit,
navigateToSignIn: () -> Unit,
navigateToSurveyDetail: (String) -> Unit,
) {
composable(route = profileNavigationRoute) {
ProfileRoute(
navigateToProfileSetting = navigateToProfileSetting,
navigateToAttendance = navigateToAttendance,
navigateToSignIn = navigateToSignIn,
navigateToSurveyDetail = navigateToSurveyDetail,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ internal fun UserProfile(
userRespondedSurveysState: ProfileViewModel.SurveysState,
attendanceCardBoardColor: Color,
navigateToAttendance: () -> Unit,
navigateToSurveyDetail: (String) -> Unit,
) {
Column(modifier = Modifier.padding(horizontal = 10.dp)) {
ProfileAttendanceCard(
Expand All @@ -63,6 +64,7 @@ internal fun UserProfile(

MySurveyHistory(
userRespondedSurveysState = userRespondedSurveysState,
navigateToSurveyDetail = navigateToSurveyDetail,
modifier = Modifier.padding(vertical = 20.dp),
)
}
Expand Down Expand Up @@ -204,6 +206,7 @@ private fun MyAttendanceStatus(
@Composable
private fun MySurveyHistory(
userRespondedSurveysState: ProfileViewModel.SurveysState,
navigateToSurveyDetail: (String) -> Unit,
modifier: Modifier = Modifier,
) {
Column(modifier = modifier) {
Expand Down Expand Up @@ -243,7 +246,10 @@ private fun MySurveyHistory(
items = userRespondedSurveysState.surveys,
key = { survey -> survey.surveyId },
) { survey ->
WappSurveyHistoryRow(survey)
WappSurveyHistoryRow(
survey,
onClick = navigateToSurveyDetail,
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,20 @@ internal fun SubjectiveQuestionCard(surveyAnswer: SurveyAnswer) {
color = WappTheme.colors.white,
textAlign = TextAlign.Start,
)

Spacer(modifier = Modifier.height(16.dp))

Text(
text = surveyAnswer.questionAnswer,
style = WappTheme.typography.contentRegular,
color = WappTheme.colors.white,
color = WappTheme.colors.yellow34,
textAlign = TextAlign.Start,
)
Divider()

Divider(
color = WappTheme.colors.gray82,
modifier = Modifier.padding(top = 5.dp),
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.wap.wapp.feature.survey.check.detail

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
Expand All @@ -18,19 +20,30 @@ import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.wap.designsystem.WappTheme
import com.wap.designsystem.component.CircleLoader
import com.wap.designsystem.component.WappButton
import com.wap.wapp.core.commmon.extensions.toSupportingText
import com.wap.wapp.core.model.survey.QuestionType
import com.wap.wapp.feature.survey.check.navigation.SurveyDetailBackStack
import kotlinx.coroutines.flow.collectLatest

@Composable
internal fun SurveyDetailRoute(
viewModel: SurveyDetailViewModel = hiltViewModel(),
surveyId: String,
backStack: String,
navigateToSurveyCheck: () -> Unit,
navigateToProfile: () -> Unit,
) {
val surveyUiState by viewModel.surveyUiState.collectAsStateWithLifecycle()
val snackBarHostState = remember { SnackbarHostState() }
val navigateToPrevPage = {
if (backStack == SurveyDetailBackStack.SURVEY_CHECK.name) {
navigateToSurveyCheck()
} else {
navigateToProfile()
}
}

LaunchedEffect(true) {
viewModel.getSurvey(surveyId)
Expand All @@ -45,8 +58,8 @@ internal fun SurveyDetailRoute(
SurveyDetailScreen(
snackBarHostState = snackBarHostState,
surveyUiState = surveyUiState,
onDoneButtonClicked = { navigateToSurveyCheck() },
onBackButtonClicked = { navigateToSurveyCheck() },
onDoneButtonClicked = navigateToPrevPage,
onBackButtonClicked = navigateToPrevPage,
)
}

Expand All @@ -65,50 +78,60 @@ internal fun SurveyDetailScreen(
onBackButtonClicked = onBackButtonClicked,
)
},
contentWindowInsets = WindowInsets(0.dp),
snackbarHost = { SnackbarHost(snackBarHostState) },
containerColor = WappTheme.colors.backgroundBlack,
) { paddingValues ->
Column(
modifier = Modifier
.padding(paddingValues)
.padding(vertical = 16.dp, horizontal = 8.dp)
.fillMaxSize()
.verticalScroll(scrollState),
verticalArrangement = Arrangement.spacedBy(32.dp),
.padding(paddingValues)
.padding(top = 16.dp, start = 8.dp, end = 8.dp),
) {
when (surveyUiState) {
is SurveyDetailViewModel.SurveyUiState.Init -> {}
Column(
modifier = Modifier
.weight(1f)
.fillMaxSize()
.verticalScroll(scrollState),
verticalArrangement = Arrangement.spacedBy(32.dp),
) {
when (surveyUiState) {
is SurveyDetailViewModel.SurveyUiState.Loading -> {
Spacer(modifier = Modifier.weight(1f))

is SurveyDetailViewModel.SurveyUiState.Success -> {
SurveyInformationCard(
title = surveyUiState.survey.title,
content = surveyUiState.survey.content,
userName = surveyUiState.survey.userName,
eventName = surveyUiState.survey.eventName,
)
CircleLoader(modifier = Modifier.fillMaxSize())

Column(
verticalArrangement = Arrangement.spacedBy(32.dp),
) {
surveyUiState.survey.surveyAnswerList.forEach { surveyAnswer ->
when (surveyAnswer.questionType) {
QuestionType.OBJECTIVE -> {
ObjectiveQuestionCard(surveyAnswer)
}
Spacer(modifier = Modifier.weight(1f))
}

QuestionType.SUBJECTIVE -> {
SubjectiveQuestionCard(surveyAnswer)
is SurveyDetailViewModel.SurveyUiState.Success -> {
SurveyInformationCard(
title = surveyUiState.survey.title,
content = surveyUiState.survey.content,
userName = surveyUiState.survey.userName,
eventName = surveyUiState.survey.eventName,
)

Column(
verticalArrangement = Arrangement.spacedBy(32.dp),
) {
surveyUiState.survey.surveyAnswerList.forEach { surveyAnswer ->
when (surveyAnswer.questionType) {
QuestionType.OBJECTIVE -> ObjectiveQuestionCard(surveyAnswer)

QuestionType.SUBJECTIVE -> SubjectiveQuestionCard(surveyAnswer)
}
}
}
}

WappButton(
onClick = onDoneButtonClicked,
textRes = com.wap.wapp.core.designsystem.R.string.done,
)
}
}

WappButton(
onClick = onDoneButtonClicked,
textRes = com.wap.wapp.core.designsystem.R.string.done,
modifier = Modifier.padding(vertical = 20.dp),
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class SurveyDetailViewModel @Inject constructor(
val errorFlow: SharedFlow<Throwable> = _errorFlow.asSharedFlow()

private val _surveyUiState: MutableStateFlow<SurveyUiState> =
MutableStateFlow(SurveyUiState.Init)
MutableStateFlow(SurveyUiState.Loading)
val surveyUiState: StateFlow<SurveyUiState> = _surveyUiState.asStateFlow()

fun getSurvey(surveyId: String) {
Expand All @@ -38,8 +38,7 @@ class SurveyDetailViewModel @Inject constructor(
}

sealed class SurveyUiState {
data object Init : SurveyUiState()

data object Loading : SurveyUiState()
data class Success(val survey: Survey) : SurveyUiState()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import com.wap.wapp.feature.survey.check.detail.SurveyDetailRoute

fun NavController.navigateToSurveyDetail(
surveyId: String,
backStack: SurveyDetailBackStack = SurveyDetailBackStack.SURVEY_CHECK,
navOptions: NavOptions? = navOptions {},
) = this.navigate(SurveyCheckRoute.surveyDetailRoute(surveyId), navOptions)
) = this.navigate(SurveyCheckRoute.surveyDetailRoute(surveyId, backStack.name), navOptions)

fun NavController.navigateToSurveyCheck(navOptions: NavOptions? = navOptions {}) =
this.navigate(SurveyCheckRoute.surveyCheckRoute, navOptions)
Expand All @@ -22,6 +23,7 @@ fun NavGraphBuilder.surveyCheckNavGraph(
navigateToSurveyDetail: (String) -> Unit,
navigateToSurveyCheck: () -> Unit,
navigateToSurvey: () -> Unit,
navigateToProfile: () -> Unit,
) {
composable(route = SurveyCheckRoute.surveyCheckRoute) {
SurveyCheckScreen(
Expand All @@ -31,22 +33,33 @@ fun NavGraphBuilder.surveyCheckNavGraph(
}

composable(
route = SurveyCheckRoute.surveyDetailRoute("{id}"),
route = SurveyCheckRoute.surveyDetailRoute("{id}", "{backStack}"),
arguments = listOf(
navArgument("id") {
type = NavType.StringType
},
navArgument("backStack") {
type = NavType.StringType
},
),
) { navBackStackEntry ->
val surveyId = navBackStackEntry.arguments?.getString("id") ?: ""
val backStack = navBackStackEntry.arguments?.getString("backStack") ?: "SURVEY_CHECK"
SurveyDetailRoute(
navigateToSurveyCheck = navigateToSurveyCheck,
surveyId = surveyId,
backStack = backStack,
navigateToSurveyCheck = navigateToSurveyCheck,
navigateToProfile = navigateToProfile,
)
}
}

object SurveyCheckRoute {
const val surveyCheckRoute = "survey/check"
fun surveyDetailRoute(surveyId: String) = "survey/detail/$surveyId"
fun surveyDetailRoute(surveyId: String, backStack: String) =
"survey/detail/$surveyId/$backStack"
}

enum class SurveyDetailBackStack {
SURVEY_CHECK, PROFILE
}
Loading