Skip to content

Commit

Permalink
[Jetsurvey] Adding question description
Browse files Browse the repository at this point in the history
  • Loading branch information
florina-muntenescu committed Nov 2, 2020
1 parent d75e4c1 commit 77e548d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ data class Survey(
data class Question(
val id: Int,
@StringRes val questionText: Int,
val answer: PossibleAnswer
val answer: PossibleAnswer,
@StringRes val description: Int? = null
)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,26 +54,6 @@ import com.example.compose.jetsurvey.R
import com.example.compose.jetsurvey.theme.JetsurveyTheme
import com.example.compose.jetsurvey.theme.questionBackground

@Preview
@Composable
fun QuestionPreview() {
val question = Question(
id = 2,
questionText = R.string.pick_superhero,
answer = PossibleAnswer.SingleChoice(
optionsStringRes = listOf(
R.string.spiderman,
R.string.ironman,
R.string.unikitty,
R.string.captain_planet
)
)
)
JetsurveyTheme {
Question(question = question, answer = null, onAnswer = {}, onAction = { _, _ -> })
}
}

@Composable
fun Question(
question: Question,
Expand Down Expand Up @@ -102,6 +82,15 @@ fun Question(
}
}
Spacer(modifier = Modifier.preferredHeight(24.dp))
if (question.description != null) {
ProvideEmphasis(emphasis = AmbientEmphasisLevels.current.medium) {
Text(
text = stringResource(id = question.description),
style = MaterialTheme.typography.caption,
modifier = Modifier.fillMaxWidth().padding(bottom = 24.dp, start = 8.dp)
)
}
}
when (question.answer) {
is PossibleAnswer.SingleChoice -> SingleChoiceQuestion(
possibleAnswer = question.answer,
Expand Down Expand Up @@ -173,7 +162,7 @@ private fun SingleChoiceQuestion(
width = 1.dp,
color = MaterialTheme.colors.surface.copy(alpha = 0.12f)
),
modifier = Modifier.padding(vertical = 4.dp)
modifier = Modifier.padding(vertical = 8.dp)
) {
Row(
modifier = Modifier
Expand All @@ -197,7 +186,6 @@ private fun SingleChoiceQuestion(
selectedColor = MaterialTheme.colors.primary
)
)

}
}
}
Expand Down Expand Up @@ -317,3 +305,24 @@ private fun SliderQuestion(
)
}
}

@Preview
@Composable
fun QuestionPreview() {
val question = Question(
id = 2,
questionText = R.string.pick_superhero,
answer = PossibleAnswer.SingleChoice(
optionsStringRes = listOf(
R.string.spiderman,
R.string.ironman,
R.string.unikitty,
R.string.captain_planet
)
),
description = R.string.select_one
)
JetsurveyTheme {
Question(question = question, answer = null, onAnswer = {}, onAction = { _, _ -> })
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ private val jetpackQuestions = listOf(
R.string.dance,
R.string.watch_movies
)
)
),
description = R.string.select_all
),
Question(
id = 2,
Expand All @@ -48,7 +49,8 @@ private val jetpackQuestions = listOf(
R.string.unikitty,
R.string.captain_planet
)
)
),
description = R.string.select_one
),
Question(
id = 7,
Expand All @@ -60,12 +62,14 @@ private val jetpackQuestions = listOf(
R.string.back_to_future,
R.string.outbreak
)
)
),
description = R.string.select_one
),
Question(
id = 3,
questionText = R.string.takeaway,
answer = Action(label = R.string.pick_date, actionType = PICK_DATE)
answer = Action(label = R.string.pick_date, actionType = PICK_DATE),
description = R.string.select_date
),
Question(
id = 4,
Expand Down
3 changes: 3 additions & 0 deletions Jetsurvey/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
<!-- survey-->
<string name="which_jetpack_library">Which Jetpack library are you?</string>
<string name="question_count">\u00A0of %d</string>
<string name="select_one">Select one.</string>
<string name="select_all">Select all that apply.</string>
<string name="select_date">Select date.</string>

<!-- question 1-->
<string name="in_my_free_time">In my free time I like to …</string>
Expand Down

0 comments on commit 77e548d

Please sign in to comment.