1 00:00:04,730 --> 00:00:06,530 all right so remote all our changes in 2 00:00:06,530 --> 00:00:08,360 the last three videos to our top ten 3 00:00:08,360 --> 00:00:10,250 downloader it's now time to check this 4 00:00:10,250 --> 00:00:12,110 out does it actually work what I'm gonna 5 00:00:12,110 --> 00:00:14,389 do first is put a log cat into floating 6 00:00:14,389 --> 00:00:24,109 mode so we can actually see this and 7 00:00:24,109 --> 00:00:26,240 we'll run our application as always I 8 00:00:26,240 --> 00:00:28,369 fast forward this to get it showing 9 00:00:28,369 --> 00:00:33,630 quickly 10 00:00:33,630 --> 00:00:35,130 all right so so far so good the app 11 00:00:35,130 --> 00:00:37,110 seems to be running but we've got a lot 12 00:00:37,110 --> 00:00:39,750 of data in the logging here 13 00:00:39,750 --> 00:00:41,070 I think we're logging a bit too much 14 00:00:41,070 --> 00:00:43,110 here so let's comment out some of this 15 00:00:43,110 --> 00:00:46,290 stuff so look at our paws applications 16 00:00:46,290 --> 00:00:49,790 class so let's move tag to be consistent 17 00:00:49,790 --> 00:00:52,980 outside of the class and also make it a 18 00:00:52,980 --> 00:00:56,670 constant and we'll also take the 19 00:00:56,670 --> 00:00:58,890 opportunity to remove the logging on 20 00:00:58,890 --> 00:01:00,510 line 16 so I want to just comment that 21 00:01:00,510 --> 00:01:01,640 line out again 22 00:01:01,640 --> 00:01:08,970 so let's now run the up again okay so I 23 00:01:08,970 --> 00:01:10,710 think there's a bit tidier and if you do 24 00:01:10,710 --> 00:01:12,240 get some error or information log 25 00:01:12,240 --> 00:01:13,500 entries from other parts of the system 26 00:01:13,500 --> 00:01:15,360 and I've got some there now you can 27 00:01:15,360 --> 00:01:17,190 filter them out what I'm going to do is 28 00:01:17,190 --> 00:01:19,950 just just show debug only errors but 29 00:01:19,950 --> 00:01:22,680 simple ways D capital D zap forward 30 00:01:22,680 --> 00:01:24,600 slash and you can see that makes it much 31 00:01:24,600 --> 00:01:26,490 easier to try and focus on just what 32 00:01:26,490 --> 00:01:27,990 we've got we've got a few other things 33 00:01:27,990 --> 00:01:29,729 there but it is a lot easy to see all of 34 00:01:29,729 --> 00:01:32,280 our entries now right so before checking 35 00:01:32,280 --> 00:01:33,750 for unnecessary downloads I want to make 36 00:01:33,750 --> 00:01:35,250 sure the app still works and it's just 37 00:01:35,250 --> 00:01:37,800 tab back over to that first thing I'm 38 00:01:37,800 --> 00:01:42,210 going to select songs from the list then 39 00:01:42,210 --> 00:01:44,700 we saw there that download our download 40 00:01:44,700 --> 00:01:46,890 URL got called if you scroll over and 41 00:01:46,890 --> 00:01:48,390 have a look we can see that other these 42 00:01:48,390 --> 00:01:51,300 songs was actually called there the 43 00:01:51,300 --> 00:01:52,350 download URL was called 44 00:01:52,350 --> 00:01:54,149 doing background was in turn called and 45 00:01:54,149 --> 00:01:56,490 because the URL had changed that set off 46 00:01:56,490 --> 00:01:58,800 the new async task the download the 47 00:01:58,800 --> 00:02:00,149 doing background was an executed from 48 00:02:00,149 --> 00:02:02,490 the download data racing task have feed 49 00:02:02,490 --> 00:02:04,289 view models on data available functions 50 00:02:04,289 --> 00:02:06,869 getting called there as you can see and 51 00:02:06,869 --> 00:02:08,490 when the live data object gets updated 52 00:02:08,490 --> 00:02:10,380 main activities picking up those changes 53 00:02:10,380 --> 00:02:12,630 and it's updating the data as you can 54 00:02:12,630 --> 00:02:15,120 see there in the interface so that's 55 00:02:15,120 --> 00:02:17,250 looking good let's try the top 25 56 00:02:17,250 --> 00:02:20,690 instead of the top 10 so select top 25 57 00:02:20,690 --> 00:02:22,980 you can see it clearly we've got more 58 00:02:22,980 --> 00:02:24,300 songs showing up there so that's good 59 00:02:24,300 --> 00:02:28,410 and in terms of our log entries with the 60 00:02:28,410 --> 00:02:30,569 top 25 being downloaded they're on data 61 00:02:30,569 --> 00:02:34,890 available being called again so so far 62 00:02:34,890 --> 00:02:36,630 so good just before I rotate the device 63 00:02:36,630 --> 00:02:37,770 I'm going to top an entry in the lock 64 00:02:37,770 --> 00:02:41,700 rotating and let's try rotating it now 65 00:02:41,700 --> 00:02:46,000 and see what happens 66 00:02:46,000 --> 00:02:48,220 and looking at the data you can see that 67 00:02:48,220 --> 00:02:49,930 data is still there clearly you've got 68 00:02:49,930 --> 00:02:51,700 that there but looking at the log entry 69 00:02:51,700 --> 00:02:55,030 though and accidentally scrolled in so I 70 00:02:55,030 --> 00:02:55,990 go back down to the end and see what 71 00:02:55,990 --> 00:02:57,910 happened so we've got our rotating it 72 00:02:57,910 --> 00:03:00,010 tree that I added there firstly notice 73 00:03:00,010 --> 00:03:02,200 notice how quick the data reloaded when 74 00:03:02,200 --> 00:03:04,900 I did rotate into landscape and that's 75 00:03:04,900 --> 00:03:06,340 because the data didn't have to be 76 00:03:06,340 --> 00:03:08,200 downloaded again and we can see there 77 00:03:08,200 --> 00:03:10,410 that the activities uncreate was called 78 00:03:10,410 --> 00:03:13,320 so activity was destroyed and recreated 79 00:03:13,320 --> 00:03:15,640 because of that that caused the download 80 00:03:15,640 --> 00:03:17,770 URL function to be called again and you 81 00:03:17,770 --> 00:03:18,910 can see it was called within them Anika 82 00:03:18,910 --> 00:03:21,400 was 25 again but this time because of 83 00:03:21,400 --> 00:03:23,590 the Euro hasn't changed and the v-model 84 00:03:23,590 --> 00:03:24,880 still has all the data 85 00:03:24,880 --> 00:03:26,530 there's no download needed you can see 86 00:03:26,530 --> 00:03:28,840 clearly there there wasn't a call to our 87 00:03:28,840 --> 00:03:31,660 download data async task as there was 88 00:03:31,660 --> 00:03:34,120 previously the adapters populated with 89 00:03:34,120 --> 00:03:35,860 the current data and the app appears 90 00:03:35,860 --> 00:03:37,650 much slicker than it did before and 91 00:03:37,650 --> 00:03:40,150 we've also saved battery life and 92 00:03:40,150 --> 00:03:42,220 avoided additional data costs for our 93 00:03:42,220 --> 00:03:44,260 users as well all right so that's pretty 94 00:03:44,260 --> 00:03:45,910 cool and now that brings to an end this 95 00:03:45,910 --> 00:03:48,190 section in our introduction to view 96 00:03:48,190 --> 00:03:51,280 model and live data so keep in mind that 97 00:03:51,280 --> 00:03:52,720 Google have now deprecated the lower 98 00:03:52,720 --> 00:03:55,000 classes but if you use them I think 99 00:03:55,000 --> 00:03:56,620 you'll agree that the view model that 100 00:03:56,620 --> 00:03:59,950 replaces them is easy to use and I think 101 00:03:59,950 --> 00:04:02,200 it's more flexible as well combined with 102 00:04:02,200 --> 00:04:04,989 live data it's a great way to separate 103 00:04:04,989 --> 00:04:07,510 your UI from other logic and also solves 104 00:04:07,510 --> 00:04:09,880 many of the lifecycle problems that we 105 00:04:09,880 --> 00:04:11,709 sometimes struggle with Android 106 00:04:11,709 --> 00:04:13,690 development now a lot easier as a result 107 00:04:13,690 --> 00:04:15,640 will be using view model again in our 108 00:04:15,640 --> 00:04:17,829 data base app we originally used to 109 00:04:17,829 --> 00:04:19,570 cursorloader but now that that's been 110 00:04:19,570 --> 00:04:21,668 deprecated we've rewritten it to use a 111 00:04:21,668 --> 00:04:23,919 view model instead so we'll see you in 112 00:04:23,919 --> 00:04:25,360 the next section when we start work on 113 00:04:25,360 --> 00:04:27,540 that