Compare commits

..

No commits in common. "d54998cf29e59c3f335664370512f5cd33f71b80" and "14f13dd91240b7d964ffd4f209d21ff0ec3d4984" have entirely different histories.

8 changed files with 61 additions and 77 deletions

View File

@ -1,6 +0,0 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"local>android/.github:renovate-config"
]
}

View File

@ -5,12 +5,15 @@ This app contains an order flow for cupcakes with options for quantity, flavor,
The order details get displayed on an order summary screen and can be shared to another app to
send the order.
TODO
Pre-requisites
--------------
* Experience with Kotlin syntax.
* How to create and run a project in Android Studio.
* How to create composable functions
* TODO
Getting Started

View File

@ -21,8 +21,6 @@ import androidx.annotation.StringRes
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material3.Icon
@ -117,10 +115,7 @@ fun CupcakeApp(
NavHost(
navController = navController,
startDestination = CupcakeScreen.Start.name,
modifier = Modifier
.fillMaxSize()
.verticalScroll(rememberScrollState())
.padding(innerPadding)
modifier = Modifier.padding(innerPadding)
) {
composable(route = CupcakeScreen.Start.name) {
StartOrderScreen(

View File

@ -18,13 +18,13 @@ package com.example.cupcake
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.core.view.WindowCompat
import com.example.cupcake.ui.theme.CupcakeTheme
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
enableEdgeToEdge()
super.onCreate(savedInstanceState)
WindowCompat.setDecorFitsSystemWindows(window, false)
setContent {
CupcakeTheme {
CupcakeApp()

View File

@ -39,7 +39,6 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import com.example.cupcake.R
import com.example.cupcake.ui.components.FormattedPriceLabel
import com.example.cupcake.ui.theme.CupcakeTheme
/**
* Composable that displays the list of items as [RadioButton] options,
@ -55,14 +54,14 @@ fun SelectOptionScreen(
onCancelButtonClicked: () -> Unit = {},
onNextButtonClicked: () -> Unit = {},
modifier: Modifier = Modifier
) {
){
var selectedValue by rememberSaveable { mutableStateOf("") }
Column(
modifier = modifier,
verticalArrangement = Arrangement.SpaceBetween
) {
Column(modifier = Modifier.padding(dimensionResource(R.dimen.padding_medium))) {
Column(modifier = Modifier.padding(dimensionResource(R.dimen.padding_medium))){
options.forEach { item ->
Row(
modifier = Modifier.selectable(
@ -73,7 +72,7 @@ fun SelectOptionScreen(
}
),
verticalAlignment = Alignment.CenterVertically
) {
){
RadioButton(
selected = selectedValue == item,
onClick = {
@ -101,14 +100,12 @@ fun SelectOptionScreen(
Row(
modifier = Modifier
.fillMaxWidth()
.padding(dimensionResource(R.dimen.padding_medium)),
.padding(dimensionResource(R.dimen.padding_medium))
.weight(1f, false),
horizontalArrangement = Arrangement.spacedBy(dimensionResource(R.dimen.padding_medium)),
verticalAlignment = Alignment.Bottom
) {
OutlinedButton(
modifier = Modifier.weight(1f),
onClick = onCancelButtonClicked
) {
){
OutlinedButton(modifier = Modifier.weight(1f), onClick = onCancelButtonClicked) {
Text(stringResource(R.string.cancel))
}
Button(
@ -126,12 +123,10 @@ fun SelectOptionScreen(
@Preview
@Composable
fun SelectOptionPreview() {
CupcakeTheme {
SelectOptionScreen(
subtotal = "299.99",
options = listOf("Option 1", "Option 2", "Option 3", "Option 4"),
modifier = Modifier.fillMaxHeight()
)
}
fun SelectOptionPreview(){
SelectOptionScreen(
subtotal = "299.99",
options = listOf("Option 1", "Option 2", "Option 3", "Option 4"),
modifier = Modifier.fillMaxHeight()
)
}

View File

@ -19,7 +19,9 @@ import androidx.annotation.StringRes
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
@ -39,7 +41,6 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.example.cupcake.R
import com.example.cupcake.data.DataSource
import com.example.cupcake.ui.theme.CupcakeTheme
/**
* Composable that allows the user to select the desired cupcake quantity and expects
@ -51,7 +52,7 @@ fun StartOrderScreen(
quantityOptions: List<Pair<Int, Int>>,
onNextButtonClicked: (Int) -> Unit,
modifier: Modifier = Modifier
) {
){
Column(
modifier = modifier,
verticalArrangement = Arrangement.SpaceBetween
@ -74,19 +75,20 @@ fun StartOrderScreen(
)
Spacer(modifier = Modifier.height(dimensionResource(R.dimen.padding_small)))
}
Column(
modifier = Modifier.fillMaxWidth(),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(
dimensionResource(id = R.dimen.padding_medium)
)
) {
quantityOptions.forEach { item ->
SelectQuantityButton(
labelResourceId = item.first,
onClick = { onNextButtonClicked(item.second) },
modifier = Modifier.fillMaxWidth(),
Row(modifier = Modifier.weight(1f, false)) {
Column(
modifier = Modifier.fillMaxWidth(),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(
dimensionResource(id = R.dimen.padding_medium)
)
) {
quantityOptions.forEach { item ->
SelectQuantityButton(
labelResourceId = item.first,
onClick = { onNextButtonClicked(item.second) }
)
}
}
}
}
@ -101,7 +103,7 @@ fun SelectQuantityButton(
@StringRes labelResourceId: Int,
onClick: () -> Unit,
modifier: Modifier = Modifier
) {
){
Button(
onClick = onClick,
modifier = modifier.widthIn(min = 250.dp)
@ -112,14 +114,10 @@ fun SelectQuantityButton(
@Preview
@Composable
fun StartOrderPreview() {
CupcakeTheme {
StartOrderScreen(
quantityOptions = DataSource.quantityOptions,
onNextButtonClicked = {},
modifier = Modifier
.fillMaxSize()
.padding(dimensionResource(R.dimen.padding_medium))
)
}
fun StartOrderPreview(){
StartOrderScreen(
quantityOptions = DataSource.quantityOptions,
onNextButtonClicked = {},
modifier = Modifier.fillMaxSize().padding(dimensionResource(R.dimen.padding_medium))
)
}

View File

@ -38,7 +38,6 @@ import androidx.compose.ui.tooling.preview.Preview
import com.example.cupcake.R
import com.example.cupcake.data.OrderUiState
import com.example.cupcake.ui.components.FormattedPriceLabel
import com.example.cupcake.ui.theme.CupcakeTheme
/**
* This composable expects [orderUiState] that represents the order state, [onCancelButtonClicked]
@ -51,7 +50,7 @@ fun OrderSummaryScreen(
onCancelButtonClicked: () -> Unit,
onSendButtonClicked: (String, String) -> Unit,
modifier: Modifier = Modifier
) {
){
val resources = LocalContext.current.resources
val numberOfCupcakes = resources.getQuantityString(
@ -98,7 +97,9 @@ fun OrderSummaryScreen(
)
}
Row(
modifier = Modifier.padding(dimensionResource(R.dimen.padding_medium))
modifier = Modifier
.weight(1f, false)
.padding(dimensionResource(R.dimen.padding_medium))
) {
Column(
verticalArrangement = Arrangement.spacedBy(dimensionResource(R.dimen.padding_small))
@ -122,13 +123,11 @@ fun OrderSummaryScreen(
@Preview
@Composable
fun OrderSummaryPreview() {
CupcakeTheme {
OrderSummaryScreen(
orderUiState = OrderUiState(0, "Test", "Test", "$300.00"),
onSendButtonClicked = { subject: String, summary: String -> },
onCancelButtonClicked = {},
modifier = Modifier.fillMaxHeight()
)
}
fun OrderSummaryPreview(){
OrderSummaryScreen(
orderUiState = OrderUiState(0, "Test", "Test", "$300.00"),
onSendButtonClicked = { subject: String, summary: String -> },
onCancelButtonClicked = {},
modifier = Modifier.fillMaxHeight()
)
}

View File

@ -14,11 +14,11 @@
limitations under the License.
-->
<resources>
<string name="app_name">Donut</string>
<string name="order_cupcakes">Pesan Donut</string>
<string name="one_cupcake">Pesan 1 Donat</string>
<string name="six_cupcakes">Pesan Paket 6 Donut</string>
<string name="twelve_cupcakes">Pesan Paket 12 Donut</string>
<string name="app_name">Cupcake</string>
<string name="order_cupcakes">Order Cupcakes</string>
<string name="one_cupcake">One Cupcake</string>
<string name="six_cupcakes">Six Cupcakes</string>
<string name="twelve_cupcakes">Twelve Cupcakes</string>
<string name="choose_flavor">Choose Flavor</string>
<string name="vanilla">Vanilla</string>
<string name="chocolate">Chocolate</string>
@ -36,11 +36,11 @@
<string name="pickup_date">Pickup date</string>
<string name="subtotal_price">Subtotal %s</string>
<string name="total_price">Total %s</string>
<string name="new_cupcake_order">New Donut Order</string>
<string name="new_cupcake_order">New Cupcake Order</string>
<string name="order_details">Quantity: %1$s \nFlavor: %2$s \nPickup date: %3$s \nTotal: %4$s \n\nThank you!</string>
<string name="back_button">Back</string>
<plurals name="cupcakes">
<item quantity="one">%d Donut</item>
<item quantity="other">%d Donut</item>
<item quantity="one">%d cupcake</item>
<item quantity="other">%d cupcakes</item>
</plurals>
</resources>