Skip to content

Commit

Permalink
덕퀴즈 시작 화면에서 문제 당 주어지는 시간, 도전 조건이 피그마 스펙에 맞게 보여져야 함 (#508)
Browse files Browse the repository at this point in the history
* refactor: ExamData에 문구 및 시간 관련 데이터 추가

* feat: refactor 시험 상세에서 시험 시작으로 이동하는 플로우

* remove: unused import
  • Loading branch information
EvergreenTree97 authored May 28, 2023
1 parent 20f1dca commit 408f6f6
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ object Extras {
/** using for FriendsActivity */
const val FriendType = "ExtraFriendType"
const val ProfileNickName = "ProfileNickName"

/** using for StartActivity */
const val RequirementQuestion = "ExtraRequirementQuestion"
const val RequirementPlaceholder = "ExtraRequirementPlaceholder"
const val Timer = "ExtraTimer"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
package team.duckie.app.android.data.exam.mapper

import kotlinx.collections.immutable.toImmutableList
import team.duckie.app.android.common.kotlin.AllowCyclomaticComplexMethod
import team.duckie.app.android.common.kotlin.exception.duckieResponseFieldNpe
import team.duckie.app.android.common.kotlin.fastMap
import team.duckie.app.android.data.category.mapper.toDomain
import team.duckie.app.android.data.exam.model.AnswerData
import team.duckie.app.android.data.exam.model.ChoiceData
Expand Down Expand Up @@ -46,9 +49,6 @@ import team.duckie.app.android.domain.exam.model.ProfileExam
import team.duckie.app.android.domain.exam.model.Question
import team.duckie.app.android.domain.exam.model.Solution
import team.duckie.app.android.domain.quiz.model.QuizInfo
import team.duckie.app.android.common.kotlin.AllowCyclomaticComplexMethod
import team.duckie.app.android.common.kotlin.exception.duckieResponseFieldNpe
import team.duckie.app.android.common.kotlin.fastMap

@AllowCyclomaticComplexMethod
internal fun ExamData.toDomain() = Exam(
Expand All @@ -73,6 +73,9 @@ internal fun ExamData.toDomain() = Exam(
quizs = quizs?.fastMap(QuizInfoResponse::toDomain)?.toImmutableList(),
perfectScoreImageUrl = perfectScoreImageUrl,
problems = problems?.fastMap(ProblemData::toDomain)?.toImmutableList(),
timer = timer,
requirementPlaceholder = requirementPlaceholder,
requirementQuestion = requirementQuestion,
)

internal fun ExamsData.toDomain() = exams?.fastMap { examData -> examData.toDomain() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ internal data class ExamData(

@field:JsonProperty("problems")
val problems: List<ProblemData>? = null,

@field:JsonProperty("timer")
val timer: Int? = null,

@field:JsonProperty("requirementQuestion")
val requirementQuestion: String? = null,

@field:JsonProperty("requirementPlaceholder")
val requirementPlaceholder: String? = null,
)

internal data class ExamsData(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ data class Exam(
val problems: ImmutableList<Problem>?,
val quizs: ImmutableList<QuizInfo>?,
val perfectScoreImageUrl: String?,
val timer: Int?,
val requirementQuestion: String?,
val requirementPlaceholder: String?,
) {
companion object {
/*
Expand Down Expand Up @@ -66,6 +69,9 @@ data class Exam(
quizs = null,
perfectScoreImageUrl = null,
problems = null,
timer = null,
requirementQuestion = null,
requirementPlaceholder = null,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ import androidx.compose.foundation.layout.systemBarsPadding
import androidx.compose.ui.Modifier
import dagger.hilt.android.AndroidEntryPoint
import org.orbitmvi.orbit.viewmodel.observe
import team.duckie.app.android.common.android.exception.handling.reporter.reportToCrashlyticsIfNeeded
import team.duckie.app.android.common.android.exception.handling.reporter.reportToToast
import team.duckie.app.android.common.android.ui.BaseActivity
import team.duckie.app.android.common.android.ui.const.Extras
import team.duckie.app.android.common.android.ui.startActivityWithAnimation
import team.duckie.app.android.common.compose.ToastWrapper
import team.duckie.app.android.common.kotlin.exception.DuckieResponseException
import team.duckie.app.android.feature.detail.screen.DetailScreen
import team.duckie.app.android.feature.detail.viewmodel.DetailViewModel
import team.duckie.app.android.feature.detail.viewmodel.sideeffect.DetailSideEffect
import team.duckie.app.android.feature.start.exam.screen.StartExamActivity
import team.duckie.app.android.navigator.feature.profile.ProfileNavigator
import team.duckie.app.android.navigator.feature.search.SearchNavigator
import team.duckie.app.android.common.compose.ToastWrapper
import team.duckie.app.android.common.android.exception.handling.reporter.reportToCrashlyticsIfNeeded
import team.duckie.app.android.common.android.exception.handling.reporter.reportToToast
import team.duckie.app.android.common.kotlin.exception.DuckieResponseException
import team.duckie.app.android.common.android.ui.BaseActivity
import team.duckie.app.android.common.android.ui.const.Extras
import team.duckie.app.android.common.android.ui.startActivityWithAnimation
import team.duckie.quackquack.ui.color.QuackColor
import team.duckie.quackquack.ui.theme.QuackTheme
import javax.inject.Inject
Expand Down Expand Up @@ -105,7 +105,9 @@ class DetailActivity : BaseActivity() {
is DetailSideEffect.StartQuiz -> startActivityWithAnimation<StartExamActivity>(
intentBuilder = {
putExtra(Extras.ExamId, sideEffect.examId)
putExtra(Extras.CertifyingStatement, sideEffect.certifyingStatement)
putExtra(Extras.Timer, sideEffect.timer)
putExtra(Extras.RequirementQuestion, sideEffect.requirementQuestion)
putExtra(Extras.RequirementPlaceholder, sideEffect.requirementPlaceholder)
putExtra(Extras.IsQuiz, sideEffect.isQuiz)
},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ class DetailViewModel @Inject constructor(
postSideEffect(
DetailSideEffect.StartQuiz(
examId = result.id,
certifyingStatement = certifyingStatement,
requirementQuestion = exam.requirementQuestion ?: "",
requirementPlaceholder = exam.requirementPlaceholder ?: "",
timer = exam.timer ?: 0,
isQuiz = isQuiz,
),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ sealed class DetailSideEffect {

class StartQuiz(
val examId: Int,
val certifyingStatement: String,
val requirementQuestion: String,
val requirementPlaceholder: String,
val timer: Int,
val isQuiz: Boolean,
) : DetailSideEffect()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import team.duckie.app.android.common.compose.ui.ImeSpacer
import team.duckie.app.android.common.compose.ui.Spacer
import team.duckie.app.android.feature.start.exam.R
import team.duckie.app.android.feature.start.exam.viewmodel.StartExamState
import team.duckie.app.android.feature.start.exam.viewmodel.StartExamViewModel
import team.duckie.app.android.common.compose.ui.ImeSpacer
import team.duckie.app.android.common.compose.ui.Spacer
import team.duckie.quackquack.ui.color.QuackColor
import team.duckie.quackquack.ui.component.QuackBody2
import team.duckie.quackquack.ui.component.QuackGrayscaleTextField
Expand Down Expand Up @@ -68,7 +68,7 @@ internal fun StartQuizInputScreen(modifier: Modifier, viewModel: StartExamViewMo
modifier = Modifier
.padding(top = 12.dp)
.fillMaxWidth(),
limitTime = 10,
limitTime = state.timer,
)
QuackTitle2(
modifier = Modifier.padding(top = 34.dp),
Expand All @@ -77,13 +77,13 @@ internal fun StartQuizInputScreen(modifier: Modifier, viewModel: StartExamViewMo
Spacer(space = 4.dp)
QuackHeadLine1(
modifier = Modifier.padding(top = 4.dp),
text = state.certifyingStatement, // TODO(EvergreenTree97) 추후 도전 조건 response 생기면 변경
text = state.requirementQuestion, // TODO(EvergreenTree97) 추후 도전 조건 response 생기면 변경
)
QuackGrayscaleTextField(
modifier = Modifier.padding(top = 14.dp),
text = certifyingStatementText,
onTextChanged = viewModel::inputCertifyingStatement,
placeholderText = "ex) $certifyingStatement",
placeholderText = "ex) ${state.requirementPlaceholder}",
)
}
Spacer(modifier = Modifier.weight(1f))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ sealed class StartExamState {
/** [StartExamViewModel] 데이터를 잘 받았을 때의 상태를 나타냅니다. */
data class Input(
val examId: Int,
val certifyingStatement: String,
val certifyingStatement: String = "",
val certifyingStatementInputText: String = "",
val requirementQuestion: String = "",
val requirementPlaceholder: String = "",
val timer: Int = 0,
val isQuiz: Boolean = true,
) : StartExamState() {
val isCertified: Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import org.orbitmvi.orbit.syntax.simple.intent
import org.orbitmvi.orbit.syntax.simple.postSideEffect
import org.orbitmvi.orbit.syntax.simple.reduce
import org.orbitmvi.orbit.viewmodel.container
import team.duckie.app.android.common.kotlin.AllowMagicNumber
import team.duckie.app.android.common.kotlin.exception.DuckieClientLogicProblemException
import team.duckie.app.android.common.android.savedstate.getOrThrow
import team.duckie.app.android.common.android.ui.const.Extras
import team.duckie.app.android.common.kotlin.AllowMagicNumber
import javax.inject.Inject

@HiltViewModel
Expand All @@ -29,20 +29,29 @@ internal class StartExamViewModel @Inject constructor(

/** state 를 초기 설정한다. */
fun initState() {
val examId = savedStateHandle.getStateFlow(Extras.ExamId, -1).value
val certifyingStatement = savedStateHandle
.getStateFlow(Extras.CertifyingStatement, "").value
val isQuiz = savedStateHandle.getStateFlow(Extras.IsQuiz, false).value

intent {
reduce {
if (examId == -1 || certifyingStatement == "") {
StartExamState.Error(DuckieClientLogicProblemException(code = ""))
} else {
val examId = savedStateHandle.getStateFlow(Extras.ExamId, -1).value
val isQuiz = savedStateHandle.getStateFlow(Extras.IsQuiz, false).value
if (isQuiz) {
val requirementQuestion = savedStateHandle.getOrThrow<String>(Extras.RequirementQuestion)
val requirementPlaceholder = savedStateHandle.getOrThrow<String>(Extras.RequirementPlaceholder)
val timer = savedStateHandle.getOrThrow<Int>(Extras.Timer)
reduce {
StartExamState.Input(
examId = examId,
requirementQuestion = requirementQuestion,
requirementPlaceholder = requirementPlaceholder,
timer = timer,
isQuiz = true,
)
}
} else {
val certifyingStatement = savedStateHandle.getOrThrow<String>(Extras.CertifyingStatement)
reduce {
StartExamState.Input(
examId = examId,
certifyingStatement = certifyingStatement,
isQuiz = isQuiz,
isQuiz = false,
)
}
}
Expand Down

0 comments on commit 408f6f6

Please sign in to comment.