Skip to content

Commit

Permalink
Merge pull request #132 from pknu-wap/feature/tgyuu/#130
Browse files Browse the repository at this point in the history
  • Loading branch information
tgyuuAn authored Feb 22, 2024
2 parents c0cebbf + 13bf640 commit 6ca013b
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 50 deletions.
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) },
)
},
)
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
}

0 comments on commit 6ca013b

Please sign in to comment.