1616
1717package com.example.compose.jetsurvey.survey
1818
19- import androidx.annotation.StringRes
2019import androidx.compose.foundation.BorderStroke
2120import androidx.compose.foundation.Image
2221import androidx.compose.foundation.background
22+ import androidx.compose.foundation.border
2323import androidx.compose.foundation.clickable
2424import androidx.compose.foundation.layout.Arrangement
2525import androidx.compose.foundation.layout.Column
@@ -36,6 +36,7 @@ import androidx.compose.foundation.layout.wrapContentSize
3636import androidx.compose.foundation.lazy.LazyColumn
3737import androidx.compose.foundation.selection.selectable
3838import androidx.compose.material.Button
39+ import androidx.compose.material.ButtonDefaults
3940import androidx.compose.material.Checkbox
4041import androidx.compose.material.CheckboxDefaults
4142import androidx.compose.material.ContentAlpha
@@ -50,6 +51,7 @@ import androidx.compose.material.Surface
5051import androidx.compose.material.Text
5152import androidx.compose.material.icons.Icons
5253import androidx.compose.material.icons.filled.AddAPhoto
54+ import androidx.compose.material.icons.filled.ArrowDropDown
5355import androidx.compose.material.icons.filled.SwapHoriz
5456import androidx.compose.runtime.Composable
5557import androidx.compose.runtime.CompositionLocalProvider
@@ -61,11 +63,15 @@ import androidx.compose.ui.Alignment
6163import androidx.compose.ui.Modifier
6264import androidx.compose.ui.res.painterResource
6365import androidx.compose.ui.res.stringResource
66+ import androidx.compose.ui.text.style.TextAlign
6467import androidx.compose.ui.tooling.preview.Preview
6568import androidx.compose.ui.unit.dp
6669import com.example.compose.jetsurvey.R
6770import com.example.compose.jetsurvey.theme.JetsurveyTheme
6871import com.google.accompanist.coil.rememberCoilPainter
72+ import java.text.SimpleDateFormat
73+ import java.util.Date
74+ import java.util.Locale
6975
7076@Composable
7177fun Question (
@@ -305,7 +311,6 @@ private fun ActionQuestion(
305311 SurveyActionType .PICK_DATE -> {
306312 DateQuestion (
307313 questionId = questionId,
308- answerLabel = possibleAnswer.label,
309314 answer = answer,
310315 onAction = onAction,
311316 modifier = modifier
@@ -379,25 +384,41 @@ private fun PhotoQuestion(
379384@Composable
380385private fun DateQuestion (
381386 questionId : Int ,
382- @StringRes answerLabel : Int ,
383387 answer : Answer .Action ? ,
384388 onAction : (Int , SurveyActionType ) -> Unit ,
385389 modifier : Modifier = Modifier
386390) {
387- // val date = Date()
388- // val formatter = SimpleDateFormat("dd/MM/yyyy")
391+ val date = if (answer != null && answer.result is SurveyActionResult .Date ) {
392+ answer.result.date
393+ } else {
394+ SimpleDateFormat (" EEE, MMM d" , Locale .getDefault()).format(Date ())
395+ }
389396 Button (
390397 onClick = { onAction(questionId, SurveyActionType .PICK_DATE ) },
391- modifier = modifier.padding(vertical = 20 .dp)
392- ) {
393- Text (text = stringResource(id = answerLabel))
394- }
398+ colors = ButtonDefaults .buttonColors(
399+ backgroundColor = MaterialTheme .colors.onPrimary,
400+ contentColor = MaterialTheme .colors.onSecondary
401+ ),
402+ shape = MaterialTheme .shapes.small,
403+ modifier = modifier
404+ .padding(vertical = 20 .dp)
405+ .height(54 .dp),
406+ elevation = ButtonDefaults .elevation(0 .dp),
407+ border = BorderStroke (1 .dp, MaterialTheme .colors.onSurface.copy(alpha = 0.12f ))
395408
396- if (answer != null && answer.result is SurveyActionResult . Date ) {
409+ ) {
397410 Text (
398- text = stringResource(R .string.selected_date, answer.result.date),
399- style = MaterialTheme .typography.h4,
400- modifier = Modifier .padding(vertical = 20 .dp)
411+ text = date,
412+ modifier = Modifier
413+ .fillMaxWidth()
414+ .weight(1.8f )
415+ )
416+ Icon (
417+ imageVector = Icons .Filled .ArrowDropDown ,
418+ contentDescription = null ,
419+ modifier = Modifier
420+ .fillMaxWidth()
421+ .weight(0.2f )
401422 )
402423 }
403424}
@@ -430,10 +451,7 @@ private fun SliderQuestion(
430451 mutableStateOf(answer?.answerValue ? : possibleAnswer.defaultValue)
431452 }
432453 Row (modifier = modifier) {
433- Text (
434- text = stringResource(id = possibleAnswer.startText),
435- modifier = Modifier .align(Alignment .CenterVertically )
436- )
454+
437455 Slider (
438456 value = sliderPosition,
439457 onValueChange = {
@@ -446,9 +464,31 @@ private fun SliderQuestion(
446464 .weight(1f )
447465 .padding(horizontal = 16 .dp)
448466 )
467+ }
468+ Row {
469+ Text (
470+ text = stringResource(id = possibleAnswer.startText),
471+ style = MaterialTheme .typography.caption,
472+ textAlign = TextAlign .Start ,
473+ modifier = Modifier
474+ .fillMaxWidth()
475+ .weight(1.8f )
476+ )
477+ Text (
478+ text = stringResource(id = possibleAnswer.neutralText),
479+ style = MaterialTheme .typography.caption,
480+ textAlign = TextAlign .Center ,
481+ modifier = Modifier
482+ .fillMaxWidth()
483+ .weight(1.8f )
484+ )
449485 Text (
450486 text = stringResource(id = possibleAnswer.endText),
451- modifier = Modifier .align(Alignment .CenterVertically )
487+ style = MaterialTheme .typography.caption,
488+ textAlign = TextAlign .End ,
489+ modifier = Modifier
490+ .fillMaxWidth()
491+ .weight(1.8f )
452492 )
453493 }
454494}
0 commit comments