Good day. Welcome back. We've allowed the user to change the day that a week starts
on and modified the DatePickerFragment class to use that day.
To test it, we need to make a change to our durations report.
Now the DurationsReport class doesn't have a calendar.
Rather than add one, I'm going to expose the FirstDayOfWeek
property from the DurationsViewModel class.
We want it to be read-only
just like we've done for the DisplayWeek property.
FirstDayOfWeek is now available to the durations report activity
but it can't be changed by it.
That gives us an error in BroadcastReceiver's onReceive function.
We have to modify the _FirstDayOfWeek.
In durations report,
we can pass that value to the dialogues arguments
in the ShowDatePickerDialog function.
All right. Does it work?
I'll run the app again and check the settings.
The week's set to start on a Tuesday,
so let's see how the date picker looks now.
In reports, we've got data for the current week
when I tap the calendar the week starts on a Tuesday
and the dates showing in the report
correctly reflect a week that starts on Tuesday.
I'm not aware of any country that does start their week on a Tuesday,
but our Australian users can now choose Monday or Sunday as their start
day and have the calendar look as they expect.
There's more testing you should do to make sure everything's working correctly.
One obvious test is to make sure we haven't broken anything
if the user hasn't set a starting day in the settings.
That would involve uninstalling the app to clear the shared preferences.
A quick way to test without uninstalling
is to use the device file explorer
to delete the shared preferences file.
Doing that doesn't replace a proper test
but it's a useful technique when you're still developing.
If you do that
be aware that android apps don't expect their preferences files to be deleted.
You may have to run the app several times
before it notices that there is no longer a shared preference file.
We've added some code that only runs on API 21 and above.
When you use a feature like that one that's not available on earlier versions,
make sure you test the app on an earlier version.
In this case that would be API 19 or earlier.
API 20 was a version of API 19
released for wearable devices,
so you won't find an API 20 system image for the emulator.
Okay. I'll stop this video here. In the next video,
we'll add the settings option to our reports menu
and see how we can observe changes to the shared preferences.
See you there.