Welcome back, everyone.
In the last video we moved the code to access the database
into our ViewModel.
To test the change we need to make some changes
to the durations report activity.
First, I'll declare an instance of our ViewModel
and use lazy initialization.
In the oncreate function,
we'll observe the durations ViewModel instead of calling LoadData.
If you're prompted for the observer import,
make sure you choose androidx.lifecycle.observer.
All right. Our activity is still very basic.
We've got to add the ability to select different dates
and sort by columns,
but it should still work. I like to test apps often
whenever they're in a state that should run,
so does it work, run the app and tap the reports icon.
And that looks good. We've got our data for May displayed.
Make sure the logcat's visible,
and add a comment rotating at the end.
Next, rotate the device.
This time the database isn't re-queried.
That's good. We've kept our durations report activity
focused just on the UI
and also prevented unnecessary work.
I know we're using a local database here,
but it's still going to save the user's batteries,
and you can use exactly this approach when collecting data over the internet.
That would have a far greater impact on battery life
and also on your users pockets if they're on a meted connection.
In the next, video we'll start adding the remaining functionality to the reports.
We've still got to allow the report to be filtered by date
display either a single day or a full week
and implement sorting by the various columns.
We've got lots to do, I'll see you there.