The lemonade app will consist 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.
Screen1
Tapping the lemon tree presents the user with a lemon that they can tap to “squeeze” for an unspecified number of times (the exact number of required squeezes is randomly generated) before moving to the next screen.
Screen2
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.
Screen3
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.
Screen4
The different states of the app (whether the user is selecting a lemon, squeezing the lemon, drinking the lemonade, and, finally, the empty glass) is represented by something called a state machine.
* This method determines the state and proceeds with the correct action. */private fun clickLemonImage() { when (lemonadeState) {
Then we set up the view elements according to the state.
/** Set up the view elements according to the state. */ private fun setViewElements() { val textAction: TextView = findViewById(R.id.text_action) // val lemonImage: ImageView = findViewById(R.id.image_lemon_state)