1
00:00:00,560 --> 00:00:01,310
Welcome back.

2
00:00:01,340 --> 00:00:06,770
In this video, I would like to talk about the recital of you on a theoretical level and why we use

3
00:00:06,770 --> 00:00:12,650
it, because we will use recycled views quite a bit and they are superimportant pretty much in any application

4
00:00:12,890 --> 00:00:17,760
because they allow us to use lists on and list views and views and those kind of things.

5
00:00:17,780 --> 00:00:19,070
So let's look at it.

6
00:00:19,400 --> 00:00:26,480
First of all, Android used to use the list, view and review classes for displaying lists I recycled,

7
00:00:26,480 --> 00:00:29,780
which can be thought of as a combination of a list for you and grade you.

8
00:00:29,930 --> 00:00:33,560
So it allows us to do both, however, and recycle you.

9
00:00:33,560 --> 00:00:39,050
There are features that separate your code into maintainable components even as they enforce memory

10
00:00:39,050 --> 00:00:40,460
efficient design pattern.

11
00:00:40,470 --> 00:00:46,960
So it's a lot more efficient, pretty much so it's a better way to create lists than list view and great.

12
00:00:46,970 --> 00:00:49,890
You ever work and why should we use a recycle you?

13
00:00:49,910 --> 00:00:55,640
Well, imagine you're creating a list you with complicated custom items such as, for example, in Facebook,

14
00:00:55,640 --> 00:01:01,760
you have images and then you have text and then you have the like button amount of likes who posted

15
00:01:01,760 --> 00:01:02,570
it and so forth.

16
00:01:02,570 --> 00:01:07,190
All these kind of things, they are complicated custom icon items, so to speak.

17
00:01:07,580 --> 00:01:13,100
And you create a road layout for the items and use that layout inside your adapter.

18
00:01:13,550 --> 00:01:19,910
Well, you inflate your item layout and get view referencing each view with a unique idea you provided

19
00:01:19,910 --> 00:01:22,400
in XML to customize and have your logic.

20
00:01:22,610 --> 00:01:26,820
You add to the list view and it's ready to be drawn on the screen.

21
00:01:27,200 --> 00:01:28,760
Well, is it or is it not?

22
00:01:29,000 --> 00:01:35,450
Well, the thing is, list using is only do half the job of achieving true memory efficiency and that

23
00:01:35,450 --> 00:01:40,610
is something that is super important and more complicated.

24
00:01:40,610 --> 00:01:46,050
Your individual list items become, of course, because then there is a lot going on and there's a lot

25
00:01:46,050 --> 00:01:46,700
to load.

26
00:01:46,700 --> 00:01:52,550
And if you have many images that need to be loaded, then, well, this whole stuff has to be super

27
00:01:52,550 --> 00:01:52,940
efficient.

28
00:01:52,940 --> 00:02:00,170
Otherwise it feels lagi, especially now with faster and faster screens in terms of the frequency they

29
00:02:00,170 --> 00:02:00,770
display.

30
00:02:00,780 --> 00:02:04,270
For example, with 120 hertz, everything needs to be super fast.

31
00:02:05,270 --> 00:02:10,130
Another reason to use the recycler view is to recycle the item layout, but don't keep references to

32
00:02:10,130 --> 00:02:15,560
the layout children forcing you to call, find by view for every child of your item layout every time

33
00:02:15,560 --> 00:02:16,390
you call, get view.

34
00:02:16,640 --> 00:02:18,310
So it's not doing that.

35
00:02:18,320 --> 00:02:24,440
That's what list used did all this calling around can become process or intransitive, especially for

36
00:02:24,440 --> 00:02:25,640
complicated layouts.

37
00:02:25,640 --> 00:02:31,250
And furthermore, the situation can cause your list of scrolling to become jerky and nonresponsive as

38
00:02:31,250 --> 00:02:33,170
it tries to grab your references.

39
00:02:33,440 --> 00:02:38,930
So it was fine back in the day, but then things got a lot more complicated.

40
00:02:39,080 --> 00:02:43,910
Of course, devices got faster, but still, why not improve if it's not perfect?

41
00:02:43,910 --> 00:02:44,170
Right.

42
00:02:44,690 --> 00:02:47,900
So that's what they thought when they created the recycler use.

43
00:02:48,080 --> 00:02:53,360
Android initially provided a solution to this problem on the Android developer side with smooth scrolling

44
00:02:53,360 --> 00:02:55,370
via the power of the view.

45
00:02:55,370 --> 00:02:56,300
Hold the pattern.

46
00:02:56,870 --> 00:03:02,750
And with this pattern, it becomes an in-memory reference to all the views needed to fill your layout.

47
00:03:02,930 --> 00:03:09,170
You set the references once and reuse them working around the performance that comes with repeatedly

48
00:03:09,170 --> 00:03:15,650
calling this find view by ID and find Ubaidi is something that we've never used before because we just

49
00:03:15,890 --> 00:03:16,720
didn't need to do it.

50
00:03:16,730 --> 00:03:18,080
That's the beauty of Kotlin.

51
00:03:18,080 --> 00:03:19,760
They just got rid of this whole thing.

52
00:03:20,060 --> 00:03:21,980
You don't need to use it anymore.

53
00:03:21,980 --> 00:03:25,580
In Java, it's quite prominent and very important to use it.

54
00:03:25,580 --> 00:03:31,130
But well, and Cottan it's less important and you can even reduce your code to where it's not even used

55
00:03:31,130 --> 00:03:31,460
at all.

56
00:03:31,730 --> 00:03:33,290
So it's pretty cool.

57
00:03:33,740 --> 00:03:37,040
Take note that this is an optional pattern for a list for grid view.

58
00:03:37,040 --> 00:03:41,260
If you're unaware of this detail, then you may wonder why your list you introduce so slow.

59
00:03:41,450 --> 00:03:44,090
Well, the thing is, we never used despues anchorages.

60
00:03:44,090 --> 00:03:49,670
So this is something that doesn't really bother us too much because we will use recyclables all the

61
00:03:49,670 --> 00:03:49,940
time.

62
00:03:49,940 --> 00:03:52,940
So we're not even going to start with doing list of using reviews.

63
00:03:52,940 --> 00:03:55,490
OK, we're going to start with recycling use straight away.

64
00:03:55,490 --> 00:03:59,990
So it's going to be a lot more efficient from the start and you will see how to build those things.

65
00:04:01,040 --> 00:04:01,550
All right.

66
00:04:02,000 --> 00:04:05,240
So the arrival of the recycle, you changed everything.

67
00:04:05,390 --> 00:04:08,510
It still uses an adapter to act as a data source.

68
00:04:08,510 --> 00:04:15,450
However, you have to create value holders to keep references in memory to provide a new view recycler.

69
00:04:15,470 --> 00:04:21,320
You either create a new view holder object to inflate the layout and hold those references or recycles

70
00:04:21,320 --> 00:04:23,420
one from the existing stack.

71
00:04:24,110 --> 00:04:25,660
So why is it called recycle of you?

72
00:04:25,670 --> 00:04:31,070
Well, another perk of using recycled use is that they come with default animations that you don't have

73
00:04:31,070 --> 00:04:34,610
to create or add yourself because it requires a view.

74
00:04:34,610 --> 00:04:40,610
Holder, the recycler view knows which animation to apply to which item and adds them as required.

75
00:04:41,090 --> 00:04:44,570
So you can also create your own animations and apply them as needed.

76
00:04:46,880 --> 00:04:52,190
Now, there is something called layout manager in of use, and we're going to actually use that in order

77
00:04:52,190 --> 00:04:59,090
to adjust our respective elements so the list items in our list.

78
00:04:59,390 --> 00:05:03,730
So the last and most interesting component of our recital is its layout manager.

79
00:05:03,740 --> 00:05:10,370
The subject positions the recycle of use items and tells it when to recycle items that have transitioned

80
00:05:10,370 --> 00:05:11,070
off screen.

81
00:05:11,360 --> 00:05:16,480
And this is something that Lisieux used to do by themselves back in the day.

82
00:05:16,700 --> 00:05:22,970
So you can imagine that when working with the lists, there are multiple things which are important

83
00:05:22,970 --> 00:05:23,870
to consider.

84
00:05:24,110 --> 00:05:31,700
So one of them is, for example, when you scroll, then you want to see the next list elements directly.

85
00:05:31,700 --> 00:05:32,860
You don't want them to load.

86
00:05:32,870 --> 00:05:37,690
You don't want them to take up time in order to load whatever is displayed in them.

87
00:05:38,060 --> 00:05:39,410
You want to see directly.

88
00:05:39,620 --> 00:05:41,960
It has to feel smooth and looks smooth.

89
00:05:42,140 --> 00:05:45,110
And that is something that has achieved a lot easier with a recycler of use.

90
00:05:45,990 --> 00:05:53,060
Now, another thing is you need, of course, to free up space memory space of elements that are not

91
00:05:53,060 --> 00:05:53,870
visible anymore.

92
00:05:53,900 --> 00:05:57,730
So if a list item is not visible anymore, it's off screen already.

93
00:05:58,040 --> 00:06:02,660
Then at one point you need to release the memory and you shouldn't do that directly.

94
00:06:02,660 --> 00:06:04,700
Maybe the user wants to scroll back.

95
00:06:04,730 --> 00:06:05,060
All right.

96
00:06:05,070 --> 00:06:10,160
So maybe he wants to see whatever he scrolled away so it doesn't have to be done directly.

97
00:06:10,280 --> 00:06:15,380
But it's something that we might have used more disrespect of UCLASS and layout manager handle themselves.

98
00:06:15,380 --> 00:06:16,300
So it's super powerful.

99
00:06:16,970 --> 00:06:22,010
So the result of you has broken out this functionality to allow for different kinds of layouts, vertical

100
00:06:22,010 --> 00:06:25,720
horizontal grids, staggered or a very custom.

101
00:06:26,030 --> 00:06:28,490
So that is the cool thing and super powerful.

102
00:06:28,490 --> 00:06:33,620
You're not limited to gret or less use, but you can really go ahead and build your own layouts and

103
00:06:33,620 --> 00:06:37,210
they are still going to be efficient because they will still be recycled views.

104
00:06:37,250 --> 00:06:37,520
Right.

105
00:06:38,060 --> 00:06:41,960
So layout manager offers free choices by default.

106
00:06:42,230 --> 00:06:47,000
So the linear layout manager positions item to look like a standard list.

107
00:06:47,060 --> 00:06:52,940
You then the layout manager positions items in a format similar to a great view.

108
00:06:52,940 --> 00:06:59,330
And then we have the staggered grid layout manager, which positions items in a staggered grid format.

109
00:06:59,840 --> 00:07:04,730
The cool thing is you can of course, go ahead and create your own layout, manages to use with a recycler

110
00:07:04,730 --> 00:07:07,850
view if you want some extra customization.

111
00:07:08,720 --> 00:07:12,260
So these are the basics of recyclable use.

112
00:07:13,720 --> 00:07:19,870
And I found this guy right here under guard, psychopath outcomes, and that's using the recycled view,

113
00:07:20,170 --> 00:07:20,930
which is pretty cool.

114
00:07:21,130 --> 00:07:27,100
So this guy created a great guide on recycled views, how they work and what you can do with it.

115
00:07:27,310 --> 00:07:29,020
And it's a super extended one.

116
00:07:29,020 --> 00:07:30,960
You can see there are a bunch of sections.

117
00:07:30,970 --> 00:07:35,140
So using recyclable use, defining a model, modifying the adapter.

118
00:07:35,140 --> 00:07:40,140
So a lot of stuff you can see there, he even goes to animator's.

119
00:07:40,150 --> 00:07:45,090
And so this is an example of what you can do with a staggered grid layout.

120
00:07:45,110 --> 00:07:46,780
You can see pretty cool.

121
00:07:47,230 --> 00:07:50,860
Of course, it really depends on the images you have and the stuff.

122
00:07:50,860 --> 00:07:57,040
But in the end, you can see it's neither a real grid layout nor is it a list view.

123
00:07:57,040 --> 00:07:58,850
It's really a staggered grid.

124
00:07:58,870 --> 00:08:00,150
So pretty powerful stuff.

125
00:08:00,430 --> 00:08:07,210
And then also when it comes to animations, as you can see, the elements, they get bigger the further

126
00:08:07,210 --> 00:08:09,920
they are when they're loading process, so to speak.

127
00:08:10,480 --> 00:08:13,890
OK, so this is just one website.

128
00:08:13,900 --> 00:08:17,700
Of course, there are a bunch of other great to list websites.

129
00:08:18,070 --> 00:08:23,620
So this is also, for example, a grid view here that is used in the.

130
00:08:25,010 --> 00:08:25,940
Google Play store.

131
00:08:26,240 --> 00:08:31,360
OK, so they also use this effect here and you can see you can pretty much find anything here.

132
00:08:31,580 --> 00:08:33,770
So I would highly recommend to check that out.

133
00:08:33,770 --> 00:08:38,630
If you want to know more about recyclable use, of course, we're going to use recycled views and we

134
00:08:38,630 --> 00:08:42,669
are going to use some of the features that are explained in here, but of course, not everything.

135
00:08:42,679 --> 00:08:48,610
So that is something that I in general really encourage you to do each time that we cover something

136
00:08:48,610 --> 00:08:54,410
new, that you should also look into other resources to get a bigger understanding of it, because the

137
00:08:54,410 --> 00:09:00,080
more different examples you can see, the better your understanding of something where a concept will

138
00:09:00,080 --> 00:09:00,530
become.

139
00:09:01,100 --> 00:09:03,560
OK, so see you in the next video.

