1
00:00:00,535 --> 00:00:04,035
(light electronic jingle)

2
00:00:05,320 --> 00:00:07,530
In this section, we're going to create an app

3
00:00:07,530 --> 00:00:10,420
that stores data in a SQLite database.

4
00:00:10,420 --> 00:00:12,290
Now the app's gonna be a task timer

5
00:00:12,290 --> 00:00:14,595
that we can use to record how long to spend

6
00:00:14,595 --> 00:00:16,670
on different tasks.

7
00:00:16,670 --> 00:00:18,590
It's useful if you have to complete

8
00:00:18,590 --> 00:00:22,030
time sheets for billing customers for your work for example.

9
00:00:22,030 --> 00:00:24,520
And it introduces some very important techniques

10
00:00:24,520 --> 00:00:27,250
for Android programming including all the operations

11
00:00:27,250 --> 00:00:30,170
you'll need to perform on the database.

12
00:00:30,170 --> 00:00:32,479
Any databases will have separate tables to store

13
00:00:32,479 --> 00:00:36,220
the tasks that we'll be timing and the timing's themselves

14
00:00:36,220 --> 00:00:38,131
so that you'll be seeing how to add data

15
00:00:38,131 --> 00:00:40,910
to a database when tables are joined.

16
00:00:40,910 --> 00:00:43,310
Now more importantly perhaps, you'll also see

17
00:00:43,310 --> 00:00:47,050
how to delete associated records in a joined table.

18
00:00:47,050 --> 00:00:48,857
In this case if you delete a task,

19
00:00:48,857 --> 00:00:52,210
then all the timings associated with that task

20
00:00:52,210 --> 00:00:53,960
will also need to be deleted.

21
00:00:53,960 --> 00:00:56,140
Of course it's good practise to warn users

22
00:00:56,140 --> 00:00:58,190
that this will happen and the app will also

23
00:00:58,190 --> 00:01:01,450
use dialogues to warn the user and allow them

24
00:01:01,450 --> 00:01:03,380
to cancel the operation.

25
00:01:03,380 --> 00:01:05,410
Although the focus of Android apps tends to be phones,

26
00:01:05,410 --> 00:01:08,590
it's well worth considering tablet users

27
00:01:08,590 --> 00:01:10,280
when producing your apps.

28
00:01:10,280 --> 00:01:13,046
In this app, editing a task record on a phone

29
00:01:13,046 --> 00:01:16,430
will show a different screen because there just isn't

30
00:01:16,430 --> 00:01:19,010
enough room on a phone's display.

31
00:01:19,010 --> 00:01:22,010
But on a tablet, users will be able to edit the task

32
00:01:22,010 --> 00:01:25,970
details alongside the lists of tasks.

33
00:01:25,970 --> 00:01:28,780
Now we achieve that by using fragments

34
00:01:28,780 --> 00:01:31,350
and we'll also be seeing how to implement those fragments

35
00:01:31,350 --> 00:01:32,670
in our apps.

36
00:01:32,670 --> 00:01:35,340
Now another thing that this app will need to do

37
00:01:35,340 --> 00:01:38,430
is record and display dates, and we'll be using

38
00:01:38,430 --> 00:01:41,340
the Java calendar classes to do that.

39
00:01:41,340 --> 00:01:43,600
Now it may seem like an easy thing to do,

40
00:01:43,600 --> 00:01:45,440
but you have to be really very careful

41
00:01:45,440 --> 00:01:46,803
when dealing with time.

42
00:01:48,059 --> 00:01:49,210
Users can download your app from almost

43
00:01:49,210 --> 00:01:51,947
anywhere in the world, and it's very easy to mess up

44
00:01:51,947 --> 00:01:54,810
when dealing with different time zones.

45
00:01:54,810 --> 00:01:56,410
So we're going to be looking at how to safely

46
00:01:56,410 --> 00:01:59,810
deal with time across the world in your apps.

47
00:01:59,810 --> 00:02:02,020
We'll also see another way to respond to events

48
00:02:02,020 --> 00:02:03,263
from a recycler view.

49
00:02:04,271 --> 00:02:06,580
And our list of tasks will include buttons to edit

50
00:02:06,580 --> 00:02:09,150
or delete the task and we'll need to respond

51
00:02:09,150 --> 00:02:13,230
to taps on the task itself to start and stop timing.

52
00:02:13,230 --> 00:02:16,830
So let's have a look at the app running on an emulator.

53
00:02:16,830 --> 00:02:19,730
So the first thing we do is provide the user

54
00:02:19,730 --> 00:02:22,750
with basic information on how to use the app

55
00:02:22,750 --> 00:02:24,170
when they first run it.

56
00:02:24,170 --> 00:02:26,730
So this screen will show a list of tasks

57
00:02:26,730 --> 00:02:30,111
that the user set up, but until they create some tasks,

58
00:02:30,111 --> 00:02:32,250
the display would be empty.

59
00:02:32,250 --> 00:02:34,218
And we've taken advantage of all that space

60
00:02:34,218 --> 00:02:36,590
to give them some basic instructions.

61
00:02:36,590 --> 00:02:40,738
So tapping on the plus icon up here in the toolbar

62
00:02:40,738 --> 00:02:43,270
allows new details to be entered.

63
00:02:43,270 --> 00:02:45,890
Now we've seen edit text hints before,

64
00:02:45,890 --> 00:02:49,167
and they're a very useful way of letting the user know

65
00:02:49,167 --> 00:02:51,440
when they should enter and what they should enter

66
00:02:51,440 --> 00:02:52,780
into each field.

67
00:02:52,780 --> 00:02:54,800
I'm gonna cancel that and go back home

68
00:02:54,800 --> 00:02:56,483
and select abandon changes.

69
00:02:57,446 --> 00:03:00,033
Gonna rotate the phone into landscape now.

70
00:03:01,590 --> 00:03:04,713
I'm gonna tap on the plus option in the toolbar again.

71
00:03:05,560 --> 00:03:08,840
Now the app is using fragments here and can take advantage

72
00:03:08,840 --> 00:03:11,840
of the extra screen width to perform the editing

73
00:03:11,840 --> 00:03:13,720
on the right hand side of the screen.

74
00:03:13,720 --> 00:03:16,033
Alright, so I'm gonna enter some details here now.

75
00:03:16,910 --> 00:03:20,330
I'm going to type task timer for the name.

76
00:03:21,374 --> 00:03:23,206
Click on next.

77
00:03:23,206 --> 00:03:27,539
Gonna type Android database app for the description.

78
00:03:28,660 --> 00:03:30,710
And notice when I started typing that the Android

79
00:03:30,710 --> 00:03:33,060
keyboard took over and in landscape,

80
00:03:33,060 --> 00:03:35,490
each field is presented for editing.

81
00:03:35,490 --> 00:03:37,798
And Android is also adding this next button

82
00:03:37,798 --> 00:03:39,950
to move on to the next field.

83
00:03:39,950 --> 00:03:42,196
So I'm going to add to zero here for sort order,

84
00:03:42,196 --> 00:03:43,930
and that's how this app should appear

85
00:03:43,930 --> 00:03:45,230
at the start of this list,

86
00:03:45,230 --> 00:03:46,880
and then I'm gonna click on done.

87
00:03:48,110 --> 00:03:49,837
And when I click on save over here,

88
00:03:49,837 --> 00:03:52,000
the data saved to the database

89
00:03:52,000 --> 00:03:55,270
and we've now got one task in our list.

90
00:03:55,270 --> 00:03:57,430
So let's add another task now in landscape mode

91
00:03:57,430 --> 00:03:58,830
and then we'll swing over to portrait

92
00:03:58,830 --> 00:03:59,980
for the one after that.

93
00:04:00,830 --> 00:04:02,600
So this is my Java course entry,

94
00:04:02,600 --> 00:04:06,770
so I'm gonna type in Java course and click on next.

95
00:04:06,770 --> 00:04:08,330
Description I'm gonna leave blank

96
00:04:08,330 --> 00:04:10,210
and that's because the task name says enough.

97
00:04:10,210 --> 00:04:15,210
So next and for sort order, I'm going to enter 10,

98
00:04:15,240 --> 00:04:19,170
number 10, click on done, and then click on save.

99
00:04:19,170 --> 00:04:22,410
Now the Java course task is sorting below the task,

100
00:04:22,410 --> 00:04:25,080
timer task, and that's because task timer

101
00:04:25,080 --> 00:04:27,180
had a sort order of zero.

102
00:04:27,180 --> 00:04:29,433
Right, so I'll switch back to portrait now.

103
00:04:30,861 --> 00:04:33,560
I'm gonna tap on the plus icon in the toolbar

104
00:04:33,560 --> 00:04:35,550
to enter one more task.

105
00:04:35,550 --> 00:04:38,301
Now because the screen isn't wide enough

106
00:04:38,301 --> 00:04:40,203
to show the list and allowed data entry,

107
00:04:41,057 --> 00:04:42,930
the fragments displayed by itself here in portrait mode.

108
00:04:42,930 --> 00:04:46,060
Using fragments lets us write apps that automatically

109
00:04:46,060 --> 00:04:49,240
adapt to extra screen space to give the user

110
00:04:49,240 --> 00:04:50,483
a better experience.

111
00:04:52,114 --> 00:04:54,610
Right, so the name for this task is gonna be cycling.

112
00:04:55,650 --> 00:04:57,780
Now it's good to take a break from the computer now and then

113
00:04:57,780 --> 00:05:00,630
so I'm gonna record how much time I spent cycling.

114
00:05:00,630 --> 00:05:03,290
But that is a slightly vague name, so I'm gonna make

115
00:05:03,290 --> 00:05:05,033
the description ride my bicycle.

116
00:05:08,480 --> 00:05:11,780
And in portrait mode there's enough space to display

117
00:05:11,780 --> 00:05:14,400
the edit text and the keyboard as you can see,

118
00:05:14,400 --> 00:05:17,740
so Android doesn't have to present the fields one by one.

119
00:05:17,740 --> 00:05:20,760
Now the data is not saved, which means it'll be lost

120
00:05:20,760 --> 00:05:22,680
if we use the home or back buttons to return

121
00:05:22,680 --> 00:05:24,170
to the previous screen.

122
00:05:24,170 --> 00:05:28,740
So I click on back, so what I'll do is come up here

123
00:05:28,740 --> 00:05:30,543
and just fix the top right there.

124
00:05:31,861 --> 00:05:32,694
So I click on back.

125
00:05:33,570 --> 00:05:36,463
So to prevent the loss of data, we're showing a dialogue

126
00:05:36,463 --> 00:05:38,640
here so that the user knows they're about

127
00:05:38,640 --> 00:05:40,910
to lose data if they continue.

128
00:05:40,910 --> 00:05:43,160
In my case I want to save those changes so I'm gonna

129
00:05:43,160 --> 00:05:45,550
choose continue editing.

130
00:05:45,550 --> 00:05:47,780
So I'm going to leave the sort order blank

131
00:05:47,780 --> 00:05:49,840
and it should default to zero.

132
00:05:49,840 --> 00:05:52,247
That means that this task will sort to the top of the list

133
00:05:52,247 --> 00:05:55,090
and if two tasks have the same sort order,

134
00:05:55,090 --> 00:05:56,530
then they'll appear alphabetically.

135
00:05:56,530 --> 00:06:00,630
So when I click on save we can see that cycling

136
00:06:00,630 --> 00:06:01,800
is at the top.

137
00:06:01,800 --> 00:06:05,320
Now to start timing a task we just long tap it,

138
00:06:05,320 --> 00:06:06,950
I'll do that now.

139
00:06:06,950 --> 00:06:08,600
The heading changes to show which task

140
00:06:08,600 --> 00:06:10,740
is currently being timed.

141
00:06:10,740 --> 00:06:12,810
Now if we were building a customer for this task

142
00:06:12,810 --> 00:06:15,540
or any of the tasks, we probably wouldn't be interested

143
00:06:15,540 --> 00:06:18,782
in charging for every second, so I'll stop timing that now.

144
00:06:18,782 --> 00:06:20,613
And if you go into settings,

145
00:06:23,200 --> 00:06:26,570
and we've got options here to ignore timings for tasks

146
00:06:26,570 --> 00:06:29,090
that last less than a certain amount of time.

147
00:06:29,090 --> 00:06:31,653
Now you've probably seen sliders like this before,

148
00:06:31,653 --> 00:06:34,030
but what's not obvious is just how much control

149
00:06:34,030 --> 00:06:36,710
you can provide by using them.

150
00:06:36,710 --> 00:06:38,630
In most applications dragging the slider

151
00:06:38,630 --> 00:06:41,593
would increase some value in a linear fashion.

152
00:06:42,540 --> 00:06:44,420
It would really make a lot of sense here.

153
00:06:44,420 --> 00:06:47,340
If you wanted to ignore timings less than five minutes,

154
00:06:47,340 --> 00:06:50,520
that's 300 seconds and you'd have to drag the slider

155
00:06:50,520 --> 00:06:52,650
a long way to get that high.

156
00:06:52,650 --> 00:06:54,330
But this slider is a little bit different though.

157
00:06:54,330 --> 00:06:56,240
I'm just going to tab to it now,

158
00:06:56,240 --> 00:06:57,500
and I'm gonna use my keyboard just

159
00:06:57,500 --> 00:06:59,850
to show you the increments.

160
00:06:59,850 --> 00:07:01,570
So as we start off you can see the increments

161
00:07:01,570 --> 00:07:04,240
are five seconds and that is true

162
00:07:04,240 --> 00:07:06,113
until we get to 55 seconds.

163
00:07:07,590 --> 00:07:09,030
After that though if I do another one,

164
00:07:09,030 --> 00:07:11,400
notice how it's now jumped to one minute,

165
00:07:11,400 --> 00:07:13,580
then it counts in five minute increments

166
00:07:13,580 --> 00:07:16,280
until it gets to 15 minutes, then the next time

167
00:07:16,280 --> 00:07:19,330
it goes to 30 minutes, then to 45 minutes,

168
00:07:19,330 --> 00:07:21,027
then it jumps to one hour, then the next

169
00:07:21,027 --> 00:07:23,410
increment is two hours.

170
00:07:23,410 --> 00:07:25,244
So you can see that we can provide a lot of flexibility

171
00:07:25,244 --> 00:07:27,770
without having to clutter the screen up

172
00:07:27,770 --> 00:07:29,710
with all sorts of different sliders.

173
00:07:29,710 --> 00:07:31,470
And we'll be seeing how to create a slider

174
00:07:31,470 --> 00:07:33,960
like this in this app as well.

175
00:07:33,960 --> 00:07:36,260
So I'll move that slider back to zero now,

176
00:07:36,260 --> 00:07:38,598
otherwise we'd have to wait a long time

177
00:07:38,598 --> 00:07:40,600
to get any real timing data to display in the reports

178
00:07:40,600 --> 00:07:42,050
that we're about to look at.

179
00:07:42,050 --> 00:07:45,600
Now this settings menu also lets us choose which day

180
00:07:45,600 --> 00:07:47,380
a week starts on.

181
00:07:47,380 --> 00:07:48,970
Some companies start on a Sunday

182
00:07:48,970 --> 00:07:51,810
when they're doing accounting, others start on a Monday.

183
00:07:51,810 --> 00:07:56,810
So tapping the day here brings up this list of days,

184
00:07:56,840 --> 00:07:58,300
which is a dialogue where you can

185
00:07:58,300 --> 00:08:00,030
choose the day of the week.

186
00:08:00,030 --> 00:08:01,900
And it's probably a bit pointless including

187
00:08:01,900 --> 00:08:04,420
the other weekdays in this app, but this is a good

188
00:08:04,420 --> 00:08:07,380
example of how to choose one of a range of options,

189
00:08:07,380 --> 00:08:10,430
and for that reason all the weekdays are included.

190
00:08:10,430 --> 00:08:13,283
So I'm going to make my week day start on a Monday.

191
00:08:14,760 --> 00:08:17,066
Alright, so I'm gonna click on back now

192
00:08:17,066 --> 00:08:18,393
to go back to our list of tasks.

193
00:08:19,701 --> 00:08:22,500
Alright, so let's start another timing for my Java course.

194
00:08:22,500 --> 00:08:24,470
And you can see that showing on the screen there.

195
00:08:24,470 --> 00:08:27,300
Now I could just long tap that again to stop it,

196
00:08:27,300 --> 00:08:29,700
but if I want to actually swing over to another task,

197
00:08:29,700 --> 00:08:32,559
I can long tap that task and it ends the timing

198
00:08:32,559 --> 00:08:36,049
for the Java course and starts the timing for the cycling.

199
00:08:37,326 --> 00:08:39,164
Alright, so that's enough cycling

200
00:08:39,164 --> 00:08:41,299
and I'm going to long tap that to stop it.

201
00:08:41,299 --> 00:08:42,970
It's time to get back to work.

202
00:08:42,970 --> 00:08:45,780
So the second icon in the toolbar up here,

203
00:08:45,780 --> 00:08:48,160
that's used to display reports of how long

204
00:08:48,160 --> 00:08:50,320
was spent on each task.

205
00:08:50,320 --> 00:08:52,520
So this duration's report, I'll open it now,

206
00:08:53,410 --> 00:08:56,600
has got two different layouts for portrait and landscape.

207
00:08:56,600 --> 00:08:59,210
In portrait mode we can see the task name,

208
00:08:59,210 --> 00:09:01,210
the date, and how long was spent on each task.

209
00:09:01,210 --> 00:09:02,760
In other words, the duration.

210
00:09:02,760 --> 00:09:04,840
But whenever I take the device back into landscape

211
00:09:04,840 --> 00:09:08,050
again there now, we also get the description

212
00:09:08,050 --> 00:09:09,360
showing as well.

213
00:09:09,360 --> 00:09:11,680
Now you can sort the lists by clicking

214
00:09:11,680 --> 00:09:13,010
on the column headings.

215
00:09:13,010 --> 00:09:15,180
We can see the timings and task order

216
00:09:15,180 --> 00:09:17,842
or by clicking on the description column here,

217
00:09:17,842 --> 00:09:19,800
the description heading rather, you can see

218
00:09:19,800 --> 00:09:22,180
that it's now sorted by description.

219
00:09:22,180 --> 00:09:25,490
We can also display for weeks or just single days

220
00:09:25,490 --> 00:09:27,020
but with any two timing records

221
00:09:27,020 --> 00:09:29,160
that's not easy to demonstrate.

222
00:09:29,160 --> 00:09:30,840
This is a good time though to show a bug

223
00:09:30,840 --> 00:09:32,370
in the programme though.

224
00:09:32,370 --> 00:09:35,750
Now at the moment we're viewing a full week's data.

225
00:09:35,750 --> 00:09:38,270
There's only data for today and because I've only

226
00:09:38,270 --> 00:09:39,370
just done some timing.

227
00:09:41,169 --> 00:09:43,120
The button on the toolbar up here shows a one

228
00:09:43,120 --> 00:09:44,860
to indicate that it was switched to just showing

229
00:09:44,860 --> 00:09:46,040
a single day.

230
00:09:46,040 --> 00:09:49,580
So when I tap that, it changes to a seven

231
00:09:49,580 --> 00:09:51,490
as you can see on the screen there now

232
00:09:51,490 --> 00:09:54,480
to indicate that tapping it again would display a full week.

233
00:09:54,480 --> 00:09:56,730
But what's actually happened to the data?

234
00:09:56,730 --> 00:09:58,490
It was there in the week view

235
00:09:58,490 --> 00:10:00,740
and should be appearing for today.

236
00:10:00,740 --> 00:10:02,940
Well it's very easy to get things messed up

237
00:10:02,940 --> 00:10:05,760
when you're dealing with dates and times across the world.

238
00:10:05,760 --> 00:10:07,750
I can see the timings that were there

239
00:10:07,750 --> 00:10:09,917
by using the calendar icon by clicking on that

240
00:10:09,917 --> 00:10:12,920
and choosing the previous day, choosing yesterday,

241
00:10:12,920 --> 00:10:14,293
in my case it's the 12th.

242
00:10:15,251 --> 00:10:18,630
Click on okay and the entries actually appear again.

243
00:10:18,630 --> 00:10:20,480
And there's the timing data back.

244
00:10:20,480 --> 00:10:22,724
Now I selected yesterday in the calendar,

245
00:10:22,724 --> 00:10:25,070
but the date column over here is still

246
00:10:25,070 --> 00:10:26,930
showing today's date.

247
00:10:26,930 --> 00:10:30,127
So the reason for that is I'm recording this in Australia

248
00:10:30,127 --> 00:10:32,770
which is currently nine and a half hours ahead

249
00:10:32,770 --> 00:10:35,200
of Greenwich Mean Time, GMT.

250
00:10:35,200 --> 00:10:37,430
Because I'm recording this early in the morning,

251
00:10:37,430 --> 00:10:40,490
it's still yesterday effectively at Greenwich.

252
00:10:40,490 --> 00:10:43,860
Unless you specify otherwise, times are in GMT,

253
00:10:43,860 --> 00:10:45,500
Greenwich Mean Time.

254
00:10:45,500 --> 00:10:47,770
That's going to have serious implications

255
00:10:47,770 --> 00:10:50,590
for most parts of the world including places

256
00:10:50,590 --> 00:10:54,070
like the UK and Portugal that use GMT.

257
00:10:54,070 --> 00:10:56,760
In summer, both those places change there clock

258
00:10:56,760 --> 00:10:58,020
to Summer Time.

259
00:10:58,020 --> 00:11:01,040
So we've got an app here that works sometimes

260
00:11:01,040 --> 00:11:02,520
in some parts of the world,

261
00:11:02,520 --> 00:11:04,949
but won't work all the time anywhere.

262
00:11:04,949 --> 00:11:08,010
Well that's not quite true, it'll work all the time

263
00:11:08,010 --> 00:11:10,730
in Casablanca and the Azores where they stay on GMT

264
00:11:10,730 --> 00:11:12,070
all year round.

265
00:11:12,070 --> 00:11:14,000
But overall though, that's not good

266
00:11:14,000 --> 00:11:15,480
and you'll get a chance to fix this

267
00:11:15,480 --> 00:11:17,210
towards the end of the section.

268
00:11:17,210 --> 00:11:18,910
And yes, I did say you.

269
00:11:18,910 --> 00:11:20,300
But don't worry though, we'll be covering

270
00:11:20,300 --> 00:11:23,340
the problem and solution before the challenge.

271
00:11:23,340 --> 00:11:24,880
Alright, so I'm going to go back to the main

272
00:11:24,880 --> 00:11:28,550
task screen now and the menu up here

273
00:11:28,550 --> 00:11:30,870
has also got a generate option

274
00:11:30,870 --> 00:11:33,310
that we can use to generate test data.

275
00:11:33,310 --> 00:11:37,090
So I'm gonna click on that and it'll make our reports

276
00:11:37,090 --> 00:11:38,460
a bit more interesting, and you can see that

277
00:11:38,460 --> 00:11:40,540
it's completed already, depending on the speed

278
00:11:40,540 --> 00:11:42,530
of your computer it may take a while.

279
00:11:42,530 --> 00:11:44,285
This menu option won't appear though

280
00:11:44,285 --> 00:11:46,660
in the release version of the app.

281
00:11:46,660 --> 00:11:48,140
There's some code that checks to see

282
00:11:48,140 --> 00:11:49,870
if we're running in debug mode,

283
00:11:49,870 --> 00:11:50,890
which you are when you're running

284
00:11:50,890 --> 00:11:53,290
directly from Android Studio as I am

285
00:11:53,290 --> 00:11:55,570
that makes this option visible.

286
00:11:55,570 --> 00:11:57,950
The code though hasn't got any frills,

287
00:11:57,950 --> 00:12:00,130
it's really only there to generate data for use

288
00:12:00,130 --> 00:12:02,250
while we're testing so that we don't have to wait

289
00:12:02,250 --> 00:12:04,940
while we create hundreds of timings.

290
00:12:04,940 --> 00:12:07,290
Now if we were going to do something like this for users

291
00:12:07,290 --> 00:12:09,520
then you should run it as a background thread.

292
00:12:09,520 --> 00:12:12,560
Because in my case even though it was relatively fast,

293
00:12:12,560 --> 00:12:14,460
the emulator appeared to hang.

294
00:12:14,460 --> 00:12:16,110
You may find that the display's gone blank

295
00:12:16,110 --> 00:12:19,540
for example on earlier versions of Android.

296
00:12:19,540 --> 00:12:21,600
The point is though that the app was very definitely

297
00:12:21,600 --> 00:12:24,530
blocking the user interface, which was not a good thing.

298
00:12:24,530 --> 00:12:27,263
So this generate data option generates between

299
00:12:27,263 --> 00:12:30,600
100 and 500 random timing records

300
00:12:30,600 --> 00:12:33,710
for each of the tasks that exist in the database.

301
00:12:33,710 --> 00:12:35,768
So it will take a little while, but it's much quicker

302
00:12:35,768 --> 00:12:38,650
than us having to create the data ourselves.

303
00:12:38,650 --> 00:12:40,890
And actually it's a bit slower than it should be

304
00:12:40,890 --> 00:12:43,680
because the method that generates the random data

305
00:12:43,680 --> 00:12:46,120
also logs what it's doing in the log cap.

306
00:12:46,120 --> 00:12:48,010
So though the emulator screen looked like there

307
00:12:48,010 --> 00:12:51,010
was nothing happening, if I quickly bring up Android Studio,

308
00:12:52,551 --> 00:12:54,882
we can see that there's quite a few entries there showing

309
00:12:54,882 --> 00:12:58,920
details about the actual timings

310
00:12:58,920 --> 00:13:00,690
that were actually generated.

311
00:13:00,690 --> 00:13:02,070
Alright, so I'm gonna close it down here,

312
00:13:02,070 --> 00:13:03,577
back to the emulator.

313
00:13:04,994 --> 00:13:05,870
Alright, so now that I've finished

314
00:13:05,870 --> 00:13:08,070
we're going to go back to our reports again.

315
00:13:08,930 --> 00:13:09,980
Clicking on the icon.

316
00:13:11,560 --> 00:13:14,570
Now the reports sorted by name, then date.

317
00:13:14,570 --> 00:13:17,530
But we can group all the cycling tasks together

318
00:13:17,530 --> 00:13:21,610
by clicking on the task name heading like so.

319
00:13:21,610 --> 00:13:23,570
Now the first button on the toolbar,

320
00:13:23,570 --> 00:13:26,040
that's a switch between displaying a whole week

321
00:13:26,040 --> 00:13:27,650
or just the current day.

322
00:13:27,650 --> 00:13:28,727
Now at the moment it's showing a whole week's

323
00:13:28,727 --> 00:13:31,301
worth of data, but clicking on the one button

324
00:13:31,301 --> 00:13:33,083
swaps to just showing today.

325
00:13:34,070 --> 00:13:36,110
And if you're doing this in America

326
00:13:36,110 --> 00:13:38,130
within five to eight hours of midnight

327
00:13:38,130 --> 00:13:40,130
you'll be seeing tomorrow's timings.

328
00:13:40,130 --> 00:13:43,630
And that's because the USA is behind GMT.

329
00:13:43,630 --> 00:13:46,390
And as we saw earlier, the button icon

330
00:13:46,390 --> 00:13:48,440
also changes to reflect the fact

331
00:13:48,440 --> 00:13:51,440
that clicking it again will show a week.

332
00:13:51,440 --> 00:13:52,890
And again, I've got that same situation

333
00:13:52,890 --> 00:13:55,290
there with the bug that I've talked about,

334
00:13:55,290 --> 00:13:56,937
with the GMT bug, so I have to go back

335
00:13:56,937 --> 00:13:59,610
and click on the previous day to actually get

336
00:13:59,610 --> 00:14:01,820
my data to display on the screen.

337
00:14:01,820 --> 00:14:04,090
Alright, now we have seen that calendar,

338
00:14:04,090 --> 00:14:06,620
so I click that calendar again there now.

339
00:14:06,620 --> 00:14:09,490
This time I'm gonna go back about a month now.

340
00:14:09,490 --> 00:14:13,690
I'm gonna go back to May, we'll say May the 16th.

341
00:14:13,690 --> 00:14:14,703
Click on okay there.

342
00:14:16,460 --> 00:14:19,410
If I come across here now and click on the icon,

343
00:14:19,410 --> 00:14:23,040
the seven button now, the app should work out

344
00:14:23,040 --> 00:14:25,193
which seven days will be displayed based on the data

345
00:14:25,193 --> 00:14:27,980
I just chose and which day we've set

346
00:14:27,980 --> 00:14:30,540
for the first day of the weeks in the settings.

347
00:14:30,540 --> 00:14:32,280
That's easy to see there now.

348
00:14:32,280 --> 00:14:34,926
If I click the date heading firstly to sort that,

349
00:14:34,926 --> 00:14:36,167
you can see we've got entries from the 14th,

350
00:14:36,167 --> 00:14:38,910
16th, 17th, and 19th of May.

351
00:14:38,910 --> 00:14:40,796
And just to confirm if we go over

352
00:14:40,796 --> 00:14:41,890
and click on the calendar,

353
00:14:41,890 --> 00:14:43,590
that is correct because I chose Monday

354
00:14:43,590 --> 00:14:46,600
as my start of the week and that's the 14th,

355
00:14:46,600 --> 00:14:48,720
and we can see Sunday was the 13th there

356
00:14:48,720 --> 00:14:51,490
and we've got no entries showing for the 13th.

357
00:14:51,490 --> 00:14:53,040
Cancel out of that.

358
00:14:53,040 --> 00:14:54,290
So basically we're seeing data here

359
00:14:54,290 --> 00:14:57,163
from the 14th through to the 19th, which is correct.

360
00:14:58,090 --> 00:14:59,700
And that's obviously assuming there's data

361
00:14:59,700 --> 00:15:02,020
for each day of course, and if we didn't

362
00:15:02,020 --> 00:15:03,830
have that bug that I've talked about.

363
00:15:03,830 --> 00:15:05,630
Now the version of the app is currently

364
00:15:05,630 --> 00:15:08,180
displaying dates in the American format,

365
00:15:08,180 --> 00:15:10,300
month, day, year.

366
00:15:10,300 --> 00:15:12,830
That can be confusing for people in other countries,

367
00:15:12,830 --> 00:15:14,987
so we'll also be seeing how we can display the dates

368
00:15:14,987 --> 00:15:18,223
in the user's preferred format based on their country.

369
00:15:19,080 --> 00:15:20,920
Alright, so finally now there's an option

370
00:15:20,920 --> 00:15:22,730
to delete old data.

371
00:15:22,730 --> 00:15:25,030
So we get to choose a date and everything

372
00:15:25,030 --> 00:15:27,640
before that date will be deleted.

373
00:15:27,640 --> 00:15:29,290
So I'm going to choose the 16th here,

374
00:15:29,290 --> 00:15:31,600
so I'm going to click on the menu option,

375
00:15:31,600 --> 00:15:33,500
select delete old timings,

376
00:15:33,500 --> 00:15:35,353
I'm going to choose the 16th, click on okay.

377
00:15:37,830 --> 00:15:39,730
It asks us for confirmation.

378
00:15:39,730 --> 00:15:41,620
So we get a prompt here making sure that we really

379
00:15:41,620 --> 00:15:43,037
do want to delete all that data.

380
00:15:43,037 --> 00:15:46,210
And if I cancel it the data will still show.

381
00:15:46,210 --> 00:15:48,340
But if I go back to the option,

382
00:15:48,340 --> 00:15:50,083
select delete old timings,

383
00:15:51,460 --> 00:15:53,596
select the 16th of May, click on okay,

384
00:15:53,596 --> 00:15:57,390
click on okay again, and you can see now that

385
00:15:57,390 --> 00:16:00,450
the data prior to the date that I've selected

386
00:16:00,450 --> 00:16:02,230
has now been deleted.

387
00:16:02,230 --> 00:16:03,810
Well that's the theory at least,

388
00:16:03,810 --> 00:16:05,620
it was actually a bug in the programme,

389
00:16:05,620 --> 00:16:07,780
but fixing that is also going to be a challenge

390
00:16:07,780 --> 00:16:09,490
towards the end of the section.

391
00:16:09,490 --> 00:16:12,140
Alright, so we'll go back now to our main list again.

392
00:16:13,160 --> 00:16:14,840
So there's two buttons we can use to edit

393
00:16:14,840 --> 00:16:17,560
the task details and delete the tasks.

394
00:16:17,560 --> 00:16:19,810
So when I click the delete button over here,

395
00:16:19,810 --> 00:16:22,649
the trash icon next to the Java course,

396
00:16:22,649 --> 00:16:24,859
there's a dialogue option that pops up here

397
00:16:24,859 --> 00:16:27,535
warning that the timings will also be deleted.

398
00:16:27,535 --> 00:16:31,150
So our timing's data is stored in a separate table

399
00:16:31,150 --> 00:16:33,110
that links to the tasks table,

400
00:16:33,110 --> 00:16:35,340
and there's no point keeping all the timings around

401
00:16:35,340 --> 00:16:38,230
if you no longer know which task it relates to.

402
00:16:38,230 --> 00:16:41,120
So the database has been set up with a trigger.

403
00:16:41,120 --> 00:16:44,190
When a task is deleted or the timing's records

404
00:16:44,190 --> 00:16:48,120
with the same task ID are automatically deleted for us,

405
00:16:48,120 --> 00:16:49,900
and we'll be seeing how to do that as we write

406
00:16:49,900 --> 00:16:51,210
the app as well.

407
00:16:51,210 --> 00:16:53,771
So I'm gonna click on delete here now.

408
00:16:53,771 --> 00:16:55,480
It deletes that, and now if we go back

409
00:16:55,480 --> 00:16:58,330
to our reports, we shouldn't see any other

410
00:16:58,330 --> 00:17:01,520
entries related to the Java task

411
00:17:01,520 --> 00:17:02,820
because it's been deleted.

412
00:17:07,376 --> 00:17:08,319
Going back to the previous week again,

413
00:17:08,319 --> 00:17:10,589
there's nothing related to Java actually

414
00:17:10,589 --> 00:17:12,650
showing them in the list any more.

415
00:17:12,650 --> 00:17:15,730
Right, so go back to the main task list again.

416
00:17:15,730 --> 00:17:17,550
Now the app's also got an about dialogue

417
00:17:17,550 --> 00:17:18,800
in the menu in the main screen,

418
00:17:18,800 --> 00:17:21,642
so we'll click on the button there.

419
00:17:21,642 --> 00:17:23,450
An about screen is a good place to provide

420
00:17:23,450 --> 00:17:25,400
additional information about the app

421
00:17:25,400 --> 00:17:27,380
and we'll how to include clickable links

422
00:17:27,380 --> 00:17:29,060
in our screens.

423
00:17:29,060 --> 00:17:31,160
So here I can click on the link here

424
00:17:31,160 --> 00:17:33,040
to launch the Android browser.

425
00:17:33,040 --> 00:17:33,990
You can choose one.

426
00:17:37,810 --> 00:17:39,130
I needed to go through the initial defaults

427
00:17:39,130 --> 00:17:41,880
and then it will then load that web page automatically.

428
00:17:43,338 --> 00:17:46,740
And when I close the browser notice that we get

429
00:17:46,740 --> 00:17:48,240
back to our application again.

430
00:17:49,283 --> 00:17:50,950
And we'll be seeing how to do that as well.

431
00:17:50,950 --> 00:17:53,020
Now I can't demonstrate the email link,

432
00:17:53,020 --> 00:17:54,873
we just go back again and have a look.

433
00:17:56,050 --> 00:17:57,030
There's also an email link there,

434
00:17:57,030 --> 00:17:58,690
I can't demonstrate that because I don't have

435
00:17:58,690 --> 00:18:01,090
the email set up on this Android emulator,

436
00:18:01,090 --> 00:18:03,720
but on a physical device, tapping the email address

437
00:18:03,720 --> 00:18:06,160
will launch your email programme with the to address

438
00:18:06,160 --> 00:18:09,310
already filled in ready for you to type an email.

439
00:18:09,310 --> 00:18:12,020
So our previous dialogues had okay and cancel buttons,

440
00:18:12,020 --> 00:18:13,760
but this one's just got an okay button,

441
00:18:13,760 --> 00:18:16,078
so I can click on that to close that down.

442
00:18:16,078 --> 00:18:18,468
So that's our app, its basic functionality

443
00:18:18,468 --> 00:18:21,330
may be quite simple, but we're going to be learning

444
00:18:21,330 --> 00:18:24,560
a lot of useful techniques when we write this app.

445
00:18:24,560 --> 00:18:26,120
And we'll start by looking at the underlying

446
00:18:26,120 --> 00:18:28,823
database which we'll do in the next video.

