#100DaysOfCode #Day1

GOOGLE LEMONADE APP

Today I commence this challenge with a simple project by google

TRAINING /ANDROID BASICS IN KOTLIN / KOTLIN BASICS

The finished Lemonade app consists of a single screen. When users first launch the app, they're greeted with a prompt to pick a lemon by tapping a picture of a lemon tree.

1ce5b75b513d63c9.png

Tapping the lemon tree presents the user with a lemon that they can tap to "squeeze" an unspecified number of times (the exact number of required squeezes is randomly generated) before moving to the next screen.

fb63b41d58a83af7.png

Once the user has tapped to squeeze the lemon the correct number of times, they will see an image of a glass to "drink" the lemonade.

f8882c1688a0e3e7.png

After clicking to drink the lemonade, the glass appears empty, and the user can tap the image again to return to the first screen, and select another lemon from the tree.

951918f0c2d0464.png

The app is built around simplicity and is organized in a single activity.

Solution:

 /**
     * Clicking will elicit a different response depending on the state.
     * This method determines the state and proceeds with the correct action.
     */
    private fun clickLemonImage() {
        when(lemonadeState){
            SELECT -> {
                lemonadeState = SQUEEZE
                lemonSize = lemonTree.pick()
                squeezeCount = 0
            }
            SQUEEZE -> {
                squeezeCount ++
                lemonSize --
                lemonadeState = if (lemonSize == 0){ DRINK } else SQUEEZE

            }
            DRINK -> {
                lemonadeState = RESTART
                lemonSize = -1
            }
            RESTART -> lemonadeState = SELECT
        }
        setViewElements()
    }
 /**
     * Set up the view elements according to the state.
     */
    private fun setViewElements() {
        val textAction: TextView = findViewById(R.id.text_action)
        when(lemonadeState){
            SELECT -> {
                textAction.text = getString(R.string.lemon_select)
                lemonImage?.setImageResource(R.drawable.lemon_tree)
            }
            SQUEEZE -> {
                textAction.text = getString(R.string.lemon_squeeze)
                lemonImage?.setImageResource(R.drawable.lemon_squeeze)
            }
            DRINK -> {
                textAction.text = getString(R.string.lemon_drink)
                lemonImage?.setImageResource(R.drawable.lemon_drink)
            }
            RESTART -> {
                textAction.text = getString(R.string.lemon_empty_glass)
                lemonImage?.setImageResource(R.drawable.lemon_restart)
            }
        }

    }

I enjoyed working on this project, that's it for day one... Adios😊