Welcome back.
We've allowed our users to change a couple of things for the TaskTimer app,
that was in an earlier section.
So I'll quickly review what it is they can configure.
I've got the app running in the emulator, and I'll go to the settings menu.
We can change which day starts the week
and we can also choose to ignore timings
that are less than a certain number of seconds or minutes
if that's what the user wants to do.
We'll start by implementing that first day of the week setting,
that will make some of our Australian users happy
because they like to start their weeks on a Monday
and currently it starts on a Sunday.
At the moment, the app starts the week on a day determined by the user's locale.
That's how the Gregorian calendar class works.
That's a sensible default to use if they haven't changed any of the settings.
I've left my emulator set to English Australia,
and the settings dialog is currently showing Sunday
as the day that the week starts on.
I'll cancel the dialogue and switch the phone's settings
to change locale to English United Kingdom.
If I go into settings again,
this time the default first day is Monday.
We allow the user to change that. But at the moment,
we're not using their choice in our code.
We'll implement that now.
We do that in our DurationsViewModel.
I'll start by creating a couple of variables for the shared preferences
that we're going to get the settings from
and the first day of the week variable to store the value.
Settings is a reference to the shared preferences
that our settings dialog uses.
We then retrieve the settings FirstDayOfweek preference
and return the calendars FirstDayOfWeek value
if a preference hasn't been saved yet. In the init block,
we'll use that value to tell the calendar which day
it should start the week on.
I've logged the value to make it easier to check that everything's working.
We also need to set the FirstDayOfTheWeek in our BroadcastReceiver
because we create a new calendar instance there.
Okay. That's all we need to change for our app to use the FirstDayOfTheWeek
that our user wants.
Let's see if it works.
Run the app, and go into the reports.
I've still got my emulators locale set to the United Kingdom.
So the calendar should show Monday as the first day of the week.
Tap the calendar icon to check, set the date to the 14th of June
2019.
That's a Friday. And when I tap okay,
our report is showing data for the 10th
to the 16th of June.
We're going to improve this next bit shortly. At the moment,
I have to return to the main screen to access the settings.
I'll choose Tuesday from the dropdown and tap okay.
Back in the reports,
I'll set the date to the 14th of June again.
This time the week starts on Tuesday the 11th,
and we get data from the 11th to the 17th of June.
I glossed over something there. I'll tap on the calendar icon again.
You'll notice that the week still starts on Monday.
Our report is correct. It shows data for a week starting on Tuesday,
but the android DatePickerDialog doesn't reflect that.
Let's see what we can do about that in the next video. I'll meet you there.