init: Jetpack Compose project setup
32
.github/ISSUE_TEMPLATE/calculate-a-custom-tip-issue-template.md
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
---
|
||||
name: Calculate a custom tip issue template
|
||||
about: 'Issue template for Calculate a custom tip '
|
||||
title: 'Calculate a custom tip: Android Basics in Compose '
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**URL of codelab**
|
||||
|
||||
|
||||
**In which task and step of the codelab can this issue be found?**
|
||||
|
||||
|
||||
**Describe the problem**
|
||||
|
||||
|
||||
|
||||
|
||||
**Steps to reproduce?**
|
||||
1. Go to...
|
||||
2. Click on...
|
||||
3. See error...
|
||||
|
||||
**Versions**
|
||||
_Android Studio version:_
|
||||
_API version of the emulator:_
|
||||
|
||||
|
||||
**Additional information**
|
||||
_Include screenshots if they would be useful in clarifying the problem._
|
||||
32
.github/ISSUE_TEMPLATE/intro-to-state-issue-template.md
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
---
|
||||
name: Intro to state issue template
|
||||
about: 'Issue template for Intro to state in Compose '
|
||||
title: 'Intro to state in Compose: Android Basics in Compose'
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**URL of codelab**
|
||||
|
||||
|
||||
**In which task and step of the codelab can this issue be found?**
|
||||
|
||||
|
||||
**Describe the problem**
|
||||
|
||||
|
||||
|
||||
|
||||
**Steps to reproduce?**
|
||||
1. Go to...
|
||||
2. Click on...
|
||||
3. See error...
|
||||
|
||||
**Versions**
|
||||
_Android Studio version:_
|
||||
_API version of the emulator:_
|
||||
|
||||
|
||||
**Additional information**
|
||||
_Include screenshots if they would be useful in clarifying the problem._
|
||||
11
.github/renovate.json
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||
"extends": [
|
||||
"local>android/.github:renovate-config"
|
||||
],
|
||||
"baseBranches": [
|
||||
"main",
|
||||
"starter",
|
||||
"state"
|
||||
]
|
||||
}
|
||||
30
.github/workflows/main.yml
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
name: Build
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
- starter
|
||||
- state
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Set Up JDK
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: 'zulu' # See 'Supported distributions' for available options
|
||||
java-version: '17'
|
||||
cache: 'gradle'
|
||||
|
||||
- name: Setup Gradle
|
||||
uses: gradle/actions/setup-gradle@v4
|
||||
|
||||
- name: Setup Android SDK
|
||||
uses: android-actions/setup-android@v3
|
||||
|
||||
- name: Build project and run local and device tests
|
||||
run: ./gradlew :app:assembleDebug
|
||||
36
.gitignore
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
# built application files
|
||||
*.apk
|
||||
*.ap_
|
||||
|
||||
# Mac files
|
||||
.DS_Store
|
||||
|
||||
# files for the dex VM
|
||||
*.dex
|
||||
|
||||
# Java class files
|
||||
*.class
|
||||
|
||||
# generated files
|
||||
bin/
|
||||
gen/
|
||||
|
||||
# Ignore gradle files
|
||||
.gradle/
|
||||
build/
|
||||
|
||||
# Local configuration file (sdk path, etc)
|
||||
local.properties
|
||||
|
||||
# Proguard folder generated by Eclipse
|
||||
proguard/
|
||||
proguard-project.txt
|
||||
|
||||
# Eclipse files
|
||||
.project
|
||||
.classpath
|
||||
.settings/
|
||||
|
||||
# Android Studio/IDEA
|
||||
*.iml
|
||||
.idea
|
||||
36
CONTRIBUTING.md
Normal file
@ -0,0 +1,36 @@
|
||||
# How to become a contributor and submit your own code
|
||||
|
||||
## Contributor License Agreements
|
||||
|
||||
We'd love to accept your sample apps and patches! Before we can take them, we
|
||||
have to jump a couple of legal hurdles.
|
||||
|
||||
Please fill out either the individual or corporate Contributor License Agreement
|
||||
(CLA).
|
||||
|
||||
* If you are an individual writing original source code and you're sure you
|
||||
own the intellectual property, then you'll need to sign an [individual CLA]
|
||||
(https://developers.google.com/open-source/cla/individual).
|
||||
* If you work for a company that wants to allow you to contribute your work,
|
||||
then you'll need to sign a [corporate CLA]
|
||||
(https://developers.google.com/open-source/cla/corporate).
|
||||
|
||||
Follow either of the two links above to access the appropriate CLA and
|
||||
instructions for how to sign and return it. Once we receive it, we'll be able to
|
||||
accept your pull requests.
|
||||
|
||||
## Contributing A Patch
|
||||
|
||||
1. Submit an issue describing your proposed change to the repo in question.
|
||||
1. The repo owner will respond to your issue promptly.
|
||||
1. If your proposed change is accepted, and you haven't already done so, sign a
|
||||
Contributor License Agreement (see details above).
|
||||
1. Fork the desired repo, develop and test your code changes.
|
||||
1. Ensure that your code adheres to the existing style in the sample to which
|
||||
you are contributing. Refer to the
|
||||
[Google Cloud Platform Samples Style Guide]
|
||||
(https://github.com/GoogleCloudPlatform/Template/wiki/style.html) for the
|
||||
recommended coding standards for this organization.
|
||||
1. Ensure that your code has an appropriate set of unit tests which all pass.
|
||||
1. Submit a pull request.
|
||||
|
||||
202
LICENSE
Normal file
@ -0,0 +1,202 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
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
|
||||
|
||||
http://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.
|
||||
579
README.md
Normal file
@ -0,0 +1,579 @@
|
||||
# 🏋️ BMI Calculator
|
||||
|
||||
[](https://kotlinlang.org)
|
||||
[](https://developer.android.com/jetpack/compose)
|
||||
[](https://m3.material.io/)
|
||||
[](LICENSE)
|
||||
|
||||
Modern Android aplikasi untuk menghitung Body Mass Index (BMI) dengan antarmuka yang clean dan intuitif menggunakan Jetpack Compose dan Material Design 3.
|
||||
|
||||

|
||||
|
||||
---
|
||||
|
||||
## 📋 Daftar Isi
|
||||
|
||||
- [Fitur](#-fitur)
|
||||
- [Screenshots](#-screenshots)
|
||||
- [Teknologi](#-teknologi)
|
||||
- [Arsitektur](#-arsitektur)
|
||||
- [Instalasi](#-instalasi)
|
||||
- [Cara Menggunakan](#-cara-menggunakan)
|
||||
- [Testing](#-testing)
|
||||
- [Struktur Project](#-struktur-project)
|
||||
- [Kategori BMI](#-kategori-bmi)
|
||||
- [Formula Perhitungan](#-formula-perhitungan)
|
||||
- [Kontribusi](#-kontribusi)
|
||||
- [Lisensi](#-lisensi)
|
||||
- [Kontak](#-kontak)
|
||||
|
||||
---
|
||||
|
||||
## ✨ Fitur
|
||||
|
||||
### 🎯 Core Features
|
||||
|
||||
- ✅ **Perhitungan BMI Akurat** - Formula standar WHO untuk Metric dan Imperial
|
||||
- ✅ **Dual Unit System** - Support Metric (kg, cm) dan Imperial (lb, in)
|
||||
- ✅ **Kategori BMI** - Underweight, Normal, Overweight, Obese dengan color coding
|
||||
- ✅ **Healthy Weight Range** - Menampilkan rentang berat ideal berdasarkan tinggi
|
||||
- ✅ **Input Validation** - Validasi real-time untuk input yang valid
|
||||
- ✅ **Error Handling** - Error messages yang jelas dan helpful
|
||||
|
||||
### 🎨 UI/UX Features
|
||||
|
||||
- ✅ **Modern UI** - Jetpack Compose dengan Material Design 3
|
||||
- ✅ **Smooth Animations** - Spring animations untuk hasil BMI
|
||||
- ✅ **Clean Design** - Minimalist interface dengan visual hierarchy yang jelas
|
||||
- ✅ **Material Icons** - Icon yang meaningful untuk setiap elemen
|
||||
- ✅ **Welcome Screen** - Onboarding screen dengan ilustrasi
|
||||
- ✅ **Responsive Layout** - Adaptive untuk berbagai ukuran layar
|
||||
- ✅ **Color-coded Results** - Visual feedback berdasarkan kategori BMI
|
||||
|
||||
### 🔧 Technical Features
|
||||
|
||||
- ✅ **Jetpack Compose** - 100% Compose UI (no XML layouts)
|
||||
- ✅ **Material Design 3** - Latest design system
|
||||
- ✅ **Type Safety** - Kotlin with strong typing
|
||||
- ✅ **Unit Tested** - 93+ test cases dengan coverage >90%
|
||||
- ✅ **Edge-to-Edge** - Modern Android edge-to-edge support
|
||||
- ✅ **No Dependencies** - Pure Android SDK (no third-party libraries)
|
||||
|
||||
---
|
||||
|
||||
## 📱 Screenshots
|
||||
|
||||
### Welcome Screen
|
||||
<img src="screenshots/welcome.png" width="250" alt="Welcome Screen"/>
|
||||
|
||||
### Main Calculator
|
||||
<img src="screenshots/calculator.png" width="250" alt="BMI Calculator"/>
|
||||
|
||||
### Result Display
|
||||
<img src="screenshots/result.png" width="250" alt="BMI Result"/>
|
||||
|
||||
---
|
||||
|
||||
## 🛠 Teknologi
|
||||
|
||||
### Core Technologies
|
||||
|
||||
| Technology | Version | Purpose |
|
||||
|------------|---------|---------|
|
||||
| **Kotlin** | 1.9+ | Programming language |
|
||||
| **Jetpack Compose** | 2025.11 | Modern UI toolkit |
|
||||
| **Material Design 3** | Latest | Design system |
|
||||
| **Android SDK** | Min 24, Target 36 | Android platform |
|
||||
| **JUnit 4** | 4.13.2 | Unit testing |
|
||||
|
||||
### Key Libraries
|
||||
|
||||
```kotlin
|
||||
// Compose BOM
|
||||
implementation(platform("androidx.compose:compose-bom:2025.11.00"))
|
||||
|
||||
// Compose Core
|
||||
implementation("androidx.compose.ui:ui")
|
||||
implementation("androidx.compose.material3:material3")
|
||||
implementation("androidx.compose.material:material-icons-extended")
|
||||
|
||||
// Activity Compose
|
||||
implementation("androidx.activity:activity-compose:1.11.0")
|
||||
|
||||
// Core
|
||||
implementation("androidx.core:core-ktx:1.17.0")
|
||||
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.9.4")
|
||||
```
|
||||
|
||||
### Development Tools
|
||||
|
||||
- **Gradle** 8.x - Build system
|
||||
- **Android Studio** Koala+ - IDE
|
||||
- **Git** - Version control
|
||||
|
||||
---
|
||||
|
||||
## 🏗 Arsitektur
|
||||
|
||||
### Project Structure
|
||||
|
||||
```
|
||||
app/
|
||||
├── src/
|
||||
│ ├── main/
|
||||
│ │ ├── java/com/example/tiptime/
|
||||
│ │ │ ├── MainActivity.kt # Main entry point
|
||||
│ │ │ ├── WelcomeActivity.kt # Welcome screen
|
||||
│ │ │ ├── model/
|
||||
│ │ │ │ ├── BmiData.kt # BMI data class
|
||||
│ │ │ │ ├── BmiCategory.kt # BMI categories enum
|
||||
│ │ │ │ └── UnitSystem.kt # Metric/Imperial enum
|
||||
│ │ │ ├── ui/
|
||||
│ │ │ │ ├── BmiCalculatorScreen.kt # Main calculator UI
|
||||
│ │ │ │ └── theme/
|
||||
│ │ │ │ ├── Color.kt # Color definitions
|
||||
│ │ │ │ ├── Theme.kt # App theme
|
||||
│ │ │ │ └── Type.kt # Typography
|
||||
│ │ │ └── utils/
|
||||
│ │ │ └── BmiCalculator.kt # BMI calculation logic
|
||||
│ │ └── res/
|
||||
│ │ ├── drawable/
|
||||
│ │ │ └── image_bmi.png # Welcome illustration
|
||||
│ │ └── values/
|
||||
│ │ └── strings.xml # String resources
|
||||
│ └── test/
|
||||
│ └── java/com/example/tiptime/
|
||||
│ ├── utils/
|
||||
│ │ └── BmiCalculatorTest.kt # 43 unit tests
|
||||
│ └── model/
|
||||
│ ├── BmiCategoryTest.kt # 30+ unit tests
|
||||
│ ├── BmiDataTest.kt # 10 unit tests
|
||||
│ └── UnitSystemTest.kt # 10 unit tests
|
||||
```
|
||||
|
||||
### Design Pattern
|
||||
|
||||
- **MVVM-like Structure** - Separation of UI and business logic
|
||||
- **Single Activity** - Modern Android navigation
|
||||
- **Stateless Composables** - Unidirectional data flow
|
||||
- **Utility Classes** - Pure functions for calculations
|
||||
- **Material Design** - Following Material 3 guidelines
|
||||
|
||||
---
|
||||
|
||||
## 💿 Instalasi
|
||||
|
||||
### Prerequisites
|
||||
|
||||
- **Android Studio** Koala (2024.1.1) atau lebih baru
|
||||
- **JDK** 17 atau lebih baru
|
||||
- **Android SDK** API 24+ (Android 7.0)
|
||||
- **Git** untuk clone repository
|
||||
|
||||
### Clone & Build
|
||||
|
||||
```bash
|
||||
# 1. Clone repository
|
||||
git clone https://github.com/username/bmi-calculator.git
|
||||
cd bmi-calculator
|
||||
|
||||
# 2. Open di Android Studio
|
||||
# File → Open → Pilih folder project
|
||||
|
||||
# 3. Sync Gradle
|
||||
# Android Studio akan otomatis sync dependencies
|
||||
|
||||
# 4. Build project
|
||||
./gradlew build
|
||||
|
||||
# Windows:
|
||||
gradlew.bat build
|
||||
|
||||
# 5. Run aplikasi
|
||||
# Pilih device/emulator → Click Run (▶️)
|
||||
```
|
||||
|
||||
### Install APK
|
||||
|
||||
```bash
|
||||
# Build debug APK
|
||||
./gradlew assembleDebug
|
||||
|
||||
# APK tersedia di:
|
||||
# app/build/outputs/apk/debug/app-debug.apk
|
||||
|
||||
# Install ke device
|
||||
./gradlew installDebug
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📖 Cara Menggunakan
|
||||
|
||||
### Langkah Penggunaan
|
||||
|
||||
1. **Buka Aplikasi**
|
||||
- Lihat welcome screen
|
||||
- Tap "Get Started"
|
||||
|
||||
2. **Pilih Unit System**
|
||||
- **Metric**: kg & cm
|
||||
- **Imperial**: lb & in
|
||||
|
||||
3. **Input Data**
|
||||
- Masukkan **Weight** (berat badan)
|
||||
- Masukkan **Height** (tinggi badan)
|
||||
|
||||
4. **Hitung BMI**
|
||||
- Tap tombol **"Calculate BMI"**
|
||||
- Hasil akan muncul dengan animasi
|
||||
|
||||
5. **Lihat Hasil**
|
||||
- **BMI Value** - Nilai BMI Anda
|
||||
- **Category** - Underweight/Normal/Overweight/Obese
|
||||
- **Healthy Range** - Rentang berat ideal Anda
|
||||
- **BMI Categories** - Info kategori BMI
|
||||
|
||||
### Input Validation
|
||||
|
||||
| System | Weight Range | Height Range |
|
||||
|----------|--------------|--------------|
|
||||
| Metric | 1-500 kg | 50-300 cm |
|
||||
| Imperial | 2-1100 lb | 20-120 in |
|
||||
|
||||
---
|
||||
|
||||
## 🧪 Testing
|
||||
|
||||
### Unit Tests
|
||||
|
||||
Project ini memiliki **93+ unit tests** dengan coverage >90%.
|
||||
|
||||
#### Jalankan Test
|
||||
|
||||
```bash
|
||||
# Command Line
|
||||
./gradlew test
|
||||
|
||||
# Windows
|
||||
gradlew.bat test
|
||||
|
||||
# Lihat HTML Report
|
||||
# app/build/reports/tests/test/index.html
|
||||
```
|
||||
|
||||
#### Test Coverage
|
||||
|
||||
| File | Tests | Coverage |
|
||||
|------|-------|----------|
|
||||
| `BmiCalculatorTest.kt` | 43 | Perhitungan, validasi, boundary |
|
||||
| `BmiCategoryTest.kt` | 30+ | Kategori, warna, display |
|
||||
| `BmiDataTest.kt` | 10 | Data class, equality |
|
||||
| `UnitSystemTest.kt` | 10 | Enum values |
|
||||
|
||||
#### Contoh Test Cases
|
||||
|
||||
```kotlin
|
||||
// Test perhitungan BMI
|
||||
@Test
|
||||
fun calculateBmi_metric_normal_returnsCorrectBmi() {
|
||||
// 70 kg, 175 cm -> BMI = 22.86 (Normal)
|
||||
val result = BmiCalculator.calculateBmi(70.0, 175.0, UnitSystem.METRIC)
|
||||
assertEquals(22.86, result.bmi, 0.01)
|
||||
assertEquals(BmiCategory.NORMAL, result.category)
|
||||
}
|
||||
|
||||
// Test boundary values
|
||||
@Test
|
||||
fun fromBmi_exactNormalLowerBoundary_returnsNormal() {
|
||||
// BMI 18.5 (tepat batas bawah normal)
|
||||
assertEquals(BmiCategory.NORMAL, BmiCategory.fromBmi(18.5))
|
||||
}
|
||||
```
|
||||
|
||||
Untuk panduan lengkap, baca: **[TESTING_GUIDE.md](TESTING_GUIDE.md)**
|
||||
|
||||
---
|
||||
|
||||
## 📊 Kategori BMI
|
||||
|
||||
Berdasarkan standar **WHO (World Health Organization)**:
|
||||
|
||||
| Kategori | BMI Range | Color | Status |
|
||||
|----------|-----------|-------|--------|
|
||||
| **Underweight** | < 18.5 | 🔵 Blue | Berat badan kurang |
|
||||
| **Normal** | 18.5 - 24.9 | 🟢 Green | Berat badan ideal |
|
||||
| **Overweight** | 25.0 - 29.9 | 🟠 Orange | Kelebihan berat badan |
|
||||
| **Obese** | ≥ 30.0 | 🔴 Red | Obesitas |
|
||||
|
||||
### Visual Color Coding
|
||||
|
||||
```kotlin
|
||||
val UnderweightColor = Color(0xFF3B82F6) // Blue
|
||||
val NormalColor = Color(0xFF10B981) // Green
|
||||
val OverweightColor = Color(0xFFF59E0B) // Orange
|
||||
val ObeseColor = Color(0xFFEF4444) // Red
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🔬 Formula Perhitungan
|
||||
|
||||
### Metric System (kg, cm)
|
||||
|
||||
```
|
||||
BMI = weight (kg) / (height (m))²
|
||||
```
|
||||
|
||||
**Contoh:**
|
||||
- Weight: 70 kg
|
||||
- Height: 175 cm = 1.75 m
|
||||
- BMI = 70 / (1.75)² = 22.86
|
||||
|
||||
### Imperial System (lb, in)
|
||||
|
||||
```
|
||||
BMI = (weight (lb) / (height (in))²) × 703
|
||||
```
|
||||
|
||||
**Contoh:**
|
||||
- Weight: 150 lb
|
||||
- Height: 67 in
|
||||
- BMI = (150 / (67)²) × 703 = 23.49
|
||||
|
||||
### Healthy Weight Range
|
||||
|
||||
```kotlin
|
||||
// Untuk BMI 18.5 - 24.9
|
||||
minWeight = 18.5 × (height)²
|
||||
maxWeight = 24.9 × (height)²
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🎨 Theme & Colors
|
||||
|
||||
### Color Palette
|
||||
|
||||
```kotlin
|
||||
// Primary Colors
|
||||
val PrimaryBlue = Color(0xFF2563EB)
|
||||
val PrimaryBlueDark = Color(0xFF1E40AF)
|
||||
val BackgroundLight = Color(0xFFF8FAFC)
|
||||
|
||||
// Text Colors
|
||||
val TextPrimary = Color(0xFF1E293B)
|
||||
val TextSecondary = Color(0xFF64748B)
|
||||
|
||||
// BMI Category Colors
|
||||
val UnderweightColor = Color(0xFF3B82F6) // Blue
|
||||
val NormalColor = Color(0xFF10B981) // Green
|
||||
val OverweightColor = Color(0xFFF59E0B) // Orange
|
||||
val ObeseColor = Color(0xFFEF4444) // Red
|
||||
```
|
||||
|
||||
### Material Icons
|
||||
|
||||
- **FitnessCenter** - App header icon
|
||||
- **MonitorWeight** - Weight input icon
|
||||
- **Height** - Height input icon
|
||||
- **Calculate** - Calculate button icon
|
||||
|
||||
---
|
||||
|
||||
## 🔧 Configuration
|
||||
|
||||
### Build Configuration
|
||||
|
||||
```kotlin
|
||||
android {
|
||||
compileSdk = 36
|
||||
|
||||
defaultConfig {
|
||||
applicationId = "com.example.tiptime"
|
||||
minSdk = 24
|
||||
targetSdk = 36
|
||||
versionCode = 1
|
||||
versionName = "1.0"
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
||||
|
||||
kotlinOptions {
|
||||
jvmTarget = "17"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Gradle Version
|
||||
|
||||
- **Gradle**: 8.9
|
||||
- **AGP**: 8.7.3
|
||||
- **Kotlin**: 2.0.21
|
||||
|
||||
---
|
||||
|
||||
## 🤝 Kontribusi
|
||||
|
||||
Kontribusi sangat diterima! Berikut cara berkontribusi:
|
||||
|
||||
### Steps
|
||||
|
||||
1. **Fork** repository ini
|
||||
2. **Create** feature branch (`git checkout -b feature/AmazingFeature`)
|
||||
3. **Commit** changes (`git commit -m 'Add some AmazingFeature'`)
|
||||
4. **Push** to branch (`git push origin feature/AmazingFeature`)
|
||||
5. **Open** Pull Request
|
||||
|
||||
### Guidelines
|
||||
|
||||
- ✅ Ikuti Kotlin coding conventions
|
||||
- ✅ Tulis unit tests untuk fitur baru
|
||||
- ✅ Update dokumentasi jika perlu
|
||||
- ✅ Pastikan semua tests pass
|
||||
- ✅ Gunakan commit messages yang jelas
|
||||
|
||||
### Bug Reports
|
||||
|
||||
Jika menemukan bug, silakan buat issue dengan detail:
|
||||
- Deskripsi bug
|
||||
- Steps to reproduce
|
||||
- Expected vs actual behavior
|
||||
- Screenshots (jika ada)
|
||||
- Device & Android version
|
||||
|
||||
---
|
||||
|
||||
## 📝 Changelog
|
||||
|
||||
### Version 1.0.0 (November 2025)
|
||||
|
||||
**Initial Release**
|
||||
|
||||
✨ **Features:**
|
||||
- BMI calculation (Metric & Imperial)
|
||||
- Welcome screen dengan ilustrasi
|
||||
- Modern Material Design 3 UI
|
||||
- Input validation
|
||||
- Healthy weight range
|
||||
- Animated results
|
||||
- BMI categories info card
|
||||
|
||||
🧪 **Tests:**
|
||||
- 93+ unit tests
|
||||
- >90% code coverage
|
||||
- Boundary value testing
|
||||
- Edge case handling
|
||||
|
||||
🎨 **UI/UX:**
|
||||
- Clean, modern interface
|
||||
- Color-coded categories
|
||||
- Material icons
|
||||
- Smooth animations
|
||||
- Responsive layout
|
||||
|
||||
---
|
||||
|
||||
## 📄 Lisensi
|
||||
|
||||
```
|
||||
Copyright (C) 2025 BMI Calculator 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
|
||||
|
||||
http://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.
|
||||
```
|
||||
|
||||
Project ini menggunakan **Apache License 2.0**. Lihat file [LICENSE](LICENSE) untuk detail lengkap.
|
||||
|
||||
---
|
||||
|
||||
## 👥 Authors
|
||||
|
||||
**[NPM: ISI NPM ANDA]**
|
||||
**[Nama: ISI NAMA ANDA]**
|
||||
|
||||
---
|
||||
|
||||
## 📞 Kontak
|
||||
|
||||
- **Email**: your.email@example.com
|
||||
- **GitHub**: [@yourusername](https://github.com/yourusername)
|
||||
- **LinkedIn**: [Your Name](https://linkedin.com/in/yourprofile)
|
||||
|
||||
---
|
||||
|
||||
## 🙏 Acknowledgments
|
||||
|
||||
- **Android Team** - Jetpack Compose & Material Design 3
|
||||
- **WHO** - BMI classification standards
|
||||
- **Material Design** - Design guidelines & icons
|
||||
- **Kotlin Team** - Amazing programming language
|
||||
- **Open Source Community** - Inspiration & support
|
||||
|
||||
---
|
||||
|
||||
## 📚 Resources
|
||||
|
||||
### Documentation
|
||||
|
||||
- [Jetpack Compose](https://developer.android.com/jetpack/compose)
|
||||
- [Material Design 3](https://m3.material.io/)
|
||||
- [Kotlin Language](https://kotlinlang.org/docs/home.html)
|
||||
|
||||
### Related Projects
|
||||
|
||||
- [Android Compose Samples](https://github.com/android/compose-samples)
|
||||
- [Material 3 Catalog](https://github.com/material-components/material-components-android)
|
||||
|
||||
### Learning Resources
|
||||
|
||||
- [Android Basics with Compose](https://developer.android.com/courses/android-basics-compose/course)
|
||||
- [Kotlin Bootcamp](https://developer.android.com/courses/kotlin-bootcamp/overview)
|
||||
|
||||
---
|
||||
|
||||
## ⭐ Star History
|
||||
|
||||
Jika project ini membantu Anda, berikan ⭐ di GitHub!
|
||||
|
||||
[](https://star-history.com/#username/bmi-calculator&Date)
|
||||
|
||||
---
|
||||
|
||||
## 🚀 Future Enhancements
|
||||
|
||||
Rencana pengembangan untuk versi mendatang:
|
||||
|
||||
- [ ] Dark mode support
|
||||
- [ ] BMI history tracking
|
||||
- [ ] Export hasil ke PDF
|
||||
- [ ] Grafik BMI over time
|
||||
- [ ] Multi-language support (Indonesian, English)
|
||||
- [ ] Widget untuk home screen
|
||||
- [ ] Apple Health / Google Fit integration
|
||||
- [ ] BMI trends & analytics
|
||||
- [ ] Recommendations berdasarkan BMI
|
||||
- [ ] Share hasil ke social media
|
||||
|
||||
---
|
||||
|
||||
<div align="center">
|
||||
|
||||
**Made with ❤️ using Jetpack Compose**
|
||||
|
||||
[⬆ Back to Top](#-bmi-calculator)
|
||||
|
||||
</div>
|
||||
|
||||
309
TESTING_GUIDE.md
Normal file
@ -0,0 +1,309 @@
|
||||
# 🧪 Panduan Menjalankan Unit Test - BMI Calculator
|
||||
|
||||
## 📋 Test Files yang Tersedia
|
||||
|
||||
Saya telah membuat 4 file unit test:
|
||||
|
||||
1. **BmiCalculatorTest.kt** (43 test cases)
|
||||
- Test perhitungan BMI untuk sistem Metric dan Imperial
|
||||
- Test kategori BMI (Underweight, Normal, Overweight, Obese)
|
||||
- Test validasi input (weight & height)
|
||||
- Test boundary values (nilai batas antar kategori)
|
||||
- Test healthy weight range
|
||||
|
||||
2. **BmiCategoryTest.kt** (30+ test cases)
|
||||
- Test kategori BMI berdasarkan nilai BMI
|
||||
- Test display names
|
||||
- Test warna untuk setiap kategori
|
||||
- Test boundary values
|
||||
|
||||
3. **BmiDataTest.kt** (10 test cases)
|
||||
- Test BmiData data class
|
||||
- Test equality & copy functions
|
||||
|
||||
4. **UnitSystemTest.kt** (10 test cases)
|
||||
- Test UnitSystem enum (METRIC & IMPERIAL)
|
||||
- Test display names dan properties
|
||||
|
||||
---
|
||||
|
||||
## 🚀 Cara Menjalankan Test
|
||||
|
||||
### Metode 1: Menggunakan Command Line (Windows CMD)
|
||||
|
||||
#### A. Jalankan SEMUA unit tests:
|
||||
```cmd
|
||||
cd e:\androidProject\basic-android-kotlin-compose-training-tip-calculator
|
||||
gradlew.bat test
|
||||
```
|
||||
|
||||
#### B. Jalankan test untuk package tertentu:
|
||||
```cmd
|
||||
gradlew.bat test --tests "com.example.tiptime.*"
|
||||
```
|
||||
|
||||
#### C. Jalankan test untuk class tertentu:
|
||||
```cmd
|
||||
gradlew.bat test --tests "com.example.tiptime.utils.BmiCalculatorTest"
|
||||
gradlew.bat test --tests "com.example.tiptime.model.BmiCategoryTest"
|
||||
gradlew.bat test --tests "com.example.tiptime.model.BmiDataTest"
|
||||
gradlew.bat test --tests "com.example.tiptime.model.UnitSystemTest"
|
||||
```
|
||||
|
||||
#### D. Jalankan test method tertentu:
|
||||
```cmd
|
||||
gradlew.bat test --tests "com.example.tiptime.utils.BmiCalculatorTest.calculateBmi_metric_normal_returnsCorrectBmi"
|
||||
```
|
||||
|
||||
#### E. Jalankan test dengan output detail:
|
||||
```cmd
|
||||
gradlew.bat test --info
|
||||
```
|
||||
|
||||
#### F. Jalankan test dan buat HTML report:
|
||||
```cmd
|
||||
gradlew.bat test
|
||||
```
|
||||
Hasil report akan ada di: `app/build/reports/tests/test/index.html`
|
||||
|
||||
---
|
||||
|
||||
### Metode 2: Menggunakan Android Studio / IntelliJ IDEA
|
||||
|
||||
#### A. Jalankan SEMUA test dalam 1 file:
|
||||
1. Buka file test (misalnya `BmiCalculatorTest.kt`)
|
||||
2. Klik kanan pada nama class
|
||||
3. Pilih **"Run 'BmiCalculatorTest'"** (atau tekan `Ctrl+Shift+F10`)
|
||||
|
||||
#### B. Jalankan 1 test method saja:
|
||||
1. Klik pada method test yang ingin dijalankan
|
||||
2. Klik icon ▶️ hijau di sebelah kiri method
|
||||
3. Atau klik kanan → **"Run 'methodName()'"**
|
||||
|
||||
#### C. Jalankan semua test di project:
|
||||
1. Klik kanan pada folder `test` di Project Explorer
|
||||
2. Pilih **"Run 'Tests in ...'**
|
||||
3. Atau: **Run → Run... → All Tests**
|
||||
|
||||
#### D. Jalankan test dengan coverage (untuk lihat code coverage):
|
||||
1. Klik kanan pada file test
|
||||
2. Pilih **"Run 'BmiCalculatorTest' with Coverage"**
|
||||
3. Atau tekan `Ctrl+Shift+F10` dengan Coverage
|
||||
|
||||
#### E. Lihat hasil test:
|
||||
- Panel **"Run"** di bagian bawah akan menampilkan hasil
|
||||
- ✅ Green = Pass
|
||||
- ❌ Red = Fail
|
||||
- Status summary akan muncul (misalnya: "43 tests passed")
|
||||
|
||||
---
|
||||
|
||||
### Metode 3: Menggunakan Gradle Task di Android Studio
|
||||
|
||||
1. Buka **Gradle** panel (View → Tool Windows → Gradle)
|
||||
2. Navigate ke: `app → Tasks → verification → test`
|
||||
3. Double-click pada **test** task
|
||||
4. Hasil akan muncul di panel Run
|
||||
|
||||
---
|
||||
|
||||
## 📊 Membaca Hasil Test
|
||||
|
||||
### A. Command Line Output
|
||||
```
|
||||
> Task :app:testDebugUnitTest
|
||||
|
||||
com.example.tiptime.utils.BmiCalculatorTest > calculateBmi_metric_normal_returnsCorrectBmi() PASSED
|
||||
com.example.tiptime.utils.BmiCalculatorTest > calculateBmi_metric_underweight_returnsCorrectBmi() PASSED
|
||||
...
|
||||
|
||||
BUILD SUCCESSFUL in 15s
|
||||
```
|
||||
|
||||
### B. HTML Report
|
||||
Setelah menjalankan test, buka file:
|
||||
```
|
||||
app/build/reports/tests/test/index.html
|
||||
```
|
||||
|
||||
Report ini menampilkan:
|
||||
- ✅ Total tests, passed, failed, skipped
|
||||
- ⏱️ Durasi execution
|
||||
- 📊 Success rate (%)
|
||||
- 📁 Breakdown per package dan class
|
||||
- 📝 Detail setiap test case
|
||||
|
||||
### C. Android Studio Output
|
||||
Panel Run akan menampilkan:
|
||||
```
|
||||
Test Results:
|
||||
✅ BmiCalculatorTest (43 tests) - PASSED
|
||||
✅ calculateBmi_metric_normal_returnsCorrectBmi - 12ms
|
||||
✅ calculateBmi_metric_underweight_returnsCorrectBmi - 8ms
|
||||
✅ isValidWeight_metric_validWeight_returnsTrue - 5ms
|
||||
...
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🎯 Test Coverage Summary
|
||||
|
||||
### BmiCalculatorTest (43 tests):
|
||||
- ✅ Perhitungan BMI Metric (4 tests)
|
||||
- ✅ Perhitungan BMI Imperial (3 tests)
|
||||
- ✅ Boundary Cases / Batas Kategori (4 tests)
|
||||
- ✅ Validasi Weight Metric (4 tests)
|
||||
- ✅ Validasi Weight Imperial (4 tests)
|
||||
- ✅ Validasi Height Metric (4 tests)
|
||||
- ✅ Validasi Height Imperial (4 tests)
|
||||
- ✅ Healthy Weight Range (2 tests)
|
||||
- ✅ Validation Messages (2 tests)
|
||||
- ✅ Edge Cases (3 tests)
|
||||
|
||||
### BmiCategoryTest (30+ tests):
|
||||
- ✅ fromBmi() untuk setiap kategori (16 tests)
|
||||
- ✅ Display Names (4 tests)
|
||||
- ✅ Colors (5 tests)
|
||||
- ✅ Enum Values (1 test)
|
||||
- ✅ Extreme Values (2 tests)
|
||||
- ✅ Real-World Scenarios (4 tests)
|
||||
|
||||
### BmiDataTest (10 tests):
|
||||
- ✅ Data Creation (4 tests)
|
||||
- ✅ Equality (3 tests)
|
||||
- ✅ Copy Function (2 tests)
|
||||
|
||||
### UnitSystemTest (10 tests):
|
||||
- ✅ Enum Values (4 tests)
|
||||
- ✅ Display Names (2 tests)
|
||||
- ✅ Enum Behavior (4 tests)
|
||||
|
||||
---
|
||||
|
||||
## 🔍 Tips & Best Practices
|
||||
|
||||
### 1. Jalankan Test Secara Regular
|
||||
```cmd
|
||||
# Sebelum commit code:
|
||||
gradlew.bat test
|
||||
|
||||
# Setelah mengubah logic perhitungan:
|
||||
gradlew.bat test --tests "com.example.tiptime.utils.BmiCalculatorTest"
|
||||
```
|
||||
|
||||
### 2. Watch Mode (Auto-run saat file berubah)
|
||||
```cmd
|
||||
gradlew.bat test --continuous
|
||||
```
|
||||
|
||||
### 3. Parallel Execution (Lebih cepat)
|
||||
```cmd
|
||||
gradlew.bat test --parallel
|
||||
```
|
||||
|
||||
### 4. Clean sebelum test (jika hasil aneh)
|
||||
```cmd
|
||||
gradlew.bat clean test
|
||||
```
|
||||
|
||||
### 5. Debug Test yang Fail
|
||||
Di Android Studio:
|
||||
- Klik kanan pada test yang fail
|
||||
- Pilih **"Debug 'testName()'"**
|
||||
- Set breakpoint untuk inspect values
|
||||
|
||||
---
|
||||
|
||||
## ✅ Expected Results
|
||||
|
||||
Jika semua test berhasil, Anda akan melihat:
|
||||
|
||||
```
|
||||
BUILD SUCCESSFUL in 20s
|
||||
43 actionable tasks: 43 executed
|
||||
```
|
||||
|
||||
Dan di HTML report:
|
||||
```
|
||||
Tests: 93 passed, 0 failed, 0 skipped
|
||||
Success rate: 100%
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🐛 Troubleshooting
|
||||
|
||||
### Problem: "Test not found"
|
||||
**Solution:** Pastikan package name sesuai:
|
||||
```cmd
|
||||
gradlew.bat test --tests "com.example.tiptime.*"
|
||||
```
|
||||
|
||||
### Problem: "Task 'test' not found"
|
||||
**Solution:** Pastikan Anda di root project:
|
||||
```cmd
|
||||
cd e:\androidProject\basic-android-kotlin-compose-training-tip-calculator
|
||||
```
|
||||
|
||||
### Problem: Test gagal dengan assertion error
|
||||
**Solution:** Periksa:
|
||||
1. Logic di `BmiCalculator.kt` sesuai dengan expected values
|
||||
2. Boundary values (18.5, 25.0, 30.0) benar
|
||||
3. Formula perhitungan BMI correct
|
||||
|
||||
### Problem: Gradle build error
|
||||
**Solution:**
|
||||
```cmd
|
||||
gradlew.bat clean
|
||||
gradlew.bat test
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📈 Continuous Integration (CI)
|
||||
|
||||
Untuk auto-run tests di CI/CD:
|
||||
|
||||
### GitHub Actions (`.github/workflows/test.yml`):
|
||||
```yaml
|
||||
name: Run Tests
|
||||
on: [push, pull_request]
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set up JDK
|
||||
uses: actions/setup-java@v2
|
||||
with:
|
||||
java-version: '17'
|
||||
- name: Run tests
|
||||
run: ./gradlew test
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📚 References
|
||||
|
||||
- JUnit 4 Documentation: https://junit.org/junit4/
|
||||
- Android Testing Guide: https://developer.android.com/training/testing
|
||||
- Gradle Test Task: https://docs.gradle.org/current/userguide/java_testing.html
|
||||
|
||||
---
|
||||
|
||||
## 🎓 Next Steps
|
||||
|
||||
1. ✅ Jalankan semua test untuk memastikan pass
|
||||
2. ✅ Review HTML report untuk melihat coverage
|
||||
3. ✅ Tambahkan test baru jika ada logic baru
|
||||
4. ✅ Integrate test ke CI/CD pipeline
|
||||
5. ✅ Maintain test coverage > 80%
|
||||
|
||||
---
|
||||
|
||||
**Total Test Cases: 93+**
|
||||
**Expected Coverage: ~90%+ of business logic**
|
||||
**Execution Time: ~15-30 seconds**
|
||||
|
||||
Good luck testing! 🚀
|
||||
|
||||
1
app/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/build
|
||||
86
app/build.gradle.kts
Normal file
@ -0,0 +1,86 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
plugins {
|
||||
id("com.android.application")
|
||||
id("org.jetbrains.kotlin.android")
|
||||
id("org.jetbrains.kotlin.plugin.compose")
|
||||
}
|
||||
|
||||
android {
|
||||
compileSdk = 36
|
||||
|
||||
defaultConfig {
|
||||
applicationId = "com.example.tiptime"
|
||||
minSdk = 24
|
||||
targetSdk = 36
|
||||
versionCode = 1
|
||||
versionName = "1.0"
|
||||
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
vectorDrawables {
|
||||
useSupportLibrary = true
|
||||
}
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
isMinifyEnabled = false
|
||||
proguardFiles(
|
||||
getDefaultProguardFile("proguard-android-optimize.txt"),
|
||||
"proguard-rules.pro"
|
||||
)
|
||||
}
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
||||
kotlinOptions {
|
||||
jvmTarget = JavaVersion.VERSION_17.toString()
|
||||
}
|
||||
buildFeatures {
|
||||
compose = true
|
||||
}
|
||||
packaging {
|
||||
resources {
|
||||
excludes += "/META-INF/{AL2.0,LGPL2.1}"
|
||||
}
|
||||
}
|
||||
namespace = "com.example.tiptime"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
implementation(platform("androidx.compose:compose-bom:2025.11.00"))
|
||||
implementation("androidx.activity:activity-compose:1.11.0")
|
||||
implementation("androidx.compose.material3:material3")
|
||||
implementation("androidx.compose.ui:ui")
|
||||
implementation("androidx.compose.ui:ui-tooling")
|
||||
implementation("androidx.compose.ui:ui-tooling-preview")
|
||||
implementation("androidx.compose.material:material-icons-extended")
|
||||
implementation("androidx.core:core-ktx:1.17.0")
|
||||
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.9.4")
|
||||
|
||||
testImplementation("junit:junit:4.13.2")
|
||||
|
||||
androidTestImplementation(platform("androidx.compose:compose-bom:2025.11.00"))
|
||||
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
|
||||
androidTestImplementation("androidx.test.espresso:espresso-core:3.7.0")
|
||||
androidTestImplementation("androidx.test.ext:junit:1.3.0")
|
||||
|
||||
debugImplementation("androidx.compose.ui:ui-test-manifest")
|
||||
}
|
||||
21
app/proguard-rules.pro
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
||||
47
app/src/main/AndroidManifest.xml
Normal file
@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.TipTime"
|
||||
tools:targetApi="33">
|
||||
<!-- WelcomeActivity is now the launcher -->
|
||||
<activity
|
||||
android:name="com.example.tiptime.WelcomeActivity"
|
||||
android:exported="true"
|
||||
android:theme="@style/Theme.TipTime">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<!-- MainActivity remains as the app's main screen, launched from Welcome -->
|
||||
<activity
|
||||
android:name="com.example.tiptime.MainActivity"
|
||||
android:exported="true"
|
||||
android:theme="@style/Theme.TipTime" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
42
app/src/main/java/com/example/tiptime/MainActivity.kt
Normal file
@ -0,0 +1,42 @@
|
||||
package com.example.tiptime
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import com.example.tiptime.ui.BmiCalculatorScreen
|
||||
import com.example.tiptime.ui.theme.TipTimeTheme
|
||||
|
||||
/**
|
||||
* NPM: [ISI NPM ANDA]
|
||||
* Nama: [ISI NAMA ANDA]
|
||||
*
|
||||
* Activity utama untuk aplikasi BMI Calculator
|
||||
* Menggunakan Jetpack Compose untuk UI
|
||||
*/
|
||||
class MainActivity : ComponentActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
enableEdgeToEdge()
|
||||
setContent {
|
||||
AppRoot()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun AppRoot() {
|
||||
TipTimeTheme {
|
||||
Surface(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
color = MaterialTheme.colorScheme.background
|
||||
) {
|
||||
BmiCalculatorScreen()
|
||||
}
|
||||
}
|
||||
}
|
||||
116
app/src/main/java/com/example/tiptime/WelcomeActivity.kt
Normal file
@ -0,0 +1,116 @@
|
||||
package com.example.tiptime
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.ButtonDefaults
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.example.tiptime.ui.theme.TipTimeTheme
|
||||
|
||||
class WelcomeActivity : ComponentActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContent {
|
||||
TipTimeTheme {
|
||||
Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.primary) {
|
||||
WelcomeScreen(onContinue = {
|
||||
val intent = Intent(this, MainActivity::class.java)
|
||||
startActivity(intent)
|
||||
finish()
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun WelcomeScreen(onContinue: () -> Unit) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(horizontal = 32.dp, vertical = 48.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.Center
|
||||
) {
|
||||
// BMI Image
|
||||
Image(
|
||||
painter = painterResource(id = R.drawable.image_bmi),
|
||||
contentDescription = "BMI Calculator Illustration",
|
||||
modifier = Modifier
|
||||
.size(240.dp)
|
||||
.padding(bottom = 32.dp),
|
||||
contentScale = ContentScale.Fit
|
||||
)
|
||||
|
||||
// Title
|
||||
Text(
|
||||
text = stringResource(R.string.welcome_title),
|
||||
color = MaterialTheme.colorScheme.onPrimary,
|
||||
fontSize = 32.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
textAlign = TextAlign.Center,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(bottom = 16.dp)
|
||||
)
|
||||
|
||||
// Subtitle
|
||||
Text(
|
||||
text = stringResource(R.string.welcome_subtitle),
|
||||
color = MaterialTheme.colorScheme.onPrimary.copy(alpha = 0.9f),
|
||||
fontSize = 16.sp,
|
||||
textAlign = TextAlign.Center,
|
||||
lineHeight = 24.sp,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp, vertical = 8.dp)
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(48.dp))
|
||||
|
||||
// CTA Button
|
||||
Button(
|
||||
onClick = onContinue,
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
containerColor = MaterialTheme.colorScheme.onPrimary,
|
||||
contentColor = MaterialTheme.colorScheme.primary
|
||||
),
|
||||
shape = RoundedCornerShape(16.dp),
|
||||
elevation = ButtonDefaults.buttonElevation(defaultElevation = 4.dp),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(56.dp)
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(R.string.welcome_cta),
|
||||
fontSize = 18.sp,
|
||||
fontWeight = FontWeight.SemiBold
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
58
app/src/main/java/com/example/tiptime/model/BmiData.kt
Normal file
@ -0,0 +1,58 @@
|
||||
package com.example.tiptime.model
|
||||
|
||||
/**
|
||||
* NPM: [ISI NPM ANDA]
|
||||
* Nama: [ISI NAMA ANDA]
|
||||
*
|
||||
* Data class untuk menyimpan hasil perhitungan BMI
|
||||
*/
|
||||
data class BmiData(
|
||||
val bmi: Double,
|
||||
val category: BmiCategory,
|
||||
val healthyWeightRange: String
|
||||
)
|
||||
|
||||
/**
|
||||
* Enum class untuk kategori BMI
|
||||
*/
|
||||
enum class BmiCategory(val displayName: String, val color: androidx.compose.ui.graphics.Color) {
|
||||
UNDERWEIGHT(
|
||||
"Underweight",
|
||||
androidx.compose.ui.graphics.Color(0xFF3B82F6)
|
||||
),
|
||||
NORMAL(
|
||||
"Normal Weight",
|
||||
androidx.compose.ui.graphics.Color(0xFF10B981)
|
||||
),
|
||||
OVERWEIGHT(
|
||||
"Overweight",
|
||||
androidx.compose.ui.graphics.Color(0xFFF59E0B)
|
||||
),
|
||||
OBESE(
|
||||
"Obese",
|
||||
androidx.compose.ui.graphics.Color(0xFFEF4444)
|
||||
);
|
||||
|
||||
companion object {
|
||||
/**
|
||||
* Menentukan kategori BMI berdasarkan nilai BMI
|
||||
* Referensi: WHO BMI Classification
|
||||
*/
|
||||
fun fromBmi(bmi: Double): BmiCategory {
|
||||
return when {
|
||||
bmi < 18.5 -> UNDERWEIGHT
|
||||
bmi < 25.0 -> NORMAL
|
||||
bmi < 30.0 -> OVERWEIGHT
|
||||
else -> OBESE
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enum class untuk sistem pengukuran
|
||||
*/
|
||||
enum class UnitSystem(val displayName: String) {
|
||||
METRIC("Metric (kg, cm)"),
|
||||
IMPERIAL("Imperial (lb, in)")
|
||||
}
|
||||
480
app/src/main/java/com/example/tiptime/ui/BmiCalculatorScreen.kt
Normal file
@ -0,0 +1,480 @@
|
||||
package com.example.tiptime.ui
|
||||
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.core.Spring
|
||||
import androidx.compose.animation.core.spring
|
||||
import androidx.compose.animation.expandVertically
|
||||
import androidx.compose.animation.fadeIn
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Calculate
|
||||
import androidx.compose.material.icons.filled.FitnessCenter
|
||||
import androidx.compose.material.icons.filled.Height
|
||||
import androidx.compose.material.icons.filled.MonitorWeight
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Brush
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.input.KeyboardType
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.example.tiptime.model.BmiData
|
||||
import com.example.tiptime.model.UnitSystem
|
||||
import com.example.tiptime.ui.theme.*
|
||||
import com.example.tiptime.utils.BmiCalculator
|
||||
import java.util.Locale
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun BmiCalculatorScreen() {
|
||||
var weight by remember { mutableStateOf("") }
|
||||
var height by remember { mutableStateOf("") }
|
||||
var selectedSystem by remember { mutableStateOf(UnitSystem.METRIC) }
|
||||
var bmiResult by remember { mutableStateOf<BmiData?>(null) }
|
||||
var showError by remember { mutableStateOf(false) }
|
||||
var errorMessage by remember { mutableStateOf("") }
|
||||
|
||||
Scaffold(
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
title = {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.Center,
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
Spacer(modifier = Modifier.width(8.dp))
|
||||
Text(
|
||||
"BMI Calculator",
|
||||
fontSize = 22.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = Color.White
|
||||
)
|
||||
}
|
||||
},
|
||||
colors = TopAppBarDefaults.topAppBarColors(
|
||||
containerColor = PrimaryBlue
|
||||
)
|
||||
)
|
||||
}
|
||||
) { paddingValues ->
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(paddingValues)
|
||||
.background(BackgroundLight)
|
||||
.verticalScroll(rememberScrollState())
|
||||
.padding(20.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
// Unit System Selector
|
||||
UnitSystemSelector(
|
||||
selectedSystem = selectedSystem,
|
||||
onSystemChange = {
|
||||
selectedSystem = it
|
||||
weight = ""
|
||||
height = ""
|
||||
bmiResult = null
|
||||
showError = false
|
||||
}
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(24.dp))
|
||||
|
||||
// Input Card
|
||||
InputCard(
|
||||
weight = weight,
|
||||
height = height,
|
||||
selectedSystem = selectedSystem,
|
||||
onWeightChange = {
|
||||
weight = it
|
||||
showError = false
|
||||
},
|
||||
onHeightChange = {
|
||||
height = it
|
||||
showError = false
|
||||
}
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(24.dp))
|
||||
|
||||
// Calculate Button
|
||||
CalculateButton(
|
||||
onClick = {
|
||||
if (BmiCalculator.isValidWeight(weight, selectedSystem) &&
|
||||
BmiCalculator.isValidHeight(height, selectedSystem)) {
|
||||
val result = BmiCalculator.calculateBmi(
|
||||
weight.toDouble(),
|
||||
height.toDouble(),
|
||||
selectedSystem
|
||||
)
|
||||
bmiResult = result
|
||||
showError = false
|
||||
} else {
|
||||
showError = true
|
||||
val messages = BmiCalculator.getValidationMessage(selectedSystem)
|
||||
errorMessage = when {
|
||||
!BmiCalculator.isValidWeight(weight, selectedSystem) -> messages.first
|
||||
!BmiCalculator.isValidHeight(height, selectedSystem) -> messages.second
|
||||
else -> "Please enter valid values"
|
||||
}
|
||||
bmiResult = null
|
||||
}
|
||||
},
|
||||
enabled = weight.isNotBlank() && height.isNotBlank()
|
||||
)
|
||||
|
||||
// Error Message
|
||||
if (showError) {
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
ErrorMessage(errorMessage)
|
||||
}
|
||||
|
||||
// Result Card
|
||||
AnimatedVisibility(
|
||||
visible = bmiResult != null,
|
||||
enter = fadeIn() + expandVertically(
|
||||
animationSpec = spring(
|
||||
dampingRatio = Spring.DampingRatioMediumBouncy,
|
||||
stiffness = Spring.StiffnessLow
|
||||
)
|
||||
)
|
||||
) {
|
||||
bmiResult?.let { result ->
|
||||
Column {
|
||||
Spacer(modifier = Modifier.height(24.dp))
|
||||
ResultCard(result)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(32.dp))
|
||||
|
||||
// Info Card
|
||||
BmiInfoCard()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun UnitSystemSelector(
|
||||
selectedSystem: UnitSystem,
|
||||
onSystemChange: (UnitSystem) -> Unit
|
||||
) {
|
||||
Card(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
colors = CardDefaults.cardColors(containerColor = Color.White),
|
||||
elevation = CardDefaults.cardElevation(defaultElevation = 2.dp),
|
||||
shape = RoundedCornerShape(16.dp)
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier.padding(16.dp)
|
||||
) {
|
||||
Text(
|
||||
"Unit System",
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
fontWeight = FontWeight.SemiBold,
|
||||
color = TextPrimary
|
||||
)
|
||||
Spacer(modifier = Modifier.height(12.dp))
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.spacedBy(12.dp)
|
||||
) {
|
||||
UnitSystem.entries.forEach { system ->
|
||||
FilterChip(
|
||||
selected = selectedSystem == system,
|
||||
onClick = { onSystemChange(system) },
|
||||
label = { Text(system.displayName) },
|
||||
modifier = Modifier.weight(1f),
|
||||
colors = FilterChipDefaults.filterChipColors(
|
||||
selectedContainerColor = PrimaryBlue,
|
||||
selectedLabelColor = Color.White
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun InputCard(
|
||||
weight: String,
|
||||
height: String,
|
||||
selectedSystem: UnitSystem,
|
||||
onWeightChange: (String) -> Unit,
|
||||
onHeightChange: (String) -> Unit
|
||||
) {
|
||||
Card(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
colors = CardDefaults.cardColors(containerColor = Color.White),
|
||||
elevation = CardDefaults.cardElevation(defaultElevation = 2.dp),
|
||||
shape = RoundedCornerShape(16.dp)
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier.padding(20.dp)
|
||||
) {
|
||||
val weightLabel = if (selectedSystem == UnitSystem.METRIC) "Weight (kg)" else "Weight (lb)"
|
||||
val heightLabel = if (selectedSystem == UnitSystem.METRIC) "Height (cm)" else "Height (in)"
|
||||
|
||||
// Weight Input
|
||||
OutlinedTextField(
|
||||
value = weight,
|
||||
onValueChange = onWeightChange,
|
||||
label = { Text(weightLabel) },
|
||||
leadingIcon = {
|
||||
Icon(
|
||||
imageVector = Icons.Default.MonitorWeight,
|
||||
contentDescription = "Weight",
|
||||
tint = PrimaryBlue
|
||||
)
|
||||
},
|
||||
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Decimal),
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
singleLine = true,
|
||||
colors = OutlinedTextFieldDefaults.colors(
|
||||
focusedBorderColor = PrimaryBlue,
|
||||
focusedLabelColor = PrimaryBlue
|
||||
)
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
// Height Input
|
||||
OutlinedTextField(
|
||||
value = height,
|
||||
onValueChange = onHeightChange,
|
||||
label = { Text(heightLabel) },
|
||||
leadingIcon = {
|
||||
Icon(
|
||||
imageVector = Icons.Default.Height,
|
||||
contentDescription = "Height",
|
||||
tint = PrimaryBlue
|
||||
)
|
||||
},
|
||||
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Decimal),
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
singleLine = true,
|
||||
colors = OutlinedTextFieldDefaults.colors(
|
||||
focusedBorderColor = PrimaryBlue,
|
||||
focusedLabelColor = PrimaryBlue
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun CalculateButton(
|
||||
onClick: () -> Unit,
|
||||
enabled: Boolean
|
||||
) {
|
||||
Button(
|
||||
onClick = onClick,
|
||||
enabled = enabled,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(56.dp),
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
containerColor = PrimaryBlue,
|
||||
disabledContainerColor = PrimaryBlue.copy(alpha = 0.5f)
|
||||
),
|
||||
shape = RoundedCornerShape(12.dp),
|
||||
elevation = ButtonDefaults.buttonElevation(defaultElevation = 4.dp)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.Calculate,
|
||||
contentDescription = null,
|
||||
modifier = Modifier.size(20.dp)
|
||||
)
|
||||
Spacer(modifier = Modifier.width(8.dp))
|
||||
Text(
|
||||
"Calculate BMI",
|
||||
fontSize = 18.sp,
|
||||
fontWeight = FontWeight.SemiBold
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun ErrorMessage(message: String) {
|
||||
Card(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
colors = CardDefaults.cardColors(
|
||||
containerColor = Color(0xFFFEE2E2)
|
||||
),
|
||||
shape = RoundedCornerShape(12.dp)
|
||||
) {
|
||||
Text(
|
||||
text = message,
|
||||
modifier = Modifier.padding(16.dp),
|
||||
color = Color(0xFFDC2626),
|
||||
style = MaterialTheme.typography.bodyMedium
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun ResultCard(result: BmiData) {
|
||||
Card(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
colors = CardDefaults.cardColors(containerColor = Color.White),
|
||||
elevation = CardDefaults.cardElevation(defaultElevation = 4.dp),
|
||||
shape = RoundedCornerShape(16.dp)
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier.padding(24.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Text(
|
||||
"Your BMI Result",
|
||||
style = MaterialTheme.typography.titleLarge,
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = TextPrimary
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(24.dp))
|
||||
|
||||
// BMI Value with gradient background
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(140.dp)
|
||||
.clip(RoundedCornerShape(70.dp))
|
||||
.background(
|
||||
Brush.radialGradient(
|
||||
colors = listOf(
|
||||
result.category.color.copy(alpha = 0.3f),
|
||||
result.category.color.copy(alpha = 0.1f)
|
||||
)
|
||||
)
|
||||
),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Column(horizontalAlignment = Alignment.CenterHorizontally) {
|
||||
Text(
|
||||
text = String.format(Locale.US, "%.1f", result.bmi),
|
||||
fontSize = 42.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = result.category.color
|
||||
)
|
||||
Text(
|
||||
text = "BMI",
|
||||
fontSize = 14.sp,
|
||||
color = TextSecondary
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(24.dp))
|
||||
|
||||
// Category Badge
|
||||
Surface(
|
||||
color = result.category.color,
|
||||
shape = RoundedCornerShape(20.dp),
|
||||
modifier = Modifier.padding(horizontal = 16.dp)
|
||||
) {
|
||||
Text(
|
||||
text = result.category.displayName,
|
||||
modifier = Modifier.padding(horizontal = 24.dp, vertical = 12.dp),
|
||||
fontSize = 18.sp,
|
||||
fontWeight = FontWeight.SemiBold,
|
||||
color = Color.White
|
||||
)
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(20.dp))
|
||||
|
||||
HorizontalDivider()
|
||||
|
||||
Spacer(modifier = Modifier.height(20.dp))
|
||||
|
||||
// Healthy Weight Range
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Text(
|
||||
"Healthy Weight:",
|
||||
style = MaterialTheme.typography.bodyLarge,
|
||||
color = TextSecondary
|
||||
)
|
||||
Text(
|
||||
result.healthyWeightRange,
|
||||
style = MaterialTheme.typography.bodyLarge,
|
||||
fontWeight = FontWeight.SemiBold,
|
||||
color = TextPrimary
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun BmiInfoCard() {
|
||||
Card(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
colors = CardDefaults.cardColors(
|
||||
containerColor = PrimaryBlue.copy(alpha = 0.05f)
|
||||
),
|
||||
shape = RoundedCornerShape(16.dp)
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier.padding(16.dp)
|
||||
) {
|
||||
Text(
|
||||
"BMI Categories",
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
fontWeight = FontWeight.SemiBold,
|
||||
color = TextPrimary
|
||||
)
|
||||
Spacer(modifier = Modifier.height(12.dp))
|
||||
BmiCategoryRow("Underweight", "< 18.5", UnderweightColor)
|
||||
BmiCategoryRow("Normal", "18.5 - 24.9", NormalColor)
|
||||
BmiCategoryRow("Overweight", "25.0 - 29.9", ObeseColor)
|
||||
BmiCategoryRow("Obese", "≥ 30.0", ObeseColor)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun BmiCategoryRow(category: String, range: String, color: Color) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(vertical = 6.dp),
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(12.dp)
|
||||
.clip(RoundedCornerShape(6.dp))
|
||||
.background(color)
|
||||
)
|
||||
Spacer(modifier = Modifier.width(12.dp))
|
||||
Text(
|
||||
category,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = TextPrimary
|
||||
)
|
||||
}
|
||||
Text(
|
||||
range,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
fontWeight = FontWeight.Medium,
|
||||
color = TextSecondary
|
||||
)
|
||||
}
|
||||
}
|
||||
33
app/src/main/java/com/example/tiptime/ui/theme/Color.kt
Normal file
@ -0,0 +1,33 @@
|
||||
package com.example.tiptime.ui.theme
|
||||
|
||||
import androidx.compose.ui.graphics.Color
|
||||
|
||||
/**
|
||||
* NPM: [ISI NPM ANDA]
|
||||
* Nama: [ISI NAMA ANDA]
|
||||
*
|
||||
* Definisi warna untuk aplikasi BMI Calculator
|
||||
*/
|
||||
|
||||
// Primary Colors
|
||||
val Purple80 = Color(0xFFD0BCFF)
|
||||
val PurpleGrey80 = Color(0xFFCCC2DC)
|
||||
val Pink80 = Color(0xFFEFB8C8)
|
||||
|
||||
val Purple40 = Color(0xFF6650a4)
|
||||
val PurpleGrey40 = Color(0xFF625b71)
|
||||
val Pink40 = Color(0xFF7D5260)
|
||||
|
||||
// Custom BMI Colors
|
||||
val PrimaryBlue = Color(0xFF2563EB)
|
||||
val PrimaryBlueDark = Color(0xFF1E40AF)
|
||||
val BackgroundLight = Color(0xFFF8FAFC)
|
||||
val CardBackground = Color(0xFFFFFFFF)
|
||||
val TextPrimary = Color(0xFF1E293B)
|
||||
val TextSecondary = Color(0xFF64748B)
|
||||
|
||||
// BMI Category Colors
|
||||
val UnderweightColor = Color(0xFF3B82F6)
|
||||
val NormalColor = Color(0xFF10B981)
|
||||
val OverweightColor = Color(0xFFF59E0B)
|
||||
val ObeseColor = Color(0xFFEF4444)
|
||||
124
app/src/main/java/com/example/tiptime/ui/theme/Theme.kt
Normal file
@ -0,0 +1,124 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
package com.example.tiptime.ui.theme
|
||||
|
||||
import android.os.Build
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.darkColorScheme
|
||||
import androidx.compose.material3.dynamicDarkColorScheme
|
||||
import androidx.compose.material3.dynamicLightColorScheme
|
||||
import androidx.compose.material3.lightColorScheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
|
||||
private val LightColorScheme = lightColorScheme(
|
||||
primary = PrimaryBlue,
|
||||
onPrimary = Color.White,
|
||||
primaryContainer = PrimaryBlueDark,
|
||||
onPrimaryContainer = Color.White,
|
||||
|
||||
secondary = PrimaryBlueDark,
|
||||
onSecondary = Color.White,
|
||||
secondaryContainer = CardBackground,
|
||||
onSecondaryContainer = TextPrimary,
|
||||
|
||||
tertiary = PrimaryBlue,
|
||||
onTertiary = Color.White,
|
||||
tertiaryContainer = CardBackground,
|
||||
onTertiaryContainer = TextPrimary,
|
||||
|
||||
error = Color(0xFFB00020),
|
||||
errorContainer = Color(0xFFB00020),
|
||||
onError = Color.White,
|
||||
onErrorContainer = Color.White,
|
||||
|
||||
background = BackgroundLight,
|
||||
onBackground = TextPrimary,
|
||||
surface = CardBackground,
|
||||
onSurface = TextPrimary,
|
||||
surfaceVariant = BackgroundLight,
|
||||
onSurfaceVariant = TextSecondary,
|
||||
outline = TextSecondary,
|
||||
inverseOnSurface = Color.White,
|
||||
inverseSurface = PrimaryBlueDark,
|
||||
inversePrimary = PrimaryBlueDark,
|
||||
surfaceTint = PrimaryBlue,
|
||||
outlineVariant = TextSecondary,
|
||||
scrim = Color.Black.copy(alpha = 0.5f),
|
||||
)
|
||||
|
||||
private val DarkColorScheme = darkColorScheme(
|
||||
primary = PrimaryBlueDark,
|
||||
onPrimary = Color.White,
|
||||
primaryContainer = PrimaryBlue,
|
||||
onPrimaryContainer = Color.White,
|
||||
|
||||
secondary = PrimaryBlue,
|
||||
onSecondary = Color.White,
|
||||
secondaryContainer = CardBackground,
|
||||
onSecondaryContainer = TextPrimary,
|
||||
|
||||
tertiary = PrimaryBlueDark,
|
||||
onTertiary = Color.White,
|
||||
tertiaryContainer = CardBackground,
|
||||
onTertiaryContainer = TextPrimary,
|
||||
|
||||
error = Color(0xFFCF6679),
|
||||
errorContainer = Color(0xFFCF6679),
|
||||
onError = Color.Black,
|
||||
onErrorContainer = Color.Black,
|
||||
|
||||
background = Color(0xFF0B1220),
|
||||
onBackground = Color.White,
|
||||
surface = Color(0xFF071022),
|
||||
onSurface = Color.White,
|
||||
surfaceVariant = Color(0xFF172033),
|
||||
onSurfaceVariant = TextSecondary,
|
||||
outline = TextSecondary,
|
||||
inverseOnSurface = TextPrimary,
|
||||
inverseSurface = PrimaryBlue,
|
||||
inversePrimary = PrimaryBlue,
|
||||
surfaceTint = PrimaryBlueDark,
|
||||
outlineVariant = TextSecondary,
|
||||
scrim = Color.Black.copy(alpha = 0.7f),
|
||||
)
|
||||
|
||||
@Composable
|
||||
fun TipTimeTheme(
|
||||
darkTheme: Boolean = isSystemInDarkTheme(),
|
||||
// Dynamic color is available on Android 12+
|
||||
// Dynamic color in this app is turned off for learning purposes
|
||||
dynamicColor: Boolean = false,
|
||||
content: @Composable () -> Unit
|
||||
) {
|
||||
val colorScheme = when {
|
||||
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
|
||||
val context = LocalContext.current
|
||||
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
|
||||
}
|
||||
|
||||
darkTheme -> DarkColorScheme
|
||||
else -> LightColorScheme
|
||||
}
|
||||
|
||||
MaterialTheme(
|
||||
colorScheme = colorScheme,
|
||||
typography = Typography,
|
||||
content = content
|
||||
)
|
||||
}
|
||||
33
app/src/main/java/com/example/tiptime/ui/theme/Type.kt
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
package com.example.tiptime.ui.theme
|
||||
|
||||
import androidx.compose.material3.Typography
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.font.FontFamily
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.sp
|
||||
|
||||
// Set of Material typography styles to start with
|
||||
val Typography = Typography(
|
||||
displaySmall = TextStyle(
|
||||
fontFamily = FontFamily.Default,
|
||||
fontWeight = FontWeight.Bold,
|
||||
fontSize = 36.sp,
|
||||
lineHeight = 44.sp,
|
||||
letterSpacing = 0.sp,
|
||||
)
|
||||
)
|
||||
112
app/src/main/java/com/example/tiptime/utils/BmiCalculator.kt
Normal file
@ -0,0 +1,112 @@
|
||||
package com.example.tiptime.utils
|
||||
|
||||
import com.example.tiptime.model.BmiCategory
|
||||
import com.example.tiptime.model.BmiData
|
||||
import com.example.tiptime.model.UnitSystem
|
||||
import kotlin.math.pow
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
/**
|
||||
* NPM: [ISI NPM ANDA]
|
||||
* Nama: [ISI NAMA ANDA]
|
||||
*
|
||||
* Utility class untuk perhitungan BMI
|
||||
*/
|
||||
object BmiCalculator {
|
||||
|
||||
/**
|
||||
* Menghitung BMI berdasarkan berat, tinggi, dan sistem unit
|
||||
*
|
||||
* @param weight Berat badan (kg untuk Metric, lb untuk Imperial)
|
||||
* @param height Tinggi badan (cm untuk Metric, in untuk Imperial)
|
||||
* @param system Sistem pengukuran yang digunakan
|
||||
* @return BmiData yang berisi BMI, kategori, dan rentang berat ideal
|
||||
*/
|
||||
fun calculateBmi(weight: Double, height: Double, system: UnitSystem): BmiData {
|
||||
val bmi = when (system) {
|
||||
UnitSystem.METRIC -> {
|
||||
// Formula: BMI = weight (kg) / (height (m))^2
|
||||
val heightInMeters = height / 100.0
|
||||
weight / heightInMeters.pow(2)
|
||||
}
|
||||
UnitSystem.IMPERIAL -> {
|
||||
// Formula: BMI = (weight (lb) / (height (in))^2) * 703
|
||||
(weight / height.pow(2)) * 703
|
||||
}
|
||||
}
|
||||
|
||||
val category = BmiCategory.fromBmi(bmi)
|
||||
val healthyRange = calculateHealthyWeightRange(height, system)
|
||||
|
||||
return BmiData(bmi, category, healthyRange)
|
||||
}
|
||||
|
||||
/**
|
||||
* Menghitung rentang berat badan ideal (BMI 18.5 - 24.9)
|
||||
*
|
||||
* @param height Tinggi badan
|
||||
* @param system Sistem pengukuran
|
||||
* @return String rentang berat ideal
|
||||
*/
|
||||
private fun calculateHealthyWeightRange(height: Double, system: UnitSystem): String {
|
||||
return when (system) {
|
||||
UnitSystem.METRIC -> {
|
||||
val heightInMeters = height / 100.0
|
||||
val minWeight = (18.5 * heightInMeters.pow(2)).roundToInt()
|
||||
val maxWeight = (24.9 * heightInMeters.pow(2)).roundToInt()
|
||||
"$minWeight - $maxWeight kg"
|
||||
}
|
||||
UnitSystem.IMPERIAL -> {
|
||||
val minWeight = ((18.5 * height.pow(2)) / 703).roundToInt()
|
||||
val maxWeight = ((24.9 * height.pow(2)) / 703).roundToInt()
|
||||
"$minWeight - $maxWeight lb"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validasi input berat badan
|
||||
*
|
||||
* @param weight Berat badan
|
||||
* @param system Sistem pengukuran
|
||||
* @return true jika valid, false jika tidak
|
||||
*/
|
||||
fun isValidWeight(weight: String, system: UnitSystem): Boolean {
|
||||
val weightValue = weight.toDoubleOrNull() ?: return false
|
||||
return when (system) {
|
||||
UnitSystem.METRIC -> weightValue in 1.0..500.0 // kg
|
||||
UnitSystem.IMPERIAL -> weightValue in 2.0..1100.0 // lb
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validasi input tinggi badan
|
||||
*
|
||||
* @param height Tinggi badan
|
||||
* @param system Sistem pengukuran
|
||||
* @return true jika valid, false jika tidak
|
||||
*/
|
||||
fun isValidHeight(height: String, system: UnitSystem): Boolean {
|
||||
val heightValue = height.toDoubleOrNull() ?: return false
|
||||
return when (system) {
|
||||
UnitSystem.METRIC -> heightValue in 50.0..300.0 // cm
|
||||
UnitSystem.IMPERIAL -> heightValue in 20.0..120.0 // inch
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mendapatkan pesan error untuk input tidak valid
|
||||
*/
|
||||
fun getValidationMessage(system: UnitSystem): Pair<String, String> {
|
||||
return when (system) {
|
||||
UnitSystem.METRIC -> Pair(
|
||||
"Weight must be between 1-500 kg",
|
||||
"Height must be between 50-300 cm"
|
||||
)
|
||||
UnitSystem.IMPERIAL -> Pair(
|
||||
"Weight must be between 2-1100 lb",
|
||||
"Height must be between 20-120 in"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
185
app/src/main/res/drawable/ic_launcher_background.xml
Normal file
@ -0,0 +1,185 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ 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 xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportWidth="108"
|
||||
android:viewportHeight="108">
|
||||
<path
|
||||
android:fillColor="#3DDC84"
|
||||
android:pathData="M0,0h108v108h-108z" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M9,0L9,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,0L19,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M29,0L29,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M39,0L39,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M49,0L49,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M59,0L59,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M69,0L69,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M79,0L79,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M89,0L89,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M99,0L99,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,9L108,9"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,19L108,19"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,29L108,29"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,39L108,39"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,49L108,49"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,59L108,59"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,69L108,69"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,79L108,79"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,89L108,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,99L108,99"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,29L89,29"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,39L89,39"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,49L89,49"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,59L89,59"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,69L89,69"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,79L89,79"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M29,19L29,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M39,19L39,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M49,19L49,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M59,19L59,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M69,19L69,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M79,19L79,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
</vector>
|
||||
46
app/src/main/res/drawable/ic_launcher_foreground.xml
Normal file
@ -0,0 +1,46 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ 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 xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:aapt="http://schemas.android.com/aapt"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportWidth="108"
|
||||
android:viewportHeight="108">
|
||||
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
|
||||
<aapt:attr name="android:fillColor">
|
||||
<gradient
|
||||
android:endX="85.84757"
|
||||
android:endY="92.4963"
|
||||
android:startX="42.9492"
|
||||
android:startY="49.59793"
|
||||
android:type="linear">
|
||||
<item
|
||||
android:color="#44000000"
|
||||
android:offset="0.0" />
|
||||
<item
|
||||
android:color="#00000000"
|
||||
android:offset="1.0" />
|
||||
</gradient>
|
||||
</aapt:attr>
|
||||
</path>
|
||||
<path
|
||||
android:fillColor="#FFFFFF"
|
||||
android:fillType="nonZero"
|
||||
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
|
||||
android:strokeWidth="1"
|
||||
android:strokeColor="#00000000" />
|
||||
</vector>
|
||||
BIN
app/src/main/res/drawable/image_bmi.png
Normal file
|
After Width: | Height: | Size: 1.4 MiB |
22
app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
Normal file
@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@drawable/ic_launcher_background" />
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||
<monochrome android:drawable="@drawable/ic_launcher_foreground" />
|
||||
</adaptive-icon>
|
||||
22
app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
Normal file
@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@drawable/ic_launcher_background" />
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||
<monochrome android:drawable="@drawable/ic_launcher_foreground" />
|
||||
</adaptive-icon>
|
||||
BIN
app/src/main/res/mipmap-hdpi/ic_launcher.webp
Normal file
|
After Width: | Height: | Size: 1.4 KiB |
BIN
app/src/main/res/mipmap-hdpi/ic_launcher_round.webp
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
app/src/main/res/mipmap-mdpi/ic_launcher.webp
Normal file
|
After Width: | Height: | Size: 982 B |
BIN
app/src/main/res/mipmap-mdpi/ic_launcher_round.webp
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
BIN
app/src/main/res/mipmap-xhdpi/ic_launcher.webp
Normal file
|
After Width: | Height: | Size: 1.9 KiB |
BIN
app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
Normal file
|
After Width: | Height: | Size: 3.8 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp
Normal file
|
After Width: | Height: | Size: 5.8 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
Normal file
|
After Width: | Height: | Size: 3.8 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp
Normal file
|
After Width: | Height: | Size: 7.6 KiB |
25
app/src/main/res/values/strings.xml
Normal file
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
<resources>
|
||||
<string name="app_name">BMIcalcu</string>
|
||||
<string name="calculate_tip">Calculate BMI</string>
|
||||
|
||||
<!-- Welcome screen strings -->
|
||||
<string name="welcome_title">Welcome to BMI calculator</string>
|
||||
<string name="welcome_subtitle">Quickly calculate your BMI with a clean and modern interface.</string>
|
||||
<string name="welcome_cta">Get Started</string>
|
||||
</resources>
|
||||
19
app/src/main/res/values/themes.xml
Normal file
@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
<resources>
|
||||
<style name="Theme.TipTime" parent="android:Theme.Material.Light.NoActionBar" />
|
||||
</resources>
|
||||
224
app/src/test/java/com/example/tiptime/model/BmiCategoryTest.kt
Normal file
@ -0,0 +1,224 @@
|
||||
package com.example.tiptime.model
|
||||
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNotNull
|
||||
import org.junit.Test
|
||||
|
||||
/**
|
||||
* Unit tests untuk BmiCategory
|
||||
*
|
||||
* Test coverage:
|
||||
* - Kategori BMI berdasarkan nilai BMI
|
||||
* - Display names untuk setiap kategori
|
||||
* - Warna untuk setiap kategori
|
||||
* - Boundary values (batas antar kategori)
|
||||
*/
|
||||
class BmiCategoryTest {
|
||||
|
||||
// ==================== Test fromBmi() Method ====================
|
||||
|
||||
@Test
|
||||
fun fromBmi_underweightRange_returnsUnderweight() {
|
||||
// BMI < 18.5 harus return UNDERWEIGHT
|
||||
assertEquals(BmiCategory.UNDERWEIGHT, BmiCategory.fromBmi(10.0))
|
||||
assertEquals(BmiCategory.UNDERWEIGHT, BmiCategory.fromBmi(15.0))
|
||||
assertEquals(BmiCategory.UNDERWEIGHT, BmiCategory.fromBmi(18.0))
|
||||
assertEquals(BmiCategory.UNDERWEIGHT, BmiCategory.fromBmi(18.4))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun fromBmi_normalRange_returnsNormal() {
|
||||
// BMI 18.5 - 24.9 harus return NORMAL
|
||||
assertEquals(BmiCategory.NORMAL, BmiCategory.fromBmi(18.5))
|
||||
assertEquals(BmiCategory.NORMAL, BmiCategory.fromBmi(20.0))
|
||||
assertEquals(BmiCategory.NORMAL, BmiCategory.fromBmi(22.5))
|
||||
assertEquals(BmiCategory.NORMAL, BmiCategory.fromBmi(24.5))
|
||||
assertEquals(BmiCategory.NORMAL, BmiCategory.fromBmi(24.9))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun fromBmi_overweightRange_returnsOverweight() {
|
||||
// BMI 25.0 - 29.9 harus return OVERWEIGHT
|
||||
assertEquals(BmiCategory.OVERWEIGHT, BmiCategory.fromBmi(25.0))
|
||||
assertEquals(BmiCategory.OVERWEIGHT, BmiCategory.fromBmi(27.0))
|
||||
assertEquals(BmiCategory.OVERWEIGHT, BmiCategory.fromBmi(29.5))
|
||||
assertEquals(BmiCategory.OVERWEIGHT, BmiCategory.fromBmi(29.9))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun fromBmi_obeseRange_returnsObese() {
|
||||
// BMI >= 30.0 harus return OBESE
|
||||
assertEquals(BmiCategory.OBESE, BmiCategory.fromBmi(30.0))
|
||||
assertEquals(BmiCategory.OBESE, BmiCategory.fromBmi(35.0))
|
||||
assertEquals(BmiCategory.OBESE, BmiCategory.fromBmi(40.0))
|
||||
assertEquals(BmiCategory.OBESE, BmiCategory.fromBmi(50.0))
|
||||
}
|
||||
|
||||
// ==================== Test Boundary Values (Nilai Batas) ====================
|
||||
|
||||
@Test
|
||||
fun fromBmi_exactUnderweightBoundary_returnsUnderweight() {
|
||||
// BMI 18.49999 harus UNDERWEIGHT
|
||||
assertEquals(BmiCategory.UNDERWEIGHT, BmiCategory.fromBmi(18.49))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun fromBmi_exactNormalLowerBoundary_returnsNormal() {
|
||||
// BMI 18.5 (tepat) harus NORMAL
|
||||
assertEquals(BmiCategory.NORMAL, BmiCategory.fromBmi(18.5))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun fromBmi_exactNormalUpperBoundary_returnsNormal() {
|
||||
// BMI 24.9999 harus NORMAL
|
||||
assertEquals(BmiCategory.NORMAL, BmiCategory.fromBmi(24.99))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun fromBmi_exactOverweightLowerBoundary_returnsOverweight() {
|
||||
// BMI 25.0 (tepat) harus OVERWEIGHT
|
||||
assertEquals(BmiCategory.OVERWEIGHT, BmiCategory.fromBmi(25.0))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun fromBmi_exactOverweightUpperBoundary_returnsOverweight() {
|
||||
// BMI 29.9999 harus OVERWEIGHT
|
||||
assertEquals(BmiCategory.OVERWEIGHT, BmiCategory.fromBmi(29.99))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun fromBmi_exactObeseLowerBoundary_returnsObese() {
|
||||
// BMI 30.0 (tepat) harus OBESE
|
||||
assertEquals(BmiCategory.OBESE, BmiCategory.fromBmi(30.0))
|
||||
}
|
||||
|
||||
// ==================== Test Display Names ====================
|
||||
|
||||
@Test
|
||||
fun underweight_hasCorrectDisplayName() {
|
||||
assertEquals("Underweight", BmiCategory.UNDERWEIGHT.displayName)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun normal_hasCorrectDisplayName() {
|
||||
assertEquals("Normal Weight", BmiCategory.NORMAL.displayName)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun overweight_hasCorrectDisplayName() {
|
||||
assertEquals("Overweight", BmiCategory.OVERWEIGHT.displayName)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun obese_hasCorrectDisplayName() {
|
||||
assertEquals("Obese", BmiCategory.OBESE.displayName)
|
||||
}
|
||||
|
||||
// ==================== Test Colors ====================
|
||||
|
||||
@Test
|
||||
fun underweight_hasBlueColor() {
|
||||
// Underweight = Blue (0xFF3B82F6)
|
||||
assertEquals(Color(0xFF3B82F6), BmiCategory.UNDERWEIGHT.color)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun normal_hasGreenColor() {
|
||||
// Normal = Green (0xFF10B981)
|
||||
assertEquals(Color(0xFF10B981), BmiCategory.NORMAL.color)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun overweight_hasOrangeColor() {
|
||||
// Overweight = Orange (0xFFF59E0B)
|
||||
assertEquals(Color(0xFFF59E0B), BmiCategory.OVERWEIGHT.color)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun obese_hasRedColor() {
|
||||
// Obese = Red (0xFFEF4444)
|
||||
assertEquals(Color(0xFFEF4444), BmiCategory.OBESE.color)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun allCategories_haveNonNullColors() {
|
||||
// Pastikan semua kategori punya warna yang valid
|
||||
assertNotNull(BmiCategory.UNDERWEIGHT.color)
|
||||
assertNotNull(BmiCategory.NORMAL.color)
|
||||
assertNotNull(BmiCategory.OVERWEIGHT.color)
|
||||
assertNotNull(BmiCategory.OBESE.color)
|
||||
}
|
||||
|
||||
// ==================== Test Enum Values ====================
|
||||
|
||||
@Test
|
||||
fun allBmiCategories_exist() {
|
||||
// Pastikan semua 4 kategori ada
|
||||
val categories = BmiCategory.entries
|
||||
assertEquals(4, categories.size)
|
||||
|
||||
// Verifikasi urutan
|
||||
assertEquals(BmiCategory.UNDERWEIGHT, categories[0])
|
||||
assertEquals(BmiCategory.NORMAL, categories[1])
|
||||
assertEquals(BmiCategory.OVERWEIGHT, categories[2])
|
||||
assertEquals(BmiCategory.OBESE, categories[3])
|
||||
}
|
||||
|
||||
// ==================== Test Extreme Values ====================
|
||||
|
||||
@Test
|
||||
fun fromBmi_veryLowBmi_returnsUnderweight() {
|
||||
// BMI sangat rendah (misalnya kasus ekstrem)
|
||||
assertEquals(BmiCategory.UNDERWEIGHT, BmiCategory.fromBmi(10.0))
|
||||
assertEquals(BmiCategory.UNDERWEIGHT, BmiCategory.fromBmi(5.0))
|
||||
assertEquals(BmiCategory.UNDERWEIGHT, BmiCategory.fromBmi(1.0))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun fromBmi_veryHighBmi_returnsObese() {
|
||||
// BMI sangat tinggi (misalnya kasus ekstrem)
|
||||
assertEquals(BmiCategory.OBESE, BmiCategory.fromBmi(40.0))
|
||||
assertEquals(BmiCategory.OBESE, BmiCategory.fromBmi(50.0))
|
||||
assertEquals(BmiCategory.OBESE, BmiCategory.fromBmi(100.0))
|
||||
}
|
||||
|
||||
// ==================== Test Real-World Scenarios ====================
|
||||
|
||||
@Test
|
||||
fun fromBmi_typicalUnderweightValue_returnsUnderweight() {
|
||||
// Contoh BMI underweight yang umum: 17.5
|
||||
val category = BmiCategory.fromBmi(17.5)
|
||||
assertEquals(BmiCategory.UNDERWEIGHT, category)
|
||||
assertEquals("Underweight", category.displayName)
|
||||
assertEquals(Color(0xFF3B82F6), category.color)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun fromBmi_typicalNormalValue_returnsNormal() {
|
||||
// Contoh BMI normal yang umum: 22.0
|
||||
val category = BmiCategory.fromBmi(22.0)
|
||||
assertEquals(BmiCategory.NORMAL, category)
|
||||
assertEquals("Normal Weight", category.displayName)
|
||||
assertEquals(Color(0xFF10B981), category.color)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun fromBmi_typicalOverweightValue_returnsOverweight() {
|
||||
// Contoh BMI overweight yang umum: 27.5
|
||||
val category = BmiCategory.fromBmi(27.5)
|
||||
assertEquals(BmiCategory.OVERWEIGHT, category)
|
||||
assertEquals("Overweight", category.displayName)
|
||||
assertEquals(Color(0xFFF59E0B), category.color)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun fromBmi_typicalObeseValue_returnsObese() {
|
||||
// Contoh BMI obese yang umum: 32.5
|
||||
val category = BmiCategory.fromBmi(32.5)
|
||||
assertEquals(BmiCategory.OBESE, category)
|
||||
assertEquals("Obese", category.displayName)
|
||||
assertEquals(Color(0xFFEF4444), category.color)
|
||||
}
|
||||
}
|
||||
|
||||
120
app/src/test/java/com/example/tiptime/model/BmiDataTest.kt
Normal file
@ -0,0 +1,120 @@
|
||||
package com.example.tiptime.model
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNotEquals
|
||||
import org.junit.Test
|
||||
|
||||
/**
|
||||
* Unit tests untuk BmiData dan UnitSystem
|
||||
*
|
||||
* Test coverage:
|
||||
* - BmiData data class properties
|
||||
* - UnitSystem enum values
|
||||
* - Data class equality
|
||||
*/
|
||||
class BmiDataTest {
|
||||
|
||||
// ==================== Test BmiData Creation ====================
|
||||
|
||||
@Test
|
||||
fun bmiData_creation_withValidValues() {
|
||||
val bmiData = BmiData(
|
||||
bmi = 22.5,
|
||||
category = BmiCategory.NORMAL,
|
||||
healthyWeightRange = "56-76 kg"
|
||||
)
|
||||
|
||||
assertEquals(22.5, bmiData.bmi, 0.0)
|
||||
assertEquals(BmiCategory.NORMAL, bmiData.category)
|
||||
assertEquals("56-76 kg", bmiData.healthyWeightRange)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun bmiData_underweight_hasCorrectProperties() {
|
||||
val bmiData = BmiData(
|
||||
bmi = 17.5,
|
||||
category = BmiCategory.UNDERWEIGHT,
|
||||
healthyWeightRange = "50-68 kg"
|
||||
)
|
||||
|
||||
assertEquals(17.5, bmiData.bmi, 0.0)
|
||||
assertEquals(BmiCategory.UNDERWEIGHT, bmiData.category)
|
||||
assertEquals("50-68 kg", bmiData.healthyWeightRange)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun bmiData_overweight_hasCorrectProperties() {
|
||||
val bmiData = BmiData(
|
||||
bmi = 27.5,
|
||||
category = BmiCategory.OVERWEIGHT,
|
||||
healthyWeightRange = "55-75 kg"
|
||||
)
|
||||
|
||||
assertEquals(27.5, bmiData.bmi, 0.0)
|
||||
assertEquals(BmiCategory.OVERWEIGHT, bmiData.category)
|
||||
assertEquals("55-75 kg", bmiData.healthyWeightRange)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun bmiData_obese_hasCorrectProperties() {
|
||||
val bmiData = BmiData(
|
||||
bmi = 32.0,
|
||||
category = BmiCategory.OBESE,
|
||||
healthyWeightRange = "58-79 kg"
|
||||
)
|
||||
|
||||
assertEquals(32.0, bmiData.bmi, 0.0)
|
||||
assertEquals(BmiCategory.OBESE, bmiData.category)
|
||||
assertEquals("58-79 kg", bmiData.healthyWeightRange)
|
||||
}
|
||||
|
||||
// ==================== Test Data Class Equality ====================
|
||||
|
||||
@Test
|
||||
fun bmiData_equality_sameValues_areEqual() {
|
||||
val bmiData1 = BmiData(22.5, BmiCategory.NORMAL, "56-76 kg")
|
||||
val bmiData2 = BmiData(22.5, BmiCategory.NORMAL, "56-76 kg")
|
||||
|
||||
assertEquals(bmiData1, bmiData2)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun bmiData_equality_differentBmi_areNotEqual() {
|
||||
val bmiData1 = BmiData(22.5, BmiCategory.NORMAL, "56-76 kg")
|
||||
val bmiData2 = BmiData(23.5, BmiCategory.NORMAL, "56-76 kg")
|
||||
|
||||
assertNotEquals(bmiData1, bmiData2)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun bmiData_equality_differentCategory_areNotEqual() {
|
||||
val bmiData1 = BmiData(22.5, BmiCategory.NORMAL, "56-76 kg")
|
||||
val bmiData2 = BmiData(22.5, BmiCategory.OVERWEIGHT, "56-76 kg")
|
||||
|
||||
assertNotEquals(bmiData1, bmiData2)
|
||||
}
|
||||
|
||||
// ==================== Test Copy Function ====================
|
||||
|
||||
@Test
|
||||
fun bmiData_copy_modifyBmi_createsNewInstance() {
|
||||
val original = BmiData(22.5, BmiCategory.NORMAL, "56-76 kg")
|
||||
val copied = original.copy(bmi = 25.0)
|
||||
|
||||
assertEquals(25.0, copied.bmi, 0.0)
|
||||
assertEquals(BmiCategory.NORMAL, copied.category)
|
||||
assertEquals("56-76 kg", copied.healthyWeightRange)
|
||||
assertNotEquals(original, copied)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun bmiData_copy_modifyCategory_createsNewInstance() {
|
||||
val original = BmiData(22.5, BmiCategory.NORMAL, "56-76 kg")
|
||||
val copied = original.copy(category = BmiCategory.OVERWEIGHT)
|
||||
|
||||
assertEquals(22.5, copied.bmi, 0.0)
|
||||
assertEquals(BmiCategory.OVERWEIGHT, copied.category)
|
||||
assertEquals("56-76 kg", copied.healthyWeightRange)
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,81 @@
|
||||
package com.example.tiptime.model
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
/**
|
||||
* Unit tests untuk UnitSystem enum
|
||||
*
|
||||
* Test coverage:
|
||||
* - Enum values
|
||||
* - Display names
|
||||
* - Enum properties
|
||||
*/
|
||||
class UnitSystemTest {
|
||||
|
||||
// ==================== Test Enum Values ====================
|
||||
|
||||
@Test
|
||||
fun unitSystem_hasMetricValue() {
|
||||
val metric = UnitSystem.METRIC
|
||||
assertEquals("Metric (kg, cm)", metric.displayName)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun unitSystem_hasImperialValue() {
|
||||
val imperial = UnitSystem.IMPERIAL
|
||||
assertEquals("Imperial (lb, in)", imperial.displayName)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun unitSystem_hasTwoValues() {
|
||||
val values = UnitSystem.entries
|
||||
assertEquals(2, values.size)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun unitSystem_ordersCorrectly() {
|
||||
val values = UnitSystem.entries
|
||||
assertEquals(UnitSystem.METRIC, values[0])
|
||||
assertEquals(UnitSystem.IMPERIAL, values[1])
|
||||
}
|
||||
|
||||
// ==================== Test Display Names ====================
|
||||
|
||||
@Test
|
||||
fun metric_displayName_containsKgAndCm() {
|
||||
val displayName = UnitSystem.METRIC.displayName
|
||||
assert(displayName.contains("kg"))
|
||||
assert(displayName.contains("cm"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun imperial_displayName_containsLbAndIn() {
|
||||
val displayName = UnitSystem.IMPERIAL.displayName
|
||||
assert(displayName.contains("lb"))
|
||||
assert(displayName.contains("in"))
|
||||
}
|
||||
|
||||
// ==================== Test Enum Behavior ====================
|
||||
|
||||
@Test
|
||||
fun unitSystem_valueOf_metric_returnsMetric() {
|
||||
val system = UnitSystem.valueOf("METRIC")
|
||||
assertEquals(UnitSystem.METRIC, system)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun unitSystem_valueOf_imperial_returnsImperial() {
|
||||
val system = UnitSystem.valueOf("IMPERIAL")
|
||||
assertEquals(UnitSystem.IMPERIAL, system)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun unitSystem_entries_containsBothSystems() {
|
||||
val entries = UnitSystem.entries
|
||||
assertEquals(2, entries.size)
|
||||
assert(entries.contains(UnitSystem.METRIC))
|
||||
assert(entries.contains(UnitSystem.IMPERIAL))
|
||||
}
|
||||
}
|
||||
|
||||
269
app/src/test/java/com/example/tiptime/utils/BmiCalculatorTest.kt
Normal file
@ -0,0 +1,269 @@
|
||||
package com.example.tiptime.utils
|
||||
|
||||
import com.example.tiptime.model.BmiCategory
|
||||
import com.example.tiptime.model.UnitSystem
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
/**
|
||||
* Unit tests untuk BmiCalculator
|
||||
*
|
||||
* Test coverage:
|
||||
* - Perhitungan BMI untuk sistem Metric
|
||||
* - Perhitungan BMI untuk sistem Imperial
|
||||
* - Kategori BMI (Underweight, Normal, Overweight, Obese)
|
||||
* - Validasi input weight dan height
|
||||
* - Perhitungan healthy weight range
|
||||
*/
|
||||
class BmiCalculatorTest {
|
||||
|
||||
// ==================== Test Perhitungan BMI Metric ====================
|
||||
|
||||
@Test
|
||||
fun calculateBmi_metric_underweight_returnsCorrectBmi() {
|
||||
// Test case: 45 kg, 170 cm -> BMI = 15.57 (Underweight)
|
||||
val result = BmiCalculator.calculateBmi(45.0, 170.0, UnitSystem.METRIC)
|
||||
|
||||
assertEquals(15.57, result.bmi, 0.01)
|
||||
assertEquals(BmiCategory.UNDERWEIGHT, result.category)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun calculateBmi_metric_normal_returnsCorrectBmi() {
|
||||
// Test case: 70 kg, 175 cm -> BMI = 22.86 (Normal)
|
||||
val result = BmiCalculator.calculateBmi(70.0, 175.0, UnitSystem.METRIC)
|
||||
|
||||
assertEquals(22.86, result.bmi, 0.01)
|
||||
assertEquals(BmiCategory.NORMAL, result.category)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun calculateBmi_metric_overweight_returnsCorrectBmi() {
|
||||
// Test case: 85 kg, 175 cm -> BMI = 27.76 (Overweight)
|
||||
val result = BmiCalculator.calculateBmi(85.0, 175.0, UnitSystem.METRIC)
|
||||
|
||||
assertEquals(27.76, result.bmi, 0.01)
|
||||
assertEquals(BmiCategory.OVERWEIGHT, result.category)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun calculateBmi_metric_obese_returnsCorrectBmi() {
|
||||
// Test case: 100 kg, 170 cm -> BMI = 34.60 (Obese)
|
||||
val result = BmiCalculator.calculateBmi(100.0, 170.0, UnitSystem.METRIC)
|
||||
|
||||
assertEquals(34.60, result.bmi, 0.01)
|
||||
assertEquals(BmiCategory.OBESE, result.category)
|
||||
}
|
||||
|
||||
// ==================== Test Perhitungan BMI Imperial ====================
|
||||
|
||||
@Test
|
||||
fun calculateBmi_imperial_normal_returnsCorrectBmi() {
|
||||
// Test case: 150 lb, 67 in -> BMI = 23.49 (Normal)
|
||||
val result = BmiCalculator.calculateBmi(150.0, 67.0, UnitSystem.IMPERIAL)
|
||||
|
||||
assertEquals(23.49, result.bmi, 0.01)
|
||||
assertEquals(BmiCategory.NORMAL, result.category)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun calculateBmi_imperial_overweight_returnsCorrectBmi() {
|
||||
// Test case: 180 lb, 65 in -> BMI = 29.96 (Overweight)
|
||||
val result = BmiCalculator.calculateBmi(180.0, 65.0, UnitSystem.IMPERIAL)
|
||||
|
||||
assertEquals(29.96, result.bmi, 0.01)
|
||||
assertEquals(BmiCategory.OVERWEIGHT, result.category)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun calculateBmi_imperial_obese_returnsCorrectBmi() {
|
||||
// Test case: 220 lb, 65 in -> BMI = 36.62 (Obese)
|
||||
val result = BmiCalculator.calculateBmi(220.0, 65.0, UnitSystem.IMPERIAL)
|
||||
|
||||
assertEquals(36.62, result.bmi, 0.01)
|
||||
assertEquals(BmiCategory.OBESE, result.category)
|
||||
}
|
||||
|
||||
// ==================== Test Boundary Cases (Batas Kategori) ====================
|
||||
|
||||
@Test
|
||||
fun calculateBmi_metric_exactlyUnderweightBoundary_returnsUnderweight() {
|
||||
// Test case: BMI = 18.4 (tepat di bawah batas normal)
|
||||
val result = BmiCalculator.calculateBmi(56.0, 175.0, UnitSystem.METRIC)
|
||||
|
||||
assertTrue(result.bmi < 18.5)
|
||||
assertEquals(BmiCategory.UNDERWEIGHT, result.category)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun calculateBmi_metric_exactlyNormalLowerBoundary_returnsNormal() {
|
||||
// Test case: BMI = 18.5 (batas bawah normal)
|
||||
val result = BmiCalculator.calculateBmi(56.64, 175.0, UnitSystem.METRIC)
|
||||
|
||||
assertTrue(result.bmi >= 18.5 && result.bmi < 25.0)
|
||||
assertEquals(BmiCategory.NORMAL, result.category)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun calculateBmi_metric_exactlyOverweightLowerBoundary_returnsOverweight() {
|
||||
// Test case: BMI = 25.0 (batas bawah overweight)
|
||||
val result = BmiCalculator.calculateBmi(76.56, 175.0, UnitSystem.METRIC)
|
||||
|
||||
assertTrue(result.bmi >= 25.0 && result.bmi < 30.0)
|
||||
assertEquals(BmiCategory.OVERWEIGHT, result.category)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun calculateBmi_metric_exactlyObeseLowerBoundary_returnsObese() {
|
||||
// Test case: BMI = 30.0 (batas bawah obese)
|
||||
val result = BmiCalculator.calculateBmi(91.88, 175.0, UnitSystem.METRIC)
|
||||
|
||||
assertTrue(result.bmi >= 30.0)
|
||||
assertEquals(BmiCategory.OBESE, result.category)
|
||||
}
|
||||
|
||||
// ==================== Test Validasi Weight ====================
|
||||
|
||||
@Test
|
||||
fun isValidWeight_metric_validWeight_returnsTrue() {
|
||||
assertTrue(BmiCalculator.isValidWeight("70", UnitSystem.METRIC))
|
||||
assertTrue(BmiCalculator.isValidWeight("50.5", UnitSystem.METRIC))
|
||||
assertTrue(BmiCalculator.isValidWeight("1", UnitSystem.METRIC))
|
||||
assertTrue(BmiCalculator.isValidWeight("500", UnitSystem.METRIC))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun isValidWeight_metric_invalidWeight_returnsFalse() {
|
||||
assertFalse(BmiCalculator.isValidWeight("0", UnitSystem.METRIC))
|
||||
assertFalse(BmiCalculator.isValidWeight("-10", UnitSystem.METRIC))
|
||||
assertFalse(BmiCalculator.isValidWeight("501", UnitSystem.METRIC))
|
||||
assertFalse(BmiCalculator.isValidWeight("abc", UnitSystem.METRIC))
|
||||
assertFalse(BmiCalculator.isValidWeight("", UnitSystem.METRIC))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun isValidWeight_imperial_validWeight_returnsTrue() {
|
||||
assertTrue(BmiCalculator.isValidWeight("150", UnitSystem.IMPERIAL))
|
||||
assertTrue(BmiCalculator.isValidWeight("100.5", UnitSystem.IMPERIAL))
|
||||
assertTrue(BmiCalculator.isValidWeight("2", UnitSystem.IMPERIAL))
|
||||
assertTrue(BmiCalculator.isValidWeight("1100", UnitSystem.IMPERIAL))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun isValidWeight_imperial_invalidWeight_returnsFalse() {
|
||||
assertFalse(BmiCalculator.isValidWeight("0", UnitSystem.IMPERIAL))
|
||||
assertFalse(BmiCalculator.isValidWeight("-5", UnitSystem.IMPERIAL))
|
||||
assertFalse(BmiCalculator.isValidWeight("1101", UnitSystem.IMPERIAL))
|
||||
assertFalse(BmiCalculator.isValidWeight("xyz", UnitSystem.IMPERIAL))
|
||||
}
|
||||
|
||||
// ==================== Test Validasi Height ====================
|
||||
|
||||
@Test
|
||||
fun isValidHeight_metric_validHeight_returnsTrue() {
|
||||
assertTrue(BmiCalculator.isValidHeight("175", UnitSystem.METRIC))
|
||||
assertTrue(BmiCalculator.isValidHeight("160.5", UnitSystem.METRIC))
|
||||
assertTrue(BmiCalculator.isValidHeight("50", UnitSystem.METRIC))
|
||||
assertTrue(BmiCalculator.isValidHeight("300", UnitSystem.METRIC))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun isValidHeight_metric_invalidHeight_returnsFalse() {
|
||||
assertFalse(BmiCalculator.isValidHeight("0", UnitSystem.METRIC))
|
||||
assertFalse(BmiCalculator.isValidHeight("-100", UnitSystem.METRIC))
|
||||
assertFalse(BmiCalculator.isValidHeight("301", UnitSystem.METRIC))
|
||||
assertFalse(BmiCalculator.isValidHeight("abc", UnitSystem.METRIC))
|
||||
assertFalse(BmiCalculator.isValidHeight("", UnitSystem.METRIC))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun isValidHeight_imperial_validHeight_returnsTrue() {
|
||||
assertTrue(BmiCalculator.isValidHeight("67", UnitSystem.IMPERIAL))
|
||||
assertTrue(BmiCalculator.isValidHeight("70.5", UnitSystem.IMPERIAL))
|
||||
assertTrue(BmiCalculator.isValidHeight("20", UnitSystem.IMPERIAL))
|
||||
assertTrue(BmiCalculator.isValidHeight("120", UnitSystem.IMPERIAL))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun isValidHeight_imperial_invalidHeight_returnsFalse() {
|
||||
assertFalse(BmiCalculator.isValidHeight("0", UnitSystem.IMPERIAL))
|
||||
assertFalse(BmiCalculator.isValidHeight("-10", UnitSystem.IMPERIAL))
|
||||
assertFalse(BmiCalculator.isValidHeight("121", UnitSystem.IMPERIAL))
|
||||
assertFalse(BmiCalculator.isValidHeight("xyz", UnitSystem.IMPERIAL))
|
||||
}
|
||||
|
||||
// ==================== Test Healthy Weight Range ====================
|
||||
|
||||
@Test
|
||||
fun calculateBmi_metric_includesHealthyWeightRange() {
|
||||
val result = BmiCalculator.calculateBmi(70.0, 175.0, UnitSystem.METRIC)
|
||||
|
||||
// Untuk height 175 cm, healthy range = 56-76 kg (approx)
|
||||
assertTrue(result.healthyWeightRange.contains("kg"))
|
||||
assertTrue(result.healthyWeightRange.contains("-"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun calculateBmi_imperial_includesHealthyWeightRange() {
|
||||
val result = BmiCalculator.calculateBmi(150.0, 67.0, UnitSystem.IMPERIAL)
|
||||
|
||||
// Untuk height 67 in, healthy range dalam lb
|
||||
assertTrue(result.healthyWeightRange.contains("lb"))
|
||||
assertTrue(result.healthyWeightRange.contains("-"))
|
||||
}
|
||||
|
||||
// ==================== Test Validation Messages ====================
|
||||
|
||||
@Test
|
||||
fun getValidationMessage_metric_returnsCorrectMessages() {
|
||||
val messages = BmiCalculator.getValidationMessage(UnitSystem.METRIC)
|
||||
|
||||
assertTrue(messages.first.contains("kg"))
|
||||
assertTrue(messages.second.contains("cm"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getValidationMessage_imperial_returnsCorrectMessages() {
|
||||
val messages = BmiCalculator.getValidationMessage(UnitSystem.IMPERIAL)
|
||||
|
||||
assertTrue(messages.first.contains("lb"))
|
||||
assertTrue(messages.second.contains("in"))
|
||||
}
|
||||
|
||||
// ==================== Test Edge Cases ====================
|
||||
|
||||
@Test
|
||||
fun calculateBmi_metric_veryTallPerson_returnsCorrectBmi() {
|
||||
// Test case: 80 kg, 200 cm -> BMI = 20.0 (Normal)
|
||||
val result = BmiCalculator.calculateBmi(80.0, 200.0, UnitSystem.METRIC)
|
||||
|
||||
assertEquals(20.0, result.bmi, 0.01)
|
||||
assertEquals(BmiCategory.NORMAL, result.category)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun calculateBmi_metric_veryShortPerson_returnsCorrectBmi() {
|
||||
// Test case: 40 kg, 150 cm -> BMI = 17.78 (Underweight)
|
||||
val result = BmiCalculator.calculateBmi(40.0, 150.0, UnitSystem.METRIC)
|
||||
|
||||
assertEquals(17.78, result.bmi, 0.01)
|
||||
assertEquals(BmiCategory.UNDERWEIGHT, result.category)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun calculateBmi_imperial_decimalValues_returnsCorrectBmi() {
|
||||
// Test case dengan decimal: 165.5 lb, 68.5 in
|
||||
val result = BmiCalculator.calculateBmi(165.5, 68.5, UnitSystem.IMPERIAL)
|
||||
|
||||
assertTrue(result.bmi > 0)
|
||||
assertTrue(result.category in listOf(
|
||||
BmiCategory.UNDERWEIGHT,
|
||||
BmiCategory.NORMAL,
|
||||
BmiCategory.OVERWEIGHT,
|
||||
BmiCategory.OBESE
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
23
build.gradle.kts
Normal file
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
plugins {
|
||||
id("com.android.application") version "8.13.0" apply false
|
||||
id("com.android.library") version "8.13.0" apply false
|
||||
id("org.jetbrains.kotlin.android") version "2.1.0" apply false
|
||||
id("org.jetbrains.kotlin.plugin.compose") version "2.1.0" apply false
|
||||
}
|
||||
30
gradle.properties
Normal file
@ -0,0 +1,30 @@
|
||||
# Project-wide Gradle settings.
|
||||
# IDE (e.g. Android Studio) users:
|
||||
# Gradle settings configured through the IDE *will override*
|
||||
# any settings specified in this file.
|
||||
# For more details on how to configure your build environment visit
|
||||
# http://www.gradle.org/docs/current/userguide/build_environment.html
|
||||
# Specifies the JVM arguments used for the daemon process.
|
||||
# The setting is particularly useful for tweaking memory settings.
|
||||
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
|
||||
# When configured, Gradle will run in incubating parallel mode.
|
||||
# This option should only be used with decoupled projects. More details, visit
|
||||
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
|
||||
# org.gradle.parallel=true
|
||||
# AndroidX package structure to make it clearer which packages are bundled with the
|
||||
# Android operating system, and which are packaged with your app's APK
|
||||
# https://developer.android.com/topic/libraries/support-library/androidx-rn
|
||||
android.useAndroidX=true
|
||||
# Kotlin code style for this project: "official" or "obsolete":
|
||||
kotlin.code.style=official
|
||||
# Enables namespacing of each library's R class so that its R class includes only the
|
||||
# resources declared in the library itself and none from the library's dependencies,
|
||||
# thereby reducing the size of the R class for that library
|
||||
android.nonTransitiveRClass=true
|
||||
android.defaults.buildfeatures.buildconfig=true
|
||||
android.nonFinalResIds=false
|
||||
# Suppress AGP warning about unsupported compileSdk 36 when using AGP tested up to 35
|
||||
android.suppressUnsupportedCompileSdk=36
|
||||
|
||||
# Note: android.defaults.buildfeatures.buildconfig=true is deprecated; to keep BuildConfig enabled,
|
||||
# set android.buildFeatures.buildConfig = true in module-level build.gradle.kts if needed.
|
||||
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
7
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
251
gradlew
vendored
Normal file
@ -0,0 +1,251 @@
|
||||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright © 2015-2021 the original authors.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Gradle start up script for POSIX generated by Gradle.
|
||||
#
|
||||
# Important for running:
|
||||
#
|
||||
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||
# noncompliant, but you have some other compliant shell such as ksh or
|
||||
# bash, then to run this script, type that shell name before the whole
|
||||
# command line, like:
|
||||
#
|
||||
# ksh Gradle
|
||||
#
|
||||
# Busybox and similar reduced shells will NOT work, because this script
|
||||
# requires all of these POSIX shell features:
|
||||
# * functions;
|
||||
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||
# * compound commands having a testable exit status, especially «case»;
|
||||
# * various built-in commands including «command», «set», and «ulimit».
|
||||
#
|
||||
# Important for patching:
|
||||
#
|
||||
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||
#
|
||||
# The "traditional" practice of packing multiple parameters into a
|
||||
# space-separated string is a well documented source of bugs and security
|
||||
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||
# options in "$@", and eventually passing that to Java.
|
||||
#
|
||||
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||
# see the in-line comments for details.
|
||||
#
|
||||
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
|
||||
# Resolve links: $0 may be a link
|
||||
app_path=$0
|
||||
|
||||
# Need this for daisy-chained symlinks.
|
||||
while
|
||||
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||
[ -h "$app_path" ]
|
||||
do
|
||||
ls=$( ls -ld "$app_path" )
|
||||
link=${ls#*' -> '}
|
||||
case $link in #(
|
||||
/*) app_path=$link ;; #(
|
||||
*) app_path=$APP_HOME$link ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# This is normally unused
|
||||
# shellcheck disable=SC2034
|
||||
APP_BASE_NAME=${0##*/}
|
||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
} >&2
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
} >&2
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "$( uname )" in #(
|
||||
CYGWIN* ) cygwin=true ;; #(
|
||||
Darwin* ) darwin=true ;; #(
|
||||
MSYS* | MINGW* ) msys=true ;; #(
|
||||
NONSTOP* ) nonstop=true ;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||
else
|
||||
JAVACMD=$JAVA_HOME/bin/java
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD=java
|
||||
if ! command -v java >/dev/null 2>&1
|
||||
then
|
||||
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
case $MAX_FD in #(
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command, stacking in reverse order:
|
||||
# * args from the command line
|
||||
# * the main class name
|
||||
# * -classpath
|
||||
# * -D...appname settings
|
||||
# * --module-path (only if needed)
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if "$cygwin" || "$msys" ; then
|
||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||
|
||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
for arg do
|
||||
if
|
||||
case $arg in #(
|
||||
-*) false ;; # don't mess with options #(
|
||||
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||
[ -e "$t" ] ;; #(
|
||||
*) false ;;
|
||||
esac
|
||||
then
|
||||
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||
fi
|
||||
# Roll the args list around exactly as many times as the number of
|
||||
# args, so each arg winds up back in the position where it started, but
|
||||
# possibly modified.
|
||||
#
|
||||
# NB: a `for` loop captures its iteration list before it begins, so
|
||||
# changing the positional parameters here affects neither the number of
|
||||
# iterations, nor the values presented in `arg`.
|
||||
shift # remove old arg
|
||||
set -- "$@" "$arg" # push replacement arg
|
||||
done
|
||||
fi
|
||||
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Collect all arguments for the java command:
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||
# and any embedded shellness will be escaped.
|
||||
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||
# treated as '${Hostname}' itself on the command line.
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-classpath "$CLASSPATH" \
|
||||
org.gradle.wrapper.GradleWrapperMain \
|
||||
"$@"
|
||||
|
||||
# Stop when "xargs" is not available.
|
||||
if ! command -v xargs >/dev/null 2>&1
|
||||
then
|
||||
die "xargs is not available"
|
||||
fi
|
||||
|
||||
# Use "xargs" to parse quoted args.
|
||||
#
|
||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||
#
|
||||
# In Bash we could simply go:
|
||||
#
|
||||
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||
# set -- "${ARGS[@]}" "$@"
|
||||
#
|
||||
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||
# character that might be a shell metacharacter, then use eval to reverse
|
||||
# that process (while maintaining the separation between arguments), and wrap
|
||||
# the whole thing up as a single "set" statement.
|
||||
#
|
||||
# This will of course break if any of these variables contains a newline or
|
||||
# an unmatched quote.
|
||||
#
|
||||
|
||||
eval "set -- $(
|
||||
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||
xargs -n1 |
|
||||
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||
tr '\n' ' '
|
||||
)" '"$@"'
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
94
gradlew.bat
vendored
Normal file
@ -0,0 +1,94 @@
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
@rem SPDX-License-Identifier: Apache-2.0
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%"=="" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%"=="" set DIRNAME=.
|
||||
@rem This is normally unused
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if %ERRORLEVEL% equ 0 goto execute
|
||||
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if %ERRORLEVEL% equ 0 goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
set EXIT_CODE=%ERRORLEVEL%
|
||||
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||
exit /b %EXIT_CODE%
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
32
settings.gradle.kts
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
pluginManagement {
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
dependencyResolutionManagement {
|
||||
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
rootProject.name = "Tip Time"
|
||||
include(":app")
|
||||