1
00:00:05,360 --> 00:00:06,760
Welcome back again, everyone.

2
00:00:07,310 --> 00:00:10,010
The changes to our ViewModels are very simple.

3
00:00:10,610 --> 00:00:12,860
In the TaskTimerViewModel,

4
00:00:12,860 --> 00:00:15,760
we need to observe the changes to the settings

5
00:00:15,760 --> 00:00:19,360
and update our new parameters table when the setting changes.

6
00:00:19,960 --> 00:00:23,960
That's easy because we're already observing the shared preferences.

7
00:00:25,460 --> 00:00:29,450
What we need to do is to update the database parameters table.

8
00:02:21,950 --> 00:02:23,450
So there's nothing new there.

9
00:02:23,450 --> 00:02:26,950
It's our standard approach for updating data in the database.

10
00:02:27,940 --> 00:02:30,930
Use ID short timing on line 50,

11
00:02:31,590 --> 00:02:35,790
rather than having to remember that the parameter we want has the id of 1.

12
00:02:36,450 --> 00:02:40,770
Although we've only got one parameter, it's still a good idea to avoid having

13
00:02:40,770 --> 00:02:42,370
magic numbers in our code.

14
00:02:42,770 --> 00:02:45,770
We can tell without having to even think about it,

15
00:02:45,770 --> 00:02:47,970
which parameter we're updating here.

16
00:02:49,180 --> 00:02:52,180
The next change is in the SaveTiming function.

17
00:02:54,510 --> 00:02:57,810
The comment on line 198

18
00:02:57,810 --> 00:02:59,810
gives away what the change needs to be.

19
00:03:00,810 --> 00:03:04,410
At the moment, we're only saving timings that are long enough,

20
00:03:05,010 --> 00:03:07,210
but we want to save all timings.

21
00:03:07,210 --> 00:03:10,810
The view will filter out the ones that we don't want to include in our totals.

22
00:03:11,470 --> 00:03:14,770
The change here just involves deleting all the code

23
00:03:14,770 --> 00:03:16,370
that deletes the short timings.

24
00:03:27,670 --> 00:03:29,870
Reformat the code from the code menu

25
00:03:34,170 --> 00:03:35,870
to make everything look nice again.

26
00:03:37,170 --> 00:03:41,170
The change in the DurationsViewModel class is also simple.

27
00:03:41,670 --> 00:03:43,470
But let's test the app first

28
00:03:43,970 --> 00:03:46,470
that'll make it more obvious what the change is for.

29
00:03:47,460 --> 00:03:48,450
Run the app,

30
00:03:52,650 --> 00:03:54,950
type app database

31
00:03:57,450 --> 00:04:01,750
into the logcat search box to save hunting through the logcat to find it.

32
00:04:05,550 --> 00:04:08,950
To test this feature, I'm going to clear out all our data.

33
00:04:09,750 --> 00:04:13,550
We want to be able to spot when some things aren't being included in the results,

34
00:04:14,050 --> 00:04:17,350
and that's a lot easier if we don't have a whole lot of rogue data.

35
00:04:17,850 --> 00:04:21,649
The easiest way to do that is to uninstall the application,

36
00:04:22,010 --> 00:04:23,010
so I'll do that.

37
00:04:23,710 --> 00:04:26,810
This also tests a database is created correctly

38
00:04:26,810 --> 00:04:28,610
when the app is first installed.

39
00:04:47,410 --> 00:04:49,910
After doing that, run the app again.

40
00:04:52,910 --> 00:04:56,910
You'll see the table and the views being created in the logcat.

41
00:05:01,710 --> 00:05:05,210
The instructions should also be correct on the emulator.

42
00:05:06,010 --> 00:05:08,370
They no longer refer to a delete button

43
00:05:08,370 --> 00:05:11,570
but instead the user is told to swipe a task left to delete it.

44
00:05:12,170 --> 00:05:14,870
Next, create 5 tasks.

45
00:05:30,670 --> 00:05:32,670
It's very exciting watching me type,

46
00:05:32,670 --> 00:05:35,670
so that's why we sped up the video for that part.

47
00:05:36,170 --> 00:05:40,470
Okay. There was a reason I stuck with that boring set of names for the tasks.

48
00:05:41,270 --> 00:05:44,270
It's going to make a quick test of the app a lot easier.

49
00:05:44,770 --> 00:05:46,970
Of course, you'll test the app thoroughly.

50
00:05:47,470 --> 00:05:50,790
When you come to do that, generate some more test data

51
00:05:50,790 --> 00:05:53,890
and use a spreadsheet to make sure that the reports are accurate.

52
00:05:54,880 --> 00:05:58,180
At the moment, I'm just testing that out change works.

53
00:05:58,840 --> 00:06:01,500
This is the minimum amount of testing we should do

54
00:06:01,500 --> 00:06:04,000
before passing the app on to the test team.

55
00:06:04,990 --> 00:06:09,590
If you haven't got a test team and as a sole developer you probably won't have,

56
00:06:09,990 --> 00:06:13,290
then you need to do all the work of validating the reports yourself.

57
00:06:13,950 --> 00:06:18,050
It's tedious, as we've said before, but it is essential.

58
00:06:18,930 --> 00:06:21,290
I'm going to pause the video now

59
00:06:21,290 --> 00:06:24,290
and create some timings for various tasks,

60
00:06:24,540 --> 00:06:27,840
some will be short less than 5 seconds

61
00:06:27,840 --> 00:06:32,040
others will be a lot longer, and you don't want to sit there waiting for several minutes

62
00:06:32,040 --> 00:06:33,940
to elapse while we time tasks.

63
00:06:34,740 --> 00:06:37,740
Before I do that, I'll filter the logcat

64
00:06:37,740 --> 00:06:40,540
by typing start time into the search box.

65
00:06:46,940 --> 00:06:50,820
I'll quickly start timing task 2, then stop it again

66
00:06:50,820 --> 00:06:52,820
so you can see the logcat entry.

67
00:07:02,820 --> 00:07:06,420
We get the task ID at the start of the log entry

68
00:07:06,420 --> 00:07:08,020
and the duration at the end.

69
00:07:08,620 --> 00:07:11,610
Task 2 has the ID 2,

70
00:07:11,970 --> 00:07:14,970
which is why I was boring in my choice of task names.

71
00:07:15,570 --> 00:07:19,170
We can easily identify the durations that should be filtered out

72
00:07:19,470 --> 00:07:21,570
and which tasks they relate to.

73
00:07:22,270 --> 00:07:25,870
That's a lot easier than examining the database to see what's been saved.

74
00:07:27,270 --> 00:07:30,260
You can copy all the entries into a text editor,

75
00:07:30,260 --> 00:07:34,460
so you've got them on hand when it comes time to verify that the report is correct.

76
00:07:35,120 --> 00:07:39,920
Okay. I'll pause the video now and create a few new timings.

77
00:07:41,820 --> 00:07:43,120
Okay. Welcome back.

78
00:07:44,000 --> 00:07:47,250
As you can see in my logcat, I've got a load of timings,

79
00:07:47,250 --> 00:07:50,550
varying from a couple of seconds to nearly a minute,

80
00:07:50,550 --> 00:07:53,150
and one really long one where I went and got a cup of tea.

81
00:07:57,950 --> 00:08:01,060
On the emulator, go into reports

82
00:08:03,360 --> 00:08:05,360
and let's make sure that things add up.

83
00:08:05,860 --> 00:08:08,360
We've got our raw data in the logcat.

84
00:08:08,610 --> 00:08:11,610
Any useful technique that you can use

85
00:08:11,610 --> 00:08:13,710
is to hold down the alt key

86
00:08:13,710 --> 00:08:16,710
and click just before the start of the first ID

87
00:08:17,310 --> 00:08:18,310
then drag,

88
00:08:19,670 --> 00:08:24,070
so that we just get the data that we want and not all the information over on the left.

89
00:08:25,070 --> 00:08:28,070
If we copy that we can paste it into a spreadsheet.

90
00:08:28,870 --> 00:08:30,870
I'm going to use numbers on the macintosh,

91
00:08:33,970 --> 00:08:37,970
and when we paste it in each thing goes into a separate column.

92
00:08:38,520 --> 00:08:40,720
I'm going to sort by the first column

93
00:08:45,120 --> 00:08:48,120
because that's going to make it easier for us to add things up.

94
00:09:34,620 --> 00:09:37,980
Of course that was just a quick and dirty way of doing it.

95
00:09:37,980 --> 00:09:41,780
When you perform thorough testing, you should probably export the timings

96
00:09:41,780 --> 00:09:43,480
into a CSV file

97
00:09:43,480 --> 00:09:46,980
then put that into a spreadsheet program and have it do a lot more of the work.

98
00:09:47,680 --> 00:09:50,180
Back in the emulator, I'll go to the reports.

99
00:09:55,780 --> 00:09:59,080
We're currently totaling the durations for all the records,

100
00:09:59,630 --> 00:10:01,630
and it reflects that task 1

101
00:10:02,230 --> 00:10:05,430
307 seconds is 5 minutes and 7 seconds

102
00:10:05,680 --> 00:10:08,680
task 2 is 2, task 3 is 32,

103
00:10:09,040 --> 00:10:12,640
4 is 39 and 5 is 58. So that's all working fine.

104
00:10:13,540 --> 00:10:16,440
So let's go into settings and change the value.

105
00:10:22,800 --> 00:10:26,000
I'll set it to ignore timings of less than 5 seconds.

106
00:10:26,700 --> 00:10:27,800
We click okay,

107
00:10:29,100 --> 00:10:30,200
and nothing changes.

108
00:10:31,560 --> 00:10:35,160
That's what we still have to implement in the DurationsViewModel.

109
00:10:35,460 --> 00:10:38,460
The data doesn't refresh when we change that setting.

110
00:10:39,260 --> 00:10:42,260
Until we make that change to DurationsViewModel,

111
00:10:42,560 --> 00:10:44,760
tap back to return to the main screen,

112
00:10:46,120 --> 00:10:47,920
and then go to the reports again.

113
00:10:49,280 --> 00:10:52,780
Now all timings less than 5 seconds have been ignored.

114
00:10:53,580 --> 00:10:57,680
Task 2 has disappeared because the whole task was less than 5 seconds.

115
00:10:58,450 --> 00:11:01,220
And so we've got different values showing on the report.

116
00:11:01,880 --> 00:11:05,880
In the next video, we'll make the changes to the DurationsViewModel

117
00:11:05,880 --> 00:11:09,780
class so that the reports update automatically. I'll see you there.

