1 00:00:00,440 --> 00:00:02,440 We're almost done with the app. 2 00:00:02,440 --> 00:00:06,870 All that's left is to make sure when we select a pizza from main activity, 3 00:00:06,870 --> 00:00:10,690 that we then display that pizza in creator activity. 4 00:00:10,690 --> 00:00:16,680 Let's flip over to creator activity, and remember that when we select a pizza, 5 00:00:16,680 --> 00:00:22,450 we pass that pizza's ID over to creator activity inside of an intent. 6 00:00:22,450 --> 00:00:26,560 From here all we need to do is use this pizzaId 7 00:00:26,560 --> 00:00:31,800 to populate our viewModel with the name of the pizza and which toppings it has. 8 00:00:31,800 --> 00:00:36,880 So instead of immediately setting our title to viewModel.pizzaName, 9 00:00:36,880 --> 00:00:41,307 let's wrap this in a thread and first populate our view model. 10 00:00:46,461 --> 00:00:52,762 Provided we have an actual pizza, let's make sure that pizzaID isn't equal to -1. 11 00:00:59,463 --> 00:01:02,858 And then let's update our view model's pizza name. 12 00:01:02,858 --> 00:01:10,620 ViewModel.pizzaName = db.pizzaDoa().getPizzaById, 13 00:01:10,620 --> 00:01:14,120 pass in the pizzaID. 14 00:01:14,120 --> 00:01:15,610 And then retrieve the name property. 15 00:01:17,300 --> 00:01:21,160 And let's finish by updating our view models switch states. 16 00:01:21,160 --> 00:01:25,046 First, we'll need to retrieve the topping IDs for this pizzaID. 17 00:01:25,046 --> 00:01:34,380 Val toppingIds = db.pizzaToppingDao().getToppingIDsForPiz- 18 00:01:34,380 --> 00:01:39,050 zaID and pass in the pizzaID. 19 00:01:39,050 --> 00:01:42,930 Then we'll need to loop through the topping IDs. 20 00:01:42,930 --> 00:01:45,497 So toppingIDs.forEach. 21 00:01:48,157 --> 00:01:53,269 And for each topping ID, we'll need to retrieve the topping it corresponds to and 22 00:01:53,269 --> 00:01:57,305 update switch states with a value of true for that topping. 23 00:01:57,305 --> 00:01:58,611 So let's retrieve the topping. 24 00:01:58,611 --> 00:02:03,752 Val topping = db.toppingDao().getToppingById, 25 00:02:03,752 --> 00:02:10,290 passing in the ID, which is it, and then let's add it to switch states. 26 00:02:11,320 --> 00:02:16,130 So viewModel.switchStates, with the key of topping, 27 00:02:17,700 --> 00:02:20,380 and we'll give it a value of true. 28 00:02:20,380 --> 00:02:22,950 All right, that should do it. 29 00:02:22,950 --> 00:02:25,003 Let's run the app and see what we've got. 30 00:02:30,712 --> 00:02:35,310 Let's click on our pizza, and awesome, it works. 31 00:02:36,660 --> 00:02:40,010 We've covered a lot in this course, from finding out about view models, 32 00:02:40,010 --> 00:02:41,800 to learning the ins and outs of Room, and 33 00:02:41,800 --> 00:02:45,580 even using lab data to make our UI update automatically. 34 00:02:45,580 --> 00:02:48,240 Room and architecture components in general 35 00:02:48,240 --> 00:02:52,270 have done a lot to make Android development a more pleasant experience. 36 00:02:52,270 --> 00:02:55,590 But none of that matters if you don't remember what we learn here. 37 00:02:55,590 --> 00:02:59,695 If you've got the time I recommend trying to make a new app using Room 38 00:02:59,695 --> 00:03:01,065 all on your own. 39 00:03:01,065 --> 00:03:05,265 It could be a mood tracker, a calorie counter, or even just a to-do list. 40 00:03:05,265 --> 00:03:07,595 But if you really want this information to stick, 41 00:03:07,595 --> 00:03:10,885 you'll need to work through a project of your own making. 42 00:03:10,885 --> 00:03:14,275 Just remember, if you get stuck or have any issues, or 43 00:03:14,275 --> 00:03:17,565 even if something just doesn't make sense, reach out to the community for 44 00:03:17,565 --> 00:03:20,425 help and we'll be sure to get you on the right track. 45 00:03:20,425 --> 00:03:21,225 Until next time.