Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
da7ca9d
[Jetsnack] Add interaction to cart.
JolandaVerhoef Oct 27, 2020
be889b9
[Jetsnack] Animate snack count in cart.
JolandaVerhoef Oct 27, 2020
34ff388
[Jetsnack] Apply spotless fixes
JolandaVerhoef Oct 27, 2020
1cb1501
[Jetsnack] Fix review comments
JolandaVerhoef Oct 29, 2020
047af3e
Merge pull request #260 from android/jv/js_cart_state_flow
JolandaVerhoef Oct 29, 2020
4354d04
[Jetsurvey] Styling the questions progress indicator
florina-muntenescu Oct 28, 2020
d75e4c1
[Jetsurvey] Styling Single and Multiple choice questions
florina-muntenescu Oct 31, 2020
77e548d
[Jetsurvey] Adding question description
florina-muntenescu Oct 31, 2020
8cec984
[Jetsurvey] Setting correct border and background colors
florina-muntenescu Nov 2, 2020
13d04f3
[Jetsurvey] Make the entire Row clickable
florina-muntenescu Nov 2, 2020
b2b8816
[Jetsurvey] Adding end padding to description
florina-muntenescu Nov 4, 2020
cc48218
Merge pull request #265 from android/fm/jetsurvey_redesign2
florina-muntenescu Nov 4, 2020
2e132b5
[Jetsurvey] Update to 6953474 snapshot
florina-muntenescu Nov 6, 2020
c87772e
[Owl] Update to snapshot 6953474 & Accompanist Insets.
nickbutcher Nov 6, 2020
b88faed
[Jetsurvey] Removing ContentAlpha.high
florina-muntenescu Nov 6, 2020
5a6895e
Merge pull request #270 from android/nb/owl_alpha07
nickbutcher Nov 6, 2020
f05a667
[Jetchat] Update to snapshot 6953474
JoseAlcerreca Nov 6, 2020
3c14527
[Jetsurvey] Removing unneeded compiler args
florina-muntenescu Nov 6, 2020
308a6ca
[Jetsnack] Update to snapshot 6953474
JolandaVerhoef Nov 6, 2020
b4e0386
Some fixes
JoseAlcerreca Nov 6, 2020
a541a2d
Merge branch 'dev_alpha07' of github.com:android/compose-samples into…
JoseAlcerreca Nov 6, 2020
38877e0
[Rally] Update to snapshot 6953474
JoseAlcerreca Nov 6, 2020
4f6c460
Fixes tests
JoseAlcerreca Nov 6, 2020
d5d46ad
Fixes tests and text field in dark theme
JoseAlcerreca Nov 6, 2020
69126da
Merge pull request #269 from android/fm/jetsurvey_alpha07
florina-muntenescu Nov 6, 2020
b5ad9bf
[Jetsurvey] Take a selfie
florina-muntenescu Nov 3, 2020
b189bf6
[Jetsurvey] 2nd attempt to camera
florina-muntenescu Nov 4, 2020
1bb7948
[Jetsurvey] Saving the image in the uri
florina-muntenescu Nov 6, 2020
f5b360d
[Jetsurvey] Saving the image cleaned up
florina-muntenescu Nov 8, 2020
8c39a94
[Jetsurvey] Updating the take a photo UI
florina-muntenescu Nov 8, 2020
afde277
Update CONTRIBUTING.md
nickbutcher Nov 9, 2020
05521d4
Merge pull request #277 from android/nb/contrib
nickbutcher Nov 9, 2020
ba9954e
[Jetsurvey] Rebase issues
florina-muntenescu Nov 9, 2020
65d752a
[Jetsnack] Fix review comments
JolandaVerhoef Nov 9, 2020
c83c3cf
Merge branch 'dev_alpha07' into jv/js_alpha07
JolandaVerhoef Nov 9, 2020
44b1708
[Jetsurvey] Fixing the way the state is updated when taking a photo
florina-muntenescu Nov 9, 2020
0732eba
[Jetsurvey] Handling the photo uri creation in a different class
florina-muntenescu Nov 9, 2020
0937e24
[Jetcaster] Update to Compose alpha07 snapshot (#278)
chrisbanes Nov 9, 2020
4dcdb9b
[JetNews] bump to alpha07
yrezgui Nov 9, 2020
193caa8
[JetNews] Update imports (alpha07)
yrezgui Nov 9, 2020
b0e28ed
[JetNews] Rearrange imports (alpha07)
yrezgui Nov 9, 2020
24e7bf6
[JetNews] Update test imports (alpha07)
yrezgui Nov 9, 2020
40a4194
[Jetsnack] Update to snapshot 6961312
JolandaVerhoef Nov 10, 2020
e95b96b
[Jetsurvey] Updating to 6961312 snapshot and addressing review comments
florina-muntenescu Nov 10, 2020
b6ed842
[JetNews] Update spanshot to 6953474 (alpha07)
yrezgui Nov 10, 2020
d5cc734
Merge branch 'dev_alpha07' into jv/js_alpha07
JolandaVerhoef Nov 10, 2020
cf59158
[Jetsurvey] Adding the camera feature only for devices 29+
florina-muntenescu Nov 10, 2020
8a44a0b
Merge pull request #279 from android/fm/camera
florina-muntenescu Nov 10, 2020
d0ab6f3
[JetNews] Remove ContentAlpha.high
yrezgui Nov 10, 2020
4dc2d50
Updates to 6964664
JoseAlcerreca Nov 11, 2020
e955700
Updates snapshot to 6964664
JoseAlcerreca Nov 11, 2020
f5e0219
[Jetsnack] Update to snapshot 6964664
JolandaVerhoef Nov 11, 2020
c40635d
Merge branch 'dev_alpha07' into jv/js_alpha07
JolandaVerhoef Nov 11, 2020
01c0804
Merge branch 'dev_alpha07' into dev_alpha07
yrezgui Nov 11, 2020
6fcd168
[Jetsnack] Fix review comment
JolandaVerhoef Nov 11, 2020
7ea8d53
Merge pull request #271 from android/jv/js_alpha07
JolandaVerhoef Nov 11, 2020
9a5d45f
Merge pull request #272 from JoseAlcerreca/jetchat_alpha07
JoseAlcerreca Nov 11, 2020
cb0a46f
Merge branch 'dev_alpha07' into rally_alpha07
JoseAlcerreca Nov 11, 2020
95c442a
[Jetnews] Bring back a forgotten ContentAlpha.medium
yrezgui Nov 11, 2020
0295dce
Merge branch 'dev_alpha07' into dev_alpha07
yrezgui Nov 11, 2020
a68a925
Merge pull request #273 from JoseAlcerreca/rally_alpha07
JoseAlcerreca Nov 11, 2020
00a472b
Merge branch 'dev_alpha07' into dev_alpha07
yrezgui Nov 11, 2020
8534fc2
Merge pull request #280 from yrezgui/dev_alpha07
yrezgui Nov 11, 2020
1239fac
[Crane] Updates to snapshot 6953474 (#268)
manuelvicnt Nov 11, 2020
a5f219b
[All] Updating to Compose alpha07
florina-muntenescu Nov 11, 2020
008e4ae
[All] Updating Accompanist to 0.3.3.1
florina-muntenescu Nov 11, 2020
7701008
Merge pull request #282 from android/fm/update_alpha07
florina-muntenescu Nov 12, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -16,10 +16,12 @@

package com.example.compose.jetsurvey.survey

import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.ScrollableColumn
import androidx.compose.foundation.Text
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
Expand All @@ -37,6 +39,7 @@ import androidx.compose.material.ProvideEmphasis
import androidx.compose.material.RadioButton
import androidx.compose.material.RadioButtonConstants
import androidx.compose.material.Slider
import androidx.compose.material.Surface
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand All @@ -49,27 +52,6 @@ import androidx.compose.ui.unit.dp
import androidx.ui.tooling.preview.Preview
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(
Expand All @@ -84,9 +66,14 @@ fun Question(
contentPadding = PaddingValues(start = 20.dp, end = 20.dp)
) {
Spacer(modifier = Modifier.preferredHeight(44.dp))
val backgroundColor = if (MaterialTheme.colors.isLight) {
MaterialTheme.colors.onSurface.copy(alpha = 0.04f)
} else {
MaterialTheme.colors.onSurface.copy(alpha = 0.06f)
}
Row(
modifier = Modifier.fillMaxWidth().background(
color = MaterialTheme.colors.questionBackground,
color = backgroundColor,
shape = MaterialTheme.shapes.small
)
) {
Expand All @@ -99,6 +86,17 @@ 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, end = 8.dp)
)
}
}
when (question.answer) {
is PossibleAnswer.SingleChoice -> SingleChoiceQuestion(
possibleAnswer = question.answer,
Expand Down Expand Up @@ -164,28 +162,37 @@ private fun SingleChoiceQuestion(
Unit
}
val optionSelected = text == selectedOption
Row(
modifier = Modifier
.fillMaxWidth()
.selectable(
selected = optionSelected,
onClick = onClickHandle
)
.padding(vertical = 4.dp),
verticalAlignment = Alignment.CenterVertically
Surface(
shape = MaterialTheme.shapes.small,
border = BorderStroke(
width = 1.dp,
color = MaterialTheme.colors.onSurface.copy(alpha = 0.12f)
),
modifier = Modifier.padding(vertical = 8.dp)
) {
RadioButton(
selected = optionSelected,
onClick = onClickHandle,
colors = RadioButtonConstants.defaultColors(
selectedColor = MaterialTheme.colors.primary
Row(
modifier = Modifier
.fillMaxWidth()
.selectable(
selected = optionSelected,
onClick = onClickHandle
)
.padding(vertical = 16.dp, horizontal = 24.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween
) {
Text(
text = text
)
)

Text(
text = text,
modifier = Modifier.padding(horizontal = 16.dp)
)
RadioButton(
selected = optionSelected,
onClick = onClickHandle,
colors = RadioButtonConstants.defaultColors(
selectedColor = MaterialTheme.colors.primary
)
)
}
}
}
}
Expand All @@ -205,31 +212,40 @@ private fun MultipleChoiceQuestion(
val selectedOption = answer?.answersStringRes?.contains(option.value)
mutableStateOf(selectedOption ?: false)
}
Row(
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 4.dp)
.clickable(
onClick = {
checkedState = !checkedState
onAnswerSelected(option.value, checkedState)
}
)
Surface(
shape = MaterialTheme.shapes.small,
border = BorderStroke(
width = 1.dp,
color = MaterialTheme.colors.onSurface.copy(alpha = 0.12f)
),
modifier = Modifier.padding(vertical = 4.dp)
) {
Checkbox(
checked = checkedState,
onCheckedChange = { selected ->
checkedState = selected
onAnswerSelected(option.value, selected)
},
colors = CheckboxConstants.defaultColors(
checkedColor = MaterialTheme.colors.primary
Row(
modifier = Modifier
.fillMaxWidth()
.clickable(
onClick = {
checkedState = !checkedState
onAnswerSelected(option.value, checkedState)
}
)
.padding(vertical = 16.dp, horizontal = 24.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween
) {
Text(text = option.key)

Checkbox(
checked = checkedState,
onCheckedChange = { selected ->
checkedState = selected
onAnswerSelected(option.value, selected)
},
colors = CheckboxConstants.defaultColors(
checkedColor = MaterialTheme.colors.primary
),
)
)
Text(
text = option.key,
modifier = Modifier.padding(horizontal = 16.dp)
)
}
}
}
}
Expand Down Expand Up @@ -295,3 +311,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
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ import androidx.compose.runtime.savedinstancestate.savedInstanceState
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.annotatedString
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.unit.dp
import com.example.compose.jetsurvey.R
import com.example.compose.jetsurvey.theme.progressIndicatorBackground
Expand Down Expand Up @@ -144,6 +147,33 @@ private fun SurveyResult(result: SurveyState.Result, modifier: Modifier = Modifi
}
}

@Composable
private fun TopAppBarTitle(
questionIndex: Int,
totalQuestionsCount: Int,
modifier: Modifier = Modifier
) {
val indexStyle = MaterialTheme.typography.caption.toSpanStyle().copy(
fontWeight = FontWeight.Bold
)
val totalStyle = MaterialTheme.typography.caption.toSpanStyle().copy(
fontWeight = FontWeight.SemiBold
)
val text = annotatedString {
withStyle(style = indexStyle) {
append("${questionIndex + 1}")
}
withStyle(style = totalStyle) {
append(stringResource(R.string.question_count, totalQuestionsCount))
}
}
Text(
text = text,
style = MaterialTheme.typography.caption,
modifier = modifier
)
}

@OptIn(ExperimentalLayout::class)
@Composable
private fun SurveyTopAppBar(
Expand All @@ -153,13 +183,9 @@ private fun SurveyTopAppBar(
) {
ConstraintLayout(modifier = Modifier.fillMaxWidth()) {
val (button, text, progress) = createRefs()
Text(
text = stringResource(
R.string.question_count,
questionIndex + 1,
totalQuestionsCount
),
style = MaterialTheme.typography.caption,
TopAppBarTitle(
questionIndex = questionIndex,
totalQuestionsCount = totalQuestionsCount,
modifier = Modifier.padding(vertical = 20.dp).constrainAs(text) {
centerHorizontallyTo(parent)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ val Colors.snackbarAction: Color
val Colors.progressIndicatorBackground: Color
get() = if (isLight) Color.Black.copy(alpha = 0.12f) else Color.Black.copy(alpha = 0.24f)

@Composable
val Colors.questionBackground: Color
get() = if (isLight) Gray100 else Gray900

@Composable
fun JetsurveyTheme(darkTheme: Boolean = isSystemInDarkTheme(), content: @Composable() () -> Unit) {
val colors = if (darkTheme) {
Expand Down
5 changes: 4 additions & 1 deletion Jetsurvey/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@

<!-- survey-->
<string name="which_jetpack_library">Which Jetpack library are you?</string>
<string name="question_count">%1$d of %2$d</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