Skip to content

ThanaReka/Android-App-Using-Jetpack-Libraries

Repository files navigation

Android-App-Using-Jetpack-Libraries

STEPS TO COMPLETE THE UI:

I) Initializing the App:

  1. Create an app called Penny Drop.
  2. Create 2 Fragment classes: PickPlayersFragment and GameFragment.
  3. Create a called navigation.xml with the 2 Fragments as items.
  4. Add 2 images as Vector Assets in the drawable folder to be used as the icons for the 2 fragments in the menu.
  5. Create a navigation graph called nav_graph.xml after adding a variable called nav_version in top-level build.gradle and then incorporating the variable in the dependencies under the app's build.gradle file.
  6. Include both Fragment classes as destinations in nav_graph.xml.
  7. Add a container and BottomNavigationView to activity_main.xml.
  8. Connect the to the BottomNavigationView in MainActivity by using the NavController.

II) Build the Individual Fragments and Add Data Binding to the App:

  1. Add the FAB button to fragment_pick_players.xml.
  2. Create a base layout file called player_list_item featuring and for the individual rows.
  3. Include Player Rows in the fragment using the tag.
  4. Add a Generic layout Tag to fragment_pick_players.xml and Use Data Binding in PickPlayersFragment.
  5. Enable Data Binding by adding the Kotlin kapt plugin and the dataBinding flag in the app’s build.gradle file.
  6. Add data and checkboxHidden and switchHidden variable Tags Inside player_list_item.xml.
  7. Conditionally Display the CheckBox and SwitchCompat for a Player.
  8. Assign values to both app:checkboxHidden and app:switchHidden Variables so that only the will be hidden from the mainPlayer and the will be hidden from the main player and player two while the rest will remain as is.
  9. Add a Generic layout Tag to fragment_game.xml and Use Data Binding in PickPlayersFragmentGameFragment.
  10. Add relevant TextViews (including textCurrentTurnInfo.movementMethod = ScrollingMovementMethod to enable movement of scrollbars), plus the Roll and Pass Buttons.
  11. Create layout_coin_slot.xml including a slotNum to use with the .
  12. Add Coin Slots to GameFragment using the tag.

III) Build the Individual Fragments and Add Data Binding to the App:

  1. Add the ViewModel and LiveData Dependencies to build.gradle file.
  2. Add NewPlayer data class.
  3. Create PickPlayersViewModel and add in the NewPlayer Instances.
  4. Update PickPlayersFragment to Use PickPlayersViewModel by first adding a called viewModel to fragment_pick_players of type PickPlayersViewModel.
  5. Get an Instance of PickPlayersViewModel via the by activityViewModels() syntax.
  6. Bind that instance to the viewModel variable on FragmentPickPlayersBinding.
  7. Bind each NewPlayer using the player variable tags inside player_list_item.xml.
  8. Add app:player attributes to the fragment_pick_players using a collection syntax (example, viewModel.players[0]) to get each individual player.
  9. Update the android:visibility attributes in player_list_item.xml to use player.canBeRemoved and player.canBeToggled in the CheckBox and SwitchCompat.
  10. Use two-way binding to bind player’s name in edit text and player.isIncluded player.isHuman via android:checked property in the CheckBox and SwitchCompat.
  11. Create the AI Class and add AI Spinner in player_list_item.xml.
  12. Use the "android:enabled"@{player.isIncluded}" attribute in , , and tags to disable views in a player list item
  13. Create drawable selector to help change the icon on the based on its state (android:state_checked = true/false) using the : android:thumb"@drawable/ai_toggle_bg" attribute.
  14. Similarly, create color selectors to help change the color on the based on its state using the android:thumbTint and android:trackTint attributes.
  15. Create the GameViewModel class and the Player class to keep track of a player’s status in a game (this will handle the connection between the Game view and the GameHandler later on).
  16. Get a List by converting NewPlayer into Player using the toPlayer​() function in the NewPlayer data class.
  17. Once the players have been added to the GameViewModel, create a new function inside GameViewModel called startGame, which brings in the List and gets a game set up.
  18. Bring in an instance of GameViewModel inside PickPlayersFragment, and transfer over the players when someone clicks the Play button.
  19. Also transfer over the players when someone clicks the Play button by mapping each NewPlayer to a Player via the toPlayer function created in NewPlayer data class.
  20. Create slot class, then add LiveData to GameViewModel to be bound to components in layout_game.xml.
  21. Add a called viewModel of type GameViewModel to fragment_game.
  22. Update GameFragment to use GameViewModel and set a lifecycleOwner, which ensures our LiveData will.
  23. Bind the relevant text values to the values from GameViewModel for CurrentPlayer using the player tags inside fragment_game.xml.
  24. Update Button Bindings by changing android:background and android:enabled attributes to use the values from mvm.canRoll/vm.canPass, and update the android:onClick to incorporate the appropriate methods.
  25. Update Slot Bindings by converting to app:slot to "@{vm.slots[]}" within slot tags in fragment_game.
  26. Replace the slotNum with slot in layout_coin_slot.xml, and then

Android-App-Using-Jetpack-Libraries

STEPS TO COMPLETE THE UI:

I) Initializing the App:

  1. Create an app called Penny Drop.
  2. Create 2 Fragment classes: PickPlayersFragment and GameFragment.
  3. Create a called navigation.xml with the 2 Fragments as items.
  4. Add 2 images as Vector Assets in the drawable folder to be used as the icons for the 2 fragments in the menu.
  5. Create a navigation graph called nav_graph.xml after adding a variable called nav_version in top-level build.gradle and then incorporating the variable in the dependencies under the app's build.gradle file.
  6. Include both Fragment classes as destinations in nav_graph.xml.
  7. Add a container and BottomNavigationView to activity_main.xml.
  8. Connect the to the BottomNavigationView in MainActivity by using the NavController.

II) Build the Individual Fragments and Add Data Binding to the App:

  1. Add the FAB button to fragment_pick_players.xml.
  2. Create a base layout file called player_list_item featuring and for the individual rows.
  3. Include Player Rows in the fragment using the tag.
  4. Add a Generic layout Tag to fragment_pick_players.xml and Use Data Binding in PickPlayersFragment.
  5. Enable Data Binding by adding the Kotlin kapt plugin and the dataBinding flag in the app’s build.gradle file.
  6. Add data and checkboxHidden and switchHidden variable Tags Inside player_list_item.xml.
  7. Conditionally Display the CheckBox and SwitchCompat for a Player.
  8. Assign values to both app:checkboxHidden and app:switchHidden Variables so that only the will be hidden from the mainPlayer and the will be hidden from the main player and player two while the rest will remain as is.
  9. Add a Generic layout Tag to fragment_game.xml and Use Data Binding in PickPlayersFragmentGameFragment.
  10. Add relevant TextViews (including textCurrentTurnInfo.movementMethod = ScrollingMovementMethod to enable movement of scrollbars), plus the Roll and Pass Buttons.
  11. Create layout_coin_slot.xml including a slotNum to use with the .
  12. Add Coin Slots to GameFragment using the tag.

III) Binding Data with ViewModels:

  1. Add the ViewModel and LiveData Dependencies to build.gradle file.
  2. Add NewPlayer data class.
  3. Create PickPlayersViewModel and add in the NewPlayer Instances.
  4. Update PickPlayersFragment to Use PickPlayersViewModel by first adding a called viewModel to fragment_pick_players of type PickPlayersViewModel.
  5. Get an Instance of PickPlayersViewModel via the by activityViewModels() syntax.
  6. Bind that instance to the viewModel variable on FragmentPickPlayersBinding.
  7. Bind each NewPlayer using the player variable tags inside player_list_item.xml.
  8. Add app:player attributes to the fragment_pick_players using a collection syntax (example, viewModel.players[0]) to get each individual player.
  9. Update the android:visibility attributes in player_list_item.xml to use player.canBeRemoved and player.canBeToggled in the CheckBox and SwitchCompat.
  10. Use two-way binding to bind the player’s name in edit text and player.isIncluded player.isHuman via android:checked property in the CheckBox and SwitchCompat.
  11. Create the AI Class and add AI Spinner in player_list_item.xml.
  12. Use the "android:enabled"@{player.isIncluded}" attribute in , , and tags to disable views in a player list item
  13. Create a drawable selector to help change the icon on the based on its state (android:state_checked = true/false) using the : android:thumb"@drawable/ai_toggle_bg" attribute.
  14. Similarly, create color selectors to help change the color on the based on its state using the android:thumbTint and android:trackTint attributes.
  15. Create the GameViewModel class and the Player class to keep track of a player’s status in a game (this will handle the connection between the Game view and the GameHandler later on).
  16. Get a List by converting NewPlayer into Player using the toPlayer​() function in the NewPlayer data class.
  17. Once the players have been added to the GameViewModel, create a new function inside GameViewModel called startGame, which brings in the List and gets a game set up.
  18. Bring in an instance of GameViewModel inside PickPlayersFragment, and transfer over the players when someone clicks the Play button.
  19. Also transfer over the players when someone clicks the Play button by mapping each NewPlayer to a Player via the toPlayer function created in NewPlayer data class.
  20. Create slot class, then add LiveData to GameViewModel to be bound to components in layout_game.xml.
  21. Add a called viewModel of type GameViewModel to fragment_game.
  22. Update GameFragment to use GameViewModel and set a lifecycleOwner, which ensures our LiveData will.
  23. Bind the relevant text values to the values from GameViewModel for CurrentPlayer using the player tags inside fragment_game.xml.
  24. Update Button Bindings by changing android:background and android:enabled attributes to use the values from mvm.canRoll/vm.canPass, and update the android:onClick to incorporate the appropriate methods.
  25. Update Slot Bindings by converting to app:slot to "@{vm.slots[]}" within slot tags in fragment_game.
  26. Replace the slotNum with slot.number in layout_coin_slot.xml, and use slot.lastRolled to change textColor accordingly.
  27. Create Binding Adapters along with package-level functions to be used for the app:isHidden property in coinImageCoinSlot of the layout_coin_slot.xml file.

INCORPORATING FUNCTIONALITY INTO THE GAME USING CONDITIONAL GAME LOGIC:

  1. Create the GameHandler object in game package, consisting of roll() , pass(), rollDie() and nextPlayer() stateless functions that will take care of rolling and passing, then return a result to the GameViewModel.
  2. Create the TurnResult data class (to be later used by the GameViewModel) along with the TurnEnd enum class.
  3. Handle User Rolls by adding the rollDie function to GameHandler.kt and incorporating it into the roll function.
  4. Add the penniesLeft() function as a Helper Method to Player Class.
  5. Complete the logic for when the Slot is already rolled inside the if...else block.
  6. Add the nextPlayer function to GameHandler.kt to grab the Next Player.
  7. Handle an Open Slot by using the penniesLeft() function inside the roll() function to see if the player has won.
  8. Complete the logic to Handle Users Passing.
  9. Start a Game in  GameViewModel by adding clear() function to the Slot class and the startGame function plus the notifyChange() and generateCurrentStandings() functions to  GameViewModel.
  10. Complete the GameViewModel Functions: roll() and pass() inside GameViewModel.
  11. Add updateFromGameHandler​ and updateSlots in GameViewModel to update the UI.
  12. Create Turn Summary Text using generateTurnText function in GameViewModel.
  13. Handle Multiple Conditionals with when Statements in the generateTurnText function.
  14. Handle AI Turns using Coroutines via the playAITurn() function and add rollAgain() as First-Class Function to AI data class.

References: https://learning-oreilly-com.ezproxy.torontopubliclibrary.ca/library/view/kotlin-and-android/9781680508673/f_0005.xhtml

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages