From a0c731ac1a71c505b7aa4fd4092c1ce0b07f05d5 Mon Sep 17 00:00:00 2001 From: jeongjaino Date: Tue, 30 Jan 2024 20:08:32 +0900 Subject: [PATCH 01/16] =?UTF-8?q?[CHORE]=20#95=20:=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=ED=95=98=EB=8A=94=20=EC=95=84=EC=9D=B4=EC=BD=98=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/res/drawable/ic_add_question.xml | 9 +++++++++ core/designresource/src/main/res/drawable/ic_back.xml | 4 ++-- core/designresource/src/main/res/drawable/ic_close.xml | 9 +++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 core/designresource/src/main/res/drawable/ic_add_question.xml create mode 100644 core/designresource/src/main/res/drawable/ic_close.xml diff --git a/core/designresource/src/main/res/drawable/ic_add_question.xml b/core/designresource/src/main/res/drawable/ic_add_question.xml new file mode 100644 index 000000000..27bcc74f6 --- /dev/null +++ b/core/designresource/src/main/res/drawable/ic_add_question.xml @@ -0,0 +1,9 @@ + + + diff --git a/core/designresource/src/main/res/drawable/ic_back.xml b/core/designresource/src/main/res/drawable/ic_back.xml index e73971936..0aaf65619 100644 --- a/core/designresource/src/main/res/drawable/ic_back.xml +++ b/core/designresource/src/main/res/drawable/ic_back.xml @@ -1,6 +1,6 @@ + + From 252d41820df16c7114eb0bf032a686e607dc90fd Mon Sep 17 00:00:00 2001 From: jeongjaino Date: Tue, 30 Jan 2024 20:08:45 +0900 Subject: [PATCH 02/16] =?UTF-8?q?[CHORE]=20#95=20:=20=EC=82=AC=EC=9A=A9=20?= =?UTF-8?q?String=20Resource=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- feature/management-survey/src/main/res/values/strings.xml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/feature/management-survey/src/main/res/values/strings.xml b/feature/management-survey/src/main/res/values/strings.xml index c3a3b3470..4bd9bc11f 100644 --- a/feature/management-survey/src/main/res/values/strings.xml +++ b/feature/management-survey/src/main/res/values/strings.xml @@ -4,7 +4,7 @@ 수정 완료 설문 등록 / 4 - 문항 추가 + 질문 추가 설문 등록하기 설문 삭제 취소 @@ -47,4 +47,7 @@ "이전 달을 보여주는 화살표 입니다." "다음 달을 보여주는 화살표 입니다." 설문 수정 + 이전 + 다음 질문 + 이전 질문 From 8195c1c70c744aa5c3b9e2c88df487a4b555499f Mon Sep 17 00:00:00 2001 From: jeongjaino Date: Tue, 30 Jan 2024 20:11:40 +0900 Subject: [PATCH 03/16] =?UTF-8?q?[FEATURE]=20#95=20:=20=EA=B4=80=EB=A6=AC?= =?UTF-8?q?=ED=83=AD=EC=97=90=EC=84=9C=20=EC=84=A4=EB=AC=B8=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20=EB=B0=94=ED=85=80=20=EB=B0=94=20=EC=86=8C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/wap/wapp/MainActivity.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/com/wap/wapp/MainActivity.kt b/app/src/main/java/com/wap/wapp/MainActivity.kt index e2e791e55..754c37aa9 100644 --- a/app/src/main/java/com/wap/wapp/MainActivity.kt +++ b/app/src/main/java/com/wap/wapp/MainActivity.kt @@ -116,6 +116,7 @@ private fun handleBottomBarState( attendanceManagementNavigationRoute -> setBottomBarState(false) ManagementSurveyRoute.surveyFormRegistrationRoute -> setBottomBarState(false) eventRegistrationNavigationRoute -> setBottomBarState(false) + ManagementSurveyRoute.surveyFormEditRoute("{id}") -> setBottomBarState(false) else -> setBottomBarState(true) } From 1425940d57c29ef995dfb2be99f42fce56c3b31a Mon Sep 17 00:00:00 2001 From: jeongjaino Date: Tue, 30 Jan 2024 20:12:37 +0900 Subject: [PATCH 04/16] =?UTF-8?q?[CHORE]=20#95=20:=20=EB=B6=88=ED=95=84?= =?UTF-8?q?=EC=9A=94=ED=95=9C=20Column=20=EC=86=8C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../management/survey/SurveyEventContent.kt | 61 ++++++++++--------- 1 file changed, 31 insertions(+), 30 deletions(-) diff --git a/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/SurveyEventContent.kt b/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/SurveyEventContent.kt index 775377f0c..1a4ee7e6d 100644 --- a/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/SurveyEventContent.kt +++ b/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/SurveyEventContent.kt @@ -29,43 +29,44 @@ internal fun SurveyEventContent( selectedEvent: Event, onEventSelected: (Event) -> Unit, onNextButtonClicked: () -> Unit, - modifier: Modifier = Modifier, ) { - WappTitle( - title = stringResource(R.string.event_selection_title), - content = stringResource(R.string.event_selection_content), - modifier = Modifier.padding(top = 10.dp, bottom = 40.dp), - ) + Column(modifier = Modifier.fillMaxSize()) { + WappTitle( + title = stringResource(R.string.event_selection_title), + content = stringResource(R.string.event_selection_content), + modifier = Modifier.padding(top = 10.dp, bottom = 40.dp), + ) - LazyColumn( - verticalArrangement = Arrangement.spacedBy(16.dp), - modifier = modifier, - ) { - when (eventsState) { - is EventsState.Loading -> item { - CircleLoader( - modifier = Modifier.fillMaxSize(), - ) - } - - is EventsState.Success -> - items(eventsState.events) { event -> - EventCard( - event = event, - selectedEvent = selectedEvent, - onEventSelected = onEventSelected, + LazyColumn( + verticalArrangement = Arrangement.spacedBy(16.dp), + modifier = Modifier.weight(1f), + ) { + when (eventsState) { + is EventsState.Loading -> item { + CircleLoader( + modifier = Modifier.fillMaxSize(), ) } - is EventsState.Failure -> {} + is EventsState.Success -> + items(eventsState.events) { event -> + EventCard( + event = event, + selectedEvent = selectedEvent, + onEventSelected = onEventSelected, + ) + } + + is EventsState.Failure -> {} + } } - } - WappButton( - textRes = R.string.next, - onClick = onNextButtonClicked, - modifier = Modifier.padding(top = 20.dp, bottom = 20.dp), - ) + WappButton( + textRes = R.string.next, + onClick = onNextButtonClicked, + modifier = Modifier.padding(top = 16.dp), + ) + } } @Composable From 18c65b148704a56cd98052c495ebe2673234eef3 Mon Sep 17 00:00:00 2001 From: jeongjaino Date: Tue, 30 Jan 2024 20:13:00 +0900 Subject: [PATCH 05/16] =?UTF-8?q?[FEATURE]=20#95=20:=20=EB=92=A4=EB=A1=9C?= =?UTF-8?q?=20=EA=B0=80=EA=B8=B0=20=EB=B2=84=ED=8A=BC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../survey/SurveyDeadlineContent.kt | 21 +++++++++++++---- .../survey/SurveyInformationContent.kt | 23 +++++++++++++++---- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/SurveyDeadlineContent.kt b/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/SurveyDeadlineContent.kt index 698d751cc..7cdccab0a 100644 --- a/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/SurveyDeadlineContent.kt +++ b/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/SurveyDeadlineContent.kt @@ -41,6 +41,7 @@ internal fun SurveyDeadlineContent( onTimePickerStateChanged: (Boolean) -> Unit, onDateChanged: (LocalDate) -> Unit, onTimeChanged: (LocalTime) -> Unit, + onPreviousButtonClicked: () -> Unit, onRegisterButtonClicked: () -> Unit, ) { if (showDatePicker) { @@ -93,11 +94,21 @@ internal fun SurveyDeadlineContent( Spacer(modifier = Modifier.weight(1f)) - WappButton( - textRes = R.string.register_survey, - onClick = onRegisterButtonClicked, - modifier = Modifier.padding(bottom = 20.dp), - ) + Row( + horizontalArrangement = Arrangement.spacedBy(8.dp), + ) { + WappButton( + textRes = R.string.previous, + onClick = onPreviousButtonClicked, + modifier = Modifier.weight(1f), + ) + + WappButton( + textRes = R.string.next, + onClick = onRegisterButtonClicked, + modifier = Modifier.weight(1f), + ) + } } } diff --git a/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/SurveyInformationContent.kt b/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/SurveyInformationContent.kt index 07181eabf..ba91f118d 100644 --- a/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/SurveyInformationContent.kt +++ b/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/SurveyInformationContent.kt @@ -2,6 +2,7 @@ package com.wap.wapp.feature.management.survey import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth @@ -25,6 +26,7 @@ internal fun SurveyInformationContent( onTitleChanged: (String) -> Unit, content: String, onContentChanged: (String) -> Unit, + onPreviousButtonClicked: () -> Unit, onNextButtonClicked: () -> Unit, ) { val scrollState = rememberScrollState() @@ -69,12 +71,23 @@ internal fun SurveyInformationContent( .fillMaxWidth() .height(200.dp), ) + Spacer(modifier = Modifier.weight(1f)) - WappButton( - onClick = onNextButtonClicked, - textRes = R.string.next, - modifier = Modifier.padding(top = 4.dp, bottom = 20.dp), - ) + Row( + horizontalArrangement = Arrangement.spacedBy(8.dp), + ) { + WappButton( + textRes = R.string.previous, + onClick = onPreviousButtonClicked, + modifier = Modifier.weight(1f), + ) + + WappButton( + textRes = R.string.next, + onClick = onNextButtonClicked, + modifier = Modifier.weight(1f), + ) + } } } From 6af4ce185126595fbd58974fb7f96597fa291476 Mon Sep 17 00:00:00 2001 From: jeongjaino Date: Tue, 30 Jan 2024 20:13:24 +0900 Subject: [PATCH 06/16] =?UTF-8?q?[FEATURE]=20#95=20:=20=EB=92=A4=EB=A1=9C?= =?UTF-8?q?=20=EA=B0=80=EA=B8=B0=20=EB=B2=84=ED=8A=BC=EA=B3=BC=20=EC=A7=88?= =?UTF-8?q?=EB=AC=B8=20=EC=95=9E=20=EB=92=A4=20=EC=A0=84=ED=99=98=20?= =?UTF-8?q?=EB=B2=84=ED=8A=BC=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../survey/SurveyQuestionContent.kt | 110 ++++++++++++++---- 1 file changed, 90 insertions(+), 20 deletions(-) diff --git a/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/SurveyQuestionContent.kt b/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/SurveyQuestionContent.kt index 0d9dda43d..ee7c892fd 100644 --- a/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/SurveyQuestionContent.kt +++ b/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/SurveyQuestionContent.kt @@ -1,5 +1,7 @@ package com.wap.wapp.feature.management.survey +import androidx.compose.foundation.Image +import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row @@ -8,6 +10,7 @@ import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.verticalScroll @@ -20,12 +23,14 @@ import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.SpanStyle import androidx.compose.ui.text.buildAnnotatedString import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.withStyle import androidx.compose.ui.unit.dp +import com.wap.wapp.core.designresource.R.drawable import com.wap.designsystem.WappTheme import com.wap.designsystem.component.WappButton import com.wap.designsystem.component.WappRoundedTextField @@ -36,12 +41,15 @@ import com.wap.wapp.core.model.survey.QuestionType internal fun SurveyQuestionContent( question: String, questionType: QuestionType, + questionNumber: Int, + totalQuestionNumber: Int, onQuestionChanged: (String) -> Unit, onQuestionTypeChanged: (QuestionType) -> Unit, + onPreviousQuestionButtonClicked: () -> Unit, + onNextQuestionButtonClicked: () -> Unit, + onPreviousButtonClicked: () -> Unit, onNextButtonClicked: () -> Unit, onAddSurveyQuestionButtonClicked: () -> Unit, - currentQuestionIndex: Int, - totalQuestionIndex: Int, ) { val scrollState = rememberScrollState() @@ -66,19 +74,11 @@ internal fun SurveyQuestionContent( color = WappTheme.colors.white, ) - Text( - color = WappTheme.colors.white, - style = WappTheme.typography.contentRegular, - text = buildAnnotatedString { - withStyle( - style = SpanStyle( - WappTheme.colors.yellow34, - ), - ) { append(currentQuestionIndex.toString()) } - append(" / $totalQuestionIndex") - }, - textAlign = TextAlign.End, - modifier = Modifier.fillMaxWidth(), + SurveyQuestionNumberText( + questionNumber = questionNumber + 1, + totalQuestionNumber = totalQuestionNumber + 1, + onPreviousQuestionButtonClicked = onPreviousQuestionButtonClicked, + onNextQuestionButtonClicked = onNextQuestionButtonClicked, ) } @@ -125,15 +125,65 @@ internal fun SurveyQuestionContent( onAddSurveyQuestionButtonClicked() }, onNextButtonClicked = onNextButtonClicked, + onPreviousButtonClicked = onPreviousButtonClicked, modifier = Modifier.padding(top = 10.dp, bottom = 20.dp), ) } } @Composable -private fun SurveyQuestionTypeDescription( - type: QuestionType, +private fun SurveyQuestionNumberText( + questionNumber: Int, + totalQuestionNumber: Int, + onPreviousQuestionButtonClicked: () -> Unit, + onNextQuestionButtonClicked: () -> Unit, ) { + Row( + modifier = Modifier.fillMaxWidth(), + horizontalArrangement = Arrangement.End, + verticalAlignment = Alignment.CenterVertically, + ) { + // 이전 질문 버튼 + if (questionNumber > 1) { + Image( + painter = painterResource(id = drawable.ic_back), + contentDescription = stringResource(R.string.previous_question), + modifier = Modifier + .size(14.dp) + .padding(end = 4.dp) + .clickable { onPreviousQuestionButtonClicked() }, + ) + } + + Text( + color = WappTheme.colors.white, + style = WappTheme.typography.contentRegular, + text = buildAnnotatedString { + withStyle( + style = SpanStyle( + WappTheme.colors.yellow34, + ), + ) { append(questionNumber.toString()) } + append(" / $totalQuestionNumber") + }, + ) + + // 다음 질문 버튼 + if (questionNumber < totalQuestionNumber) { + Image( + painter = painterResource(id = drawable.ic_forward), + contentDescription = stringResource(R.string.next_question), + modifier = Modifier + .size(14.dp) + .padding(start = 4.dp) + .clickable { onNextQuestionButtonClicked() }, + ) + } + } +} + +@Composable +private fun SurveyQuestionTypeDescription(type: QuestionType) { when (type) { QuestionType.SUBJECTIVE -> { Text( @@ -240,21 +290,41 @@ private fun SurveyQuestionTypeCard( private fun SurveyQuestionButton( onAddSurveyQuestionButtonClicked: () -> Unit, onNextButtonClicked: () -> Unit, + onPreviousButtonClicked: () -> Unit, modifier: Modifier = Modifier, ) { + Column( + modifier = Modifier + .fillMaxWidth() + .clickable { onAddSurveyQuestionButtonClicked() }, + horizontalAlignment = Alignment.CenterHorizontally, + ) { + Image( + painter = painterResource(id = drawable.ic_add_question), + contentDescription = stringResource(id = R.string.add_survey_question), + modifier = Modifier.size(40.dp), + ) + + Text( + text = stringResource(id = R.string.add_survey_question), + color = WappTheme.colors.yellow34, + style = WappTheme.typography.labelRegular, + ) + } + Row( horizontalArrangement = Arrangement.spacedBy(8.dp), modifier = modifier, ) { WappButton( - onClick = onAddSurveyQuestionButtonClicked, - textRes = R.string.add_survey_question, + textRes = R.string.previous, + onClick = onPreviousButtonClicked, modifier = Modifier.weight(1f), ) WappButton( - onClick = onNextButtonClicked, textRes = R.string.next, + onClick = onNextButtonClicked, modifier = Modifier.weight(1f), ) } From 2e13274df732497ae30f428ac89c41d19f34a5a3 Mon Sep 17 00:00:00 2001 From: jeongjaino Date: Tue, 30 Jan 2024 20:14:01 +0900 Subject: [PATCH 07/16] =?UTF-8?q?[FEATURE]=20#95=20:=20=EC=A7=88=EB=AC=B8?= =?UTF-8?q?=20=EC=88=9C=EC=84=9C=20=EB=B3=80=EA=B2=BD=20(=EB=B9=A0?= =?UTF-8?q?=EB=A5=B8=20#94=20=ED=95=AB=ED=94=BD=EC=8A=A4=EB=A5=BC=20?= =?UTF-8?q?=EC=9C=84=ED=95=9C=20=EC=A4=91=EA=B0=84=20=EC=BB=A4=EB=B0=8B)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../management/survey/SurveyFormContent.kt | 153 +++++++++--------- .../survey/edit/SurveyFormEditScreen.kt | 48 +++--- .../survey/edit/SurveyFormEditViewModel.kt | 15 +- .../SurveyFormRegistrationScreen.kt | 107 ++++++++---- .../SurveyFormRegistrationViewModel.kt | 68 ++++++-- 5 files changed, 247 insertions(+), 144 deletions(-) diff --git a/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/SurveyFormContent.kt b/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/SurveyFormContent.kt index 1b0620713..d0ca88dd7 100644 --- a/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/SurveyFormContent.kt +++ b/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/SurveyFormContent.kt @@ -1,11 +1,8 @@ package com.wap.wapp.feature.management.survey -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.TimePickerState import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier import com.wap.wapp.core.model.event.Event import com.wap.wapp.core.model.survey.QuestionType import com.wap.wapp.feature.management.survey.registration.SurveyFormRegistrationViewModel @@ -24,97 +21,103 @@ internal fun SurveyFormContent( questionType: QuestionType, time: LocalTime, date: LocalDate, - currentQuestionIndex: Int, - totalQuestionSize: Int, + questionNumber: Int, + totalQuestionNumber: Int, timePickerState: TimePickerState, showDatePicker: Boolean, showTimePicker: Boolean, onDateChanged: (LocalDate) -> Unit, onDatePickerStateChanged: (Boolean) -> Unit, onTimePickerStateChanged: (Boolean) -> Unit, - onEventListChanged: () -> Unit, + onEventContentInitialized: () -> Unit, onEventSelected: (Event) -> Unit, onTitleChanged: (String) -> Unit, onContentChanged: (String) -> Unit, onQuestionChanged: (String) -> Unit, onQuestionTypeChanged: (QuestionType) -> Unit, + onPreviousQuestionButtonClicked: () -> Unit, + onNextQuestionButtonClicked: () -> Unit, onTimeChanged: (LocalTime) -> Unit, + onPreviousButtonClicked: (SurveyFormState) -> Unit, // previousState onNextButtonClicked: (SurveyFormState, SurveyFormState) -> Unit, // (currentState, nextState) onAddQuestionButtonClicked: () -> Unit, onRegisterButtonClicked: () -> Unit, - modifier: Modifier = Modifier, ) { - Column( - modifier = modifier.fillMaxSize(), - ) { - when (surveyRegistrationState) { - SurveyFormState.EVENT_SELECTION -> { - onEventListChanged() - SurveyEventContent( - eventsState = eventsState, - selectedEvent = eventSelection, - onEventSelected = onEventSelected, - onNextButtonClicked = { - onNextButtonClicked( - SurveyFormState.EVENT_SELECTION, - SurveyFormState.INFORMATION, - ) - }, - modifier = Modifier - .fillMaxSize() - .weight(1f), - ) - } + when (surveyRegistrationState) { + SurveyFormState.EVENT_SELECTION -> { + onEventContentInitialized() + SurveyEventContent( + eventsState = eventsState, + selectedEvent = eventSelection, + onEventSelected = onEventSelected, + onNextButtonClicked = { + onNextButtonClicked( + SurveyFormState.EVENT_SELECTION, + SurveyFormState.INFORMATION, + ) + }, + ) + } - SurveyFormState.INFORMATION -> { - SurveyInformationContent( - title = title, - onTitleChanged = onTitleChanged, - content = content, - onContentChanged = onContentChanged, - onNextButtonClicked = { - onNextButtonClicked( - SurveyFormState.INFORMATION, - SurveyFormState.QUESTION, - ) - }, - ) - } + SurveyFormState.INFORMATION -> { + SurveyInformationContent( + title = title, + onTitleChanged = onTitleChanged, + content = content, + onContentChanged = onContentChanged, + onPreviousButtonClicked = { + onPreviousButtonClicked(SurveyFormState.EVENT_SELECTION) + }, + onNextButtonClicked = { + onNextButtonClicked( + SurveyFormState.INFORMATION, + SurveyFormState.QUESTION, + ) + }, + ) + } - SurveyFormState.QUESTION -> { - SurveyQuestionContent( - question = question, - questionType = questionType, - onQuestionTypeChanged = { defaultQuestionType -> - onQuestionTypeChanged(defaultQuestionType) - }, - onQuestionChanged = onQuestionChanged, - onAddSurveyQuestionButtonClicked = onAddQuestionButtonClicked, - currentQuestionIndex = currentQuestionIndex, - totalQuestionIndex = totalQuestionSize, - onNextButtonClicked = { - onNextButtonClicked( - SurveyFormState.QUESTION, - SurveyFormState.DEADLINE, - ) - }, - ) - } + SurveyFormState.QUESTION -> { + SurveyQuestionContent( + question = question, + questionType = questionType, + onQuestionTypeChanged = { defaultQuestionType -> + onQuestionTypeChanged(defaultQuestionType) + }, + onQuestionChanged = onQuestionChanged, + onAddSurveyQuestionButtonClicked = onAddQuestionButtonClicked, + questionNumber = questionNumber, + totalQuestionNumber = totalQuestionNumber, + onPreviousButtonClicked = { + onPreviousButtonClicked(SurveyFormState.INFORMATION) + }, + onNextButtonClicked = { + onNextButtonClicked( + SurveyFormState.QUESTION, + SurveyFormState.DEADLINE, + ) + }, + onPreviousQuestionButtonClicked = onPreviousQuestionButtonClicked, + onNextQuestionButtonClicked = onNextQuestionButtonClicked, + ) + } - SurveyFormState.DEADLINE -> { - SurveyDeadlineContent( - time = time, - date = date, - timePickerState = timePickerState, - showDatePicker = showDatePicker, - showTimePicker = showTimePicker, - onDateChanged = onDateChanged, - onTimePickerStateChanged = onTimePickerStateChanged, - onTimeChanged = onTimeChanged, - onRegisterButtonClicked = onRegisterButtonClicked, - onDatePickerStateChanged = onDatePickerStateChanged, - ) - } + SurveyFormState.DEADLINE -> { + SurveyDeadlineContent( + time = time, + date = date, + timePickerState = timePickerState, + showDatePicker = showDatePicker, + showTimePicker = showTimePicker, + onDateChanged = onDateChanged, + onTimePickerStateChanged = onTimePickerStateChanged, + onTimeChanged = onTimeChanged, + onRegisterButtonClicked = onRegisterButtonClicked, + onDatePickerStateChanged = onDatePickerStateChanged, + onPreviousButtonClicked = { + onPreviousButtonClicked(SurveyFormState.QUESTION) + }, + ) } } } diff --git a/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/edit/SurveyFormEditScreen.kt b/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/edit/SurveyFormEditScreen.kt index 4765338d9..5238e1ed1 100644 --- a/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/edit/SurveyFormEditScreen.kt +++ b/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/edit/SurveyFormEditScreen.kt @@ -43,6 +43,7 @@ import androidx.hilt.navigation.compose.hiltViewModel import com.wap.designsystem.WappTheme import com.wap.designsystem.component.WappSubTopBar import com.wap.wapp.core.commmon.extensions.toSupportingText +import com.wap.wapp.core.designresource.R.drawable import com.wap.wapp.feature.management.survey.R import com.wap.wapp.feature.management.survey.SurveyFormContent import com.wap.wapp.feature.management.survey.SurveyFormState @@ -99,13 +100,24 @@ internal fun SurveyFormEditScreen( containerColor = WappTheme.colors.backgroundBlack, modifier = Modifier.fillMaxSize(), contentWindowInsets = WindowInsets(0.dp), + topBar = { + WappSubTopBar( + titleRes = R.string.survey_edit, + showLeftButton = true, + showRightButton = true, + leftButtonDrawableRes = drawable.ic_close, + modifier = Modifier.padding(top = 16.dp), + onClickLeftButton = navigateToManagement, + onClickRightButton = { showDeleteSurveyDialog = true }, + ) + }, ) { paddingValues -> Column( modifier = Modifier .fillMaxSize() .padding(paddingValues) // paddingValue padding - .padding(16.dp), // dp value padding - verticalArrangement = Arrangement.spacedBy(32.dp), + .padding(vertical = 16.dp, horizontal = 20.dp), // dp value padding + verticalArrangement = Arrangement.spacedBy(20.dp), ) { if (showDeleteSurveyDialog) { DeleteSurveyDialog( @@ -114,21 +126,9 @@ internal fun SurveyFormEditScreen( ) } - Column( - verticalArrangement = Arrangement.spacedBy(16.dp), - ) { - WappSubTopBar( - titleRes = R.string.survey_edit, - showLeftButton = true, - showRightButton = true, - onClickLeftButton = navigateToManagement, - onClickRightButton = { showDeleteSurveyDialog = true }, - ) - - SurveyFormStateIndicator( - surveyRegistrationState = currentRegistrationState, - ) - } + SurveyFormStateIndicator( + surveyRegistrationState = currentRegistrationState, + ) SurveyFormContent( surveyRegistrationState = currentRegistrationState, @@ -143,11 +143,11 @@ internal fun SurveyFormEditScreen( timePickerState = timePickerState, showDatePicker = showDatePicker, showTimePicker = showTimePicker, - currentQuestionIndex = totalQuestionSize, - totalQuestionSize = totalQuestionSize, + questionNumber = totalQuestionSize, + totalQuestionNumber = totalQuestionSize, onDatePickerStateChanged = { state -> showDatePicker = state }, onTimePickerStateChanged = { state -> showTimePicker = state }, - onEventListChanged = { viewModel.getEventList() }, + onEventContentInitialized = { viewModel.getEventList() }, onEventSelected = { event -> viewModel.setSurveyEventSelection(event) }, onTitleChanged = { title -> viewModel.setSurveyTitle(title) }, onContentChanged = { content -> viewModel.setSurveyContent(content) }, @@ -155,8 +155,16 @@ internal fun SurveyFormEditScreen( onQuestionTypeChanged = { questionType -> viewModel.setSurveyQuestionType(questionType) }, + onPreviousQuestionButtonClicked = {}, + onNextQuestionButtonClicked = {}, onDateChanged = viewModel::setSurveyDateDeadline, onTimeChanged = { localTime -> viewModel.setSurveyTimeDeadline(localTime) }, + onPreviousButtonClicked = { previousState -> + if (previousState == SurveyFormState.QUESTION) { + viewModel.setSurveyQuestionFromAnsweredList() + } + viewModel.setSurveyFormState(previousState) + }, onNextButtonClicked = { currentState, nextState -> if (viewModel.validateSurveyForm(currentState).not()) { // 유효성 검증 return@SurveyFormContent diff --git a/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/edit/SurveyFormEditViewModel.kt b/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/edit/SurveyFormEditViewModel.kt index a7ab39c46..fdb9c4cd8 100644 --- a/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/edit/SurveyFormEditViewModel.kt +++ b/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/edit/SurveyFormEditViewModel.kt @@ -90,7 +90,8 @@ class SurveyFormEditViewModel @Inject constructor( setSurveyFormId(surveyForm.surveyFormId) setSurveyEventSelection(EVENT_SELECTION_INIT.copy(eventId = surveyForm.eventId)) setSurveyTitle(surveyForm.title) - setSurveyQuestionList(surveyForm.surveyQuestionList.toMutableList()) + setSurveyQuestionList(surveyForm.surveyQuestionList) + setSurveyQuestionFromAnsweredList() setSurveyContent(surveyForm.content) setSurveyTimeDeadline(surveyForm.deadline.toLocalTime()) setSurveyDateDeadline(surveyForm.deadline.toLocalDate()) @@ -195,13 +196,15 @@ class SurveyFormEditViewModel @Inject constructor( fun setSurveyDateDeadline(date: LocalDate) { _surveyDateDeadline.value = date } - private fun setSurveyQuestionList(surveyQuestionList: MutableList) { - // 마지막 질문은 UI에 노출 - val lastSurveyQuestion = surveyQuestionList.removeLast() + // 이전 버튼 클릭시 진입점이 질문 페이지인 경우, 응답 목록에서 마지막 질문 노출 + private fun setSurveyQuestionList(surveyQuestionList: List) { + _surveyQuestionList.value.addAll(surveyQuestionList) + } + + fun setSurveyQuestionFromAnsweredList() { + val lastSurveyQuestion = _surveyQuestionList.value.removeLast() setSurveyQuestion(lastSurveyQuestion.questionTitle) setSurveyQuestionType(lastSurveyQuestion.questionType) - - _surveyQuestionList.value.addAll(surveyQuestionList) } private fun clearSurveyQuestionState() { _surveyQuestion.value = "" } diff --git a/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/registration/SurveyFormRegistrationScreen.kt b/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/registration/SurveyFormRegistrationScreen.kt index 932c71688..b307865a5 100644 --- a/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/registration/SurveyFormRegistrationScreen.kt +++ b/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/registration/SurveyFormRegistrationScreen.kt @@ -1,5 +1,6 @@ package com.wap.wapp.feature.management.survey.registration +import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.WindowInsets import androidx.compose.foundation.layout.fillMaxSize @@ -11,7 +12,6 @@ import androidx.compose.material3.SnackbarHostState import androidx.compose.material3.rememberTimePickerState import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect -import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember @@ -19,9 +19,11 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier 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.WappSubTopBar import com.wap.wapp.core.commmon.extensions.toSupportingText +import com.wap.wapp.core.designresource.R.drawable import com.wap.wapp.feature.management.survey.R import com.wap.wapp.feature.management.survey.SurveyFormContent import com.wap.wapp.feature.management.survey.SurveyFormState @@ -34,16 +36,19 @@ internal fun SurveyRegistrationScreen( viewModel: SurveyFormRegistrationViewModel = hiltViewModel(), navigateToManagement: () -> Unit, ) { - val currentRegistrationState = viewModel.currentSurveyFormState.collectAsState().value - val eventList = viewModel.eventList.collectAsState().value - val eventSelection = viewModel.surveyEventSelection.collectAsState().value - val title = viewModel.surveyTitle.collectAsState().value - val content = viewModel.surveyContent.collectAsState().value - val question = viewModel.surveyQuestion.collectAsState().value - val questionType = viewModel.surveyQuestionType.collectAsState().value - val totalQuestionSize = viewModel.surveyQuestionList.collectAsState().value.size + 1 - val time = viewModel.surveyTimeDeadline.collectAsState().value - val date = viewModel.surveyDateDeadline.collectAsState().value + val currentRegistrationState = + viewModel.currentSurveyFormState.collectAsStateWithLifecycle().value + val eventList = viewModel.eventList.collectAsStateWithLifecycle().value + val eventSelection = viewModel.surveyEventSelection.collectAsStateWithLifecycle().value + val title = viewModel.surveyTitle.collectAsStateWithLifecycle().value + val content = viewModel.surveyContent.collectAsStateWithLifecycle().value + val questionTitle = viewModel.surveyQuestionTitle.collectAsStateWithLifecycle().value + val questionType = viewModel.surveyQuestionType.collectAsStateWithLifecycle().value + val questionNumber = viewModel.surveyQuestionNumber.collectAsStateWithLifecycle().value + val totalQuestionNumber = + viewModel.surveyQuestionTotalNumber.collectAsStateWithLifecycle().value + val time = viewModel.surveyTimeDeadline.collectAsStateWithLifecycle().value + val date = viewModel.surveyDateDeadline.collectAsStateWithLifecycle().value val snackBarHostState = remember { SnackbarHostState() } val timePickerState = rememberTimePickerState() var showDatePicker by remember { mutableStateOf(false) } @@ -72,20 +77,23 @@ internal fun SurveyRegistrationScreen( containerColor = WappTheme.colors.backgroundBlack, modifier = Modifier.fillMaxSize(), contentWindowInsets = WindowInsets(0.dp), - ) { paddingValues -> - Column( - modifier = Modifier - .fillMaxSize() - .padding(paddingValues) // paddingValue padding - .padding(top = 16.dp, start = 20.dp, end = 20.dp), // dp value padding - ) { + topBar = { WappSubTopBar( titleRes = R.string.survey_registeration, showLeftButton = true, onClickLeftButton = navigateToManagement, - modifier = Modifier.padding(bottom = 16.dp), + leftButtonDrawableRes = drawable.ic_close, + modifier = Modifier.padding(top = 16.dp), ) - + }, + ) { paddingValues -> + Column( + modifier = Modifier + .fillMaxSize() + .padding(paddingValues) + .padding(vertical = 16.dp, horizontal = 20.dp), + verticalArrangement = Arrangement.spacedBy(20.dp), + ) { SurveyFormStateIndicator( surveyRegistrationState = currentRegistrationState, ) @@ -96,42 +104,79 @@ internal fun SurveyRegistrationScreen( eventSelection = eventSelection, title = title, content = content, - question = question, + question = questionTitle, questionType = questionType, date = date, time = time, timePickerState = timePickerState, showDatePicker = showDatePicker, showTimePicker = showTimePicker, - currentQuestionIndex = totalQuestionSize, - totalQuestionSize = totalQuestionSize, + questionNumber = questionNumber, + totalQuestionNumber = totalQuestionNumber, onDatePickerStateChanged = { state -> showDatePicker = state }, onTimePickerStateChanged = { state -> showTimePicker = state }, - onEventListChanged = { viewModel.getEventList() }, + onEventContentInitialized = { viewModel.getEventList() }, onEventSelected = { event -> viewModel.setSurveyEventSelection(event) }, onTitleChanged = { title -> viewModel.setSurveyTitle(title) }, onContentChanged = { content -> viewModel.setSurveyContent(content) }, - onQuestionChanged = { question -> viewModel.setSurveyQuestion(question) }, + onQuestionChanged = { question -> viewModel.setSurveyQuestionTitle(question) }, onQuestionTypeChanged = { questionType -> viewModel.setSurveyQuestionType(questionType) }, - onDateChanged = viewModel::setSurveyDateDeadline, - onTimeChanged = { localTime -> viewModel.setSurveyTimeDeadline(localTime) }, - onNextButtonClicked = { currentState, nextState -> - if (viewModel.validateSurveyForm(currentState).not()) { + onNextQuestionButtonClicked = { + if (viewModel.validateSurveyForm(SurveyFormState.QUESTION).not()) { + return@SurveyFormContent // 답변 검증 + } + + viewModel.editSurveyQuestion() // 답변 수정 + + viewModel.setNextQuestionNumber() // 다음 질문 불러오기 + viewModel.setQuestion() + }, + onPreviousQuestionButtonClicked = { + if (viewModel.validateSurveyForm(SurveyFormState.QUESTION).not()) { return@SurveyFormContent } - if (currentState == SurveyFormState.QUESTION) { + // 다른 질문으로 넘어가기 전, 상태 저장 + if (questionNumber == totalQuestionNumber) { viewModel.addSurveyQuestion() + } else { + viewModel.editSurveyQuestion() } - viewModel.setSurveyFormState(nextState) + viewModel.setPreviousQuestionNumber() // 이전 질문 불러오기 + viewModel.setQuestion() }, onAddQuestionButtonClicked = { if (viewModel.validateSurveyForm(SurveyFormState.QUESTION)) { viewModel.addSurveyQuestion() } + viewModel.setLastQuestionNumber() + }, + onDateChanged = viewModel::setSurveyDateDeadline, + onTimeChanged = { localTime -> viewModel.setSurveyTimeDeadline(localTime) }, + onPreviousButtonClicked = { previousState -> + if (previousState == SurveyFormState.QUESTION) { + viewModel.setSurveyQuestionFromQuestionList() + } + + viewModel.setSurveyFormState(previousState) + }, + onNextButtonClicked = { currentState, nextState -> + if (viewModel.validateSurveyForm(currentState).not()) { + return@SurveyFormContent + } + + if (currentState == SurveyFormState.QUESTION) { + if (questionNumber == totalQuestionNumber) { + viewModel.addSurveyQuestion() + } else { + viewModel.editSurveyQuestion() + } + } + + viewModel.setSurveyFormState(nextState) }, onRegisterButtonClicked = { if (viewModel.validateSurveyForm(SurveyFormState.DEADLINE)) { diff --git a/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/registration/SurveyFormRegistrationViewModel.kt b/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/registration/SurveyFormRegistrationViewModel.kt index 308d4dd7c..5696669ab 100644 --- a/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/registration/SurveyFormRegistrationViewModel.kt +++ b/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/registration/SurveyFormRegistrationViewModel.kt @@ -47,16 +47,21 @@ class SurveyFormRegistrationViewModel @Inject constructor( private val _surveyContent: MutableStateFlow = MutableStateFlow("") val surveyContent = _surveyContent.asStateFlow() - private val _surveyQuestion: MutableStateFlow = MutableStateFlow("") - val surveyQuestion = _surveyQuestion.asStateFlow() + private val _surveyQuestionTitle: MutableStateFlow = MutableStateFlow("") + val surveyQuestionTitle = _surveyQuestionTitle.asStateFlow() private val _surveyQuestionType: MutableStateFlow = MutableStateFlow(QuestionType.SUBJECTIVE) val surveyQuestionType = _surveyQuestionType.asStateFlow() - private val _surveyQuestionList: MutableStateFlow> = + private val _surveyQuestionNumber: MutableStateFlow = MutableStateFlow(0) + val surveyQuestionNumber = _surveyQuestionNumber.asStateFlow() + + private val _surveyQuestionTotalNumber: MutableStateFlow = MutableStateFlow(0) + val surveyQuestionTotalNumber = _surveyQuestionTotalNumber.asStateFlow() + + private val surveyQuestionList: MutableStateFlow> = MutableStateFlow(mutableListOf()) - val surveyQuestionList = _surveyQuestionList.asStateFlow() private val _surveyTimeDeadline: MutableStateFlow = MutableStateFlow(DateUtil.generateNowTime()) @@ -79,7 +84,7 @@ class SurveyFormRegistrationViewModel @Inject constructor( event = surveyEventSelection.value, title = _surveyTitle.value, content = _surveyContent.value, - surveyQuestionList = _surveyQuestionList.value, + surveyQuestionList = surveyQuestionList.value, deadlineDate = _surveyDateDeadline.value, deadlineTime = _surveyTimeDeadline.value, ).onSuccess { @@ -130,27 +135,66 @@ class SurveyFormRegistrationViewModel @Inject constructor( fun setSurveyContent(content: String) { _surveyContent.value = content } - fun setSurveyQuestion(question: String) { _surveyQuestion.value = question } + fun setSurveyQuestionTitle(title: String) { _surveyQuestionTitle.value = title } fun setSurveyQuestionType(type: QuestionType) { _surveyQuestionType.value = type } - fun setSurveyTimeDeadline(time: LocalTime) { _surveyTimeDeadline.value = time } + fun setNextQuestionNumber() { _surveyQuestionNumber.value += 1 } - fun setSurveyDateDeadline(date: LocalDate) { _surveyDateDeadline.value = date } + fun setPreviousQuestionNumber() { _surveyQuestionNumber.value -= 1 } + + fun setLastQuestionNumber() { + _surveyQuestionTotalNumber.value += 1 // TODO + _surveyQuestionNumber.value = surveyQuestionList.value.size + } + + fun setQuestion() { + val currentNumber = _surveyQuestionNumber.value + val totalSize = surveyQuestionList.value.size + + if (currentNumber < totalSize) { + val surveyQuestion = surveyQuestionList.value[_surveyQuestionNumber.value] + setSurveyQuestionTitle(surveyQuestion.questionTitle) + setSurveyQuestionType(surveyQuestion.questionType) + return + } + + clearSurveyQuestionState() + } fun addSurveyQuestion() { - _surveyQuestionList.value.add( + surveyQuestionList.value.add( SurveyQuestion( - questionTitle = _surveyQuestion.value, + questionTitle = _surveyQuestionTitle.value, questionType = _surveyQuestionType.value, ), ) clearSurveyQuestionState() } - private fun clearSurveyQuestionState() { _surveyQuestion.value = "" } + fun editSurveyQuestion() { + val questionNumber = _surveyQuestionNumber.value + surveyQuestionList.value[questionNumber] = SurveyQuestion( + questionTitle = _surveyQuestionTitle.value, + questionType = _surveyQuestionType.value, + ) + clearSurveyQuestionState() + } + + fun setSurveyQuestionFromQuestionList() { + // 작성된 질문 목록을 불러올 때, 마지막 질문은 UI에 노출 + val lastSurveyQuestion = surveyQuestionList.value.removeLast() + setSurveyQuestionTitle(lastSurveyQuestion.questionTitle) + setSurveyQuestionType(lastSurveyQuestion.questionType) + } + + fun setSurveyTimeDeadline(time: LocalTime) { _surveyTimeDeadline.value = time } + + fun setSurveyDateDeadline(date: LocalDate) { _surveyDateDeadline.value = date } + + private fun clearSurveyQuestionState() { _surveyQuestionTitle.value = "" } - private fun isNotValidSurveyQuestion() = _surveyQuestion.value.isBlank() + private fun isNotValidSurveyQuestion() = _surveyQuestionTitle.value.isBlank() private fun isNotValidEventSelection() = _surveyEventSelection.value.eventId == EVENT_SELECTION_INIT.eventId From 80dbd6abcf96446dd4ef245bf2b0fe4608f4a1b3 Mon Sep 17 00:00:00 2001 From: jeongjaino Date: Wed, 31 Jan 2024 23:42:00 +0900 Subject: [PATCH 08/16] =?UTF-8?q?[STYLE]=20#95=20:=20=EC=9D=B8=EC=9E=90=20?= =?UTF-8?q?=EB=84=A4=EC=9D=B4=EB=B0=8D=20=EC=88=98=EC=A0=95=20questionNumb?= =?UTF-8?q?er=20->=20currentQuestionNumber?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../feature/management/survey/SurveyFormContent.kt | 12 ++++++------ .../management/survey/SurveyQuestionContent.kt | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/SurveyFormContent.kt b/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/SurveyFormContent.kt index d0ca88dd7..232dbfc93 100644 --- a/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/SurveyFormContent.kt +++ b/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/SurveyFormContent.kt @@ -19,9 +19,9 @@ internal fun SurveyFormContent( content: String, question: String, questionType: QuestionType, - time: LocalTime, - date: LocalDate, - questionNumber: Int, + timeDeadline: LocalTime, + dateDeadline: LocalDate, + currentQuestionNumber: Int, totalQuestionNumber: Int, timePickerState: TimePickerState, showDatePicker: Boolean, @@ -86,7 +86,7 @@ internal fun SurveyFormContent( }, onQuestionChanged = onQuestionChanged, onAddSurveyQuestionButtonClicked = onAddQuestionButtonClicked, - questionNumber = questionNumber, + currentQuestionNumber = currentQuestionNumber, totalQuestionNumber = totalQuestionNumber, onPreviousButtonClicked = { onPreviousButtonClicked(SurveyFormState.INFORMATION) @@ -104,8 +104,8 @@ internal fun SurveyFormContent( SurveyFormState.DEADLINE -> { SurveyDeadlineContent( - time = time, - date = date, + timeDeadline = timeDeadline, + dateDeadline = dateDeadline, timePickerState = timePickerState, showDatePicker = showDatePicker, showTimePicker = showTimePicker, diff --git a/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/SurveyQuestionContent.kt b/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/SurveyQuestionContent.kt index ee7c892fd..41f4b34d7 100644 --- a/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/SurveyQuestionContent.kt +++ b/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/SurveyQuestionContent.kt @@ -41,7 +41,7 @@ import com.wap.wapp.core.model.survey.QuestionType internal fun SurveyQuestionContent( question: String, questionType: QuestionType, - questionNumber: Int, + currentQuestionNumber: Int, totalQuestionNumber: Int, onQuestionChanged: (String) -> Unit, onQuestionTypeChanged: (QuestionType) -> Unit, @@ -75,7 +75,7 @@ internal fun SurveyQuestionContent( ) SurveyQuestionNumberText( - questionNumber = questionNumber + 1, + questionNumber = currentQuestionNumber + 1, totalQuestionNumber = totalQuestionNumber + 1, onPreviousQuestionButtonClicked = onPreviousQuestionButtonClicked, onNextQuestionButtonClicked = onNextQuestionButtonClicked, From aefdaac1569e90ee9012d1dd2d5897c535b024ec Mon Sep 17 00:00:00 2001 From: jeongjaino Date: Wed, 31 Jan 2024 23:42:24 +0900 Subject: [PATCH 09/16] =?UTF-8?q?[STYLE]=20#95=20:=20=EC=9D=B8=EC=9E=90=20?= =?UTF-8?q?=EB=84=A4=EC=9D=B4=EB=B0=8D=20=EC=88=98=EC=A0=95=20time,=20date?= =?UTF-8?q?=20=3D>=20timeDeadline,=20dateDeadline?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../feature/management/survey/SurveyDeadlineContent.kt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/SurveyDeadlineContent.kt b/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/SurveyDeadlineContent.kt index 7cdccab0a..89bb23cc9 100644 --- a/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/SurveyDeadlineContent.kt +++ b/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/SurveyDeadlineContent.kt @@ -32,8 +32,8 @@ import java.time.LocalTime @OptIn(ExperimentalMaterial3Api::class) @Composable internal fun SurveyDeadlineContent( - date: LocalDate, - time: LocalTime, + dateDeadline: LocalDate, + timeDeadline: LocalTime, timePickerState: TimePickerState, showDatePicker: Boolean, showTimePicker: Boolean, @@ -46,7 +46,7 @@ internal fun SurveyDeadlineContent( ) { if (showDatePicker) { WappDatePickerDialog( - date = date, + date = dateDeadline, onDismissRequest = { onDatePickerStateChanged(false) }, onDateChanged = onDateChanged, ) @@ -78,7 +78,7 @@ internal fun SurveyDeadlineContent( DeadlineCard( title = stringResource(R.string.date), - hint = date.format(DateUtil.yyyyMMddFormatter), + hint = dateDeadline.format(DateUtil.yyyyMMddFormatter), onCardClicked = { onDatePickerStateChanged(true) }, @@ -86,7 +86,7 @@ internal fun SurveyDeadlineContent( DeadlineCard( title = stringResource(R.string.time), - hint = time.format(DateUtil.HHmmFormatter), + hint = timeDeadline.format(DateUtil.HHmmFormatter), onCardClicked = { onTimePickerStateChanged(true) }, From 13cc8bce596b4091d5c0de8e657c165a66430b56 Mon Sep 17 00:00:00 2001 From: jeongjaino Date: Wed, 31 Jan 2024 23:43:04 +0900 Subject: [PATCH 10/16] =?UTF-8?q?[REFACTOR]=20#95=20:=20=EC=9D=B4=EC=A0=84?= =?UTF-8?q?=20=EC=A7=88=EB=AC=B8,=20=EC=9D=B4=ED=9B=84=20=EC=A7=88?= =?UTF-8?q?=EB=AC=B8,=20=EC=A7=88=EB=AC=B8=20=EC=B6=94=EA=B0=80=ED=95=98?= =?UTF-8?q?=EA=B8=B0,=20=EB=8B=A4=EC=9D=8C=20=EB=B2=84=ED=8A=BC=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SurveyFormRegistrationScreen.kt | 52 +++++++++++-------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/registration/SurveyFormRegistrationScreen.kt b/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/registration/SurveyFormRegistrationScreen.kt index b307865a5..f516199c1 100644 --- a/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/registration/SurveyFormRegistrationScreen.kt +++ b/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/registration/SurveyFormRegistrationScreen.kt @@ -39,16 +39,17 @@ internal fun SurveyRegistrationScreen( val currentRegistrationState = viewModel.currentSurveyFormState.collectAsStateWithLifecycle().value val eventList = viewModel.eventList.collectAsStateWithLifecycle().value - val eventSelection = viewModel.surveyEventSelection.collectAsStateWithLifecycle().value + val eventSelection = viewModel.eventSelection.collectAsStateWithLifecycle().value val title = viewModel.surveyTitle.collectAsStateWithLifecycle().value val content = viewModel.surveyContent.collectAsStateWithLifecycle().value - val questionTitle = viewModel.surveyQuestionTitle.collectAsStateWithLifecycle().value - val questionType = viewModel.surveyQuestionType.collectAsStateWithLifecycle().value - val questionNumber = viewModel.surveyQuestionNumber.collectAsStateWithLifecycle().value + val questionTitle = viewModel.questionTitle.collectAsStateWithLifecycle().value + val questionType = viewModel.questionType.collectAsStateWithLifecycle().value + val currentQuestionNumber = viewModel.currentQuestionNumber.collectAsStateWithLifecycle().value val totalQuestionNumber = - viewModel.surveyQuestionTotalNumber.collectAsStateWithLifecycle().value - val time = viewModel.surveyTimeDeadline.collectAsStateWithLifecycle().value - val date = viewModel.surveyDateDeadline.collectAsStateWithLifecycle().value + viewModel.totalQuestionNumber.collectAsStateWithLifecycle().value + val questionList = viewModel.questionList.collectAsStateWithLifecycle().value + val timeDeadline = viewModel.timeDeadline.collectAsStateWithLifecycle().value + val dateDeadline = viewModel.dateDeadline.collectAsStateWithLifecycle().value val snackBarHostState = remember { SnackbarHostState() } val timePickerState = rememberTimePickerState() var showDatePicker by remember { mutableStateOf(false) } @@ -106,12 +107,12 @@ internal fun SurveyRegistrationScreen( content = content, question = questionTitle, questionType = questionType, - date = date, - time = time, + dateDeadline = dateDeadline, + timeDeadline = timeDeadline, timePickerState = timePickerState, showDatePicker = showDatePicker, showTimePicker = showTimePicker, - questionNumber = questionNumber, + currentQuestionNumber = currentQuestionNumber, totalQuestionNumber = totalQuestionNumber, onDatePickerStateChanged = { state -> showDatePicker = state }, onTimePickerStateChanged = { state -> showTimePicker = state }, @@ -123,9 +124,9 @@ internal fun SurveyRegistrationScreen( onQuestionTypeChanged = { questionType -> viewModel.setSurveyQuestionType(questionType) }, - onNextQuestionButtonClicked = { + onNextQuestionButtonClicked = { // '>' 버튼 if (viewModel.validateSurveyForm(SurveyFormState.QUESTION).not()) { - return@SurveyFormContent // 답변 검증 + return@SurveyFormContent } viewModel.editSurveyQuestion() // 답변 수정 @@ -133,13 +134,13 @@ internal fun SurveyRegistrationScreen( viewModel.setNextQuestionNumber() // 다음 질문 불러오기 viewModel.setQuestion() }, - onPreviousQuestionButtonClicked = { + onPreviousQuestionButtonClicked = { // '<' 버튼 if (viewModel.validateSurveyForm(SurveyFormState.QUESTION).not()) { return@SurveyFormContent } - // 다른 질문으로 넘어가기 전, 상태 저장 - if (questionNumber == totalQuestionNumber) { + // 다른 질문으로 넘어가기 전, 질문 추가 혹은 저장 + if (currentQuestionNumber == questionList.size) { viewModel.addSurveyQuestion() } else { viewModel.editSurveyQuestion() @@ -148,28 +149,35 @@ internal fun SurveyRegistrationScreen( viewModel.setPreviousQuestionNumber() // 이전 질문 불러오기 viewModel.setQuestion() }, - onAddQuestionButtonClicked = { - if (viewModel.validateSurveyForm(SurveyFormState.QUESTION)) { - viewModel.addSurveyQuestion() + onAddQuestionButtonClicked = { // 문항 추가 버튼 + if (viewModel.validateSurveyForm(SurveyFormState.QUESTION).not()) { + return@SurveyFormContent } - viewModel.setLastQuestionNumber() + + if (currentQuestionNumber == questionList.size) { + viewModel.addSurveyQuestion() // 질문 추가 + } else { + viewModel.editSurveyQuestion() + } + + viewModel.setLastQuestion() }, onDateChanged = viewModel::setSurveyDateDeadline, onTimeChanged = { localTime -> viewModel.setSurveyTimeDeadline(localTime) }, - onPreviousButtonClicked = { previousState -> + onPreviousButtonClicked = { previousState -> // 이전 버튼 if (previousState == SurveyFormState.QUESTION) { viewModel.setSurveyQuestionFromQuestionList() } viewModel.setSurveyFormState(previousState) }, - onNextButtonClicked = { currentState, nextState -> + onNextButtonClicked = { currentState, nextState -> // 다음 버튼 if (viewModel.validateSurveyForm(currentState).not()) { return@SurveyFormContent } if (currentState == SurveyFormState.QUESTION) { - if (questionNumber == totalQuestionNumber) { + if (currentQuestionNumber == questionList.size) { // 마지막 질문인 경우 viewModel.addSurveyQuestion() } else { viewModel.editSurveyQuestion() From 6741b89035c5459894a54b4527daffc215a52001 Mon Sep 17 00:00:00 2001 From: jeongjaino Date: Wed, 31 Jan 2024 23:43:09 +0900 Subject: [PATCH 11/16] =?UTF-8?q?[REFACTOR]=20#95=20:=20=EC=9D=B4=EC=A0=84?= =?UTF-8?q?=20=EC=A7=88=EB=AC=B8,=20=EC=9D=B4=ED=9B=84=20=EC=A7=88?= =?UTF-8?q?=EB=AC=B8,=20=EC=A7=88=EB=AC=B8=20=EC=B6=94=EA=B0=80=ED=95=98?= =?UTF-8?q?=EA=B8=B0,=20=EB=8B=A4=EC=9D=8C=20=EB=B2=84=ED=8A=BC=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../survey/edit/SurveyFormEditScreen.kt | 6 +- .../SurveyFormRegistrationViewModel.kt | 96 +++++++++---------- 2 files changed, 51 insertions(+), 51 deletions(-) diff --git a/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/edit/SurveyFormEditScreen.kt b/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/edit/SurveyFormEditScreen.kt index 5238e1ed1..5eb7b6285 100644 --- a/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/edit/SurveyFormEditScreen.kt +++ b/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/edit/SurveyFormEditScreen.kt @@ -138,12 +138,12 @@ internal fun SurveyFormEditScreen( content = content, question = question, questionType = questionType, - date = date, - time = time, + dateDeadline = date, + timeDeadline = time, timePickerState = timePickerState, showDatePicker = showDatePicker, showTimePicker = showTimePicker, - questionNumber = totalQuestionSize, + currentQuestionNumber = totalQuestionSize, totalQuestionNumber = totalQuestionSize, onDatePickerStateChanged = { state -> showDatePicker = state }, onTimePickerStateChanged = { state -> showTimePicker = state }, diff --git a/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/registration/SurveyFormRegistrationViewModel.kt b/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/registration/SurveyFormRegistrationViewModel.kt index 5696669ab..ddcf362a9 100644 --- a/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/registration/SurveyFormRegistrationViewModel.kt +++ b/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/registration/SurveyFormRegistrationViewModel.kt @@ -37,9 +37,9 @@ class SurveyFormRegistrationViewModel @Inject constructor( private val _eventList: MutableStateFlow = MutableStateFlow(EventsState.Loading) val eventList: StateFlow = _eventList.asStateFlow() - private val _surveyEventSelection: MutableStateFlow = + private val _eventSelection: MutableStateFlow = MutableStateFlow(EVENT_SELECTION_INIT) - val surveyEventSelection = _surveyEventSelection.asStateFlow() + val eventSelection = _eventSelection.asStateFlow() private val _surveyTitle: MutableStateFlow = MutableStateFlow("") val surveyTitle = _surveyTitle.asStateFlow() @@ -47,29 +47,30 @@ class SurveyFormRegistrationViewModel @Inject constructor( private val _surveyContent: MutableStateFlow = MutableStateFlow("") val surveyContent = _surveyContent.asStateFlow() - private val _surveyQuestionTitle: MutableStateFlow = MutableStateFlow("") - val surveyQuestionTitle = _surveyQuestionTitle.asStateFlow() + private val _questionTitle: MutableStateFlow = MutableStateFlow("") + val questionTitle = _questionTitle.asStateFlow() - private val _surveyQuestionType: MutableStateFlow = + private val _questionType: MutableStateFlow = MutableStateFlow(QuestionType.SUBJECTIVE) - val surveyQuestionType = _surveyQuestionType.asStateFlow() + val questionType = _questionType.asStateFlow() - private val _surveyQuestionNumber: MutableStateFlow = MutableStateFlow(0) - val surveyQuestionNumber = _surveyQuestionNumber.asStateFlow() + private val _currentQuestionNumber: MutableStateFlow = MutableStateFlow(0) + val currentQuestionNumber = _currentQuestionNumber.asStateFlow() // 현재 질문의 번호 UI State - private val _surveyQuestionTotalNumber: MutableStateFlow = MutableStateFlow(0) - val surveyQuestionTotalNumber = _surveyQuestionTotalNumber.asStateFlow() + private val _totalQuestionNumber: MutableStateFlow = MutableStateFlow(0) + val totalQuestionNumber = _totalQuestionNumber.asStateFlow() // 전체 질문의 번호 UI State - private val surveyQuestionList: MutableStateFlow> = + private val _questionList: MutableStateFlow> = MutableStateFlow(mutableListOf()) + val questionList = _questionList.asStateFlow() // 사용자가 작성한 질문 목록 - private val _surveyTimeDeadline: MutableStateFlow = + private val _timeDeadline: MutableStateFlow = MutableStateFlow(DateUtil.generateNowTime()) - val surveyTimeDeadline = _surveyTimeDeadline.asStateFlow() + val timeDeadline = _timeDeadline.asStateFlow() - private val _surveyDateDeadline: MutableStateFlow = + private val _dateDeadline: MutableStateFlow = MutableStateFlow(DateUtil.generateNowDate()) - val surveyDateDeadline = _surveyDateDeadline.asStateFlow() + val dateDeadline = _dateDeadline.asStateFlow() fun getEventList() = viewModelScope.launch { getEventListUseCase().onSuccess { eventList -> @@ -81,12 +82,12 @@ class SurveyFormRegistrationViewModel @Inject constructor( fun registerSurvey() = viewModelScope.launch { registerSurveyUseCase( - event = surveyEventSelection.value, + event = _eventSelection.value, title = _surveyTitle.value, content = _surveyContent.value, - surveyQuestionList = surveyQuestionList.value, - deadlineDate = _surveyDateDeadline.value, - deadlineTime = _surveyTimeDeadline.value, + surveyQuestionList = _questionList.value, + deadlineDate = _dateDeadline.value, + deadlineTime = _timeDeadline.value, ).onSuccess { _surveyRegistrationEvent.emit(SurveyRegistrationEvent.Success) }.onFailure { throwable -> @@ -129,80 +130,79 @@ class SurveyFormRegistrationViewModel @Inject constructor( fun setSurveyFormState(nextState: SurveyFormState) { _currentSurveyFormState.value = nextState } - fun setSurveyEventSelection(event: Event) { _surveyEventSelection.value = event } + fun setSurveyEventSelection(event: Event) { _eventSelection.value = event } fun setSurveyTitle(title: String) { _surveyTitle.value = title } fun setSurveyContent(content: String) { _surveyContent.value = content } - fun setSurveyQuestionTitle(title: String) { _surveyQuestionTitle.value = title } + fun setSurveyQuestionTitle(title: String) { _questionTitle.value = title } - fun setSurveyQuestionType(type: QuestionType) { _surveyQuestionType.value = type } + fun setSurveyQuestionType(type: QuestionType) { _questionType.value = type } - fun setNextQuestionNumber() { _surveyQuestionNumber.value += 1 } + fun setNextQuestionNumber() { _currentQuestionNumber.value += 1 } - fun setPreviousQuestionNumber() { _surveyQuestionNumber.value -= 1 } + fun setPreviousQuestionNumber() { _currentQuestionNumber.value -= 1 } - fun setLastQuestionNumber() { - _surveyQuestionTotalNumber.value += 1 // TODO - _surveyQuestionNumber.value = surveyQuestionList.value.size + fun setLastQuestion() { + _currentQuestionNumber.value = _questionList.value.size // 마지막 질문 번호로 변경 + _totalQuestionNumber.value += 1 // 전체 질문 갯수 추가 + clearSurveyQuestionTitle() } fun setQuestion() { - val currentNumber = _surveyQuestionNumber.value - val totalSize = surveyQuestionList.value.size + val currentNumber = _currentQuestionNumber.value + val totalSize = _questionList.value.size if (currentNumber < totalSize) { - val surveyQuestion = surveyQuestionList.value[_surveyQuestionNumber.value] + val surveyQuestion = _questionList.value[_currentQuestionNumber.value] setSurveyQuestionTitle(surveyQuestion.questionTitle) setSurveyQuestionType(surveyQuestion.questionType) return } - - clearSurveyQuestionState() } fun addSurveyQuestion() { - surveyQuestionList.value.add( + _questionList.value.add( SurveyQuestion( - questionTitle = _surveyQuestionTitle.value, - questionType = _surveyQuestionType.value, + questionTitle = _questionTitle.value, + questionType = _questionType.value, ), ) - clearSurveyQuestionState() + clearSurveyQuestionTitle() } fun editSurveyQuestion() { - val questionNumber = _surveyQuestionNumber.value - surveyQuestionList.value[questionNumber] = SurveyQuestion( - questionTitle = _surveyQuestionTitle.value, - questionType = _surveyQuestionType.value, + val questionNumber = _currentQuestionNumber.value + _questionList.value[questionNumber] = SurveyQuestion( + questionTitle = _questionTitle.value, + questionType = _questionType.value, ) - clearSurveyQuestionState() + clearSurveyQuestionTitle() } fun setSurveyQuestionFromQuestionList() { // 작성된 질문 목록을 불러올 때, 마지막 질문은 UI에 노출 - val lastSurveyQuestion = surveyQuestionList.value.removeLast() + val lastSurveyQuestion = _questionList.value.last() setSurveyQuestionTitle(lastSurveyQuestion.questionTitle) setSurveyQuestionType(lastSurveyQuestion.questionType) } - fun setSurveyTimeDeadline(time: LocalTime) { _surveyTimeDeadline.value = time } + fun setSurveyTimeDeadline(time: LocalTime) { _timeDeadline.value = time } - fun setSurveyDateDeadline(date: LocalDate) { _surveyDateDeadline.value = date } + fun setSurveyDateDeadline(date: LocalDate) { _dateDeadline.value = date } - private fun clearSurveyQuestionState() { _surveyQuestionTitle.value = "" } + private fun clearSurveyQuestionTitle() { _questionTitle.value = "" } - private fun isNotValidSurveyQuestion() = _surveyQuestionTitle.value.isBlank() + private fun isNotValidSurveyQuestion() = _questionTitle.value.isBlank() private fun isNotValidEventSelection() = - _surveyEventSelection.value.eventId == EVENT_SELECTION_INIT.eventId + _eventSelection.value.eventId == EVENT_SELECTION_INIT.eventId private fun isNotValidInformation() = _surveyTitle.value.isBlank() || _surveyContent.value.isBlank() - private fun isNotValidDeadline() = _surveyDateDeadline.value <= DateUtil.generateNowDate() + private fun isNotValidDeadline() = _dateDeadline.value <= DateUtil.generateNowDate() private fun emitValidationErrorMessage(message: String) { viewModelScope.launch { From 2f1af345914eb987cfae6fecdb591a4245d50a94 Mon Sep 17 00:00:00 2001 From: jeongjaino Date: Tue, 6 Feb 2024 21:08:16 +0900 Subject: [PATCH 12/16] =?UTF-8?q?[CHORE]=20#95=20:=20=EA=B3=B5=EC=9A=A9?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EC=82=AC=EC=9A=A9=ED=95=98=EB=8A=94=20Eve?= =?UTF-8?q?ntState=20=EC=99=B8=EB=B6=80=EB=A1=9C=20=EB=82=B4=EB=B3=B4?= =?UTF-8?q?=EB=82=B4=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wap/wapp/feature/management/survey/EventsState.kt | 9 +++++++++ .../feature/management/survey/SurveyFormContent.kt | 11 +++++------ .../registration/SurveyFormRegistrationViewModel.kt | 7 +------ 3 files changed, 15 insertions(+), 12 deletions(-) create mode 100644 feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/EventsState.kt diff --git a/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/EventsState.kt b/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/EventsState.kt new file mode 100644 index 000000000..7a5cd3ba0 --- /dev/null +++ b/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/EventsState.kt @@ -0,0 +1,9 @@ +package com.wap.wapp.feature.management.survey + +import com.wap.wapp.core.model.event.Event + +sealed class EventsState { + data object Loading : EventsState() + data class Success(val events: List) : EventsState() + data class Failure(val throwable: Throwable) : EventsState() +} diff --git a/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/SurveyFormContent.kt b/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/SurveyFormContent.kt index 232dbfc93..ce2a49fc1 100644 --- a/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/SurveyFormContent.kt +++ b/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/SurveyFormContent.kt @@ -5,7 +5,6 @@ import androidx.compose.material3.TimePickerState import androidx.compose.runtime.Composable import com.wap.wapp.core.model.event.Event import com.wap.wapp.core.model.survey.QuestionType -import com.wap.wapp.feature.management.survey.registration.SurveyFormRegistrationViewModel import java.time.LocalDate import java.time.LocalTime @@ -13,11 +12,11 @@ import java.time.LocalTime @Composable internal fun SurveyFormContent( surveyRegistrationState: SurveyFormState, - eventsState: SurveyFormRegistrationViewModel.EventsState, + eventsState: EventsState, eventSelection: Event, title: String, content: String, - question: String, + questionTitle: String, questionType: QuestionType, timeDeadline: LocalTime, dateDeadline: LocalDate, @@ -33,7 +32,7 @@ internal fun SurveyFormContent( onEventSelected: (Event) -> Unit, onTitleChanged: (String) -> Unit, onContentChanged: (String) -> Unit, - onQuestionChanged: (String) -> Unit, + onQuestionTitleChanged: (String) -> Unit, onQuestionTypeChanged: (QuestionType) -> Unit, onPreviousQuestionButtonClicked: () -> Unit, onNextQuestionButtonClicked: () -> Unit, @@ -79,12 +78,12 @@ internal fun SurveyFormContent( SurveyFormState.QUESTION -> { SurveyQuestionContent( - question = question, + questionTitle = questionTitle, questionType = questionType, onQuestionTypeChanged = { defaultQuestionType -> onQuestionTypeChanged(defaultQuestionType) }, - onQuestionChanged = onQuestionChanged, + onQuestionChanged = onQuestionTitleChanged, onAddSurveyQuestionButtonClicked = onAddQuestionButtonClicked, currentQuestionNumber = currentQuestionNumber, totalQuestionNumber = totalQuestionNumber, diff --git a/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/registration/SurveyFormRegistrationViewModel.kt b/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/registration/SurveyFormRegistrationViewModel.kt index ddcf362a9..842955ae2 100644 --- a/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/registration/SurveyFormRegistrationViewModel.kt +++ b/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/registration/SurveyFormRegistrationViewModel.kt @@ -8,6 +8,7 @@ import com.wap.wapp.core.domain.usecase.survey.PostSurveyFormUseCase import com.wap.wapp.core.model.event.Event import com.wap.wapp.core.model.survey.QuestionType import com.wap.wapp.core.model.survey.SurveyQuestion +import com.wap.wapp.feature.management.survey.EventsState import com.wap.wapp.feature.management.survey.SurveyFormState import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableSharedFlow @@ -218,12 +219,6 @@ class SurveyFormRegistrationViewModel @Inject constructor( data object Success : SurveyRegistrationEvent() } - sealed class EventsState { - data object Loading : EventsState() - data class Success(val events: List) : EventsState() - data class Failure(val throwable: Throwable) : EventsState() - } - companion object { val EVENT_SELECTION_INIT = Event("", "", "", "", LocalDateTime.MIN, LocalDateTime.MAX) } From a958ff6d7c0d47c3e80a466a2e6b3a6e7b937427 Mon Sep 17 00:00:00 2001 From: jeongjaino Date: Tue, 6 Feb 2024 21:10:11 +0900 Subject: [PATCH 13/16] [RENAME] #95 : DeleteSurvey -> SurveyDelete --- .../survey/edit/SurveyDeleteDialog.kt | 131 ++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/edit/SurveyDeleteDialog.kt diff --git a/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/edit/SurveyDeleteDialog.kt b/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/edit/SurveyDeleteDialog.kt new file mode 100644 index 000000000..fff64f6ff --- /dev/null +++ b/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/edit/SurveyDeleteDialog.kt @@ -0,0 +1,131 @@ +package com.wap.wapp.feature.management.survey.edit + +import androidx.compose.foundation.background +import androidx.compose.foundation.border +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.wrapContentSize +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material3.Button +import androidx.compose.material3.ButtonDefaults +import androidx.compose.material3.Divider +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.SpanStyle +import androidx.compose.ui.text.buildAnnotatedString +import androidx.compose.ui.text.style.TextDecoration +import androidx.compose.ui.text.withStyle +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import androidx.compose.ui.window.Dialog +import androidx.compose.ui.window.DialogProperties +import com.wap.designsystem.WappTheme +import com.wap.wapp.feature.management.survey.R + +@Composable +internal fun DeleteSurveyDialog( + deleteSurvey: () -> Unit, + onDismissRequest: () -> Unit, +) { + Dialog( + onDismissRequest = onDismissRequest, + properties = DialogProperties( + usePlatformDefaultWidth = false, + ), + ) { + Column( + verticalArrangement = Arrangement.spacedBy(16.dp), + horizontalAlignment = Alignment.CenterHorizontally, + modifier = Modifier + .wrapContentSize() + .padding(horizontal = 30.dp) + .clip(RoundedCornerShape(8.dp)) + .background(WappTheme.colors.black25), + ) { + Text( + text = stringResource(id = R.string.delete_survey), + style = WappTheme.typography.contentBold.copy(fontSize = 20.sp), + color = WappTheme.colors.yellow34, + modifier = Modifier.padding(top = 16.dp), + ) + + Divider( + color = WappTheme.colors.gray82, + modifier = Modifier.padding(horizontal = 12.dp), + ) + + Text( + text = generateDialogContentString(), + style = WappTheme.typography.contentRegular, + color = WappTheme.colors.white, + modifier = Modifier.padding(top = 12.dp, start = 12.dp, end = 12.dp), + ) + + Row( + horizontalArrangement = Arrangement.spacedBy(20.dp), + modifier = Modifier.padding(horizontal = 12.dp, vertical = 16.dp), + ) { + Button( + onClick = { + deleteSurvey() + onDismissRequest() + }, + shape = RoundedCornerShape(8.dp), + colors = ButtonDefaults.buttonColors( + containerColor = WappTheme.colors.yellow34, + ), + contentPadding = PaddingValues(vertical = 12.dp), + modifier = Modifier.weight(1f), + ) { + Text( + text = stringResource(id = R.string.complete), + style = WappTheme.typography.titleRegular, + color = WappTheme.colors.black, + ) + } + + Button( + onClick = onDismissRequest, + shape = RoundedCornerShape(10.dp), + colors = ButtonDefaults.buttonColors( + containerColor = WappTheme.colors.black25, + ), + contentPadding = PaddingValues(vertical = 12.dp), + modifier = Modifier + .weight(1f) + .border( + width = 1.dp, + color = WappTheme.colors.yellow34, + shape = RoundedCornerShape(8.dp), + ), + ) { + Text( + text = stringResource(R.string.cancel), + style = WappTheme.typography.titleRegular, + color = WappTheme.colors.yellow34, + ) + } + } + } + } +} + +@Composable +private fun generateDialogContentString() = buildAnnotatedString { + append("정말로 해당 설문을 삭제하시겠습니까?\n") + withStyle( + style = SpanStyle( + textDecoration = TextDecoration.Underline, + color = WappTheme.colors.yellow34, + ), + ) { + append("해당 설문과 관련된 답변들이 모두 삭제됩니다.") + } +} From aa6404a5a0810da2ddd09f0f3d700230f2066e96 Mon Sep 17 00:00:00 2001 From: jeongjaino Date: Tue, 6 Feb 2024 21:10:46 +0900 Subject: [PATCH 14/16] =?UTF-8?q?[STYLE]=20#95=20:=20=EB=B3=80=EC=88=98=20?= =?UTF-8?q?=EB=84=A4=EC=9D=B4=EB=B0=8D=20=EC=88=98=EC=A0=95=20question=20-?= =?UTF-8?q?>=20questionTitle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wapp/feature/management/survey/SurveyQuestionContent.kt | 4 ++-- .../survey/registration/SurveyFormRegistrationScreen.kt | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/SurveyQuestionContent.kt b/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/SurveyQuestionContent.kt index 41f4b34d7..1b1f6adf5 100644 --- a/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/SurveyQuestionContent.kt +++ b/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/SurveyQuestionContent.kt @@ -39,7 +39,7 @@ import com.wap.wapp.core.model.survey.QuestionType @Composable internal fun SurveyQuestionContent( - question: String, + questionTitle: String, questionType: QuestionType, currentQuestionNumber: Int, totalQuestionNumber: Int, @@ -83,7 +83,7 @@ internal fun SurveyQuestionContent( } WappRoundedTextField( - value = question, + value = questionTitle, onValueChange = onQuestionChanged, modifier = Modifier .fillMaxWidth() diff --git a/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/registration/SurveyFormRegistrationScreen.kt b/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/registration/SurveyFormRegistrationScreen.kt index f516199c1..970e4d782 100644 --- a/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/registration/SurveyFormRegistrationScreen.kt +++ b/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/registration/SurveyFormRegistrationScreen.kt @@ -105,7 +105,7 @@ internal fun SurveyRegistrationScreen( eventSelection = eventSelection, title = title, content = content, - question = questionTitle, + questionTitle = questionTitle, questionType = questionType, dateDeadline = dateDeadline, timeDeadline = timeDeadline, @@ -120,7 +120,7 @@ internal fun SurveyRegistrationScreen( onEventSelected = { event -> viewModel.setSurveyEventSelection(event) }, onTitleChanged = { title -> viewModel.setSurveyTitle(title) }, onContentChanged = { content -> viewModel.setSurveyContent(content) }, - onQuestionChanged = { question -> viewModel.setSurveyQuestionTitle(question) }, + onQuestionTitleChanged = { question -> viewModel.setSurveyQuestionTitle(question) }, onQuestionTypeChanged = { questionType -> viewModel.setSurveyQuestionType(questionType) }, From 0ab4acf75f5a84aa9efe443a1f4f477db2d70468 Mon Sep 17 00:00:00 2001 From: jeongjaino Date: Tue, 6 Feb 2024 21:11:24 +0900 Subject: [PATCH 15/16] =?UTF-8?q?[FEATURE]=20#95=20:=20=EC=84=A4=EB=AC=B8?= =?UTF-8?q?=20=EC=88=98=EC=A0=95=20=EC=8B=9C,=20=EC=9D=B4=EC=A0=84=20?= =?UTF-8?q?=EC=9D=B4=ED=9B=84=20=EC=A7=88=EB=AC=B8=20=EC=9D=B4=EB=8F=99=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../survey/edit/SurveyFormEditScreen.kt | 224 ++++++------------ .../survey/edit/SurveyFormEditViewModel.kt | 125 ++++++---- 2 files changed, 153 insertions(+), 196 deletions(-) diff --git a/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/edit/SurveyFormEditScreen.kt b/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/edit/SurveyFormEditScreen.kt index 5eb7b6285..04f812d60 100644 --- a/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/edit/SurveyFormEditScreen.kt +++ b/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/edit/SurveyFormEditScreen.kt @@ -1,45 +1,25 @@ package com.wap.wapp.feature.management.survey.edit -import androidx.compose.foundation.background -import androidx.compose.foundation.border import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.PaddingValues -import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.WindowInsets import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.layout.wrapContentSize -import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.material3.Button -import androidx.compose.material3.ButtonDefaults -import androidx.compose.material3.Divider import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Scaffold import androidx.compose.material3.SnackbarHost import androidx.compose.material3.SnackbarHostState -import androidx.compose.material3.Text import androidx.compose.material3.rememberTimePickerState import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect -import androidx.compose.runtime.collectAsState 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.clip -import androidx.compose.ui.res.stringResource -import androidx.compose.ui.text.SpanStyle -import androidx.compose.ui.text.buildAnnotatedString -import androidx.compose.ui.text.style.TextDecoration -import androidx.compose.ui.text.withStyle import androidx.compose.ui.unit.dp -import androidx.compose.ui.unit.sp -import androidx.compose.ui.window.Dialog -import androidx.compose.ui.window.DialogProperties import androidx.hilt.navigation.compose.hiltViewModel +import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.wap.designsystem.WappTheme import com.wap.designsystem.component.WappSubTopBar import com.wap.wapp.core.commmon.extensions.toSupportingText @@ -57,27 +37,30 @@ internal fun SurveyFormEditScreen( surveyFormId: String, navigateToManagement: () -> Unit, ) { - val currentRegistrationState = viewModel.currentSurveyFormState.collectAsState().value - val eventList = viewModel.eventList.collectAsState().value - val eventSelection = viewModel.surveyEventSelection.collectAsState().value - val title = viewModel.surveyTitle.collectAsState().value - val content = viewModel.surveyContent.collectAsState().value - val question = viewModel.surveyQuestion.collectAsState().value - val questionType = viewModel.surveyQuestionType.collectAsState().value - val totalQuestionSize = viewModel.surveyQuestionList.collectAsState().value.size + 1 - val time = viewModel.surveyTimeDeadline.collectAsState().value - val date = viewModel.surveyDateDeadline.collectAsState().value + val currentRegistrationState = + viewModel.currentSurveyFormState.collectAsStateWithLifecycle().value + val eventList = viewModel.eventList.collectAsStateWithLifecycle().value + val eventSelection = viewModel.eventSelection.collectAsStateWithLifecycle().value + val title = viewModel.surveyTitle.collectAsStateWithLifecycle().value + val content = viewModel.surveyContent.collectAsStateWithLifecycle().value + val questionTitle = viewModel.questionTitle.collectAsStateWithLifecycle().value + val questionType = viewModel.questionType.collectAsStateWithLifecycle().value + val currentQuestionNumber = viewModel.currentQuestionNumber.collectAsStateWithLifecycle().value + val totalQuestionNumber = + viewModel.totalQuestionNumber.collectAsStateWithLifecycle().value + val questionList = viewModel.questionList.collectAsStateWithLifecycle().value + val timeDeadline = viewModel.timeDeadline.collectAsStateWithLifecycle().value + val dateDeadline = viewModel.dateDeadline.collectAsStateWithLifecycle().value val snackBarHostState = remember { SnackbarHostState() } val timePickerState = rememberTimePickerState() var showDatePicker by remember { mutableStateOf(false) } var showTimePicker by remember { mutableStateOf(false) } + var showDeleteSurveyDialog by remember { mutableStateOf(false) } LaunchedEffect(true) { viewModel.getSurveyForm(surveyFormId) - } - LaunchedEffect(true) { viewModel.surveyFormEditUiEvent.collectLatest { surveyFormEditEvent -> when (surveyFormEditEvent) { is SurveyFormEditViewModel.SurveyFormEditUiEvent.EditSuccess -> @@ -136,50 +119,86 @@ internal fun SurveyFormEditScreen( eventSelection = eventSelection, title = title, content = content, - question = question, + questionTitle = questionTitle, questionType = questionType, - dateDeadline = date, - timeDeadline = time, + dateDeadline = dateDeadline, + timeDeadline = timeDeadline, timePickerState = timePickerState, showDatePicker = showDatePicker, showTimePicker = showTimePicker, - currentQuestionNumber = totalQuestionSize, - totalQuestionNumber = totalQuestionSize, + currentQuestionNumber = currentQuestionNumber, + totalQuestionNumber = totalQuestionNumber, onDatePickerStateChanged = { state -> showDatePicker = state }, onTimePickerStateChanged = { state -> showTimePicker = state }, onEventContentInitialized = { viewModel.getEventList() }, onEventSelected = { event -> viewModel.setSurveyEventSelection(event) }, onTitleChanged = { title -> viewModel.setSurveyTitle(title) }, onContentChanged = { content -> viewModel.setSurveyContent(content) }, - onQuestionChanged = { question -> viewModel.setSurveyQuestion(question) }, + onQuestionTitleChanged = { question -> viewModel.setSurveyQuestionTitle(question) }, onQuestionTypeChanged = { questionType -> viewModel.setSurveyQuestionType(questionType) }, - onPreviousQuestionButtonClicked = {}, - onNextQuestionButtonClicked = {}, + onNextQuestionButtonClicked = { // '>' 버튼 + if (viewModel.validateSurveyForm(SurveyFormState.QUESTION).not()) { + return@SurveyFormContent + } + + viewModel.editSurveyQuestion() // 답변 수정 + + viewModel.setNextQuestionNumber() // 다음 질문 불러오기 + viewModel.setQuestion() + }, + onPreviousQuestionButtonClicked = { // '<' 버튼 + if (viewModel.validateSurveyForm(SurveyFormState.QUESTION).not()) { + return@SurveyFormContent + } + + // 다른 질문으로 넘어가기 전, 질문 추가 혹은 저장 + if (currentQuestionNumber == questionList.size) { + viewModel.addSurveyQuestion() + } else { + viewModel.editSurveyQuestion() + } + + viewModel.setPreviousQuestionNumber() // 이전 질문 불러오기 + viewModel.setQuestion() + }, + onAddQuestionButtonClicked = { // 문항 추가 버튼 + if (viewModel.validateSurveyForm(SurveyFormState.QUESTION).not()) { + return@SurveyFormContent + } + + if (currentQuestionNumber == questionList.size) { + viewModel.addSurveyQuestion() // 질문 추가 + } else { + viewModel.editSurveyQuestion() + } + + viewModel.setLastQuestion() + }, onDateChanged = viewModel::setSurveyDateDeadline, onTimeChanged = { localTime -> viewModel.setSurveyTimeDeadline(localTime) }, - onPreviousButtonClicked = { previousState -> + onPreviousButtonClicked = { previousState -> // 이전 버튼 if (previousState == SurveyFormState.QUESTION) { - viewModel.setSurveyQuestionFromAnsweredList() + viewModel.setSurveyQuestionFromQuestionList() } + viewModel.setSurveyFormState(previousState) }, - onNextButtonClicked = { currentState, nextState -> - if (viewModel.validateSurveyForm(currentState).not()) { // 유효성 검증 + onNextButtonClicked = { currentState, nextState -> // 다음 버튼 + if (viewModel.validateSurveyForm(currentState).not()) { return@SurveyFormContent } if (currentState == SurveyFormState.QUESTION) { - viewModel.addSurveyQuestion() // 마지막으로 작성한 질문, 질문 목록에 추가 + if (currentQuestionNumber == questionList.size) { // 마지막 질문인 경우 + viewModel.addSurveyQuestion() + } else { + viewModel.editSurveyQuestion() + } } - viewModel.setSurveyFormState(nextState) // 다음 단계 - }, - onAddQuestionButtonClicked = { - if (viewModel.validateSurveyForm(SurveyFormState.QUESTION)) { - viewModel.addSurveyQuestion() - } + viewModel.setSurveyFormState(nextState) }, onRegisterButtonClicked = { if (viewModel.validateSurveyForm(SurveyFormState.DEADLINE)) { @@ -190,104 +209,3 @@ internal fun SurveyFormEditScreen( } } } - -@Composable -private fun DeleteSurveyDialog( - deleteSurvey: () -> Unit, - onDismissRequest: () -> Unit, -) { - Dialog( - onDismissRequest = onDismissRequest, - properties = DialogProperties( - usePlatformDefaultWidth = false, - ), - ) { - Column( - verticalArrangement = Arrangement.spacedBy(16.dp), - horizontalAlignment = Alignment.CenterHorizontally, - modifier = Modifier - .wrapContentSize() - .padding(horizontal = 30.dp) - .clip(RoundedCornerShape(8.dp)) - .background(WappTheme.colors.black25), - ) { - Text( - text = stringResource(id = R.string.delete_survey), - style = WappTheme.typography.contentBold.copy(fontSize = 20.sp), - color = WappTheme.colors.yellow34, - modifier = Modifier.padding(top = 16.dp), - ) - - Divider( - color = WappTheme.colors.gray82, - modifier = Modifier.padding(horizontal = 12.dp), - ) - - Text( - text = generateDialogContentString(), - style = WappTheme.typography.contentRegular, - color = WappTheme.colors.white, - modifier = Modifier.padding(top = 12.dp, start = 12.dp, end = 12.dp), - ) - - Row( - horizontalArrangement = Arrangement.spacedBy(20.dp), - modifier = Modifier.padding(horizontal = 12.dp, vertical = 16.dp), - ) { - Button( - onClick = { - deleteSurvey() - onDismissRequest() - }, - shape = RoundedCornerShape(8.dp), - colors = ButtonDefaults.buttonColors( - containerColor = WappTheme.colors.yellow34, - ), - contentPadding = PaddingValues(vertical = 12.dp), - modifier = Modifier.weight(1f), - ) { - Text( - text = stringResource(id = R.string.complete), - style = WappTheme.typography.titleRegular, - color = WappTheme.colors.black, - ) - } - - Button( - onClick = onDismissRequest, - shape = RoundedCornerShape(10.dp), - colors = ButtonDefaults.buttonColors( - containerColor = WappTheme.colors.black25, - ), - contentPadding = PaddingValues(vertical = 12.dp), - modifier = Modifier - .weight(1f) - .border( - width = 1.dp, - color = WappTheme.colors.yellow34, - shape = RoundedCornerShape(8.dp), - ), - ) { - Text( - text = stringResource(R.string.cancel), - style = WappTheme.typography.titleRegular, - color = WappTheme.colors.yellow34, - ) - } - } - } - } -} - -@Composable -private fun generateDialogContentString() = buildAnnotatedString { - append("정말로 해당 설문을 삭제하시겠습니까?\n") - withStyle( - style = SpanStyle( - textDecoration = TextDecoration.Underline, - color = WappTheme.colors.yellow34, - ), - ) { - append("해당 설문과 관련된 답변들이 모두 삭제됩니다.") - } -} diff --git a/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/edit/SurveyFormEditViewModel.kt b/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/edit/SurveyFormEditViewModel.kt index fdb9c4cd8..ad96b06c0 100644 --- a/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/edit/SurveyFormEditViewModel.kt +++ b/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/edit/SurveyFormEditViewModel.kt @@ -11,8 +11,8 @@ import com.wap.wapp.core.model.event.Event import com.wap.wapp.core.model.survey.QuestionType import com.wap.wapp.core.model.survey.SurveyForm import com.wap.wapp.core.model.survey.SurveyQuestion +import com.wap.wapp.feature.management.survey.EventsState import com.wap.wapp.feature.management.survey.SurveyFormState -import com.wap.wapp.feature.management.survey.registration.SurveyFormRegistrationViewModel.EventsState import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableStateFlow @@ -40,14 +40,15 @@ class SurveyFormEditViewModel @Inject constructor( MutableStateFlow(SurveyFormState.EVENT_SELECTION) val currentSurveyFormState = _currentSurveyFormState.asStateFlow() + // 불러올 설문 형식 Id + private val surveyFormId: MutableStateFlow = MutableStateFlow("") + private val _eventList: MutableStateFlow = MutableStateFlow(EventsState.Loading) val eventList: StateFlow = _eventList.asStateFlow() - private val surveyFormId: MutableStateFlow = MutableStateFlow("") - - private val _surveyEventSelection: MutableStateFlow = + private val _eventSelection: MutableStateFlow = MutableStateFlow(EVENT_SELECTION_INIT) - val surveyEventSelection = _surveyEventSelection.asStateFlow() + val eventSelection = _eventSelection.asStateFlow() private val _surveyTitle: MutableStateFlow = MutableStateFlow("") val surveyTitle = _surveyTitle.asStateFlow() @@ -55,24 +56,30 @@ class SurveyFormEditViewModel @Inject constructor( private val _surveyContent: MutableStateFlow = MutableStateFlow("") val surveyContent = _surveyContent.asStateFlow() - private val _surveyQuestion: MutableStateFlow = MutableStateFlow("") - val surveyQuestion = _surveyQuestion.asStateFlow() + private val _questionTitle: MutableStateFlow = MutableStateFlow("") + val questionTitle = _questionTitle.asStateFlow() - private val _surveyQuestionType: MutableStateFlow = + private val _questionType: MutableStateFlow = MutableStateFlow(QuestionType.SUBJECTIVE) - val surveyQuestionType = _surveyQuestionType.asStateFlow() + val questionType = _questionType.asStateFlow() - private val _surveyQuestionList: MutableStateFlow> = + private val _currentQuestionNumber: MutableStateFlow = MutableStateFlow(0) + val currentQuestionNumber = _currentQuestionNumber.asStateFlow() // 현재 질문의 번호 UI State + + private val _totalQuestionNumber: MutableStateFlow = MutableStateFlow(0) + val totalQuestionNumber = _totalQuestionNumber.asStateFlow() // 전체 질문의 번호 UI State + + private val _questionList: MutableStateFlow> = MutableStateFlow(mutableListOf()) - val surveyQuestionList = _surveyQuestionList.asStateFlow() + val questionList = _questionList.asStateFlow() // 사용자가 작성한 질문 목록 - private val _surveyTimeDeadline: MutableStateFlow = + private val _timeDeadline: MutableStateFlow = MutableStateFlow(DateUtil.generateNowTime()) - val surveyTimeDeadline = _surveyTimeDeadline.asStateFlow() + val timeDeadline = _timeDeadline.asStateFlow() - private val _surveyDateDeadline: MutableStateFlow = + private val _dateDeadline: MutableStateFlow = MutableStateFlow(DateUtil.generateNowDate()) - val surveyDateDeadline = _surveyDateDeadline.asStateFlow() + val dateDeadline = _dateDeadline.asStateFlow() fun getSurveyForm(surveyFormId: String) { // 설문 불러오기 viewModelScope.launch { @@ -91,20 +98,22 @@ class SurveyFormEditViewModel @Inject constructor( setSurveyEventSelection(EVENT_SELECTION_INIT.copy(eventId = surveyForm.eventId)) setSurveyTitle(surveyForm.title) setSurveyQuestionList(surveyForm.surveyQuestionList) - setSurveyQuestionFromAnsweredList() + setSurveyQuestionFromQuestionList() setSurveyContent(surveyForm.content) setSurveyTimeDeadline(surveyForm.deadline.toLocalTime()) setSurveyDateDeadline(surveyForm.deadline.toLocalDate()) + _currentQuestionNumber.value = _questionList.value.lastIndex + _totalQuestionNumber.value = _questionList.value.lastIndex } fun updateSurveyForm() = viewModelScope.launch { val surveyForm = SurveyForm( surveyFormId = surveyFormId.value, - eventId = _surveyEventSelection.value.eventId, + eventId = _eventSelection.value.eventId, title = _surveyTitle.value, content = _surveyContent.value, - surveyQuestionList = _surveyQuestionList.value, - deadline = LocalDateTime.of(_surveyDateDeadline.value, _surveyTimeDeadline.value), + surveyQuestionList = _questionList.value, + deadline = LocalDateTime.of(_dateDeadline.value, _timeDeadline.value), ) updateSurveyFormUseCase(surveyForm = surveyForm) @@ -168,56 +177,86 @@ class SurveyFormEditViewModel @Inject constructor( fun setSurveyFormState(nextState: SurveyFormState) { _currentSurveyFormState.value = nextState } - fun addSurveyQuestion() { - _surveyQuestionList.value.add( - SurveyQuestion( - questionTitle = _surveyQuestion.value, - questionType = _surveyQuestionType.value, - ), - ) - clearSurveyQuestionState() - } - private fun setSurveyFormId(surveyFormId: String) { this.surveyFormId.value = surveyFormId } - fun setSurveyEventSelection(event: Event) { _surveyEventSelection.value = event } + fun setSurveyEventSelection(event: Event) { _eventSelection.value = event } fun setSurveyTitle(title: String) { _surveyTitle.value = title } fun setSurveyContent(content: String) { _surveyContent.value = content } - fun setSurveyQuestion(question: String) { _surveyQuestion.value = question } + fun setSurveyQuestionTitle(question: String) { _questionTitle.value = question } + + fun setSurveyQuestionType(questionType: QuestionType) { _questionType.value = questionType } + + fun setNextQuestionNumber() { _currentQuestionNumber.value += 1 } - fun setSurveyQuestionType(questionType: QuestionType) { - _surveyQuestionType.value = questionType + fun setPreviousQuestionNumber() { _currentQuestionNumber.value -= 1 } + + fun setLastQuestion() { + _currentQuestionNumber.value = _questionList.value.size // 마지막 질문 번호로 변경 + _totalQuestionNumber.value += 1 // 전체 질문 갯수 추가 + clearSurveyQuestionTitle() } - fun setSurveyTimeDeadline(time: LocalTime) { _surveyTimeDeadline.value = time } + fun setQuestion() { + val currentNumber = _currentQuestionNumber.value + val totalSize = _questionList.value.size - fun setSurveyDateDeadline(date: LocalDate) { _surveyDateDeadline.value = date } + if (currentNumber < totalSize) { + val surveyQuestion = _questionList.value[_currentQuestionNumber.value] + setSurveyQuestionTitle(surveyQuestion.questionTitle) + setSurveyQuestionType(surveyQuestion.questionType) + return + } + } // 이전 버튼 클릭시 진입점이 질문 페이지인 경우, 응답 목록에서 마지막 질문 노출 private fun setSurveyQuestionList(surveyQuestionList: List) { - _surveyQuestionList.value.addAll(surveyQuestionList) + _questionList.value.addAll(surveyQuestionList) + } + + fun addSurveyQuestion() { + _questionList.value.add( + SurveyQuestion( + questionTitle = _questionTitle.value, + questionType = _questionType.value, + ), + ) + clearSurveyQuestionTitle() } - fun setSurveyQuestionFromAnsweredList() { - val lastSurveyQuestion = _surveyQuestionList.value.removeLast() - setSurveyQuestion(lastSurveyQuestion.questionTitle) + fun editSurveyQuestion() { + val questionNumber = _currentQuestionNumber.value + _questionList.value[questionNumber] = SurveyQuestion( + questionTitle = _questionTitle.value, + questionType = _questionType.value, + ) + clearSurveyQuestionTitle() + } + + fun setSurveyQuestionFromQuestionList() { + // 작성된 질문 목록을 불러올 때, 마지막 질문은 UI에 노출 + val lastSurveyQuestion = _questionList.value.last() + setSurveyQuestionTitle(lastSurveyQuestion.questionTitle) setSurveyQuestionType(lastSurveyQuestion.questionType) } - private fun clearSurveyQuestionState() { _surveyQuestion.value = "" } + fun setSurveyTimeDeadline(time: LocalTime) { _timeDeadline.value = time } + + fun setSurveyDateDeadline(date: LocalDate) { _dateDeadline.value = date } + + private fun clearSurveyQuestionTitle() { _questionTitle.value = "" } - private fun isNotValidSurveyQuestion() = _surveyQuestion.value.isBlank() + private fun isNotValidSurveyQuestion() = _questionTitle.value.isBlank() private fun isNotValidEventSelection() = - _surveyEventSelection.value.eventId == EVENT_SELECTION_INIT.eventId + _eventSelection.value.eventId == EVENT_SELECTION_INIT.eventId private fun isNotValidInformation() = _surveyTitle.value.isBlank() || _surveyContent.value.isBlank() - private fun isNotValidDeadline() = _surveyDateDeadline.value <= DateUtil.generateNowDate() + private fun isNotValidDeadline() = _dateDeadline.value <= DateUtil.generateNowDate() private fun emitValidationErrorMessage(message: String) { viewModelScope.launch { From dccd38c135ede2722078af5182818bf1d5f5a43b Mon Sep 17 00:00:00 2001 From: jeongjaino Date: Tue, 6 Feb 2024 21:11:47 +0900 Subject: [PATCH 16/16] =?UTF-8?q?[CHORE]=20#95=20:=20ViewModel=20EventStat?= =?UTF-8?q?e=20->=20EventState=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wap/wapp/feature/management/survey/SurveyEventContent.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/SurveyEventContent.kt b/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/SurveyEventContent.kt index 1a4ee7e6d..db8409d30 100644 --- a/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/SurveyEventContent.kt +++ b/feature/management-survey/src/main/java/com/wap/wapp/feature/management/survey/SurveyEventContent.kt @@ -21,7 +21,6 @@ import com.wap.designsystem.component.CircleLoader import com.wap.designsystem.component.WappButton import com.wap.designsystem.component.WappTitle import com.wap.wapp.core.model.event.Event -import com.wap.wapp.feature.management.survey.registration.SurveyFormRegistrationViewModel.EventsState @Composable internal fun SurveyEventContent( @@ -48,7 +47,7 @@ internal fun SurveyEventContent( ) } - is EventsState.Success -> + is EventsState.Success -> { items(eventsState.events) { event -> EventCard( event = event, @@ -56,6 +55,7 @@ internal fun SurveyEventContent( onEventSelected = onEventSelected, ) } + } is EventsState.Failure -> {} }