1
00:00:04,100 --> 00:00:05,100
Welcome back.

2
00:00:05,700 --> 00:00:09,700
We've allowed our users to change a couple of things for the TaskTimer app,

3
00:00:10,700 --> 00:00:12,400
that was in an earlier section.

4
00:00:12,650 --> 00:00:15,650
So I'll quickly review what it is they can configure.

5
00:00:16,250 --> 00:00:20,050
I've got the app running in the emulator, and I'll go to the settings menu.

6
00:00:24,410 --> 00:00:26,770
We can change which day starts the week

7
00:00:27,270 --> 00:00:29,770
and we can also choose to ignore timings

8
00:00:29,770 --> 00:00:33,370
that are less than a certain number of seconds or minutes

9
00:00:33,370 --> 00:00:35,070
if that's what the user wants to do.

10
00:00:36,060 --> 00:00:39,960
We'll start by implementing that first day of the week setting,

11
00:00:40,860 --> 00:00:43,740
that will make some of our Australian users happy

12
00:00:43,740 --> 00:00:46,540
because they like to start their weeks on a Monday

13
00:00:46,900 --> 00:00:48,900
and currently it starts on a Sunday.

14
00:00:50,100 --> 00:00:54,460
At the moment, the app starts the week on a day determined by the user's locale.

15
00:00:54,960 --> 00:00:57,560
That's how the Gregorian calendar class works.

16
00:00:57,920 --> 00:01:01,920
That's a sensible default to use if they haven't changed any of the settings.

17
00:01:02,820 --> 00:01:05,820
I've left my emulator set to English Australia,

18
00:01:06,220 --> 00:01:09,420
and the settings dialog is currently showing Sunday

19
00:01:09,420 --> 00:01:11,020
as the day that the week starts on.

20
00:01:12,320 --> 00:01:15,620
I'll cancel the dialogue and switch the phone's settings

21
00:01:15,620 --> 00:01:18,920
to change locale to English United Kingdom.

22
00:01:38,520 --> 00:01:40,520
If I go into settings again,

23
00:01:44,520 --> 00:01:47,510
this time the default first day is Monday.

24
00:01:48,110 --> 00:01:51,510
We allow the user to change that. But at the moment,

25
00:01:51,510 --> 00:01:53,610
we're not using their choice in our code.

26
00:01:54,210 --> 00:01:55,910
We'll implement that now.

27
00:01:56,570 --> 00:01:59,170
We do that in our DurationsViewModel.

28
00:02:00,530 --> 00:02:04,930
I'll start by creating a couple of variables for the shared preferences

29
00:02:05,180 --> 00:02:07,180
that we're going to get the settings from

30
00:02:07,580 --> 00:02:10,880
and the first day of the week variable to store the value.

31
00:03:10,180 --> 00:03:12,980
Settings is a reference to the shared preferences

32
00:03:12,980 --> 00:03:14,980
that our settings dialog uses.

33
00:03:15,380 --> 00:03:18,680
We then retrieve the settings FirstDayOfweek preference

34
00:03:18,880 --> 00:03:22,240
and return the calendars FirstDayOfWeek value

35
00:03:22,240 --> 00:03:26,340
if a preference hasn't been saved yet. In the init block,

36
00:03:26,640 --> 00:03:29,940
we'll use that value to tell the calendar which day

37
00:03:29,940 --> 00:03:31,300
it should start the week on.

38
00:03:41,800 --> 00:03:45,160
I've logged the value to make it easier to check that everything's working.

39
00:03:46,260 --> 00:03:50,460
We also need to set the FirstDayOfTheWeek in our BroadcastReceiver

40
00:03:50,820 --> 00:03:53,720
because we create a new calendar instance there.

41
00:04:08,380 --> 00:04:12,280
Okay. That's all we need to change for our app to use the FirstDayOfTheWeek

42
00:04:12,280 --> 00:04:13,270
that our user wants.

43
00:04:14,070 --> 00:04:15,570
Let's see if it works.

44
00:04:19,170 --> 00:04:21,769
Run the app, and go into the reports.

45
00:04:23,670 --> 00:04:27,030
I've still got my emulators locale set to the United Kingdom.

46
00:04:27,530 --> 00:04:31,830
So the calendar should show Monday as the first day of the week.

47
00:04:32,330 --> 00:04:36,530
Tap the calendar icon to check, set the date to the 14th of June

48
00:04:36,530 --> 00:04:37,730
2019.

49
00:04:43,050 --> 00:04:46,350
That's a Friday. And when I tap okay,

50
00:04:48,710 --> 00:04:52,310
our report is showing data for the 10th

51
00:04:52,310 --> 00:04:53,910
to the 16th of June.

52
00:04:54,900 --> 00:04:58,800
We're going to improve this next bit shortly. At the moment,

53
00:04:58,800 --> 00:05:01,800
I have to return to the main screen to access the settings.

54
00:05:02,600 --> 00:05:06,800
I'll choose Tuesday from the dropdown and tap okay.

55
00:05:17,800 --> 00:05:19,030
Back in the reports,

56
00:05:21,030 --> 00:05:24,030
I'll set the date to the 14th of June again.

57
00:05:37,230 --> 00:05:41,030
This time the week starts on Tuesday the 11th,

58
00:05:44,030 --> 00:05:47,630
and we get data from the 11th to the 17th of June.

59
00:05:48,430 --> 00:05:52,230
I glossed over something there. I'll tap on the calendar icon again.

60
00:05:53,530 --> 00:05:57,130
You'll notice that the week still starts on Monday.

61
00:05:57,930 --> 00:06:02,130
Our report is correct. It shows data for a week starting on Tuesday,

62
00:06:02,330 --> 00:06:05,630
but the android DatePickerDialog doesn't reflect that.

63
00:06:06,530 --> 00:06:11,030
Let's see what we can do about that in the next video. I'll meet you there.

