- Refactor Nama Package com.example.tiptime menjadi com.example.bmicalculator
- Menambahkan Comment Script untuk Nama dan NPM - Menyesuaikan nama Fungsi dan Variabel (Unit USC)
This commit is contained in:
parent
099c35f19a
commit
c69d20c1b7
@ -60,7 +60,7 @@ android {
|
|||||||
excludes += "/META-INF/{AL2.0,LGPL2.1}"
|
excludes += "/META-INF/{AL2.0,LGPL2.1}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
namespace = "com.example.tiptime"
|
namespace = "com.example.bmicalculator"
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
|||||||
@ -13,7 +13,15 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package com.example.tiptime
|
|
||||||
|
/*
|
||||||
|
UTS - BMI Calculator Project
|
||||||
|
Nama : Raihan Ariq Muzakki
|
||||||
|
NPM : 202310715297
|
||||||
|
Kelas : F5A5
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.example.bmicalculator
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.activity.ComponentActivity
|
import androidx.activity.ComponentActivity
|
||||||
@ -54,7 +62,7 @@ import androidx.compose.ui.text.input.ImeAction
|
|||||||
import androidx.compose.ui.text.input.KeyboardType
|
import androidx.compose.ui.text.input.KeyboardType
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.example.tiptime.ui.theme.TipTimeTheme
|
import com.example.bmicalculator.ui.theme.BMICalculatorTheme
|
||||||
import java.text.NumberFormat
|
import java.text.NumberFormat
|
||||||
|
|
||||||
class MainActivity : ComponentActivity() {
|
class MainActivity : ComponentActivity() {
|
||||||
@ -62,27 +70,28 @@ class MainActivity : ComponentActivity() {
|
|||||||
enableEdgeToEdge()
|
enableEdgeToEdge()
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContent {
|
setContent {
|
||||||
TipTimeTheme {
|
BMICalculatorTheme {
|
||||||
Surface(
|
Surface(
|
||||||
modifier = Modifier.fillMaxSize(),
|
modifier = Modifier.fillMaxSize(),
|
||||||
) {
|
) {
|
||||||
TipTimeLayout()
|
BMICalculatorLayout()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Tata letak Tampilan Aplikasi
|
||||||
@Composable
|
@Composable
|
||||||
fun TipTimeLayout() {
|
fun BMICalculatorLayout() {
|
||||||
var amountInput by remember { mutableStateOf("") }
|
var heightInput by remember { mutableStateOf("") }
|
||||||
var tipInput by remember { mutableStateOf("") }
|
var weightInput by remember { mutableStateOf("") }
|
||||||
var roundUp by remember { mutableStateOf(false) }
|
var unitUSC by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
val BmiHeight = amountInput.toDoubleOrNull() ?: 0.0
|
val BmiHeight = heightInput.toDoubleOrNull() ?: 0.0
|
||||||
val BmiWeight = tipInput.toDoubleOrNull() ?: 0.0
|
val BmiWeight = weightInput.toDoubleOrNull() ?: 0.0
|
||||||
val bmi = calculateBMI(BmiHeight, BmiWeight, roundUp)
|
val bmi = calculateBMI(BmiHeight, BmiWeight, unitUSC)
|
||||||
val category = calculateBMICategory(BmiHeight, BmiWeight, roundUp)
|
val category = calculateBMICategory(BmiHeight, BmiWeight, unitUSC)
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
@ -94,7 +103,7 @@ fun TipTimeLayout() {
|
|||||||
verticalArrangement = Arrangement.Center
|
verticalArrangement = Arrangement.Center
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
text = stringResource(R.string.calculate_tip),
|
text = stringResource(R.string.calculate_bmi),
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.padding(bottom = 16.dp, top = 40.dp)
|
.padding(bottom = 16.dp, top = 40.dp)
|
||||||
.align(alignment = Alignment.Start)
|
.align(alignment = Alignment.Start)
|
||||||
@ -106,8 +115,8 @@ fun TipTimeLayout() {
|
|||||||
keyboardType = KeyboardType.Number,
|
keyboardType = KeyboardType.Number,
|
||||||
imeAction = ImeAction.Next
|
imeAction = ImeAction.Next
|
||||||
),
|
),
|
||||||
value = amountInput,
|
value = heightInput,
|
||||||
onValueChanged = { amountInput = it },
|
onValueChanged = { heightInput = it },
|
||||||
modifier = Modifier.padding(bottom = 32.dp).fillMaxWidth(),
|
modifier = Modifier.padding(bottom = 32.dp).fillMaxWidth(),
|
||||||
)
|
)
|
||||||
EditNumberField(
|
EditNumberField(
|
||||||
@ -117,13 +126,13 @@ fun TipTimeLayout() {
|
|||||||
keyboardType = KeyboardType.Number,
|
keyboardType = KeyboardType.Number,
|
||||||
imeAction = ImeAction.Done
|
imeAction = ImeAction.Done
|
||||||
),
|
),
|
||||||
value = tipInput,
|
value = weightInput,
|
||||||
onValueChanged = { tipInput = it },
|
onValueChanged = { weightInput = it },
|
||||||
modifier = Modifier.padding(bottom = 32.dp).fillMaxWidth(),
|
modifier = Modifier.padding(bottom = 32.dp).fillMaxWidth(),
|
||||||
)
|
)
|
||||||
RoundTheTipRow(
|
UnitUSCFormulaRow(
|
||||||
roundUp = roundUp,
|
unitUSC = unitUSC,
|
||||||
onRoundUpChanged = { roundUp = it },
|
onUSCChanged = { unitUSC = it },
|
||||||
modifier = Modifier.padding(bottom = 32.dp)
|
modifier = Modifier.padding(bottom = 32.dp)
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
@ -139,6 +148,7 @@ fun TipTimeLayout() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fungsi media Input Tinggi Badan dan Berat Badan
|
||||||
@Composable
|
@Composable
|
||||||
fun EditNumberField(
|
fun EditNumberField(
|
||||||
@StringRes label: Int,
|
@StringRes label: Int,
|
||||||
@ -160,9 +170,9 @@ fun EditNumberField(
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun RoundTheTipRow(
|
fun UnitUSCFormulaRow(
|
||||||
roundUp: Boolean,
|
unitUSC: Boolean,
|
||||||
onRoundUpChanged: (Boolean) -> Unit,
|
onUSCChanged: (Boolean) -> Unit,
|
||||||
modifier: Modifier = Modifier
|
modifier: Modifier = Modifier
|
||||||
) {
|
) {
|
||||||
Row(
|
Row(
|
||||||
@ -174,8 +184,8 @@ fun RoundTheTipRow(
|
|||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.wrapContentWidth(Alignment.End),
|
.wrapContentWidth(Alignment.End),
|
||||||
checked = roundUp,
|
checked = unitUSC,
|
||||||
onCheckedChange = onRoundUpChanged
|
onCheckedChange = onUSCChanged
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -185,9 +195,9 @@ fun RoundTheTipRow(
|
|||||||
*
|
*
|
||||||
* Catatan: tambahkan unit test untuk kalkulasi BMI ini
|
* Catatan: tambahkan unit test untuk kalkulasi BMI ini
|
||||||
*/
|
*/
|
||||||
private fun calculateBMI(BmiHeight: Double, BmiWeight: Double = 15.0, roundUp: Boolean): String {
|
private fun calculateBMI(BmiHeight: Double, BmiWeight: Double = 15.0, unitUSC: Boolean): String {
|
||||||
var bmi = BmiWeight / 100 * BmiHeight
|
var bmi = BmiWeight / 100 * BmiHeight
|
||||||
if (roundUp) {
|
if (unitUSC) {
|
||||||
bmi = kotlin.math.ceil(bmi)
|
bmi = kotlin.math.ceil(bmi)
|
||||||
}
|
}
|
||||||
return NumberFormat.getNumberInstance().format(bmi)
|
return NumberFormat.getNumberInstance().format(bmi)
|
||||||
@ -198,9 +208,9 @@ private fun calculateBMI(BmiHeight: Double, BmiWeight: Double = 15.0, roundUp: B
|
|||||||
* Catatan: tambahkan unit test untuk kalkulasi BMI ini
|
* Catatan: tambahkan unit test untuk kalkulasi BMI ini
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private fun calculateBMICategory(BmiHeight: Double, BmiWeight: Double = 15.0, roundUp: Boolean): String {
|
private fun calculateBMICategory(BmiHeight: Double, BmiWeight: Double = 15.0, unitUSC: Boolean): String {
|
||||||
var bmi = BmiWeight / 100 * BmiHeight
|
var bmi = BmiWeight / 100 * BmiHeight
|
||||||
if (roundUp) {
|
if (unitUSC) {
|
||||||
bmi = kotlin.math.ceil(bmi)
|
bmi = kotlin.math.ceil(bmi)
|
||||||
}
|
}
|
||||||
return NumberFormat.getNumberInstance().format(bmi)
|
return NumberFormat.getNumberInstance().format(bmi)
|
||||||
@ -208,7 +218,7 @@ private fun calculateBMICategory(BmiHeight: Double, BmiWeight: Double = 15.0, ro
|
|||||||
@Preview(showBackground = true)
|
@Preview(showBackground = true)
|
||||||
@Composable
|
@Composable
|
||||||
fun TipTimeLayoutPreview() {
|
fun TipTimeLayoutPreview() {
|
||||||
TipTimeTheme {
|
BMICalculatorTheme {
|
||||||
TipTimeLayout()
|
BMICalculatorLayout()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package com.example.tiptime.ui.theme
|
package com.example.bmicalculator.ui.theme
|
||||||
|
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
|
|
||||||
@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package com.example.tiptime.ui.theme
|
package com.example.bmicalculator.ui.theme
|
||||||
|
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import androidx.compose.foundation.isSystemInDarkTheme
|
import androidx.compose.foundation.isSystemInDarkTheme
|
||||||
@ -90,7 +90,7 @@ private val DarkColorScheme = darkColorScheme(
|
|||||||
)
|
)
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun TipTimeTheme(
|
fun BMICalculatorTheme(
|
||||||
darkTheme: Boolean = isSystemInDarkTheme(),
|
darkTheme: Boolean = isSystemInDarkTheme(),
|
||||||
// Dynamic color is available on Android 12+
|
// Dynamic color is available on Android 12+
|
||||||
// Dynamic color in this app is turned off for learning purposes
|
// Dynamic color in this app is turned off for learning purposes
|
||||||
@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package com.example.tiptime.ui.theme
|
package com.example.bmicalculator.ui.theme
|
||||||
|
|
||||||
import androidx.compose.material3.Typography
|
import androidx.compose.material3.Typography
|
||||||
import androidx.compose.ui.text.TextStyle
|
import androidx.compose.ui.text.TextStyle
|
||||||
@ -16,7 +16,7 @@
|
|||||||
-->
|
-->
|
||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">BMI Calculator</string>
|
<string name="app_name">BMI Calculator</string>
|
||||||
<string name="calculate_tip">Calculate BMI</string>
|
<string name="calculate_bmi">Calculate BMI</string>
|
||||||
<string name="height">Tinggi Badan</string>
|
<string name="height">Tinggi Badan</string>
|
||||||
<string name="weight">Berat Badan</string>
|
<string name="weight">Berat Badan</string>
|
||||||
<string name="use_usc">Gunakan Unit USC (lbs/in)?</string>
|
<string name="use_usc">Gunakan Unit USC (lbs/in)?</string>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user