1
00:00:05,140 --> 00:00:06,140
Welcome back, again.

2
00:00:06,840 --> 00:00:08,340
We've got our app working,

3
00:00:08,340 --> 00:00:11,110
and it's certainly good enough to send to the test team.

4
00:00:11,610 --> 00:00:15,010
We may decide it's good enough to release as version 1.

5
00:00:15,510 --> 00:00:17,010
In some environments,

6
00:00:17,010 --> 00:00:19,510
such as a company using agile, it would be.

7
00:00:20,010 --> 00:00:22,610
Improvements would then go into the next version.

8
00:00:23,410 --> 00:00:25,010
So how can we improve it?

9
00:00:26,410 --> 00:00:29,010
Here are a few ideas for improving our app.

10
00:00:29,410 --> 00:00:33,110
We're going to hide the menu when a task is being added or edited.

11
00:00:33,770 --> 00:00:37,270
There's nothing useful that users should be doing from the menu while entering

12
00:00:37,270 --> 00:00:38,570
or editing a task,

13
00:00:39,070 --> 00:00:41,270
and we can disable the menu in the Fragment.

14
00:00:41,930 --> 00:00:46,030
Prevent the task that's currently being edited from being deleted.

15
00:00:46,690 --> 00:00:49,490
This will involve fragment to fragment communication

16
00:00:49,790 --> 00:00:53,890
because the deletion is being performed by MainActivityFragment.

17
00:00:55,490 --> 00:00:59,490
This could be a good opportunity to implement delete by swiping,

18
00:00:59,790 --> 00:01:01,690
rather than having a separate function.

19
00:01:02,390 --> 00:01:04,269
Whatever way we decide to delete,

20
00:01:04,269 --> 00:01:07,170
we'll have to implement Fragment to Fragment communication.

21
00:01:07,720 --> 00:01:10,070
There are other problems with deleting a task.

22
00:01:10,570 --> 00:01:13,070
If you delete a task that's currently being timed,

23
00:01:13,470 --> 00:01:16,470
the display doesn't update, we should fix that.

24
00:01:17,170 --> 00:01:20,530
Editing another task while a task is already being edited

25
00:01:20,530 --> 00:01:22,980
can also result in unexpected behavior.

26
00:01:24,080 --> 00:01:27,740
I'll demonstrate that because there's an interesting fix for the problem.

27
00:01:29,140 --> 00:01:32,740
At the moment, the app doesn't save timings with a duration

28
00:01:32,740 --> 00:01:37,140
shorter than the value specified in the settings. That's a useful feature.

29
00:01:38,130 --> 00:01:40,730
But if the user reduces the value to ignore,

30
00:01:41,130 --> 00:01:43,330
those timings won't appear in the report,

31
00:01:43,880 --> 00:01:46,380
they weren't saved and are lost for good.

32
00:01:47,570 --> 00:01:50,570
An improvement could be to save all the timings

33
00:01:50,870 --> 00:01:53,230
but not include the short ones in the report.

34
00:01:54,030 --> 00:01:57,230
This is an interesting one because SQLite

35
00:01:57,230 --> 00:01:59,830
doesn't support parameterized queries.

36
00:02:00,530 --> 00:02:02,830
We're going to have to come up with another solution.

37
00:02:04,330 --> 00:02:06,830
If you don't implement the last suggestion,

38
00:02:07,230 --> 00:02:11,230
create a new LiveData object in the TaskTimerViewModelclass

39
00:02:11,530 --> 00:02:14,830
and toggle it when a short timing record isn't saved.

40
00:02:15,530 --> 00:02:18,230
MainActivity can then observe the LiveData

41
00:02:18,230 --> 00:02:20,230
and display a Toast message

42
00:02:20,230 --> 00:02:22,830
to let the user know that the timing has been ignored.

43
00:02:23,530 --> 00:02:27,230
We won't be doing this, we'll be doing the earlier suggestion instead.

44
00:02:27,930 --> 00:02:30,290
We should also fix the collation issue

45
00:02:30,290 --> 00:02:33,290
that can result in unexpected ordering of tasks.

46
00:02:33,990 --> 00:02:35,290
First change is easy.

47
00:02:35,690 --> 00:02:38,290
But there's a step you have to perform first

48
00:02:38,290 --> 00:02:42,190
if you want to manipulate an activity's menu from a fragment.

49
00:02:42,990 --> 00:02:45,590
The changes are in AddEditFragment.

50
00:02:51,090 --> 00:02:53,690
Before a fragment can manipulate the menu,

51
00:02:53,990 --> 00:02:57,990
we have to call the SetHasOptionsMenu function

52
00:02:58,490 --> 00:02:59,690
and pass true to it.

53
00:03:00,290 --> 00:03:02,090
We do that in OnCreate.

54
00:03:14,390 --> 00:03:18,790
Control click on SetHasOptionsMenu to check what it does.

55
00:03:22,150 --> 00:03:25,050
The doc string explains that it lets the fragment

56
00:03:25,050 --> 00:03:27,410
participate in populating the menu.

57
00:03:28,110 --> 00:03:30,210
If we pass true to this method,

58
00:03:30,210 --> 00:03:33,510
the fragment will have its menu-related functions called,

59
00:03:33,910 --> 00:03:36,910
that includes OnCreateOptionsMenu

60
00:03:36,910 --> 00:03:39,270
and OnPrepareOptionsMenu.

61
00:03:40,370 --> 00:03:43,870
It's OnPrepareOptionsMenu that we need to override.

62
00:03:44,570 --> 00:03:47,570
I'll add it after the OnViewCreated code.

63
00:03:55,970 --> 00:03:59,330
All this does is clear the menu which is what we want.

64
00:03:59,830 --> 00:04:03,080
Let's run the app and check that it now has no menu

65
00:04:03,080 --> 00:04:04,880
when adding or editing a task.

66
00:04:07,180 --> 00:04:09,180
I'll start by adding a new

67
00:04:10,840 --> 00:04:13,340
task. The menu is not present, so that's working.

68
00:04:13,940 --> 00:04:17,940
I won't enter any details, I'll use the toolbars up button

69
00:04:17,940 --> 00:04:19,540
to return to the main screen.

70
00:04:21,740 --> 00:04:24,340
The menu reappears, so that's also working.

71
00:04:25,040 --> 00:04:27,640
We get the same behavior when editing a task.

72
00:04:30,540 --> 00:04:32,740
This time, I'll use the back button to return.

73
00:04:33,400 --> 00:04:35,900
So we can make sure that that's also working correctly.

74
00:04:37,100 --> 00:04:39,460
We're doing things differently in landscape,

75
00:04:39,760 --> 00:04:43,760
and it's important to test that as well. Rotate the device,

76
00:04:48,760 --> 00:04:50,360
and then let's edit a task.

77
00:04:52,350 --> 00:04:53,650
The menu disappears.

78
00:04:54,350 --> 00:04:58,350
Use the back button to remove the EditFragment and we should get the menu back.

79
00:04:59,600 --> 00:05:01,200
That was an easy change.

80
00:05:01,800 --> 00:05:06,500
The others won't be quite so easy. And we'll start on them in the next video.

81
00:05:07,160 --> 00:05:11,150
I'll finish this video by removing that floating action button.

82
00:05:11,810 --> 00:05:16,010
I think it's pretty obvious by now that we're not really going to have any use for it.

83
00:05:16,810 --> 00:05:19,170
Go into the ActivityMain layout

84
00:05:20,170 --> 00:05:21,770
in res/layouts

85
00:05:26,870 --> 00:05:28,670
and delete the fab.

86
00:05:31,270 --> 00:05:35,630
Now that we've made those changes, this would be a good time to try the test

87
00:05:35,830 --> 00:05:37,830
from the end of the previous video.

88
00:05:38,630 --> 00:05:41,630
See if you can tap save when editing a task,

89
00:05:42,330 --> 00:05:46,330
then tap the reports icon faster than the data can be saved.

90
00:05:47,210 --> 00:05:49,980
You shouldn't be able to lose any changes

91
00:05:49,980 --> 00:05:54,380
even if you use two fingers to tap the buttons and you use a physical device.

92
00:05:54,880 --> 00:05:57,180
All right. In the next video,

93
00:05:57,180 --> 00:06:01,080
we'll prevent a task from being deleted if it's being edited.

94
00:06:01,380 --> 00:06:02,380
I'll see you there.

