1 00:00:04,730 --> 00:00:06,860 in this video I'm going to start the 2 00:00:06,860 --> 00:00:08,930 process of converting our calculator app 3 00:00:08,930 --> 00:00:11,389 to use a view model the calculator app 4 00:00:11,389 --> 00:00:12,890 that we've created earlier in the course 5 00:00:12,890 --> 00:00:15,200 is a very simple one so it'll be very 6 00:00:15,200 --> 00:00:17,180 easy to see how the view model 7 00:00:17,180 --> 00:00:19,820 fits into the overall architecture we'll 8 00:00:19,820 --> 00:00:21,110 see how to create and use a view model 9 00:00:21,110 --> 00:00:22,970 but more importantly what that view 10 00:00:22,970 --> 00:00:25,130 model can do for us and I just want to 11 00:00:25,130 --> 00:00:26,900 make it clear that this is a very simple 12 00:00:26,900 --> 00:00:28,609 example and you almost certainly 13 00:00:28,609 --> 00:00:31,130 wouldn't use a view model in this app in 14 00:00:31,130 --> 00:00:32,900 practice so they'll be clear I'm not 15 00:00:32,900 --> 00:00:34,760 suggesting that you use view models all 16 00:00:34,760 --> 00:00:37,339 the time we're converting this app to 17 00:00:37,339 --> 00:00:39,559 demonstrate how a view model separates 18 00:00:39,559 --> 00:00:42,650 the logic from the user interface UI so 19 00:00:42,650 --> 00:00:44,839 our main activities going to do nothing 20 00:00:44,839 --> 00:00:48,080 more than display the UI to the user and 21 00:00:48,080 --> 00:00:49,909 respond to events like buttons being 22 00:00:49,909 --> 00:00:52,729 tapped it responded to those events by 23 00:00:52,729 --> 00:00:54,890 calling functions in the view model and 24 00:00:54,890 --> 00:00:57,019 it's actually up to the view model as to 25 00:00:57,019 --> 00:00:58,610 what happens when those buttons are 26 00:00:58,610 --> 00:01:01,159 tapped the activity will observe the 27 00:01:01,159 --> 00:01:03,680 view model using live data so that it 28 00:01:03,680 --> 00:01:06,650 can reflect any changes in the UI that's 29 00:01:06,650 --> 00:01:09,710 all that's going to do display data call 30 00:01:09,710 --> 00:01:11,539 view model functions when UI events 31 00:01:11,539 --> 00:01:15,159 occur in update itself when data changes 32 00:01:15,159 --> 00:01:17,509 everything else will be handled by the 33 00:01:17,509 --> 00:01:20,390 view model in more complex apps there 34 00:01:20,390 --> 00:01:22,189 might perhaps be a business logic layer 35 00:01:22,189 --> 00:01:24,950 and a data base but we're taking baby 36 00:01:24,950 --> 00:01:26,630 steps and starting slowly here at the 37 00:01:26,630 --> 00:01:28,700 moment alright so as you can see on 38 00:01:28,700 --> 00:01:30,259 screen I've got the calculator app 39 00:01:30,259 --> 00:01:32,539 opened and this is the calculator app 40 00:01:32,539 --> 00:01:34,490 from earlier in the course we're going 41 00:01:34,490 --> 00:01:36,560 to start converting that to use view 42 00:01:36,560 --> 00:01:38,840 model you can download the project from 43 00:01:38,840 --> 00:01:40,909 the resources for the last video in the 44 00:01:40,909 --> 00:01:42,799 calculator section if you don't have it 45 00:01:42,799 --> 00:01:44,450 available locally on your computer now 46 00:01:44,450 --> 00:01:46,729 if you get problems opening the projects 47 00:01:46,729 --> 00:01:49,009 from the resources try the files in 48 00:01:49,009 --> 00:01:51,319 validate cases restart option other 49 00:01:51,319 --> 00:01:52,520 words up here if you happen to get an 50 00:01:52,520 --> 00:01:54,740 error file builder that caches restart 51 00:01:54,740 --> 00:01:56,719 and go ahead and click on invalidate and 52 00:01:56,719 --> 00:01:59,240 restart and you may also need to rebuild 53 00:01:59,240 --> 00:02:01,219 the project but in my case I've got it 54 00:02:01,219 --> 00:02:05,090 working okay and as it turns out before 55 00:02:05,090 --> 00:02:06,710 we start there are a few suggestions 56 00:02:06,710 --> 00:02:10,250 from Android studio in main activity if 57 00:02:10,250 --> 00:02:12,920 I score I don't have a look here you can 58 00:02:12,920 --> 00:02:15,560 see here we've got a suggestion there 59 00:02:15,560 --> 00:02:18,140 for Android studio regarding a lambda 60 00:02:18,140 --> 00:02:18,500 right him 61 00:02:18,500 --> 00:02:21,320 it actually says where lambda arguments 62 00:02:21,320 --> 00:02:23,230 should be moved out of parentheses and 63 00:02:23,230 --> 00:02:26,890 to do that I can just come over here 64 00:02:26,890 --> 00:02:29,720 click on the light bulb and there's an 65 00:02:29,720 --> 00:02:31,220 option there to move at land or argument 66 00:02:31,220 --> 00:02:32,810 out of parentheses I'm going to click on 67 00:02:32,810 --> 00:02:36,140 that that removes that first warning 68 00:02:36,140 --> 00:02:38,540 these lint checks are revolving all the 69 00:02:38,540 --> 00:02:40,790 time so don't be surprised when you come 70 00:02:40,790 --> 00:02:43,190 back to a project and find suggestions 71 00:02:43,190 --> 00:02:44,540 and warnings that weren't there before 72 00:02:44,540 --> 00:02:47,209 this was the case here now that we've 73 00:02:47,209 --> 00:02:48,290 changed that first one there's a 74 00:02:48,290 --> 00:02:49,790 suggestion also over here if I move out 75 00:02:49,790 --> 00:02:52,190 of view that the parameter view is never 76 00:02:52,190 --> 00:02:54,500 used and could be renamed or if we have 77 00:02:54,500 --> 00:02:56,030 a look at that warning again could be 78 00:02:56,030 --> 00:02:59,209 renamed to and underscore doing that 79 00:02:59,209 --> 00:03:00,830 tells the compiler that the parameter 80 00:03:00,830 --> 00:03:02,989 isn't used and also allows it to 81 00:03:02,989 --> 00:03:05,840 optimize the code sometimes but if we 82 00:03:05,840 --> 00:03:07,040 come over there and click on the light 83 00:03:07,040 --> 00:03:09,890 bulb there's an option over there for 84 00:03:09,890 --> 00:03:11,690 another option remove single lambda 85 00:03:11,690 --> 00:03:13,760 parameter declaration so I'm going to 86 00:03:13,760 --> 00:03:15,890 click on that to accept that suggestion 87 00:03:15,890 --> 00:03:18,470 as well alright so that's no turn it up 88 00:03:18,470 --> 00:03:20,209 we've no longer get anyone so you've got 89 00:03:20,209 --> 00:03:21,770 a green tick now in the top right-hand 90 00:03:21,770 --> 00:03:25,280 corner of that class so we now need to 91 00:03:25,280 --> 00:03:28,250 create a new Kotlin file class let's do 92 00:03:28,250 --> 00:03:29,810 that so I'm going to right click on the 93 00:03:29,810 --> 00:03:32,480 calculator package new Kotlin file class 94 00:03:32,480 --> 00:03:34,510 and we're going to call this one 95 00:03:34,510 --> 00:03:40,400 calculator view model okay there's a 96 00:03:40,400 --> 00:03:42,739 view model and the class declaration 97 00:03:42,739 --> 00:03:46,580 line will be class calculator view model 98 00:03:46,580 --> 00:03:48,500 and we need to extend the view model 99 00:03:48,500 --> 00:03:50,239 class to create the view model for this 100 00:03:50,239 --> 00:03:55,370 app so it's : view model and then 101 00:03:55,370 --> 00:03:58,100 parentheses then left or right curly 102 00:03:58,100 --> 00:04:01,549 braces if you were prompted make sure 103 00:04:01,549 --> 00:04:03,650 you import the class from Android arch 104 00:04:03,650 --> 00:04:05,810 that life cycle don't view model but you 105 00:04:05,810 --> 00:04:07,280 can see in line three the imports happen 106 00:04:07,280 --> 00:04:09,110 for me automatically all right so now 107 00:04:09,110 --> 00:04:10,790 that we've done that the next step is to 108 00:04:10,790 --> 00:04:13,280 move everything out of the main activity 109 00:04:13,280 --> 00:04:16,040 class that's not related to the UI so 110 00:04:16,040 --> 00:04:18,290 any processing and all state will be 111 00:04:18,290 --> 00:04:20,899 moved to the view model what I say all 112 00:04:20,899 --> 00:04:23,630 state I mean all state that's not 113 00:04:23,630 --> 00:04:26,330 related to the UI the activity will 114 00:04:26,330 --> 00:04:27,800 still take care of restoring the 115 00:04:27,800 --> 00:04:30,380 contents of edit text widgets following 116 00:04:30,380 --> 00:04:32,270 following a rotation for example 117 00:04:32,270 --> 00:04:34,010 but that's handled by Android anyway 118 00:04:34,010 --> 00:04:36,140 along the way as we do this we're going 119 00:04:36,140 --> 00:04:38,330 to get a lot of errors but that's good 120 00:04:38,330 --> 00:04:40,160 because it highlights the bits of code 121 00:04:40,160 --> 00:04:42,020 that we would be looking at now all that 122 00:04:42,020 --> 00:04:43,760 we should be looking at rather so 123 00:04:43,760 --> 00:04:49,100 opening up our main activity you can see 124 00:04:49,100 --> 00:04:50,330 right at the top here we've got a couple 125 00:04:50,330 --> 00:04:52,490 of variables destroying the operand and 126 00:04:52,490 --> 00:04:54,260 the pending operation now they're 127 00:04:54,260 --> 00:04:57,080 functional not UI variables so I'm going 128 00:04:57,080 --> 00:04:58,190 to cut them out of here 129 00:04:58,190 --> 00:04:59,690 along with the comment that we added to 130 00:04:59,690 --> 00:05:01,940 that effect and we're gonna paste them 131 00:05:01,940 --> 00:05:03,950 at the top of the calculator view model 132 00:05:03,950 --> 00:05:10,520 class okay back to our calculator your 133 00:05:10,520 --> 00:05:11,810 model and I'm going to paste it directly 134 00:05:11,810 --> 00:05:14,000 in the class there for our calculator 135 00:05:14,000 --> 00:05:15,770 view model and obviously now that I've 136 00:05:15,770 --> 00:05:17,240 done that as expected 137 00:05:17,240 --> 00:05:19,940 we've got a load of errors now we're 138 00:05:19,940 --> 00:05:21,050 going to go through this process of 139 00:05:21,050 --> 00:05:23,420 fixing those so looking now at the 140 00:05:23,420 --> 00:05:25,280 various functions that are in this class 141 00:05:25,280 --> 00:05:27,650 an obvious function that's got nothing 142 00:05:27,650 --> 00:05:29,810 to do with their UI is this perform 143 00:05:29,810 --> 00:05:32,330 operation function if you recall that 144 00:05:32,330 --> 00:05:34,460 takes care of the calculating and we can 145 00:05:34,460 --> 00:05:36,740 freely move that into the view model so 146 00:05:36,740 --> 00:05:38,390 I'm going to cut this function entirely 147 00:05:38,390 --> 00:05:41,360 out of main activity and then we'll 148 00:05:41,360 --> 00:05:43,960 paste it into the calculator view model 149 00:05:43,960 --> 00:05:46,790 there cutting that out calculate a view 150 00:05:46,790 --> 00:05:49,970 model I'm going to paste that in now 151 00:05:49,970 --> 00:05:51,140 that when you do that you get this 152 00:05:51,140 --> 00:05:54,770 option about accepting or is it okay to 153 00:05:54,770 --> 00:05:57,110 accept the synthetic imports we don't 154 00:05:57,110 --> 00:05:58,880 want to do that so I'm gonna click on 155 00:05:58,880 --> 00:06:02,030 cancel here instead just make a bit of 156 00:06:02,030 --> 00:06:04,280 space so this is battaglia remember that 157 00:06:04,280 --> 00:06:06,350 the view model mustn't hold any 158 00:06:06,350 --> 00:06:08,330 reference to the activity referring to 159 00:06:08,330 --> 00:06:10,100 the activities widget is a definite 160 00:06:10,100 --> 00:06:11,360 no-no which is the reason we've 161 00:06:11,360 --> 00:06:13,130 cancelled that if you did happen to 162 00:06:13,130 --> 00:06:15,440 accept the imports by mistake don't 163 00:06:15,440 --> 00:06:17,270 worry we can't delete them later once we 164 00:06:17,270 --> 00:06:19,490 change the code or you can just do an 165 00:06:19,490 --> 00:06:22,280 undo and repeat the operation but for 166 00:06:22,280 --> 00:06:24,710 now you saw that I didn't accept those 167 00:06:24,710 --> 00:06:26,900 synthetic imports so go back to main 168 00:06:26,900 --> 00:06:29,450 activity again you can see that there's 169 00:06:29,450 --> 00:06:31,460 no errors in the unsaved instance state 170 00:06:31,460 --> 00:06:34,100 and on restore instance state functions 171 00:06:34,100 --> 00:06:36,590 we're not interested in saving State now 172 00:06:36,590 --> 00:06:39,140 that's the job of the view model so I'm 173 00:06:39,140 --> 00:06:40,850 going to delete these two functions 174 00:06:40,850 --> 00:06:45,220 entirely 175 00:06:45,220 --> 00:06:48,260 and once we do that we go back up to the 176 00:06:48,260 --> 00:06:50,480 top of the file we've got these three 177 00:06:50,480 --> 00:06:53,780 constants here now then longer being 178 00:06:53,780 --> 00:06:55,940 used is there the bundle keys so for 179 00:06:55,940 --> 00:06:57,680 that reason we can now delete those 180 00:06:57,680 --> 00:07:01,130 entirely now we're really breaking 181 00:07:01,130 --> 00:07:02,540 things at this point because we never 182 00:07:02,540 --> 00:07:04,550 got errors in both classes both 183 00:07:04,550 --> 00:07:06,620 mainactivity and calculator view model 184 00:07:06,620 --> 00:07:09,110 showing errors but that's actually quite 185 00:07:09,110 --> 00:07:10,760 normal when you perform a significant 186 00:07:10,760 --> 00:07:13,070 refactor to an application like we're 187 00:07:13,070 --> 00:07:15,590 doing right now let's move over now and 188 00:07:15,590 --> 00:07:18,280 focus on the calculator view model class 189 00:07:18,280 --> 00:07:21,140 now in our perform operation function 190 00:07:21,140 --> 00:07:22,610 the last two lines are referring to 191 00:07:22,610 --> 00:07:24,440 widgets in the activity now that's for 192 00:07:24,440 --> 00:07:26,060 bidness we know to access widgets 193 00:07:26,060 --> 00:07:28,040 directly so we need to change those 194 00:07:28,040 --> 00:07:30,830 lines to use local variables instead and 195 00:07:30,830 --> 00:07:32,600 I'll do that in a moment now these are 196 00:07:32,600 --> 00:07:34,610 the this is the code with errors on 197 00:07:34,610 --> 00:07:37,190 lines of 37 and 38 when we come to 198 00:07:37,190 --> 00:07:38,810 change a widget reference to a variable 199 00:07:38,810 --> 00:07:41,180 it's obvious then that the widget isn't 200 00:07:41,180 --> 00:07:43,160 going to be updated these two lines 201 00:07:43,160 --> 00:07:45,410 update the result in the display if we 202 00:07:45,410 --> 00:07:47,510 don't update the widget then obviously 203 00:07:47,510 --> 00:07:49,370 we need some other way of showing the 204 00:07:49,370 --> 00:07:51,380 result back in the UI this is where the 205 00:07:51,380 --> 00:07:54,080 Android live data class comes in we saw 206 00:07:54,080 --> 00:07:55,760 that mentioned in the documentation in 207 00:07:55,760 --> 00:07:57,950 the previous video and if you could I 208 00:07:57,950 --> 00:07:59,000 have a few which I'm just gonna bring up 209 00:07:59,000 --> 00:08:03,890 in the browser now you can see here that 210 00:08:03,890 --> 00:08:06,710 says live data is an observable data 211 00:08:06,710 --> 00:08:09,260 holder class so that means that our 212 00:08:09,260 --> 00:08:12,230 activity can observe it and react when 213 00:08:12,230 --> 00:08:15,230 it changes live data is also life cycle 214 00:08:15,230 --> 00:08:17,180 aware it won't attempt to notify an 215 00:08:17,180 --> 00:08:19,130 observer about changes unless the 216 00:08:19,130 --> 00:08:21,290 observer is active so how to read 217 00:08:21,290 --> 00:08:23,360 through this document and also follow 218 00:08:23,360 --> 00:08:25,460 the various links once we've got this 219 00:08:25,460 --> 00:08:27,650 calculator app working because it 220 00:08:27,650 --> 00:08:28,880 describes how activities are 221 00:08:28,880 --> 00:08:31,040 automatically and subscribed when they 222 00:08:31,040 --> 00:08:33,200 get destroyed for example we don't have 223 00:08:33,200 --> 00:08:35,539 to concern ourselves with unsubscribing 224 00:08:35,539 --> 00:08:37,159 manually and we'll also get 225 00:08:37,159 --> 00:08:39,559 automatically subscribed again if the 226 00:08:39,559 --> 00:08:42,200 activity is recreated as a result of a 227 00:08:42,200 --> 00:08:44,120 configuration change now if we scroll 228 00:08:44,120 --> 00:08:46,460 down a little bit down here you'll be 229 00:08:46,460 --> 00:08:47,690 able to see that there's a section here 230 00:08:47,690 --> 00:08:49,970 called working with live data objects 231 00:08:49,970 --> 00:08:51,830 this will make more sense when you've 232 00:08:51,830 --> 00:08:53,690 seen them used in our app so I do 233 00:08:53,690 --> 00:08:55,340 suggest you come back to this later and 234 00:08:55,340 --> 00:08:57,320 most of what we're going to do is 235 00:08:57,320 --> 00:08:58,070 covered here 236 00:08:58,070 --> 00:09:00,589 the section down here create live data 237 00:09:00,589 --> 00:09:04,370 objects show some sample code to create 238 00:09:04,370 --> 00:09:06,860 a live data object this is still Java 239 00:09:06,860 --> 00:09:08,990 code but Google are updating all their 240 00:09:08,990 --> 00:09:11,149 examples there is something wrong with 241 00:09:11,149 --> 00:09:13,250 that example though we'll see what that 242 00:09:13,250 --> 00:09:14,449 is when we've checked out the next 243 00:09:14,449 --> 00:09:16,490 section I want to look at so scrolling a 244 00:09:16,490 --> 00:09:18,170 little bit further we're going to get to 245 00:09:18,170 --> 00:09:21,980 the update live data object section this 246 00:09:21,980 --> 00:09:25,190 one here update live data objects this 247 00:09:25,190 --> 00:09:27,170 talks about or which reduces another 248 00:09:27,170 --> 00:09:29,240 class this is the mutable live data 249 00:09:29,240 --> 00:09:32,120 class in fact scrolling up a bit if we 250 00:09:32,120 --> 00:09:33,560 come up and look at our code example 251 00:09:33,560 --> 00:09:37,430 there you can see here that in current 252 00:09:37,430 --> 00:09:39,680 name is to clear this immutable live 253 00:09:39,680 --> 00:09:43,339 data type so a live data object doesn't 254 00:09:43,339 --> 00:09:45,440 have any functions for updating it you 255 00:09:45,440 --> 00:09:47,449 have to use a mutable live data for that 256 00:09:47,449 --> 00:09:49,040 and that's actually what's wrong with 257 00:09:49,040 --> 00:09:51,709 this example code here the mutable live 258 00:09:51,709 --> 00:09:55,399 data object in current name is public or 259 00:09:55,399 --> 00:09:57,680 more specifically the get current name 260 00:09:57,680 --> 00:10:00,560 get a method that exposes it is public 261 00:10:00,560 --> 00:10:02,839 and returns a mutable live data object 262 00:10:02,839 --> 00:10:05,029 so that means there's nothing to prevent 263 00:10:05,029 --> 00:10:07,579 the UI from updating it this snippet 264 00:10:07,579 --> 00:10:10,639 shows basic usage not necessarily best 265 00:10:10,639 --> 00:10:12,980 practice the activity could call the set 266 00:10:12,980 --> 00:10:15,620 value function to change M current name 267 00:10:15,620 --> 00:10:18,050 it shouldn't the whole point of this 268 00:10:18,050 --> 00:10:21,019 exercise is to separate the UI from the 269 00:10:21,019 --> 00:10:23,120 apps logic but there's nothing at the 270 00:10:23,120 --> 00:10:24,829 moment to prevent it with this example 271 00:10:24,829 --> 00:10:27,260 code so when you go to the trouble of 272 00:10:27,260 --> 00:10:29,209 finding these documents read them 273 00:10:29,209 --> 00:10:31,370 carefully even if some of it doesn't 274 00:10:31,370 --> 00:10:33,019 make sense it'll be there in the back of 275 00:10:33,019 --> 00:10:35,180 your mind you'll be surprised how often 276 00:10:35,180 --> 00:10:37,130 something that doesn't make sense 277 00:10:37,130 --> 00:10:39,560 suddenly does when it's time to need it 278 00:10:39,560 --> 00:10:41,300 and actually use it alright so I 279 00:10:41,300 --> 00:10:43,279 apologize for all the scrolling but I'll 280 00:10:43,279 --> 00:10:45,260 just scroll back down now to the update 281 00:10:45,260 --> 00:10:48,980 live data object section here it's 282 00:10:48,980 --> 00:10:51,560 talking about the set value and post 283 00:10:51,560 --> 00:10:54,259 value methods of the mutable live data 284 00:10:54,259 --> 00:10:56,810 object he used these to modify their 285 00:10:56,810 --> 00:11:00,110 values will be using set value but if 286 00:11:00,110 --> 00:11:02,060 the code that's changing them is running 287 00:11:02,060 --> 00:11:04,399 on a separate thread in an async task 288 00:11:04,399 --> 00:11:06,920 for example then you'd use post value 289 00:11:06,920 --> 00:11:09,589 instead of course we're using Kotlin not 290 00:11:09,589 --> 00:11:11,300 Java so we'll refer 291 00:11:11,300 --> 00:11:13,310 to the value and post value attributes 292 00:11:13,310 --> 00:11:16,040 instead of calling this setters the 293 00:11:16,040 --> 00:11:19,339 final sentence of that or in that first 294 00:11:19,339 --> 00:11:21,589 paragraph is why I suggest reading the 295 00:11:21,589 --> 00:11:23,810 entire document even if you think you've 296 00:11:23,810 --> 00:11:25,399 found what you need further up it 297 00:11:25,399 --> 00:11:28,360 actually says there that up here usually 298 00:11:28,360 --> 00:11:30,950 mutable live data was used in the view 299 00:11:30,950 --> 00:11:32,779 model and then the view model only 300 00:11:32,779 --> 00:11:36,260 exposes immutable law of data objects to 301 00:11:36,260 --> 00:11:38,510 the observers so we're going to start 302 00:11:38,510 --> 00:11:40,100 off exposing the mutable live data 303 00:11:40,100 --> 00:11:42,050 objects and then we'll change the code 304 00:11:42,050 --> 00:11:45,050 to only expose live data which the 305 00:11:45,050 --> 00:11:47,360 activity can't change alright so back to 306 00:11:47,360 --> 00:11:50,269 our code so at the moment we've got two 307 00:11:50,269 --> 00:11:53,209 references to two widgets so we need to 308 00:11:53,209 --> 00:11:56,450 replace those with live data objects so 309 00:11:56,450 --> 00:11:58,910 let's actually declare the two objects 310 00:11:58,910 --> 00:12:02,839 first so below the private fire pending 311 00:12:02,839 --> 00:12:07,730 operation line move into eval result is 312 00:12:07,730 --> 00:12:10,720 equal to it's going to be mutable live 313 00:12:10,720 --> 00:12:16,970 data of top string and let the 314 00:12:16,970 --> 00:12:19,339 parenthesis on the end I'm going to do 315 00:12:19,339 --> 00:12:22,250 this same for new numbers had Val new 316 00:12:22,250 --> 00:12:26,120 number equals it's going to also be a 317 00:12:26,120 --> 00:12:29,450 mutable live data or type string there 318 00:12:29,450 --> 00:12:32,959 and we can have the parentheses again so 319 00:12:32,959 --> 00:12:34,190 now that we've done that we can replace 320 00:12:34,190 --> 00:12:36,649 these two widget references down here on 321 00:12:36,649 --> 00:12:40,130 line 41 and 42 with our mutable live 322 00:12:40,130 --> 00:12:42,589 data objects so I've used the same names 323 00:12:42,589 --> 00:12:45,200 so the change is trivial instead of 324 00:12:45,200 --> 00:12:47,209 setting the text all we need to do is 325 00:12:47,209 --> 00:12:49,490 set the value instead of result dot set 326 00:12:49,490 --> 00:12:51,140 text we're going to change that to 327 00:12:51,140 --> 00:12:55,579 result dot value equals and get rid of 328 00:12:55,579 --> 00:12:58,610 the parentheses and operand 1 dot 2 329 00:12:58,610 --> 00:13:00,709 string and on the next line it's going 330 00:13:00,709 --> 00:13:03,050 to be a new number and set up text it's 331 00:13:03,050 --> 00:13:05,810 going to be value equals and I'll remove 332 00:13:05,810 --> 00:13:07,279 the parentheses and leave the double 333 00:13:07,279 --> 00:13:09,410 quotes in there now if you had some 334 00:13:09,410 --> 00:13:11,470 synthetic imports at the top of the file 335 00:13:11,470 --> 00:13:14,209 in the input section they should now 336 00:13:14,209 --> 00:13:16,100 have been removed if not though you 337 00:13:16,100 --> 00:13:18,230 could safely delete them we're using 338 00:13:18,230 --> 00:13:20,570 these variables now not references to 339 00:13:20,570 --> 00:13:22,970 the activities widgets as you can see I 340 00:13:22,970 --> 00:13:24,050 haven't got any of those synthetic 341 00:13:24,050 --> 00:13:25,220 imports showing anymore 342 00:13:25,220 --> 00:13:28,009 all right so let's end the video here in 343 00:13:28,009 --> 00:13:29,300 the next video we've still got some work 344 00:13:29,300 --> 00:13:30,500 to do because we've still got some 345 00:13:30,500 --> 00:13:33,079 errors showing in main activity so let's 346 00:13:33,079 --> 00:13:34,910 work on cleaning the main activity class 347 00:13:34,910 --> 00:13:38,259 up in the next video