1 00:00:00,550 --> 00:00:04,220 We now want to add some custom constructors to our model objects. 2 00:00:04,220 --> 00:00:06,790 Let's open up our page class first. 3 00:00:06,790 --> 00:00:09,490 Now, we could just type out a constructor here, but once again, 4 00:00:09,490 --> 00:00:12,250 there's a really helpful shortcut from Android Studio. 5 00:00:12,250 --> 00:00:16,400 If we click on Code, and then Generate, we can pick a Constructor. 6 00:00:16,400 --> 00:00:20,500 And we want to use all four of these as parameters, so I'll hold down Shift and 7 00:00:20,500 --> 00:00:22,320 click on the last item. 8 00:00:22,320 --> 00:00:27,040 Click OK and there we go, we have a nice tidy constructor that will populate a new 9 00:00:27,040 --> 00:00:29,232 page object with all four settings. 10 00:00:29,232 --> 00:00:31,470 Let's do the same thing for our Choice class. 11 00:00:31,470 --> 00:00:35,846 So again, I'm gonna put my cursor where I want the new constructor to go, 12 00:00:35,846 --> 00:00:41,160 then click on Code > Generate > Constructor, select both and click OK. 13 00:00:41,160 --> 00:00:44,370 All right, so let's use these back in our story class. 14 00:00:44,370 --> 00:00:46,260 Let's get rid of this code here, and 15 00:00:46,260 --> 00:00:49,440 we'll do it a little bit differently with our fancy new constructors. 16 00:00:50,950 --> 00:00:56,710 So, this time the page at index 0 will equal a new Page, 17 00:00:58,020 --> 00:01:05,140 and we can pass in those parameters we were all ready using, R.drawable.page0. 18 00:01:05,140 --> 00:01:09,415 For the text ID, R.string.page0. 19 00:01:09,415 --> 00:01:14,190 And for the choices, we can create new choice objects right in line. 20 00:01:14,190 --> 00:01:15,930 But just to make this a little easier to read, 21 00:01:15,930 --> 00:01:18,270 I'm going to put each parameter on a new line. 22 00:01:19,510 --> 00:01:22,765 So next, we have choice one, so I'll say newChoice. 23 00:01:23,900 --> 00:01:30,860 And the text will be R.string.page0_choice1. 24 00:01:30,860 --> 00:01:33,869 The second primer is the next page, but I'm gonna leave that blank for 25 00:01:33,869 --> 00:01:35,010 just a second. 26 00:01:35,010 --> 00:01:41,170 Add a comma and do it again, new Choice R.string.page0_choice2. 27 00:01:41,170 --> 00:01:41,990 With another blank. 28 00:01:43,080 --> 00:01:45,100 I will add this semicolon though. 29 00:01:45,100 --> 00:01:47,420 Right now we're working on Page 0, here. 30 00:01:47,420 --> 00:01:52,180 The first choice takes us to page 1, and the second choice takes us to page 2, so 31 00:01:52,180 --> 00:01:55,190 we can plug in the page numbers in our constructor. 32 00:01:55,190 --> 00:01:58,224 Okay, so here's the first choice, and it goes to page 1, and 33 00:01:58,224 --> 00:01:59,900 the second choice goes to page 2. 34 00:01:59,900 --> 00:02:02,270 Cool, we have our first page. 35 00:02:02,270 --> 00:02:05,590 The rest will follow this same format, so I'm just going to copy and 36 00:02:05,590 --> 00:02:07,660 paste the remaining page details. 37 00:02:07,660 --> 00:02:10,788 This code is once again available for you to copy and 38 00:02:10,788 --> 00:02:12,910 paste from the teacher's notes. 39 00:02:12,910 --> 00:02:15,860 Now, I have some errors down here at the bottom, but that's okay. 40 00:02:15,860 --> 00:02:18,940 Take a look at pages 5 and 6 in our story map. 41 00:02:18,940 --> 00:02:21,270 These are the two final pages of the story, 42 00:02:21,270 --> 00:02:23,830 which means that we don't have any choices at this point. 43 00:02:23,830 --> 00:02:25,650 How should we handle this scenario? 44 00:02:25,650 --> 00:02:27,950 Once again, we could solve this a few different ways. 45 00:02:27,950 --> 00:02:32,158 But since we don't need any choices, let's add a second custom constructor in our 46 00:02:32,158 --> 00:02:35,295 page class that simply doesn't have any choice parameters. 47 00:02:35,295 --> 00:02:41,478 So back here I'm gonna add a new one up here and I'm going to generate it. 48 00:02:41,478 --> 00:02:46,760 Code > Generate a constructor, and this time I only want image and text. 49 00:02:47,860 --> 00:02:52,890 So, without setting any choice parameters, those will now be null by default. 50 00:02:52,890 --> 00:02:55,130 Now, for this scenario where it is a final page, 51 00:02:55,130 --> 00:02:58,980 I want to add one more variable that tells us so. 52 00:02:58,980 --> 00:03:04,041 So, here at the top, lets add private boolean isFinalPage. 53 00:03:06,312 --> 00:03:08,474 IsFinalPage will be false by default, but 54 00:03:08,474 --> 00:03:12,330 I'd like to make that explicitly clear by adding = false just to make sure. 55 00:03:13,948 --> 00:03:16,700 Now, inside of our new constructor, 56 00:03:16,700 --> 00:03:19,090 we can add another line to set final page to true. 57 00:03:20,110 --> 00:03:23,760 So this.isFinalPage in this case is true. 58 00:03:23,760 --> 00:03:26,510 We'll use this when we're crafting our story in just a little bit. 59 00:03:26,510 --> 00:03:29,360 We should add getters and setters for this new variable too, so 60 00:03:29,360 --> 00:03:31,660 I'm going to add a new line down here. 61 00:03:31,660 --> 00:03:36,430 Then click on Code and Generate > Getter and Setter for the new variable. 62 00:03:36,430 --> 00:03:37,930 Click OK and there we go. 63 00:03:39,040 --> 00:03:41,790 Our data model is complete and we have a story to read. 64 00:03:41,790 --> 00:03:45,460 In the past few videos, we explored how to turn the abstract data of this app 65 00:03:45,460 --> 00:03:48,540 into a set of concrete Java objects that we could use. 66 00:03:48,540 --> 00:03:51,360 The way we structured our objects allows us to store and 67 00:03:51,360 --> 00:03:55,330 manage the data separately from the view and controller parts of our app. 68 00:03:55,330 --> 00:03:57,840 Which is a core component of the MVC pattern. 69 00:03:57,840 --> 00:03:59,039 Now, I don't know about you but 70 00:03:59,039 --> 00:04:01,310 I am really excited to finally display our story in the app. 71 00:04:01,310 --> 00:04:02,620 So, why don't you take a break for 72 00:04:02,620 --> 00:04:05,050 a co-challenge, and then we will finish it up in the next section.