google-developer-training / basic-android-kotlin-compose-training-tip-calculator

Apache License 2.0
61 stars 97 forks source link

Calculate a custom tip: Android Basics in Compose #190

Closed ghost closed 7 months ago

ghost commented 7 months ago

URL of codelab https://developer.android.com/codelabs/basic-android-kotlin-compose-calculate-tip?continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-compose-unit-2-pathway-3%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-compose-calculate-tip#5

In which task and step of the codelab can this issue be found? Task : Calculate Custom Tip Step : 4. Add a tip-percentage text field

Describe the problem The default value assigned to tipPercent parameter is never used. Due to which user is bound to enter tip percentage:

Fix 1) Don't pass argument to calculateTip method if tipPercent is 0.0 (Also created pull request for this https://github.com/google-developer-training/basic-android-kotlin-compose-training-tip-calculator/pull/192) Replace val tip = calculateTip(amount, tipPercent, roundUp) ->

val tip = if (tipPercent == 0.0) {
        calculateTip(amount = amount, roundUp = roundUp)
    } else {
        calculateTip(amount, tipPercent, roundUp)
    }

Fix 2) Change elvis operator fallback value from 0.0 to 15.0 Replace val tipPercent = tipInput.toDoubleOrNull() ?: 0.0 -> val tipPercent = tipInput.toDoubleOrNull() ?: 15.0

Fix 3) Altogether remove the default value from tipPercent parameter to the avoid confusion. private fun calculateTip(amount: Double, tipPercent: Double = 15.0, roundUp: Boolean): String -> private fun calculateTip(amount: Double, tipPercent: Double, roundUp: Boolean): String

Steps to reproduce?

  1. Download the solution code zip from the codelab.
  2. Unzip solution code and open it in Android Studio.
  3. Run the code.

Versions Android Studio version: Android Studio Iguana | 2023.2.1 Patch 1 API version of the emulator: 34

Additional information Before: 318167130-fda321e4-55aa-48c9-8dfb-069d69762c82 (2)

After: 318167233-34640c15-5881-41e3-b60b-2f1239164474

android-dev-lxl commented 7 months ago

@itsanikethere Thank you for your feedback! We value your suggestions and appreciate you taking the time to reach out. Training apps focus on teaching specific concepts, and their requirements vary based on the course curriculum. To maintain their simplicity for learning purposes, we might not be able to implement changes at this moment. However, your feedback is helpful for future development.

ghost commented 7 months ago

@android-dev-lxl image Thank you for the reply. The reason I raised this issue was because in the codelab starter app code, the feature of default tip percentage already exists, and during the codelab, the goal is to add one more feature of custom percentage for tip calculation. However, in the final output code, the already existing feature was broken. But do what you feel is correct I am still new to android and you better understand the repository.

android-dev-lxl commented 7 months ago

Yes you are correct, this is done on purpose, we are trying to change the hardcoded tip percentage to custom value entered by the user.

ghost commented 7 months ago

Okay! Thank you for responding.