First update labels
This commit is contained in:
parent
51c9a8e5ff
commit
7053fa6573
@ -79,9 +79,9 @@ fun TipTimeLayout() {
|
|||||||
var tipInput by remember { mutableStateOf("") }
|
var tipInput by remember { mutableStateOf("") }
|
||||||
var roundUp by remember { mutableStateOf(false) }
|
var roundUp by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
val amount = amountInput.toDoubleOrNull() ?: 0.0
|
val BmiHeight = amountInput.toDoubleOrNull() ?: 0.0
|
||||||
val tipPercent = tipInput.toDoubleOrNull() ?: 0.0
|
val BmiWeight = tipInput.toDoubleOrNull() ?: 0.0
|
||||||
val tip = calculateTip(amount, tipPercent, roundUp)
|
val tip = calculateBMI(BmiHeight, BmiWeight, roundUp)
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
@ -99,8 +99,8 @@ fun TipTimeLayout() {
|
|||||||
.align(alignment = Alignment.Start)
|
.align(alignment = Alignment.Start)
|
||||||
)
|
)
|
||||||
EditNumberField(
|
EditNumberField(
|
||||||
label = R.string.bill_amount,
|
label = R.string.height,
|
||||||
leadingIcon = R.drawable.money,
|
leadingIcon = R.drawable.number,
|
||||||
keyboardOptions = KeyboardOptions.Default.copy(
|
keyboardOptions = KeyboardOptions.Default.copy(
|
||||||
keyboardType = KeyboardType.Number,
|
keyboardType = KeyboardType.Number,
|
||||||
imeAction = ImeAction.Next
|
imeAction = ImeAction.Next
|
||||||
@ -110,8 +110,8 @@ fun TipTimeLayout() {
|
|||||||
modifier = Modifier.padding(bottom = 32.dp).fillMaxWidth(),
|
modifier = Modifier.padding(bottom = 32.dp).fillMaxWidth(),
|
||||||
)
|
)
|
||||||
EditNumberField(
|
EditNumberField(
|
||||||
label = R.string.how_was_the_service,
|
label = R.string.weight,
|
||||||
leadingIcon = R.drawable.percent,
|
leadingIcon = R.drawable.number,
|
||||||
keyboardOptions = KeyboardOptions.Default.copy(
|
keyboardOptions = KeyboardOptions.Default.copy(
|
||||||
keyboardType = KeyboardType.Number,
|
keyboardType = KeyboardType.Number,
|
||||||
imeAction = ImeAction.Done
|
imeAction = ImeAction.Done
|
||||||
@ -126,7 +126,7 @@ fun TipTimeLayout() {
|
|||||||
modifier = Modifier.padding(bottom = 32.dp)
|
modifier = Modifier.padding(bottom = 32.dp)
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
text = stringResource(R.string.tip_amount, tip),
|
text = stringResource(R.string.bmi_calculation, tip),
|
||||||
style = MaterialTheme.typography.displaySmall
|
style = MaterialTheme.typography.displaySmall
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.height(150.dp))
|
Spacer(modifier = Modifier.height(150.dp))
|
||||||
@ -163,7 +163,7 @@ fun RoundTheTipRow(
|
|||||||
modifier = modifier.fillMaxWidth(),
|
modifier = modifier.fillMaxWidth(),
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically
|
||||||
) {
|
) {
|
||||||
Text(text = stringResource(R.string.round_up_tip))
|
Text(text = stringResource(R.string.use_usc))
|
||||||
Switch(
|
Switch(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
@ -175,16 +175,16 @@ fun RoundTheTipRow(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates the tip based on the user input and format the tip amount
|
* Calculates the BMI
|
||||||
* according to the local currency.
|
*
|
||||||
* Example would be "$10.00".
|
* Catatan: tambahkan unit test untuk kalkulasi BMI ini
|
||||||
*/
|
*/
|
||||||
private fun calculateTip(amount: Double, tipPercent: Double = 15.0, roundUp: Boolean): String {
|
private fun calculateBMI(BmiHeight: Double, BmiWeight: Double = 15.0, roundUp: Boolean): String {
|
||||||
var tip = tipPercent / 100 * amount
|
var tip = BmiWeight / 100 * BmiHeight
|
||||||
if (roundUp) {
|
if (roundUp) {
|
||||||
tip = kotlin.math.ceil(tip)
|
tip = kotlin.math.ceil(tip)
|
||||||
}
|
}
|
||||||
return NumberFormat.getCurrencyInstance().format(tip)
|
return NumberFormat.getNumberInstance().format(tip)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Preview(showBackground = true)
|
@Preview(showBackground = true)
|
||||||
@ -193,4 +193,4 @@ fun TipTimeLayoutPreview() {
|
|||||||
TipTimeTheme {
|
TipTimeTheme {
|
||||||
TipTimeLayout()
|
TipTimeLayout()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,23 +0,0 @@
|
|||||||
<!--
|
|
||||||
~ Copyright (C) 2023 The Android Open Source Project
|
|
||||||
~
|
|
||||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
~ you may not use this file except in compliance with the License.
|
|
||||||
~ You may obtain a copy of the License at
|
|
||||||
~
|
|
||||||
~ https://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
~
|
|
||||||
~ Unless required by applicable law or agreed to in writing, software
|
|
||||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
~ See the License for the specific language governing permissions and
|
|
||||||
~ limitations under the License.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<vector android:height="24dp" android:tint="#000000"
|
|
||||||
android:viewportHeight="24" android:viewportWidth="24"
|
|
||||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
<path android:fillColor="@android:color/white" android:pathData="M7.5,11C9.43,11 11,9.43 11,7.5S9.43,4 7.5,4S4,5.57 4,7.5S5.57,11 7.5,11zM7.5,6C8.33,6 9,6.67 9,7.5S8.33,9 7.5,9S6,8.33 6,7.5S6.67,6 7.5,6z"/>
|
|
||||||
<path android:fillColor="@android:color/white" android:pathData="M4.0025,18.5831l14.5875,-14.5875l1.4142,1.4142l-14.5875,14.5875z"/>
|
|
||||||
<path android:fillColor="@android:color/white" android:pathData="M16.5,13c-1.93,0 -3.5,1.57 -3.5,3.5s1.57,3.5 3.5,3.5s3.5,-1.57 3.5,-3.5S18.43,13 16.5,13zM16.5,18c-0.83,0 -1.5,-0.67 -1.5,-1.5s0.67,-1.5 1.5,-1.5s1.5,0.67 1.5,1.5S17.33,18 16.5,18z"/>
|
|
||||||
</vector>
|
|
||||||
@ -15,10 +15,11 @@
|
|||||||
~ limitations under the License.
|
~ limitations under the License.
|
||||||
-->
|
-->
|
||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">Tip Time</string>
|
<string name="app_name">BMI Calculator</string>
|
||||||
<string name="calculate_tip">Calculate Tip</string>
|
<string name="calculate_tip">Calculate BMI</string>
|
||||||
<string name="bill_amount">Bill Amount</string>
|
<string name="height">Tinggi Badan</string>
|
||||||
<string name="how_was_the_service">Tip Percentage</string>
|
<string name="weight">Berat Badan</string>
|
||||||
<string name="round_up_tip">Round up tip?</string>
|
<string name="use_usc">Gunakan Unit USC (lbs/in)?</string>
|
||||||
<string name="tip_amount">Tip Amount: %s</string>
|
<!-- <string name="tip_amount">Tip Amount: %s</string> -->
|
||||||
|
<string name="bmi_calculation">BMI Anda: %s</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user