Finishing Up3:22 with Ben Deitch
In this video we finish the app!
We're almost done with the app. 0:00 All that's left is to make sure when we select a pizza from main activity, 0:02 that we then display that pizza in creator activity. 0:06 Let's flip over to creator activity, and remember that when we select a pizza, 0:10 we pass that pizza's ID over to creator activity inside of an intent. 0:16 From here all we need to do is use this pizzaId 0:22 to populate our viewModel with the name of the pizza and which toppings it has. 0:26 So instead of immediately setting our title to viewModel.pizzaName, 0:31 let's wrap this in a thread and first populate our view model. 0:36 Provided we have an actual pizza, let's make sure that pizzaID isn't equal to -1. 0:46 And then let's update our view model's pizza name. 0:59 ViewModel.pizzaName = db.pizzaDoa().getPizzaById, 1:02 pass in the pizzaID. 1:10 And then retrieve the name property. 1:14 And let's finish by updating our view models switch states. 1:17 First, we'll need to retrieve the topping IDs for this pizzaID. 1:21 Val toppingIds = db.pizzaToppingDao().getToppingIDsForPiz- 1:25 zaID and pass in the pizzaID. 1:34 Then we'll need to loop through the topping IDs. 1:39 So toppingIDs.forEach. 1:42 And for each topping ID, we'll need to retrieve the topping it corresponds to and 1:48 update switch states with a value of true for that topping. 1:53 So let's retrieve the topping. 1:57 Val topping = db.toppingDao().getToppingById, 1:58 passing in the ID, which is it, and then let's add it to switch states. 2:03 So viewModel.switchStates, with the key of topping, 2:11 and we'll give it a value of true. 2:17 All right, that should do it. 2:20 Let's run the app and see what we've got. 2:22 Let's click on our pizza, and awesome, it works. 2:30 We've covered a lot in this course, from finding out about view models, 2:36 to learning the ins and outs of Room, and 2:40 even using lab data to make our UI update automatically. 2:41 Room and architecture components in general 2:45 have done a lot to make Android development a more pleasant experience. 2:48 But none of that matters if you don't remember what we learn here. 2:52 If you've got the time I recommend trying to make a new app using Room 2:55 all on your own. 2:59 It could be a mood tracker, a calorie counter, or even just a to-do list. 3:01 But if you really want this information to stick, 3:05 you'll need to work through a project of your own making. 3:07 Just remember, if you get stuck or have any issues, or 3:10 even if something just doesn't make sense, reach out to the community for 3:14 help and we'll be sure to get you on the right track. 3:17 Until next time. 3:20
You need to sign up for Treehouse in order to download course files.Sign up