1
00:00:01,180 --> 00:00:07,900
Welcome back in this week, we're going to set up our exercise recycler view adaptor because we want

2
00:00:07,900 --> 00:00:13,180
to display the status of our exercise, we want to know at which exercise we're currently at.

3
00:00:13,570 --> 00:00:15,100
Are we at the jumping jacks?

4
00:00:15,100 --> 00:00:16,690
Are we at the wall said.

5
00:00:16,690 --> 00:00:18,460
Exercise push up and so forth.

6
00:00:18,700 --> 00:00:21,610
And we also would like to know how many exercises we have in total.

7
00:00:21,850 --> 00:00:24,190
So here at the bottom, it should display all of that.

8
00:00:24,520 --> 00:00:27,040
OK, so let's go ahead and set that up.

9
00:00:27,370 --> 00:00:34,810
Therefore, we will need to create a recycler view adaptor or an adapter as such that we can then use

10
00:00:34,810 --> 00:00:35,830
forward to recycle you.

11
00:00:36,160 --> 00:00:43,000
So let's create a new Scotland class, and I'm going to call this one exercise steadies adapter because

12
00:00:43,000 --> 00:00:45,000
it will just take care of the status.

13
00:00:45,340 --> 00:00:49,570
So basically of the number of exercise that we are currently at.

14
00:00:50,230 --> 00:00:58,090
So when you want to use this adapter for a recycler view, you need to follow a structure.

15
00:00:58,210 --> 00:00:59,470
So the structure is always the same.

16
00:00:59,470 --> 00:01:07,180
And I hope you checked out the demo for the basics of recyclable use using the few binding concepts

17
00:01:07,180 --> 00:01:07,600
as well.

18
00:01:07,990 --> 00:01:12,970
So we're going to require a ArrayList or a list.

19
00:01:14,230 --> 00:01:19,570
Of some sort that will be displayed inside of this recycled view.

20
00:01:19,690 --> 00:01:21,080
Otherwise, it wouldn't make sense, right?

21
00:01:21,100 --> 00:01:24,790
So you need to have some sort of list of items that you want to display there.

22
00:01:25,630 --> 00:01:32,680
So in my case, I'm just going to call them items, which will be a list items of exercise model.

23
00:01:33,190 --> 00:01:39,700
And there's a separate list like so so there will be of time exercise model, which is our individual

24
00:01:39,700 --> 00:01:40,300
exercises.

25
00:01:40,300 --> 00:01:46,180
So they will have an idea, a name and image and known whether they are completed or are currently selected.

26
00:01:46,180 --> 00:01:52,060
So these two will be very useful for our status because we will know that the completed once should

27
00:01:52,060 --> 00:01:56,410
get a particular background color and the selected one should get a different color and the noncompete

28
00:01:56,410 --> 00:01:58,180
one will get again a different color.

29
00:01:58,540 --> 00:02:05,740
OK, so this will just allow us to see which exercises we still have to do once we just quickly glance

30
00:02:05,740 --> 00:02:06,250
at the phone.

31
00:02:07,420 --> 00:02:07,810
All right.

32
00:02:08,110 --> 00:02:14,080
So if you want this to be used for a recycler, do you need to make sure that this is going to be a

33
00:02:14,080 --> 00:02:15,340
recycler view adapter?

34
00:02:15,400 --> 00:02:21,040
So here, recycler, if you don't add up to where you then need to pass a view holder to.

35
00:02:21,370 --> 00:02:26,410
OK, so here we're going to pass in our own view holder.

36
00:02:26,560 --> 00:02:30,220
So let me put that in a separate line, so it will be a little more readable.

37
00:02:30,700 --> 00:02:34,570
So here this will be the exercise status adapter view holder.

38
00:02:35,930 --> 00:02:38,770
Thought view all the.

39
00:02:39,140 --> 00:02:43,010
And here, the holder with a capital H.

40
00:02:44,570 --> 00:02:51,320
Mike, so now this doesn't exist yet, but we're going to create our own class inside of our exercise

41
00:02:51,320 --> 00:02:52,430
status view holder.

42
00:02:52,910 --> 00:02:53,730
And how does that work?

43
00:02:53,750 --> 00:02:56,310
Well, this is going to be an internal class.

44
00:02:56,330 --> 00:02:57,290
So he has class.

45
00:02:59,130 --> 00:03:06,480
You hold her hand here because we're using view binding, we need to pass the view binding to it.

46
00:03:06,600 --> 00:03:08,610
So item exercise.

47
00:03:09,780 --> 00:03:16,230
Studies binding is what we are going to pass, and it will be just a recycler view view holder.

48
00:03:16,620 --> 00:03:23,550
So we're going to inherit from the View hold a class to which we then need to pass the view binding

49
00:03:23,940 --> 00:03:24,870
object again.

50
00:03:24,990 --> 00:03:26,460
So binding that route.

51
00:03:26,850 --> 00:03:28,890
OK, so this is our view holder.

52
00:03:29,250 --> 00:03:34,020
How it's going to be in general and now we can access its items.

53
00:03:34,050 --> 00:03:40,980
So, for example, I can access to text your item to be binding dot TV item.

54
00:03:41,550 --> 00:03:43,050
So what is this TV item?

55
00:03:43,080 --> 00:03:48,510
It's this individual item that we have here, of which we will have 12 because we have 12 exercises.

56
00:03:48,780 --> 00:03:49,710
But that's the whole point.

57
00:03:49,710 --> 00:03:54,480
If we had one exercise because we decide that we don't want to make it the seven minute workout, but

58
00:03:54,480 --> 00:04:01,020
the name in the workout app, then we could very easily just add additional items to it.

59
00:04:01,620 --> 00:04:01,990
OK.

60
00:04:02,010 --> 00:04:03,930
And our quote was still work.

61
00:04:04,380 --> 00:04:04,680
All right.

62
00:04:04,680 --> 00:04:06,460
So we have this vault TV item.

63
00:04:06,870 --> 00:04:14,610
So let's actually use it because if you create a adapter, you need to implement a couple of members

64
00:04:14,610 --> 00:04:21,029
and the members that you must implement are on create view holder on bind view holder and get item count.

65
00:04:21,060 --> 00:04:22,590
So these three methods.

66
00:04:23,010 --> 00:04:27,930
So let's just click the button and you see it creates all of those methods for us, which we now need

67
00:04:27,930 --> 00:04:28,770
to implement.

68
00:04:29,400 --> 00:04:36,090
So on create view holder, that's where we want to return our own view, hold that it would just create.

69
00:04:36,510 --> 00:04:37,740
So let's return it.

70
00:04:38,250 --> 00:04:43,260
Return view holder and we need to pass in the binding.

71
00:04:43,560 --> 00:04:51,540
So here we can just go ahead and use item exercise status binding, inflate where we then use to layout

72
00:04:51,540 --> 00:04:52,290
inflator.

73
00:04:52,560 --> 00:04:58,770
But we need to get it from somewhere and we're going to get it from the parents context because we cannot

74
00:04:59,400 --> 00:05:01,920
just pass this as this recycled.

75
00:05:01,920 --> 00:05:06,420
If you doesn't have its own context, it needs to use the context from its parent, which will then

76
00:05:06,420 --> 00:05:08,850
use the context from the activity that it's it.

77
00:05:09,990 --> 00:05:10,440
All right.

78
00:05:10,950 --> 00:05:13,860
So then we also need to pass in.

79
00:05:15,050 --> 00:05:20,960
The parent, as well as whether we want to attach to parents and we're going to say we don't want to

80
00:05:20,960 --> 00:05:23,420
attach to parents, so let me put that in a separate line.

81
00:05:23,780 --> 00:05:28,430
So that's going to be the structure whenever you are using a reactive you with your own view holder

82
00:05:29,060 --> 00:05:30,260
in a default fashion.

83
00:05:30,530 --> 00:05:34,070
OK, so we have the uncreative you holder here, which is an override function.

84
00:05:34,070 --> 00:05:38,270
So it's given to us and we need to return something that is of type you holder.

85
00:05:38,420 --> 00:05:38,750
All right.

86
00:05:38,750 --> 00:05:39,910
So let's do exactly that.

87
00:05:39,920 --> 00:05:45,410
We return to view holder to which we, if we look at it, need to pass a binding object of type item

88
00:05:45,410 --> 00:05:50,480
exercise that is binding, which is exactly what we do here, but we also need to inflate it.

89
00:05:50,750 --> 00:05:57,560
And if you want to inflate it outside of a activity, which is what we are at, we are inflating inside

90
00:05:57,560 --> 00:05:59,720
of a adapter or an adapter.

91
00:05:59,720 --> 00:06:04,970
And now we need to pass in the layout inflator from as given context.

92
00:06:05,300 --> 00:06:11,270
And then we can pass in the view group, which is our parent, and we're not going to attach to it.

93
00:06:12,320 --> 00:06:13,940
Oh, we're not going to attach to the parent.

94
00:06:14,630 --> 00:06:20,180
So then what should happen for every single item when the view is bound?

95
00:06:20,450 --> 00:06:23,000
So on by-nd view holder?

96
00:06:23,510 --> 00:06:27,860
Well, what I want to get is the model of our exercise model.

97
00:06:28,040 --> 00:06:35,570
So exercise model, which will be items at the position that we're currently at.

98
00:06:36,020 --> 00:06:37,940
So what are items again?

99
00:06:38,540 --> 00:06:41,030
Well, it's this items object that gets here.

100
00:06:41,330 --> 00:06:46,940
So once we create an adapter object, we will need to pass and the list of exercise models.

101
00:06:47,360 --> 00:06:51,440
And if you recall in exercise activity, we have exactly that.

102
00:06:51,650 --> 00:06:56,870
So here we have this exercise list, which is an array list of exercise model.

103
00:06:57,110 --> 00:06:59,900
So we'll need to pass in this exercise list later on.

104
00:07:00,740 --> 00:07:06,950
So we're passing this exercise list of individual exercise models and then we get the one.

105
00:07:07,340 --> 00:07:13,490
So the exercise list item at the position that we are currently at one binding the view holder.

106
00:07:13,790 --> 00:07:20,000
So in our case, this method will be called 12 times because we have 12 view holders that we will bound

107
00:07:20,330 --> 00:07:21,380
for each position.

108
00:07:21,380 --> 00:07:21,740
One.

109
00:07:21,890 --> 00:07:29,300
OK, so here position is an integer and we are passing basically and three zero and three, two, one

110
00:07:29,300 --> 00:07:34,310
and three two and so forth, or position zero position one position to and so forth.

111
00:07:34,490 --> 00:07:40,400
And all of these will be individual items that will be displayed next to each other, which will just

112
00:07:40,400 --> 00:07:44,690
look like this little circle circle one, Circle two, Circle three, Circle four and so forth.

113
00:07:44,690 --> 00:07:46,040
You will see that once we're done with it.

114
00:07:46,700 --> 00:07:51,140
So now I can use this model in order to access its ID.

115
00:07:52,100 --> 00:08:03,400
So Holder Dot text your item dot text should be the model dot get ID Dot to string.

116
00:08:03,410 --> 00:08:04,550
So what's happening here?

117
00:08:05,870 --> 00:08:10,490
Well, we are getting the idea as a string from our model.

118
00:08:10,790 --> 00:08:11,870
So what is that?

119
00:08:12,170 --> 00:08:20,570
Well, our model is this exercise model, which has an ID with which we now get, but it's of type integer.

120
00:08:20,660 --> 00:08:23,840
So now we're converting it into a string.

121
00:08:24,440 --> 00:08:26,150
And what do we assign it to?

122
00:08:26,150 --> 00:08:28,040
Where sign it to our holders?

123
00:08:28,970 --> 00:08:30,050
Text your item.

124
00:08:30,620 --> 00:08:31,400
Text property.

125
00:08:32,030 --> 00:08:33,590
So what is this holder again?

126
00:08:33,860 --> 00:08:42,950
Well, it's this holder that is our own view holder, and we can now access this text view item object.

127
00:08:43,820 --> 00:08:48,560
OK, so this one in particular, not this one, but we're getting this one in particular.

128
00:08:48,560 --> 00:08:53,450
So we're getting the text item, which is going to be connected to the text to your item, which is

129
00:08:53,450 --> 00:08:54,350
this thing here.

130
00:08:55,040 --> 00:08:59,270
And then we actually assign an ID or a number to it.

131
00:08:59,520 --> 00:09:04,280
OK, so we're basically assigning the exercise numbers here.

132
00:09:04,700 --> 00:09:07,350
So number one for jumping jacks?

133
00:09:07,370 --> 00:09:09,140
Number two for Wall, said number three.

134
00:09:09,140 --> 00:09:11,000
Four, push up and so forth.

135
00:09:11,750 --> 00:09:18,740
And now we just need to also return how many items we will have in total inside of this recycler view.

136
00:09:19,070 --> 00:09:23,270
And here you just need to return the items that size.

137
00:09:23,480 --> 00:09:31,700
So basically, whatever array list is given to the adapter that size and our case, it's the items.

138
00:09:32,390 --> 00:09:36,020
In your case, it could be whatever you want to call it, that size.

139
00:09:37,190 --> 00:09:44,120
OK, so this by itself, unfortunately, is not going to be enough to show anything because we are not

140
00:09:44,120 --> 00:09:45,980
connecting this adapter.

141
00:09:45,980 --> 00:09:47,060
As you see, it's gray.

142
00:09:47,600 --> 00:09:55,100
We're not connecting it yet to the adapter that we have inside of our exercise somehow.

143
00:09:55,340 --> 00:09:56,120
So here.

144
00:09:58,420 --> 00:10:03,820
Activity exercise, we have our recycler view at the very bottom, this one.

145
00:10:03,850 --> 00:10:06,250
Now we just need to assign the adapted.

146
00:10:06,350 --> 00:10:11,780
We just created to disrespect a view and set it up accordingly, saying that it should not be a list

147
00:10:11,800 --> 00:10:16,360
that is a vertical list, but it should be a horizontal list and so forth.

148
00:10:16,750 --> 00:10:19,000
And that's what we're going to do in the next video.

149
00:10:19,240 --> 00:10:20,290
So see you there.

