Welcome back, again.
We've got our app working,
and it's certainly good enough to send to the test team.
We may decide it's good enough to release as version 1.
In some environments,
such as a company using agile, it would be.
Improvements would then go into the next version.
So how can we improve it?
Here are a few ideas for improving our app.
We're going to hide the menu when a task is being added or edited.
There's nothing useful that users should be doing from the menu while entering
or editing a task,
and we can disable the menu in the Fragment.
Prevent the task that's currently being edited from being deleted.
This will involve fragment to fragment communication
because the deletion is being performed by MainActivityFragment.
This could be a good opportunity to implement delete by swiping,
rather than having a separate function.
Whatever way we decide to delete,
we'll have to implement Fragment to Fragment communication.
There are other problems with deleting a task.
If you delete a task that's currently being timed,
the display doesn't update, we should fix that.
Editing another task while a task is already being edited
can also result in unexpected behavior.
I'll demonstrate that because there's an interesting fix for the problem.
At the moment, the app doesn't save timings with a duration
shorter than the value specified in the settings. That's a useful feature.
But if the user reduces the value to ignore,
those timings won't appear in the report,
they weren't saved and are lost for good.
An improvement could be to save all the timings
but not include the short ones in the report.
This is an interesting one because SQLite
doesn't support parameterized queries.
We're going to have to come up with another solution.
If you don't implement the last suggestion,
create a new LiveData object in the TaskTimerViewModelclass
and toggle it when a short timing record isn't saved.
MainActivity can then observe the LiveData
and display a Toast message
to let the user know that the timing has been ignored.
We won't be doing this, we'll be doing the earlier suggestion instead.
We should also fix the collation issue
that can result in unexpected ordering of tasks.
First change is easy.
But there's a step you have to perform first
if you want to manipulate an activity's menu from a fragment.
The changes are in AddEditFragment.
Before a fragment can manipulate the menu,
we have to call the SetHasOptionsMenu function
and pass true to it.
We do that in OnCreate.
Control click on SetHasOptionsMenu to check what it does.
The doc string explains that it lets the fragment
participate in populating the menu.
If we pass true to this method,
the fragment will have its menu-related functions called,
that includes OnCreateOptionsMenu
and OnPrepareOptionsMenu.
It's OnPrepareOptionsMenu that we need to override.
I'll add it after the OnViewCreated code.
All this does is clear the menu which is what we want.
Let's run the app and check that it now has no menu
when adding or editing a task.
I'll start by adding a new
task. The menu is not present, so that's working.
I won't enter any details, I'll use the toolbars up button
to return to the main screen.
The menu reappears, so that's also working.
We get the same behavior when editing a task.
This time, I'll use the back button to return.
So we can make sure that that's also working correctly.
We're doing things differently in landscape,
and it's important to test that as well. Rotate the device,
and then let's edit a task.
The menu disappears.
Use the back button to remove the EditFragment and we should get the menu back.
That was an easy change.
The others won't be quite so easy. And we'll start on them in the next video.
I'll finish this video by removing that floating action button.
I think it's pretty obvious by now that we're not really going to have any use for it.
Go into the ActivityMain layout
in res/layouts
and delete the fab.
Now that we've made those changes, this would be a good time to try the test
from the end of the previous video.
See if you can tap save when editing a task,
then tap the reports icon faster than the data can be saved.
You shouldn't be able to lose any changes
even if you use two fingers to tap the buttons and you use a physical device.
All right. In the next video,
we'll prevent a task from being deleted if it's being edited.
I'll see you there.