1
00:00:00,720 --> 00:00:01,770
Welcome back.

2
00:00:02,100 --> 00:00:07,230
Do you still recall why we set up this room demo, I guess.

3
00:00:07,730 --> 00:00:08,840
You hopefully did so.

4
00:00:09,270 --> 00:00:16,140
The thing is we have worked through this room demo and you've seen it's has been quite a bit right.

5
00:00:16,170 --> 00:00:21,630
It's quite a long, um well, chapter, you could almost say, even though it's still part of the seven

6
00:00:21,630 --> 00:00:22,890
minute workout chapter.

7
00:00:23,220 --> 00:00:29,190
But realistically speaking, it should have been an own chapter because if we look at it like we want

8
00:00:29,190 --> 00:00:37,080
to use the same approach more or less as we have had in our room demo for this history screen, even

9
00:00:37,080 --> 00:00:38,400
though it's a lot simpler, right?

10
00:00:38,400 --> 00:00:42,060
We're not going to added any entries that we have in our history.

11
00:00:42,060 --> 00:00:44,700
We're not going to update or delete them or anything.

12
00:00:44,700 --> 00:00:51,180
So the only thing that we are going to actually do is, first of all, insert them and then retrieve

13
00:00:51,180 --> 00:00:51,420
them.

14
00:00:51,780 --> 00:00:59,460
But we can learn from our room demo that we had set up, OK, so we will need an entity, then we will

15
00:00:59,460 --> 00:01:01,260
need a DAO.

16
00:01:01,860 --> 00:01:08,010
Like this one this and bringing all that we had, we will need a database and then we will need to have

17
00:01:08,010 --> 00:01:09,660
an adapter, which will not be an item.

18
00:01:09,660 --> 00:01:11,520
Adapter will be a different adapter, I believe.

19
00:01:11,880 --> 00:01:16,700
Well, it would be like a history adapter or history entry adapter or something like that.

20
00:01:16,950 --> 00:01:19,380
And then we can go from there.

21
00:01:19,680 --> 00:01:26,580
I know that this is quite tough, but if you really want to challenge yourself and really learn how

22
00:01:26,580 --> 00:01:34,380
to use the room database, I would recommend that you try to apply as much as you can from the room

23
00:01:34,380 --> 00:01:37,190
demo that we have seen in the last couple of videos.

24
00:01:37,200 --> 00:01:44,760
It was seven videos I believe tried to set up the same approach step by step two, then display entries

25
00:01:45,030 --> 00:01:47,700
of your last couple of exercises that you did.

26
00:01:47,940 --> 00:01:52,540
Because if you look at it, we do have this activity here.

27
00:01:52,560 --> 00:01:59,310
This main activity, which then jumps you over, let's look at it to our exercise activity in what's

28
00:01:59,310 --> 00:02:02,640
with done with the exercise activity, we jump over to the finish activity.

29
00:02:02,850 --> 00:02:11,070
So once done with exercise activity, you could say, OK, let's now make the entry into our database.

30
00:02:11,970 --> 00:02:16,530
So that would be a good spot to do it and then retrieve it.

31
00:02:17,720 --> 00:02:24,680
Inside of our history activity, because that's where we will then need to retrieve the data entries.

32
00:02:25,590 --> 00:02:30,800
OK, so it will be tough, as I said, but if you feel like a real challenge, try it.

33
00:02:31,490 --> 00:02:33,980
If you don't feel like a real challenge, you can just follow along.

34
00:02:34,160 --> 00:02:38,640
But at one point, you will need to take this challenge.

35
00:02:38,690 --> 00:02:44,480
So at one point, when you start building your own applications in the future, you will have to go

36
00:02:44,480 --> 00:02:45,010
through this.

37
00:02:45,230 --> 00:02:46,760
And why not now?

38
00:02:47,500 --> 00:02:47,930
OK.

39
00:02:48,170 --> 00:02:54,830
And also feel free to share your experience of going through this in the comments down below.

40
00:02:55,340 --> 00:03:00,620
OK, so I'm going to show you once again how it's done, but I'm going to do it less in-depth, as I

41
00:03:00,620 --> 00:03:01,640
have done in the demo.

42
00:03:01,670 --> 00:03:09,740
So if you feel like it's too tough at some points, check out the demo once again before going to the

43
00:03:09,830 --> 00:03:11,300
actual seven minute workout.

44
00:03:11,810 --> 00:03:21,710
OK, because the demo was like, I have way more advanced and complete approach, right?

45
00:03:21,740 --> 00:03:27,110
We had everything that we needed with all four major operations, right?

46
00:03:27,110 --> 00:03:29,570
We had the crew operations.

47
00:03:29,570 --> 00:03:34,640
So create, read, update and delete, create, read, update, delete.

48
00:03:35,120 --> 00:03:40,640
If you ever hear those keywords, it's basically those values or those methods that we need to set up.

49
00:03:41,150 --> 00:03:41,570
OK.

50
00:03:42,720 --> 00:03:45,030
So I'd say, let's get started.

51
00:03:47,220 --> 00:03:55,350
OK, so what do we start with, what we do have our exercise model, so we know how every given exercise

52
00:03:55,350 --> 00:04:00,900
has to look like now we will need to have our history entity.

53
00:04:01,140 --> 00:04:09,210
OK, so now let's make sure that we set up the history entity as we have seen, which is generally the

54
00:04:09,210 --> 00:04:14,030
approach that you need to have the entity, then you can set up the doubt and you can set up the database

55
00:04:14,310 --> 00:04:20,519
and then you can go ahead and set up the app, as we have done in our room demo.

56
00:04:21,360 --> 00:04:22,079
So here.

57
00:04:23,190 --> 00:04:30,370
The Dow, while entity first Dow done database, then app, and then you can set up the recycler view

58
00:04:30,390 --> 00:04:33,570
in which you want to display the data, meaning the adapter for it.

59
00:04:33,900 --> 00:04:35,340
And yeah, that's pretty much it.

60
00:04:35,640 --> 00:04:36,540
So let's get started.

61
00:04:36,750 --> 00:04:41,040
The first thing will be our rather simple entity.

62
00:04:41,340 --> 00:04:48,570
So let me go ahead and create a new entity here, which will be a Cochrane class, and I'm going to

63
00:04:48,630 --> 00:04:50,040
use a data class here.

64
00:04:51,090 --> 00:04:55,080
Which I'm going to call his story and to tee.

65
00:04:56,250 --> 00:05:01,560
OK, so this one has to have the ET entity keyword assigned to it.

66
00:05:02,070 --> 00:05:03,570
So why does it not appear here?

67
00:05:03,930 --> 00:05:10,440
Well, the thing is we of course, need to go to our Gradle and make the changes there, so we need

68
00:05:10,440 --> 00:05:13,470
to add the dependencies in order to use.

69
00:05:15,130 --> 00:05:16,570
Our good old room.

70
00:05:16,840 --> 00:05:22,840
So here we need to add our Scotland Captain Scotland kept, which stands for Scotland annotation plug

71
00:05:22,840 --> 00:05:23,050
in.

72
00:05:23,680 --> 00:05:28,800
And then we need to make sure that we add the room dependencies.

73
00:05:28,810 --> 00:05:34,210
So in here pretty much do the same thing as we have done in our room demo.

74
00:05:34,210 --> 00:05:36,610
So let's go over to the room demo, if you recall.

75
00:05:37,060 --> 00:05:42,850
Here we can just go to our cradle and copy the dependencies from there.

76
00:05:42,850 --> 00:05:48,670
So the room version and call routine support we want to have as well.

77
00:05:48,820 --> 00:05:54,040
So let's add all of those lines here into our existing project here.

78
00:05:54,820 --> 00:05:56,020
OK, into our.

79
00:05:57,290 --> 00:05:58,760
7-Minute Workout Project.

80
00:05:59,120 --> 00:06:00,290
And then let's sync it.

81
00:06:01,740 --> 00:06:02,490
Sink it in.

82
00:06:02,850 --> 00:06:07,650
OK, now that it's sink, we can use Antigene, so we need to import anti-Dean.

83
00:06:08,160 --> 00:06:08,760
All right, Andrew.

84
00:06:08,920 --> 00:06:12,420
Room antigene and we can take care of our history antigene.

85
00:06:12,750 --> 00:06:14,670
And I'm going to give it a table name here.

86
00:06:15,060 --> 00:06:20,820
Table name, which will be history table.

87
00:06:21,570 --> 00:06:23,700
OK, so this will be our exercise history.

88
00:06:24,180 --> 00:06:30,670
And then the data class will only have one primary key and it will not be named.

89
00:06:31,740 --> 00:06:34,590
But this time, and we also need to import primary key.

90
00:06:34,980 --> 00:06:38,790
This time it will really just be a date because we don't need to store anything else.

91
00:06:39,180 --> 00:06:40,830
Just a date is going to be enough.

92
00:06:41,880 --> 00:06:47,280
So you could, of course, go ahead and add IDs and have the date as a separate entry, but can also

93
00:06:47,280 --> 00:06:52,670
just simply have the date as a primary key because the date is going to be so unique, it's not just

94
00:06:52,680 --> 00:06:59,340
going to be the date of the week or month or whatever, it's going to be specific to a millisecond.

95
00:06:59,730 --> 00:07:04,230
So in the same millisecond, it's highly unlikely that we will have the same entry so we can just use

96
00:07:04,230 --> 00:07:10,740
it as the primary key because in the same milliseconds to our application, it's not even going to be

97
00:07:10,740 --> 00:07:13,530
fast enough to store multiple pieces of information.

98
00:07:14,430 --> 00:07:20,220
OK, so now let's set up the Dow and the Dow for now really just needs to insert data.

99
00:07:20,760 --> 00:07:24,630
So let's go ahead and create a new Dow file.

100
00:07:26,250 --> 00:07:32,550
Which will be called while have an interface, first of all, and I'm going to call this one his story

101
00:07:32,550 --> 00:07:33,990
doll like so.

102
00:07:35,210 --> 00:07:40,900
OK, and this will be a done deal, so we need to add the key keyword here at Dow, we need to import

103
00:07:40,910 --> 00:07:43,430
Danielle from room and we can then.

104
00:07:44,520 --> 00:07:48,180
Use our insert key word from room again.

105
00:07:48,210 --> 00:07:53,040
Import debt and use our suspend function, which will be answered function.

106
00:07:53,220 --> 00:07:56,820
And what do we need to insert while our history entity, which would just prepared, right?

107
00:07:57,480 --> 00:08:02,910
So this is the same approach as we had with our room demo, if you recall.

108
00:08:03,030 --> 00:08:09,240
So here we had set up the entity and then we have set up the DOL where we added the annotation DAO and

109
00:08:09,240 --> 00:08:14,220
then to insert method with the entity that we have created.

110
00:08:14,970 --> 00:08:16,530
OK, this extra entity?

111
00:08:17,250 --> 00:08:17,760
All right.

112
00:08:18,150 --> 00:08:24,270
So now that we have the history DAO, let's go ahead and set up our database because in our database,

113
00:08:24,270 --> 00:08:26,130
we can now use our DAO.

114
00:08:26,580 --> 00:08:29,570
So let's go ahead and create a new Kotlin file class.

115
00:08:29,580 --> 00:08:31,400
This one will be an abstract class.

116
00:08:31,410 --> 00:08:32,789
I think we don't have that here.

117
00:08:33,059 --> 00:08:40,059
So let's just use a default class here, which I'm going to call history database like so OK.

118
00:08:40,059 --> 00:08:42,929
And this history database will be an abstract class.

119
00:08:44,770 --> 00:08:49,330
Which inherits from the room database Glass, so here room data.

120
00:08:50,270 --> 00:08:55,930
I think it's with a Capital D data base, so we need to import room database for this.

121
00:08:57,680 --> 00:08:58,340
Let's do that.

122
00:08:59,390 --> 00:09:00,770
You see, it's in the room.

123
00:09:01,640 --> 00:09:07,520
And we need to add the database and annotation, so let's check out our database example.

124
00:09:08,210 --> 00:09:10,070
So here we had to improve your database.

125
00:09:10,100 --> 00:09:18,500
Now we need to add this add database annotation with the entity, class name and the version.

126
00:09:18,770 --> 00:09:25,250
OK, so let me do that as well here, which will not use the employee entity, but our history entity.

127
00:09:26,630 --> 00:09:26,940
OK.

128
00:09:27,950 --> 00:09:32,150
And now we need to create a history Dow object.

129
00:09:32,990 --> 00:09:36,290
So let's also just use the same things that we've done here.

130
00:09:36,710 --> 00:09:43,640
We can really just copy this entire thing from our employee database, from the room demo and just make

131
00:09:43,640 --> 00:09:44,450
a couple of changes.

132
00:09:44,460 --> 00:09:50,300
So this is not going to be the employee Dow, but the history Dow, which uses, of course, the history

133
00:09:50,300 --> 00:09:51,950
Dow class.

134
00:09:53,050 --> 00:10:02,200
As its basic basis, then this will be the history database that we create an instance of.

135
00:10:02,500 --> 00:10:07,120
So here we just need to replace employee database with history database.

136
00:10:07,450 --> 00:10:09,870
And of course, he had to name this is a string.

137
00:10:09,880 --> 00:10:12,050
This is very tricky when working with strings.

138
00:10:12,100 --> 00:10:13,240
Always be careful, right?

139
00:10:13,630 --> 00:10:21,070
And then the name, of course, will be history database and not the other one that we had in our previous

140
00:10:21,070 --> 00:10:21,520
example.

141
00:10:21,790 --> 00:10:27,100
So again, we have this companion object with our volatile instance of the history database, which

142
00:10:27,100 --> 00:10:29,700
is at the beginning, a null entry.

143
00:10:29,770 --> 00:10:30,610
So it's empty.

144
00:10:30,940 --> 00:10:36,280
And then we have this get instance method, which will check whether we do have an instance already.

145
00:10:36,280 --> 00:10:40,540
If we do, then just use it otherwise created.

146
00:10:40,900 --> 00:10:45,510
OK, so he just says, OK, whatever the instance was, if it already exists, if it's not null, which

147
00:10:45,510 --> 00:10:47,020
had at the beginning, of course, will be.

148
00:10:47,020 --> 00:10:52,000
But once we get the instance, for example, a second time, then the instance already exists.

149
00:10:52,330 --> 00:10:56,770
So then it will just say, OK, this local instance is going to be the existing instance.

150
00:10:57,310 --> 00:11:01,180
And then we check, OK, is the instance existing or is it null?

151
00:11:01,180 --> 00:11:06,370
If it's null, which will, it will be only at the first run or at the first time that we get the instance,

152
00:11:06,700 --> 00:11:10,060
then create an instance and set it as the global variable.

153
00:11:10,210 --> 00:11:15,700
Otherwise, make sure that you just use the old instance that you had and return it.

154
00:11:16,360 --> 00:11:16,720
OK.

155
00:11:16,810 --> 00:11:19,720
So basically, if it exists, don't do anything.

156
00:11:19,870 --> 00:11:21,190
If it doesn't exist, create it.

157
00:11:22,150 --> 00:11:24,220
So that's what we're doing here with this history database.

158
00:11:25,560 --> 00:11:32,340
So we have done A. With the Dow, we have to enter the database, so now let's go ahead and create the

159
00:11:32,340 --> 00:11:33,000
the app.

160
00:11:33,600 --> 00:11:36,810
OK, and I'm going to call this one workout app.

161
00:11:38,320 --> 00:11:45,150
So another class, which will be a normal class this time, work out and call it workout app.

162
00:11:45,850 --> 00:11:47,200
I'm not sure where the workout is.

163
00:11:47,200 --> 00:11:50,290
One word or probably it's one word, but it's fine as well.

164
00:11:50,770 --> 00:11:53,830
So here this one will inherit from application.

165
00:11:54,040 --> 00:11:54,460
OK.

166
00:11:54,880 --> 00:11:58,870
And now we need to set up the database.

167
00:11:59,080 --> 00:12:02,110
So let's look at our room database example.

168
00:12:02,620 --> 00:12:08,210
And here, let's look at the employee app we see we just created a database of lazily.

169
00:12:08,230 --> 00:12:12,460
So let's do the same thing, but with the history database this time.

170
00:12:14,480 --> 00:12:16,400
All right, now, we have to work out.

171
00:12:17,500 --> 00:12:21,280
And we need to make sure that in our manifest, we set it up as well.

172
00:12:21,610 --> 00:12:29,470
So here for the application, we need to end the Android name and it will be the Dot Workout app, which

173
00:12:29,470 --> 00:12:31,960
is this class that we just created.

174
00:12:31,960 --> 00:12:33,370
And so this class workout app.

175
00:12:35,330 --> 00:12:41,120
OK, so now we just need to make sure that we are storing the exercise that we have finished, and I

176
00:12:41,120 --> 00:12:47,270
think it's going to be best to start the exercise workout in the finish activity because we know once

177
00:12:47,270 --> 00:12:50,540
we are in the finish activity, we have gone through the exercise.

178
00:12:51,020 --> 00:12:58,160
So let's create a method which will take care of adding data or our date to the database.

179
00:12:58,370 --> 00:13:04,310
So here a private function, add to data or to add date.

180
00:13:05,210 --> 00:13:08,660
It will be will be better here to data base.

181
00:13:09,080 --> 00:13:13,280
And let's look at our the room database example once again.

182
00:13:13,700 --> 00:13:18,950
OK, because we had stored it, I think in the main activity, right, we took care of everything there.

183
00:13:19,490 --> 00:13:21,860
So update records add record.

184
00:13:21,920 --> 00:13:25,850
OK, so this was the part you see, we need to pass in the employee Dow.

185
00:13:26,270 --> 00:13:33,020
And this is where we used our call routine in order to then use the insert method using that employee

186
00:13:33,020 --> 00:13:34,990
dial with the employee entity.

187
00:13:35,030 --> 00:13:42,410
So now we need to do the same thing with the history Dow insert and I think its exercise entity or whatever

188
00:13:42,410 --> 00:13:44,780
we call it, with our history entity.

189
00:13:45,440 --> 00:13:49,160
So let's use the history object here.

190
00:13:50,290 --> 00:13:50,770
And then.

191
00:13:51,950 --> 00:13:55,160
We will need to know what we want to store.

192
00:13:55,400 --> 00:14:04,610
OK, so before we can do the life cycle stuff, so life cycle launch, life cycle, scope launch before

193
00:14:04,610 --> 00:14:08,960
we do all of that cold routine stuff and we need to import that, by the way, as well.

194
00:14:09,080 --> 00:14:15,050
This launch, as well as the lifecycle scope which has been added for me automatically the launch and

195
00:14:15,050 --> 00:14:19,250
lifecycle scope are now added as namespaces up there.

196
00:14:20,420 --> 00:14:29,930
And here I want to use my history down to insert, and I want to insert my mystery entity with a date,

197
00:14:29,930 --> 00:14:37,340
which is a string, so now I could do something like test string or something, but it would be better

198
00:14:37,340 --> 00:14:38,420
if it's actually a date.

199
00:14:39,410 --> 00:14:40,790
And in the right format.

200
00:14:41,600 --> 00:14:45,200
So in order to set up the date.

201
00:14:45,530 --> 00:14:47,030
So for now, it will be an empty string.

202
00:14:47,330 --> 00:14:49,820
We need to, of course, prepare to date up here.

203
00:14:50,510 --> 00:14:55,970
So the general structure for a date, if you want to get that would of course, to be, first of all,

204
00:14:55,970 --> 00:14:57,700
to create a calendar instance.

205
00:14:57,710 --> 00:14:59,720
So calendar get instance.

206
00:15:00,440 --> 00:15:02,030
So see will be my calendar.

207
00:15:02,030 --> 00:15:08,600
Of course, you could call it my calendar or so and then get the date time object, which will be simply

208
00:15:08,600 --> 00:15:09,800
see that time.

209
00:15:10,100 --> 00:15:13,880
So time gives me a while.

210
00:15:13,880 --> 00:15:16,760
If you can look at it, it will give me a date object.

211
00:15:16,970 --> 00:15:24,500
So get time will give me a date object, which is this see time will use to get time method of the calendar

212
00:15:24,500 --> 00:15:24,950
class.

213
00:15:25,580 --> 00:15:28,160
And now we can, of course, lock that.

214
00:15:28,520 --> 00:15:36,770
So here you could go ahead and say the date will be and then the message would be an empty string plus

215
00:15:37,130 --> 00:15:37,850
dates time.

216
00:15:38,970 --> 00:15:40,140
OK, let's import log.

217
00:15:40,440 --> 00:15:46,350
This will give us the date that we want the storm, and now we have to set up the date for autumn.

218
00:15:46,470 --> 00:15:52,950
And there is this simple date format class, so let's create it as the we've done this in the past,

219
00:15:52,950 --> 00:15:58,170
I think when we created our calculator like how old you are, calculator?

220
00:15:58,170 --> 00:15:58,800
Think you're right?

221
00:15:59,250 --> 00:16:02,560
So here we need to use the simple data format.

222
00:16:02,580 --> 00:16:04,140
I'm going to use to Android One.

223
00:16:04,680 --> 00:16:06,930
And here you need to define the pattern.

224
00:16:06,930 --> 00:16:12,660
So I'm going to use the pattern of day, day then month of month, which means the month in the sense

225
00:16:12,660 --> 00:16:16,650
of Gen Fab Ma and so forth.

226
00:16:16,830 --> 00:16:19,200
And then two year and four digits.

227
00:16:19,230 --> 00:16:23,130
So year you year the hours, the minutes and seconds.

228
00:16:24,270 --> 00:16:32,610
And I'm going to use the local default settings, so whatever is the default of the phone settings,

229
00:16:32,610 --> 00:16:33,660
so get default.

230
00:16:34,170 --> 00:16:38,910
So if the phone is said to American ours, then we'll use the American ours and so forth.

231
00:16:40,330 --> 00:16:46,420
OK, so this is going to be our simple date format and and we check what the problem here is.

232
00:16:55,210 --> 00:16:58,930
And it seems like I shouldn't have done or shouldn't have used the.

233
00:17:00,320 --> 00:17:03,800
One from Android and the check.

234
00:17:05,400 --> 00:17:13,589
I need to have the right namespace here, which is import Java, text the simple data format.

235
00:17:13,920 --> 00:17:17,579
Okay, so that's where the simple data format is stored.

236
00:17:18,540 --> 00:17:22,380
So it's not going to be this Android One that I have used earlier.

237
00:17:22,680 --> 00:17:24,450
It's actually going to be the Java one.

238
00:17:24,510 --> 00:17:25,650
Oh, it's cool Java stuff.

239
00:17:26,099 --> 00:17:26,460
OK.

240
00:17:26,670 --> 00:17:34,920
So now we can use the simple data format to get the date from the date object into a usable.

241
00:17:36,160 --> 00:17:37,820
The string formats that we can use.

242
00:17:38,300 --> 00:17:44,720
OK, so let's go ahead and create a data object, which will be our while use our simple data format

243
00:17:44,750 --> 00:17:49,490
to format the date time that we have earlier created.

244
00:17:49,520 --> 00:17:51,110
So here we get this data object.

245
00:17:51,380 --> 00:17:55,490
We use this simple date format to make a string out of this date format.

246
00:17:56,810 --> 00:18:00,530
And then, yeah, make a date out of it, which will be a string.

247
00:18:00,770 --> 00:18:06,950
So now we can use this date, we can log it using this entry here.

248
00:18:07,190 --> 00:18:11,670
So first we get the date, then we formed the date with our own pattern.

249
00:18:11,690 --> 00:18:17,210
So here you defined your pattern and then we can now use this date here.

250
00:18:17,420 --> 00:18:20,510
So let's past a date instead of an empty string.

251
00:18:23,160 --> 00:18:27,210
OK, so this will add today to our database.

252
00:18:27,660 --> 00:18:28,440
This line here.

253
00:18:28,980 --> 00:18:29,370
All right.

254
00:18:29,700 --> 00:18:31,460
So we'll call this insert method.

255
00:18:31,470 --> 00:18:32,820
I'm going to lock that as well.

256
00:18:33,120 --> 00:18:42,780
So here it will use this insert suspend function, which is a quote routine function, and then we're

257
00:18:42,780 --> 00:18:43,350
going to log it.

258
00:18:44,370 --> 00:18:48,360
So when do we want to call this add to database function?

259
00:18:49,140 --> 00:18:54,360
Well, we want to do it in the create method right inside of this on create here at the top.

260
00:18:54,630 --> 00:18:59,670
Unfortunately, however, we cannot just call the method without doing any preparation.

261
00:19:00,120 --> 00:19:06,810
So the preparation that we need to do is whenever you want to call a double is to set up a database.

262
00:19:07,290 --> 00:19:08,820
So let's set up the dial here.

263
00:19:10,340 --> 00:19:11,700
Val Dow.

264
00:19:11,720 --> 00:19:14,690
And let's check it out how we've done it in the room demo.

265
00:19:15,110 --> 00:19:21,620
So here you can hold the control key and click on Add Record and then we'll show you when it was used.

266
00:19:21,800 --> 00:19:27,050
So it was used here at the top where we said add record and we needed to pass the employee down to this

267
00:19:27,050 --> 00:19:32,660
and record method, as you recall, because, well, that's what we had here as the parameter.

268
00:19:33,230 --> 00:19:35,440
So now we need to set up the Dow.

269
00:19:35,450 --> 00:19:36,230
How did we do it?

270
00:19:36,230 --> 00:19:37,220
We did it like this.

271
00:19:37,390 --> 00:19:43,140
OK, so let's copy this line and then paste it in here to make the changes that we need to make.

272
00:19:43,160 --> 00:19:45,820
So this one will instead just be a history doll.

273
00:19:45,860 --> 00:19:48,050
Or you could just also call it out if you want to.

274
00:19:48,110 --> 00:19:48,950
Either way is fine.

275
00:19:49,310 --> 00:19:51,170
It will use our history app.

276
00:19:52,340 --> 00:19:53,060
And.

277
00:19:54,320 --> 00:19:55,390
Doesn't find it here.

278
00:19:55,570 --> 00:19:56,890
I think we call it workout app.

279
00:19:57,790 --> 00:19:58,120
Yes.

280
00:19:58,630 --> 00:20:01,630
So it wasn't just this rehab, it was the workout app.

281
00:20:01,630 --> 00:20:04,510
And then inside of workout app, we had this TV.

282
00:20:05,560 --> 00:20:13,510
OK, so this database and now we can call the history down, which will be this abstract function inside

283
00:20:13,510 --> 00:20:14,830
of our history database.

284
00:20:16,270 --> 00:20:16,810
OK.

285
00:20:19,060 --> 00:20:25,900
So now that we have the Dow, we can call our add two database method with that Dow, and that will

286
00:20:25,930 --> 00:20:28,330
basically do what we need to do.

287
00:20:28,330 --> 00:20:30,400
So this will store the entry.

288
00:20:30,790 --> 00:20:36,250
So in order to test this, what I'm going to do is I'm going to go to my.

289
00:20:37,720 --> 00:20:46,470
Exercise activity and make sure that exercise timers, rest timer is one second exercise timer is one

290
00:20:46,470 --> 00:20:49,560
second because otherwise it would take forever for me to test this.

291
00:20:49,860 --> 00:20:54,810
So let's run this real quick and we will not sit on the user interface because that's something we will

292
00:20:54,810 --> 00:20:56,280
have to set up in the next video.

293
00:20:56,490 --> 00:21:00,090
But you see, we have set up everything so far to insert the data.

294
00:21:00,300 --> 00:21:04,370
So we will also, of course, need to set up how to retrieve the data.

295
00:21:04,380 --> 00:21:09,390
And so let's go ahead and start the exercise and it will just jump through it.

296
00:21:09,400 --> 00:21:15,690
I'm going to cut the video here until it's done and while actually we can set up our lock until then.

297
00:21:16,020 --> 00:21:20,730
So there is a lot going on in the Logcat, but what's interesting to us are going to be things like

298
00:21:20,730 --> 00:21:21,150
date.

299
00:21:21,240 --> 00:21:23,370
So we can directly search for the date keyword.

300
00:21:24,090 --> 00:21:24,310
OK.

301
00:21:26,260 --> 00:21:30,460
And we're going to search for errors, which we called it here.

302
00:21:30,820 --> 00:21:33,410
So there are no date errors or not many date errors.

303
00:21:33,440 --> 00:21:34,600
OK, now it's done, actually.

304
00:21:34,990 --> 00:21:41,110
You see it says date, which is this thing here, does log entry with the date time object.

305
00:21:41,110 --> 00:21:42,270
So it's free.

306
00:21:42,280 --> 00:21:44,680
Oct. 15 10 23.

307
00:21:44,680 --> 00:21:46,700
Thirty six GMT plus two.

308
00:21:46,960 --> 00:21:51,880
Well, whatever it tells me, all of this information even telling me which time zone I'm in in the

309
00:21:51,880 --> 00:21:52,930
year of 2021.

310
00:21:53,290 --> 00:22:00,620
So now if I take the former to date, it just says 15 Oct of 20, 21, 10, 23 36.

311
00:22:00,680 --> 00:22:05,560
So you see, it gives me this same format that I have defined here in the simple date format.

312
00:22:05,560 --> 00:22:13,930
So day day 15 and then and which stands for October, like OCD or whatever month, it is the first three

313
00:22:13,930 --> 00:22:14,830
letters of that month.

314
00:22:15,760 --> 00:22:21,100
Then the year that you can see here and then hours, minutes and seconds.

315
00:22:21,100 --> 00:22:26,290
So this h h will give me the hours, I think, in a 24 hour format, which is something I really love

316
00:22:26,290 --> 00:22:26,830
as a German.

317
00:22:27,100 --> 00:22:31,060
But if you are from a different country, maybe you like this and stuff.

318
00:22:31,570 --> 00:22:36,520
So it really is something you can play around with here in the date format.

319
00:22:37,570 --> 00:22:39,130
OK, and then we have the former to date.

320
00:22:40,290 --> 00:22:46,260
Which we don't see yet, as it seems former to date.

321
00:22:46,340 --> 00:22:47,580
Oh yeah, that was the former to date.

322
00:22:47,590 --> 00:22:48,010
I'm sorry.

323
00:22:48,030 --> 00:22:49,920
Yes, because that's where we used it.

324
00:22:49,920 --> 00:22:53,790
And then that's where we locked the date that we added.

325
00:22:53,800 --> 00:22:55,920
So now we should have it in the database.

326
00:22:56,130 --> 00:22:58,740
How do we find this out that you recall?

327
00:22:59,370 --> 00:23:00,330
Well, that's a cool thing.

328
00:23:00,360 --> 00:23:02,580
The idea gives us this app inspection here.

329
00:23:03,740 --> 00:23:04,400
And.

330
00:23:05,680 --> 00:23:07,390
After a while, it takes the process.

331
00:23:08,260 --> 00:23:13,720
And then after a while, it will display the database inspector at the history table so you can click

332
00:23:13,720 --> 00:23:14,710
on the history table.

333
00:23:15,700 --> 00:23:17,350
You see it only stores to date.

334
00:23:18,860 --> 00:23:22,910
And once you click on it, I had to wait a little bit and double clicked at once again, so just to

335
00:23:22,910 --> 00:23:30,880
make sure that it displays it and you see it created this entry of 15th of October 2021 at 10:23.

336
00:23:31,580 --> 00:23:36,410
OK, so we have the entry in our database now that we have finished the exercise or the workout.

337
00:23:36,770 --> 00:23:40,760
And now let's go ahead to the next video where we're going to retrieve the data and displayed.

338
00:23:41,420 --> 00:23:41,810
OK.

339
00:23:41,990 --> 00:23:45,350
So I hope you managed parts of it yourself.

340
00:23:45,470 --> 00:23:48,410
Or at least you now know that it's always the same process, right?

341
00:23:48,440 --> 00:23:53,000
It's always the same structure that you need to go through the same steps that you need to go through

342
00:23:53,000 --> 00:23:55,550
in order to store something in the database.

343
00:23:55,550 --> 00:24:00,200
So I know that it's still tough, but once you've done it a couple of times, it will become a lot more

344
00:24:00,200 --> 00:24:02,360
natural and you will just know how to do it.

345
00:24:02,540 --> 00:24:09,590
And even if you don't know how to do it from scratch or without any assistance, you can always just

346
00:24:09,590 --> 00:24:14,210
open up the demo that we have set up and use the same approach that we have used there.

347
00:24:14,690 --> 00:24:17,210
All right, so see you in the next video.

