-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CHORE] #94 : SurveyAnswerForm 컴포저블 함수 분리
- Loading branch information
1 parent
228ea9a
commit 6d9d914
Showing
1 changed file
with
110 additions
and
0 deletions.
There are no files selected for viewing
110 changes: 110 additions & 0 deletions
110
feature/survey/src/main/java/com/wap/wapp/feature/survey/answer/SurveyAnswerForm.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package com.wap.wapp.feature.survey.answer | ||
|
||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.dp | ||
import com.wap.designsystem.component.WappButton | ||
import com.wap.wapp.core.model.survey.QuestionType | ||
import com.wap.wapp.core.model.survey.Rating | ||
import com.wap.wapp.core.model.survey.SurveyForm | ||
import com.wap.wapp.feature.survey.R | ||
|
||
@Composable | ||
internal fun SurveyAnswerForm( | ||
surveyForm: SurveyForm, | ||
modifier: Modifier, | ||
questionNumber: Int, | ||
subjectiveAnswer: String, | ||
objectiveAnswer: Rating, | ||
onSubjectiveAnswerChanged: (String) -> Unit, | ||
onObjectiveAnswerSelected: (Rating) -> Unit, | ||
onNextQuestionButtonClicked: () -> Unit, | ||
onPreviousQuestionButtonClicked: () -> Unit, | ||
) { | ||
Column( | ||
verticalArrangement = Arrangement.spacedBy(40.dp), | ||
modifier = modifier, | ||
) { | ||
val surveyQuestion = surveyForm.surveyQuestionList[questionNumber] | ||
val lastQuestionNumber = surveyForm.surveyQuestionList.lastIndex | ||
|
||
SurveyAnswerStateIndicator( | ||
index = questionNumber + 1, | ||
size = lastQuestionNumber + 1, | ||
) | ||
|
||
when (surveyQuestion.questionType) { | ||
QuestionType.SUBJECTIVE -> { | ||
SubjectiveSurveyForm( | ||
questionTitle = surveyQuestion.questionTitle, | ||
answer = subjectiveAnswer, | ||
onAnswerChanged = onSubjectiveAnswerChanged, | ||
modifier = Modifier.weight(1f), | ||
) | ||
} | ||
|
||
QuestionType.OBJECTIVE -> { | ||
ObjectiveSurveyForm( | ||
questionTitle = surveyQuestion.questionTitle, | ||
answer = objectiveAnswer, | ||
onAnswerSelected = onObjectiveAnswerSelected, | ||
modifier = Modifier.weight(1f), | ||
) | ||
} | ||
} | ||
|
||
val isFirstQuestion = questionNumber > 0 | ||
val isLastQuestion = questionNumber == lastQuestionNumber // 마지막 응답일 경우, 완료로 변경 | ||
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) { | ||
WappButton( | ||
textRes = R.string.previous, | ||
onClick = onPreviousQuestionButtonClicked, | ||
isEnabled = isFirstQuestion, | ||
modifier = Modifier.weight(1f), | ||
) | ||
|
||
SurveyAnswerButton( | ||
isLastQuestion = isLastQuestion, | ||
onButtonClicked = onNextQuestionButtonClicked, | ||
isEnabled = isButtonEnabled(surveyQuestion.questionType, subjectiveAnswer), | ||
modifier = Modifier.weight(1f), | ||
) | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun SurveyAnswerButton( | ||
isLastQuestion: Boolean, | ||
onButtonClicked: () -> Unit, | ||
isEnabled: Boolean, | ||
modifier: Modifier, | ||
) { | ||
if (isLastQuestion) { | ||
WappButton( | ||
textRes = R.string.submit, | ||
onClick = { onButtonClicked() }, | ||
isEnabled = isEnabled, | ||
modifier = modifier, | ||
) | ||
} else { | ||
WappButton( | ||
textRes = R.string.next, | ||
onClick = { onButtonClicked() }, | ||
isEnabled = isEnabled, | ||
modifier = modifier, | ||
) | ||
} | ||
} | ||
|
||
private fun isButtonEnabled( | ||
questionType: QuestionType, | ||
subjectiveAnswer: String, | ||
): Boolean { | ||
if (questionType == QuestionType.SUBJECTIVE) return subjectiveAnswer.length >= 10 | ||
|
||
return true | ||
} |