1
00:00:05,000 --> 00:00:06,200
Welcome back, everyone.

2
00:00:06,200 --> 00:00:09,900
In the last video we moved the code to access the database

3
00:00:09,900 --> 00:00:11,200
into our ViewModel.

4
00:00:11,600 --> 00:00:14,900
To test the change we need to make some changes

5
00:00:14,900 --> 00:00:16,900
to the durations report activity.

6
00:00:17,450 --> 00:00:20,750
First, I'll declare an instance of our ViewModel

7
00:00:21,110 --> 00:00:23,110
and use lazy initialization.

8
00:00:34,510 --> 00:00:36,810
In the oncreate function,

9
00:00:36,810 --> 00:00:41,410
we'll observe the durations ViewModel instead of calling LoadData.

10
00:00:51,610 --> 00:00:54,110
If you're prompted for the observer import,

11
00:00:54,110 --> 00:00:58,310
make sure you choose androidx.lifecycle.observer.

12
00:00:59,300 --> 00:01:02,180
All right. Our activity is still very basic.

13
00:01:02,180 --> 00:01:05,180
We've got to add the ability to select different dates

14
00:01:05,180 --> 00:01:06,620
and sort by columns,

15
00:01:06,620 --> 00:01:10,320
but it should still work. I like to test apps often

16
00:01:10,320 --> 00:01:12,520
whenever they're in a state that should run,

17
00:01:12,520 --> 00:01:17,420
so does it work, run the app and tap the reports icon.

18
00:01:22,320 --> 00:01:25,920
And that looks good. We've got our data for May displayed.

19
00:01:26,470 --> 00:01:28,460
Make sure the logcat's visible,

20
00:01:30,060 --> 00:01:32,660
and add a comment rotating at the end.

21
00:01:35,260 --> 00:01:37,260
Next, rotate the device.

22
00:01:43,460 --> 00:01:46,460
This time the database isn't re-queried.

23
00:01:46,960 --> 00:01:50,460
That's good. We've kept our durations report activity

24
00:01:50,460 --> 00:01:52,460
focused just on the UI

25
00:01:52,860 --> 00:01:55,160
and also prevented unnecessary work.

26
00:01:55,960 --> 00:01:58,160
I know we're using a local database here,

27
00:01:58,460 --> 00:02:01,060
but it's still going to save the user's batteries,

28
00:02:01,560 --> 00:02:05,960
and you can use exactly this approach when collecting data over the internet.

29
00:02:07,060 --> 00:02:09,759
That would have a far greater impact on battery life

30
00:02:10,160 --> 00:02:14,160
and also on your users pockets if they're on a meted connection.

31
00:02:14,960 --> 00:02:19,560
In the next, video we'll start adding the remaining functionality to the reports.

32
00:02:20,260 --> 00:02:23,250
We've still got to allow the report to be filtered by date

33
00:02:23,550 --> 00:02:26,150
display either a single day or a full week

34
00:02:26,850 --> 00:02:29,510
and implement sorting by the various columns.

35
00:02:30,060 --> 00:02:32,060
We've got lots to do, I'll see you there.

