1
00:00:04,400 --> 00:00:09,060
Good day. Welcome back. We've allowed the user to change the day that a week starts

2
00:00:09,560 --> 00:00:13,160
on and modified the DatePickerFragment class to use that day.

3
00:00:13,960 --> 00:00:17,760
To test it, we need to make a change to our durations report.

4
00:00:22,160 --> 00:00:25,460
Now the DurationsReport class doesn't have a calendar.

5
00:00:26,060 --> 00:00:31,050
Rather than add one, I'm going to expose the FirstDayOfWeek

6
00:00:31,250 --> 00:00:33,550
property from the DurationsViewModel class.

7
00:00:34,350 --> 00:00:36,350
We want it to be read-only

8
00:00:36,350 --> 00:00:39,050
just like we've done for the DisplayWeek property.

9
00:00:55,600 --> 00:01:00,000
FirstDayOfWeek is now available to the durations report activity

10
00:01:00,000 --> 00:01:01,600
but it can't be changed by it.

11
00:01:02,500 --> 00:01:07,000
That gives us an error in BroadcastReceiver's onReceive function.

12
00:01:07,600 --> 00:01:10,700
We have to modify the _FirstDayOfWeek.

13
00:01:23,900 --> 00:01:25,600
In durations report,

14
00:01:25,600 --> 00:01:28,600
we can pass that value to the dialogues arguments

15
00:01:28,600 --> 00:01:31,100
in the ShowDatePickerDialog function.

16
00:01:45,900 --> 00:01:48,100
All right. Does it work?

17
00:01:49,100 --> 00:01:51,600
I'll run the app again and check the settings.

18
00:02:01,100 --> 00:02:03,460
The week's set to start on a Tuesday,

19
00:02:03,760 --> 00:02:06,360
so let's see how the date picker looks now.

20
00:02:14,660 --> 00:02:17,160
In reports, we've got data for the current week

21
00:02:17,660 --> 00:02:21,160
when I tap the calendar the week starts on a Tuesday

22
00:02:21,520 --> 00:02:23,320
and the dates showing in the report

23
00:02:23,320 --> 00:02:26,320
correctly reflect a week that starts on Tuesday.

24
00:02:27,320 --> 00:02:30,920
I'm not aware of any country that does start their week on a Tuesday,

25
00:02:31,220 --> 00:02:35,620
but our Australian users can now choose Monday or Sunday as their start

26
00:02:35,980 --> 00:02:38,180
day and have the calendar look as they expect.

27
00:02:39,380 --> 00:02:43,380
There's more testing you should do to make sure everything's working correctly.

28
00:02:43,880 --> 00:02:46,980
One obvious test is to make sure we haven't broken anything

29
00:02:46,980 --> 00:02:50,180
if the user hasn't set a starting day in the settings.

30
00:02:51,480 --> 00:02:55,140
That would involve uninstalling the app to clear the shared preferences.

31
00:02:55,940 --> 00:02:58,940
A quick way to test without uninstalling

32
00:02:59,340 --> 00:03:01,940
is to use the device file explorer

33
00:03:01,940 --> 00:03:04,290
to delete the shared preferences file.

34
00:03:05,540 --> 00:03:07,540
Doing that doesn't replace a proper test

35
00:03:07,940 --> 00:03:10,540
but it's a useful technique when you're still developing.

36
00:03:11,840 --> 00:03:13,240
If you do that

37
00:03:13,240 --> 00:03:18,140
be aware that android apps don't expect their preferences files to be deleted.

38
00:03:18,940 --> 00:03:21,200
You may have to run the app several times

39
00:03:21,200 --> 00:03:25,300
before it notices that there is no longer a shared preference file.

40
00:03:26,900 --> 00:03:30,500
We've added some code that only runs on API 21 and above.

41
00:03:31,300 --> 00:03:35,900
When you use a feature like that one that's not available on earlier versions,

42
00:03:36,400 --> 00:03:39,600
make sure you test the app on an earlier version.

43
00:03:40,500 --> 00:03:44,500
In this case that would be API 19 or earlier.

44
00:03:45,400 --> 00:03:49,200
API 20 was a version of API 19

45
00:03:49,200 --> 00:03:51,200
released for wearable devices,

46
00:03:51,700 --> 00:03:56,000
so you won't find an API 20 system image for the emulator.

47
00:03:56,800 --> 00:03:59,300
Okay. I'll stop this video here. In the next video,

48
00:03:59,900 --> 00:04:04,200
we'll add the settings option to our reports menu

49
00:04:04,700 --> 00:04:08,200
and see how we can observe changes to the shared preferences.

50
00:04:08,200 --> 00:04:09,100
See you there.

