1
00:00:00,930 --> 00:00:01,560
Welcome back.

2
00:00:01,830 --> 00:00:06,990
So in this video, what we want to achieve is to actually display the data not only to look at which

3
00:00:07,050 --> 00:00:11,460
is not visible to the user, but on the application itself.

4
00:00:11,820 --> 00:00:15,840
So here in the history activity, we want to display a recycler view.

5
00:00:15,870 --> 00:00:20,430
So we need to have an adapter for every single entry.

6
00:00:20,760 --> 00:00:23,040
So let's go ahead and set up such an adapter.

7
00:00:23,250 --> 00:00:27,510
Of course, it doesn't have to be as complicated because we will not need an update listener, and neither

8
00:00:27,840 --> 00:00:32,250
did the listener because we are not going to update or delete the entries.

9
00:00:32,250 --> 00:00:33,810
They should just be there permanently.

10
00:00:34,030 --> 00:00:39,390
Of course, you can go ahead and implement the delete listener if you ever want to delete entries manually

11
00:00:39,390 --> 00:00:43,500
as well, or want to have that in your application and allow this to the user.

12
00:00:43,830 --> 00:00:50,160
But generally speaking, we are going to need a history adapter, which will be similar to this item

13
00:00:50,160 --> 00:00:54,150
adapter, but as I said in a simplified fashion.

14
00:00:54,540 --> 00:01:00,480
So let's go ahead and set it up so we can get inspired by our room database.

15
00:01:01,170 --> 00:01:06,570
And you can have it open as the second screen if you want to and just try it by yourself.

16
00:01:07,140 --> 00:01:13,200
And we have used multiple adapters already, but we're going to need is, of course, to have the row

17
00:01:13,200 --> 00:01:13,560
itself.

18
00:01:13,560 --> 00:01:15,300
So this is the item history row.

19
00:01:15,780 --> 00:01:20,430
So each individual item should look like this, as we have seen at the end of the last video.

20
00:01:20,820 --> 00:01:22,980
So now let's go ahead and set up such an adapter.

21
00:01:23,340 --> 00:01:33,360
Therefore, I'm going to go over to my folder here and create a new Android Cortlandt file, and this

22
00:01:33,360 --> 00:01:35,370
one will be the history adapter.

23
00:01:35,730 --> 00:01:41,250
OK, so I'm going to call this one history adapter history adapter.

24
00:01:41,460 --> 00:01:41,870
Let's go.

25
00:01:42,510 --> 00:01:49,170
This will, of course, inherit from our beautiful adapter class, from recycling to you.

26
00:01:49,260 --> 00:01:54,270
So recycler view dot adapter and now we need to pass into view holder.

27
00:01:54,600 --> 00:01:58,560
And as we always do, we create our own view holder class inside of it.

28
00:01:58,560 --> 00:02:00,300
So let's do that here as well.

29
00:02:00,630 --> 00:02:07,560
I'm just going to call this one view holder with using view binding, so it will be item history row

30
00:02:07,560 --> 00:02:13,140
binding, which is the name of our XML file you can see here item history row and then binding, as

31
00:02:13,140 --> 00:02:13,470
always.

32
00:02:14,040 --> 00:02:21,330
OK, and this will inherit from Recycler View View Holder, and we need to pass in the binding object

33
00:02:21,510 --> 00:02:22,450
here as well.

34
00:02:22,490 --> 00:02:24,150
Otherwise, what won't work?

35
00:02:24,150 --> 00:02:32,160
But of course, I want to pass the root of the binding object, which just means this entire linear

36
00:02:32,160 --> 00:02:34,740
layout basically the entire file.

37
00:02:35,430 --> 00:02:38,280
OK, so just saying, OK, this is how the view holder should look like.

38
00:02:38,790 --> 00:02:47,080
Now I need to get access to the individual items that we have on our item history row XML file.

39
00:02:47,100 --> 00:02:53,310
So one is going to be the linear layout itself, then to text to you and this other text to you.

40
00:02:53,610 --> 00:03:01,680
So this is just going to look like this El History Item Main, which uses the binding object to access

41
00:03:01,680 --> 00:03:07,320
the history item main then detects your item, which gets to text your item from the binding and TV

42
00:03:07,320 --> 00:03:09,690
position from the binding TV position.

43
00:03:10,200 --> 00:03:16,020
OK, and now we can use our view holder that we have just created, which is inside of our history adapter

44
00:03:16,020 --> 00:03:19,020
class, and it's called our view holder.

45
00:03:19,030 --> 00:03:20,610
And here we need to add the brackets.

46
00:03:20,910 --> 00:03:26,310
And when we do that, we of course need to implement the members as we have done many, many times so

47
00:03:26,310 --> 00:03:26,610
far.

48
00:03:27,270 --> 00:03:29,370
OK, now let's go ahead and implement them.

49
00:03:29,580 --> 00:03:30,270
Item count.

50
00:03:30,270 --> 00:03:38,130
Well, of course, our history adapter needs to get a parameter here as well, and the parameter will

51
00:03:38,130 --> 00:03:41,990
just be a list of our items.

52
00:03:42,030 --> 00:03:45,890
So let's call this one private vault items.

53
00:03:46,110 --> 00:03:52,980
And usually we would go ahead and create a an array list or get an array list of rather complex items,

54
00:03:52,980 --> 00:03:55,530
which would be objects that we would create.

55
00:03:55,740 --> 00:03:57,960
But in this case, we're going to really keep it simple.

56
00:03:57,960 --> 00:04:02,850
It's just going to be strings because we don't have an extra property.

57
00:04:02,850 --> 00:04:05,490
How we called those entries?

58
00:04:06,120 --> 00:04:06,630
OK.

59
00:04:07,020 --> 00:04:11,310
So it will just be strings, which means every day is just going to be a string and and we're going

60
00:04:11,310 --> 00:04:13,740
to pass that string array.

61
00:04:15,010 --> 00:04:22,530
To our history adapter, because if you look at it in our history activity, you see that we're getting

62
00:04:22,600 --> 00:04:31,400
this list and this list is just a list of, well, history entities, but we are not going to get it

63
00:04:31,450 --> 00:04:32,620
as history entities.

64
00:04:32,620 --> 00:04:35,350
But actually what we want to get is just this date.

65
00:04:36,100 --> 00:04:40,960
So now you could of course say, Oh, let's use history entities here, but it really just has one property

66
00:04:40,960 --> 00:04:45,460
so we can simplify it and just use the date itself, which is of that string.

67
00:04:45,760 --> 00:04:49,180
So that's why we have this string array list here.

68
00:04:50,110 --> 00:04:57,250
OK, so now let's go ahead and say how many items were going to return, and this will be a return item

69
00:04:57,250 --> 00:04:58,870
start size, as always.

70
00:04:59,500 --> 00:05:05,170
Now the uncreative you hold there, that's going to be, as always, our own view hold that we created

71
00:05:05,170 --> 00:05:06,400
here this view holder here.

72
00:05:06,670 --> 00:05:19,420
So return view holder with our item history binding or history row binding inflate using our layout

73
00:05:19,420 --> 00:05:25,120
inflator with our parent context, as always.

74
00:05:25,630 --> 00:05:26,020
OK.

75
00:05:26,530 --> 00:05:32,230
And we need to pass the parent as well, as well as the attached to parent falls setting.

76
00:05:33,070 --> 00:05:34,540
And that should pretty much do it.

77
00:05:35,440 --> 00:05:39,550
OK, so now let's go ahead and take care of every single row.

78
00:05:39,550 --> 00:05:41,920
So how should every single row be handled?

79
00:05:42,190 --> 00:05:44,590
Well, first of all, let's get the date.

80
00:05:45,250 --> 00:05:50,290
So I'm going to get the date, which is going to be of type string from my items.

81
00:05:50,560 --> 00:05:58,570
So I need to get it at the position because I want to assign this date to my text view and I need to

82
00:05:58,570 --> 00:06:04,840
get the position itself as well so we can just use the holder, which is this view holder and we can

83
00:06:04,840 --> 00:06:07,750
just set it's text you position.

84
00:06:08,940 --> 00:06:16,830
Text to be the position +1, so position +1 because position starts counting at zero, so if we have

85
00:06:16,830 --> 00:06:23,580
an like here, you see here, if we have this entry here, it starts at zero and we don't want that

86
00:06:23,580 --> 00:06:25,740
to start at zero, wanted to start at one.

87
00:06:26,190 --> 00:06:29,250
So we are going to say position +1.

88
00:06:29,310 --> 00:06:32,160
Now, unfortunately, position is an integer and one is an integer.

89
00:06:32,160 --> 00:06:39,420
So we need to convert the result of this calculation into a string so that we can store it in the text

90
00:06:39,420 --> 00:06:46,320
property of our 2x2 position, which is going to be this text you hear as you see.

91
00:06:47,320 --> 00:06:55,600
OK, and now let's do the same thing with our all other you, which is our item itself, so let's set

92
00:06:55,600 --> 00:06:58,240
the text of it to be the date.

93
00:06:59,690 --> 00:07:10,130
And now, if we want to get this same thing that we had with our other room history example we see.

94
00:07:11,190 --> 00:07:13,920
Where we had multiple different entries.

95
00:07:14,280 --> 00:07:21,300
So you hear me just enter something where we had changing colors, so every second one was with a gray

96
00:07:21,300 --> 00:07:24,690
background, the other second ones were with a white background.

97
00:07:25,080 --> 00:07:32,820
So if it wants to have this altering background color stuff, we just need to go ahead and use the same

98
00:07:32,820 --> 00:07:34,830
approach as we have done in the room database.

99
00:07:34,830 --> 00:07:36,600
So let's just get inspired from it.

100
00:07:37,020 --> 00:07:42,330
Therefore, we have had our item adapter with this coat here.

101
00:07:42,750 --> 00:07:49,320
OK, so if position set background color, so let's do the same thing in our new project here.

102
00:07:49,470 --> 00:07:53,790
Of course, to allow the linear layout is now called history.

103
00:07:54,380 --> 00:07:55,080
I mean.

104
00:07:56,930 --> 00:07:59,300
And the context.

105
00:08:00,620 --> 00:08:08,210
Let me see get color context, so we need to have a context object or alternatively, we can even do

106
00:08:08,210 --> 00:08:12,920
that actually, we can do it without passing any context to just pass the color.

107
00:08:13,460 --> 00:08:21,500
So there we would need the context if we want to use a color from our colors x m l file, but we can

108
00:08:21,500 --> 00:08:24,050
also just pass the color.

109
00:08:24,560 --> 00:08:30,620
So just hardcoded in here, so colored dots parse color.

110
00:08:31,130 --> 00:08:32,600
And either way, would have been fine, right?

111
00:08:32,600 --> 00:08:34,270
You could have used the same approach there.

112
00:08:34,280 --> 00:08:37,909
So I'm just going to use the white color here.

113
00:08:37,950 --> 00:08:41,150
This is white and this one will be gray.

114
00:08:41,179 --> 00:08:44,840
So let's do the same thing where we passed the colors.

115
00:08:44,840 --> 00:08:50,640
So we set the background color to be parsed, and I think we use something like BBB here.

116
00:08:51,020 --> 00:08:54,260
So BBB and it's not as many.

117
00:08:56,580 --> 00:09:01,270
Values, OK, so this will give us this color effect that we have here.

118
00:09:01,740 --> 00:09:02,820
This background color effect.

119
00:09:03,720 --> 00:09:04,190
OK.

120
00:09:04,470 --> 00:09:08,520
So I think that should be pretty much it for our history adapter.

121
00:09:08,790 --> 00:09:14,040
And now let's of course, use this history adapter inside of our history activity, because that's where

122
00:09:14,040 --> 00:09:15,720
we want to make sure to display it.

123
00:09:17,870 --> 00:09:24,920
So let's go over to get all completed dates, because here what we want to do is want to of course,

124
00:09:24,920 --> 00:09:32,240
run this for loop here, but we're going to check if all completed dates isn't empty.

125
00:09:32,480 --> 00:09:35,790
We won't need this for loop because this was just for us to test it.

126
00:09:36,230 --> 00:09:41,150
So we check if all completed dates list isn't empty.

127
00:09:43,200 --> 00:09:48,210
And only then do we want to run some code, which means only then do we want to use our binding object

128
00:09:48,210 --> 00:09:51,270
to get access to the text of history and so forth.

129
00:09:51,690 --> 00:09:57,420
So binding text view history and see that we have the binding here.

130
00:09:58,590 --> 00:09:59,880
We do have binding.

131
00:10:03,190 --> 00:10:10,000
But I'm not sure whether we set up the history activity already, so the XML file, so let me get rid

132
00:10:10,000 --> 00:10:10,960
of this line for now.

133
00:10:11,470 --> 00:10:15,610
Let's go over to our layout and see if we have anything in our history.

134
00:10:15,850 --> 00:10:17,860
Oh yeah, we only have the toolbar here.

135
00:10:18,040 --> 00:10:18,520
That's why.

136
00:10:18,580 --> 00:10:19,850
OK, so we only have the toolbar.

137
00:10:19,870 --> 00:10:23,470
Of course, we need to add a proper user interface in here.

138
00:10:23,800 --> 00:10:27,180
So I'm just going to use of this right here.

139
00:10:27,190 --> 00:10:28,750
Let me go over it real quick.

140
00:10:29,080 --> 00:10:30,730
So we still have our toolbar.

141
00:10:31,030 --> 00:10:32,470
So use a constraint layout.

142
00:10:32,470 --> 00:10:34,870
And generally speaking, I want to have this here.

143
00:10:35,080 --> 00:10:36,700
OK, so this is what I want to have.

144
00:10:36,700 --> 00:10:41,440
This layout, you can see, have the toolbar at the top, then we have our text view which says exercise

145
00:10:41,440 --> 00:10:44,100
completed or exercises completed or whatever.

146
00:10:44,470 --> 00:10:48,250
Then we have our recycler view and then we have this text view, which says no data available.

147
00:10:48,520 --> 00:10:50,800
So this text view should be visible by default.

148
00:10:50,800 --> 00:10:56,230
And this recycled view, as well as this text, you should only be visible if we have any history data

149
00:10:56,230 --> 00:10:57,130
to be displayed.

150
00:10:57,580 --> 00:10:58,930
So let's look at it.

151
00:10:58,940 --> 00:11:05,610
We have this text view here, which is going to be at the bottom of our toolbar history activity.

152
00:11:06,280 --> 00:11:08,330
Then we call it Text your history.

153
00:11:08,380 --> 00:11:12,100
Then we have the recycle view, which will be underneath text view history.

154
00:11:12,580 --> 00:11:14,390
It will be gone by default.

155
00:11:14,480 --> 00:11:16,450
So this is going to be the default visibility.

156
00:11:16,870 --> 00:11:21,490
And then we have this text you at the bottom, which is just saying that we have no data available,

157
00:11:21,490 --> 00:11:23,290
so we haven't finished exercises yet.

158
00:11:23,290 --> 00:11:28,240
We could, of course, say something like do some exercise now or something like that to motivate someone

159
00:11:28,240 --> 00:11:29,620
who gets to this mystery screen.

160
00:11:30,070 --> 00:11:36,280
And this should be also underneath the toolbar history activity, but it should be at the same time

161
00:11:36,280 --> 00:11:37,570
to the bottom of the parent.

162
00:11:37,750 --> 00:11:43,960
So it should be basically dragged towards the top as well as towards the bottom, but then be in the

163
00:11:43,960 --> 00:11:44,380
center.

164
00:11:44,500 --> 00:11:46,300
So that's what we do with this gravity center.

165
00:11:46,750 --> 00:11:53,650
So we're just saying OK, centered is no data available thing and constrain it towards the toolbar as

166
00:11:53,650 --> 00:11:55,540
well as towards the bottom of the screen.

167
00:11:56,440 --> 00:12:04,240
OK, so now let's use this activity history as XML file inside of our history activity Caity file because

168
00:12:04,240 --> 00:12:10,990
now we can use this binding object to access the properties in our XML file, so to access the text.

169
00:12:11,710 --> 00:12:12,580
So let's do that.

170
00:12:13,000 --> 00:12:15,520
Let's access our texture history here.

171
00:12:16,510 --> 00:12:21,470
Which will be binding the TV history.

172
00:12:22,480 --> 00:12:27,220
And I'm going to set that to be visible.

173
00:12:27,550 --> 00:12:28,720
So visibility.

174
00:12:29,800 --> 00:12:35,440
Well, view that visible because if we have any data, we want to make it visible.

175
00:12:35,800 --> 00:12:37,910
If we don't have data, we want to make it invisible.

176
00:12:37,930 --> 00:12:40,510
And the same goes for our respective of you.

177
00:12:40,720 --> 00:12:42,720
So we want to make that one visible as well.

178
00:12:42,730 --> 00:12:44,170
So viewed that visible.

179
00:12:45,190 --> 00:12:49,730
And we want to make our text viewed that says we don't have any data invisible.

180
00:12:49,750 --> 00:12:56,230
So text, you know, data available visibility should be said to view thought invisible.

181
00:12:56,890 --> 00:13:03,550
OK, so now we can set the respect of you to be set up and let me actually before we do that.

182
00:13:03,850 --> 00:13:04,930
Let me add to Outlook Block.

183
00:13:04,930 --> 00:13:08,500
This will make it a little or a little easier for you to follow, I believe.

184
00:13:08,800 --> 00:13:12,250
So here in the other case, we're going to do the opposite.

185
00:13:12,250 --> 00:13:16,210
So we're going to make this stuff here, invisible or gone.

186
00:13:16,510 --> 00:13:21,430
And this text view that says no data available.

187
00:13:21,580 --> 00:13:22,900
This one here visible.

188
00:13:23,050 --> 00:13:26,050
So if we have no data displayed, otherwise don't display.

189
00:13:26,650 --> 00:13:28,300
And now we can set up our recycle view.

190
00:13:28,960 --> 00:13:33,400
So here our recycle view needs to have a layout manager.

191
00:13:33,400 --> 00:13:41,800
So let me get access to this recycle view and set up its layout manager property to be a linear layout

192
00:13:41,800 --> 00:13:46,600
manager because I just want to have items to be on top of each other.

193
00:13:46,910 --> 00:13:53,050
Now, I cannot just use this here because we are inside of a lifecycle scope, so we're in a closure.

194
00:13:53,050 --> 00:14:00,010
So this is code that if we use this, then it will believe it's inside of the doll or something like

195
00:14:00,010 --> 00:14:00,220
that.

196
00:14:00,220 --> 00:14:06,610
So here we can just make sure that we use to history, activity context.

197
00:14:07,210 --> 00:14:10,780
So here let me see that I read it correctly.

198
00:14:10,810 --> 00:14:11,530
No, I did not.

199
00:14:11,620 --> 00:14:13,420
Activity like this.

200
00:14:14,410 --> 00:14:14,770
OK.

201
00:14:16,070 --> 00:14:23,000
So now that we have our respect of you, we need to set up the dates for it.

202
00:14:23,150 --> 00:14:26,300
So let's get the dates which will be in the list of strings.

203
00:14:27,650 --> 00:14:36,830
OK, and then let's get the dates from our all completed dates list.

204
00:14:38,850 --> 00:14:45,240
So it's this one here that we get from our fetching all data, so we called this method that will give

205
00:14:45,240 --> 00:14:47,310
us all the data that we have in the history table.

206
00:14:47,790 --> 00:14:51,580
And now we can use it because this is the data that we get right.

207
00:14:51,600 --> 00:14:52,560
I'll complete it dates.

208
00:14:53,340 --> 00:14:58,050
And if it's not empty, we're going through all of them and we're going to create a date out of every

209
00:14:58,050 --> 00:14:58,980
single entry.

210
00:14:59,520 --> 00:15:05,700
And now we can add every single date to our dates ArrayList that we have here, which is just an array

211
00:15:05,700 --> 00:15:08,970
list of strings and can assign it to our respective you after.

212
00:15:09,300 --> 00:15:13,350
Because if you look at our respective adapter, it requires exactly that.

213
00:15:13,350 --> 00:15:15,360
It requires an array list of strings.

214
00:15:16,080 --> 00:15:18,810
So let's add the dates in here.

215
00:15:19,960 --> 00:15:26,770
And I think data itself is not going to be it, we need to use data to date because the date will be

216
00:15:26,770 --> 00:15:29,370
a history entity, which is not a string.

217
00:15:29,650 --> 00:15:37,840
But the history entity has an entity called Let's jump over to the history entity to see that history

218
00:15:37,840 --> 00:15:38,410
entity.

219
00:15:38,590 --> 00:15:40,450
It has a string property that is called date.

220
00:15:40,760 --> 00:15:42,100
OK, so we get that date.

221
00:15:44,060 --> 00:15:46,370
Property by getting data data.

222
00:15:46,530 --> 00:15:53,060
OK, so now that we have all of the data, we can create our history adaptor because it needed to have

223
00:15:53,090 --> 00:15:53,660
our.

224
00:15:54,910 --> 00:15:57,610
Dates which we now can assign here.

225
00:15:57,760 --> 00:16:06,400
So let's use the dates, and now we can assign this history adapter to our recycler view adapter property,

226
00:16:06,520 --> 00:16:07,210
as always.

227
00:16:07,390 --> 00:16:09,310
So always the same approach, right?

228
00:16:09,350 --> 00:16:12,160
You need to set up your adapter.

229
00:16:12,520 --> 00:16:16,240
You need to prepared a list that you want to use, and usually it's in radius.

230
00:16:16,780 --> 00:16:19,690
You need to then go ahead and set up the list.

231
00:16:19,930 --> 00:16:20,950
Fill it with data.

232
00:16:21,640 --> 00:16:29,950
In our case, we get the data from our database and then use this data inside of the adapter or pass

233
00:16:29,950 --> 00:16:35,530
it to the adapter and then use this adapter that you set up as the adapter for your recycler.

234
00:16:35,530 --> 00:16:36,790
View that you have prepared.

235
00:16:37,510 --> 00:16:43,900
So here we can just use our history adapter now, and this should pretty much do it.

236
00:16:44,920 --> 00:16:52,600
So let's go ahead and testers and see if we have any exercises that we have finished inside of our history,

237
00:16:52,960 --> 00:16:54,910
screen or history activity.

238
00:16:56,680 --> 00:17:00,670
And then we can also just quickly finish some more exercises.

239
00:17:01,690 --> 00:17:03,280
So let's go over to our history.

240
00:17:03,280 --> 00:17:07,099
We see we have finished this exercise at 10, 23 36.

241
00:17:07,119 --> 00:17:09,010
So exercises completed.

242
00:17:09,910 --> 00:17:15,520
And even though you should, and as here and now, if we go through it once again, we will then see

243
00:17:15,520 --> 00:17:18,069
that this new entry has been added also.

244
00:17:18,710 --> 00:17:19,130
All right.

245
00:17:19,150 --> 00:17:24,099
So this will make it white, I think, from the background.

246
00:17:24,109 --> 00:17:29,290
So the first will be gray than white, and the third one would be gray again because that's what we

247
00:17:29,290 --> 00:17:36,250
have set up inside of our history adapter on Bind View Holder.

248
00:17:36,910 --> 00:17:40,660
So here we're iterating the colors, so we finish the exercise.

249
00:17:40,660 --> 00:17:44,170
Now let's jump over to the history and we see the new history has been added.

250
00:17:44,980 --> 00:17:45,970
So that's pretty much it.

251
00:17:46,420 --> 00:17:49,840
So now our application is pretty much complete now.

252
00:17:49,840 --> 00:17:52,000
You could, of course, make it prettier.

253
00:17:52,970 --> 00:18:00,890
Make sure that your main color is also this greenish color or, well, basically just lend the application

254
00:18:00,890 --> 00:18:02,870
to whatever you need it for.

255
00:18:03,740 --> 00:18:10,070
So I hope you enjoyed this chapter, and I hope you can use this to build your own specific apps that

256
00:18:10,070 --> 00:18:17,330
have to do either with timers or with the recycler views or with permanent data storage and so forth.

257
00:18:18,110 --> 00:18:18,800
So thanks a lot.

258
00:18:19,280 --> 00:18:20,630
And see you in the next video.

