Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:03,680 --> 00:00:09,660
in this video we are going to create a
2
00:00:06,599 --> 00:00:13,198
recyclerview to show our books inside
3
00:00:09,660 --> 00:00:15,259
our own books activity but before that I
4
00:00:13,198 --> 00:00:18,689
am going to create a model for my book
5
00:00:15,259 --> 00:00:23,280
so in my package I can say new Java
6
00:00:18,689 --> 00:00:26,100
class let's name it both for this book
7
00:00:23,280 --> 00:00:30,300
item I'm going to have an ID first of
8
00:00:26,100 --> 00:00:32,489
all let's say private int ID this ID is
9
00:00:30,300 --> 00:00:35,070
going to be unique for every book and
10
00:00:32,488 --> 00:00:37,979
later on we will identify our books by
11
00:00:35,070 --> 00:00:41,488
this ID after that we need a name
12
00:00:37,979 --> 00:00:45,959
private string name also we need the
13
00:00:41,488 --> 00:00:47,878
author private a string author I'm also
14
00:00:45,960 --> 00:00:50,670
going to define an integer for the
15
00:00:47,878 --> 00:00:56,209
number of pages so let's say private in
16
00:00:50,670 --> 00:00:56,210
pages a string maybe for the image URL
17
00:00:57,588 --> 00:01:02,939
also I'm going to define two more fields
18
00:01:00,658 --> 00:01:07,280
one is called short description and the
19
00:01:02,939 --> 00:01:07,280
other one is called long description
20
00:01:09,230 --> 00:01:13,670
we are going to show different versions
21
00:01:11,750 --> 00:01:15,200
of this description in different places
22
00:01:15,200 --> 00:01:21,620
okay let's quickly create a constructor
23
00:01:17,390 --> 00:01:24,680
I'm using alt + insert let's select all
24
00:01:21,620 --> 00:01:27,170
of our fields and also down below this
25
00:01:24,680 --> 00:01:33,380
constructor let's quickly create getters
26
00:01:27,170 --> 00:01:35,210
and setters I'm also going to create a
27
00:01:33,379 --> 00:01:39,589
two string method I believe it will be
28
00:01:35,209 --> 00:01:41,929
useful Alt + insert just to drink let's
29
00:01:39,590 --> 00:01:44,060
select all of the fields okay this is
30
00:01:44,060 --> 00:01:50,299
sometimes we named these kind of classes
31
00:01:46,340 --> 00:01:53,150
as poles pojo stands for plain old Java
32
00:01:50,299 --> 00:01:54,709
object in which the class has some
33
00:01:54,709 --> 00:01:59,479
constructor and some getters and setters
34
00:01:56,599 --> 00:02:01,489
method ok let's move on and let's
35
00:01:59,480 --> 00:02:05,120
implement the recyclerview dependency
36
00:02:01,489 --> 00:02:07,640
into our project so if I open the layout
37
00:02:05,120 --> 00:02:10,099
file let's go to the layout folder
38
00:02:07,640 --> 00:02:13,009
inside this activity all books that
39
00:02:10,099 --> 00:02:15,530
examine if we switch to design view you
40
00:02:13,009 --> 00:02:18,289
can see that we have this recycler view
41
00:02:15,530 --> 00:02:21,770
option in here and we can drag that in
42
00:02:18,289 --> 00:02:24,650
our layout let's switch to a split view
43
00:02:21,770 --> 00:02:29,390
and let's change the beads on high to
44
00:02:24,650 --> 00:02:31,689
match parent so inside this activity we
45
00:02:29,389 --> 00:02:34,519
are only going to have a recycle of view
46
00:02:31,689 --> 00:02:37,729
let's also give it an ID and let's
47
00:02:34,520 --> 00:02:39,820
initialize it in our Java file let's say
48
00:02:39,819 --> 00:02:46,489
let's open all boats activity dot Java
49
00:02:42,739 --> 00:02:50,330
class and let's initialize our recycler
50
00:02:46,489 --> 00:02:54,680
view private recycler view let's name it
51
00:02:50,330 --> 00:02:57,530
brokes recycler view and down in here
52
00:02:54,680 --> 00:03:00,650
inside on create method let's a box
53
00:02:57,530 --> 00:03:04,489
recycler view is equal to find view by
54
00:03:00,650 --> 00:03:06,770
ID r dot ID dot box recycler view after
55
00:03:04,489 --> 00:03:08,659
that it's time to create the adapter for
56
00:03:06,770 --> 00:03:11,810
this recyclerview let's quickly do that
57
00:03:08,659 --> 00:03:14,449
so in my package i can right click let's
58
00:03:11,810 --> 00:03:18,939
say new Java class I'm going to name
59
00:03:14,449 --> 00:03:18,939
this class pop recycler view adapter
60
00:03:19,949 --> 00:03:27,869
first of all let's create our view
61
00:03:22,110 --> 00:03:30,209
holder class let's say public class view
62
00:03:27,870 --> 00:03:35,009
holder I'm going to name it let's say
63
00:03:30,209 --> 00:03:37,469
extent recycler view dot view holder
64
00:03:35,009 --> 00:03:39,840
this class after that we need a
65
00:03:37,469 --> 00:03:43,159
constructor we can do that by pressing
66
00:03:39,840 --> 00:03:45,719
Alt + insert and selecting constructor
67
00:03:43,159 --> 00:03:47,849
before going further we need to create a
68
00:03:45,719 --> 00:03:50,400
layout file for every item in our
69
00:03:47,849 --> 00:03:53,909
psychology certain our layout folder
70
00:03:50,400 --> 00:04:01,110
let's say new layout resource file I'm
71
00:03:53,909 --> 00:04:03,239
going to name this list item book let's
72
00:04:01,110 --> 00:04:06,299
minimize this project pane and let's
73
00:04:03,239 --> 00:04:09,000
switch to a split view first of all I'm
74
00:04:06,299 --> 00:04:12,480
going to change this constraint layer to
75
00:04:09,000 --> 00:04:14,909
a card view so this fold layout file is
76
00:04:12,479 --> 00:04:16,978
going to be a card view and in here I'm
77
00:04:14,909 --> 00:04:18,810
going to use the material card view I
78
00:04:16,978 --> 00:04:21,478
think the style is a little bit
79
00:04:18,810 --> 00:04:27,600
different also let's change the beats
80
00:04:21,478 --> 00:04:29,969
and height to wrap content let's also
81
00:04:27,600 --> 00:04:32,760
give an ID to discard view later on you
82
00:04:29,970 --> 00:04:36,060
are going to need that let's name it
83
00:04:32,759 --> 00:04:38,659
parent inside our card view first of all
84
00:04:36,060 --> 00:04:41,100
I'm going to create a relative layout
85
00:04:38,660 --> 00:04:43,919
let's say match parent and mesh pattern
86
00:04:41,100 --> 00:04:45,600
for the vitsin height and inside this
87
00:04:43,918 --> 00:04:48,180
relative layout let's have some items
88
00:04:45,600 --> 00:04:52,229
for example I'm going to define an image
89
00:04:48,180 --> 00:04:58,050
view for the beats I believe 130 would
90
00:04:52,228 --> 00:05:00,779
be fine 130 DP also for the height I am
91
00:04:58,050 --> 00:05:04,370
going to say 200 TV that seems a little
92
00:05:00,779 --> 00:05:08,189
bit large let's decrease that to 150
93
00:05:04,370 --> 00:05:11,759
let's be with an ID I'm going to name it
94
00:05:08,189 --> 00:05:15,810
IMG book let's also have a placeholder
95
00:05:11,759 --> 00:05:18,839
let's say source and let's pass our I
96
00:05:15,810 --> 00:05:21,149
see launcher icon after this image view
97
00:05:18,839 --> 00:05:24,388
let's quickly define a text view for the
98
00:05:21,149 --> 00:05:27,949
name of our book we're going to say wrap
99
00:05:24,389 --> 00:05:31,819
content and wrap content for the text
100
00:05:31,819 --> 00:05:38,149
style of this text by same text style
101
00:05:34,939 --> 00:05:41,449
I'm going to pass bold in here beside
102
00:05:38,149 --> 00:05:44,120
that let's increase the size text size I
103
00:05:44,120 --> 00:05:53,420
let's move EQ below our image view let's
104
00:05:47,899 --> 00:05:54,829
say layout below our ID IMG book beside
105
00:05:54,829 --> 00:06:00,439
horizontally so that's a center
106
00:05:56,779 --> 00:06:01,729
horizontal true I think it's better to
107
00:06:01,730 --> 00:06:09,860
that's a margin top 5 DP or 7 DP maybe
108
00:06:06,699 --> 00:06:11,240
that's almost it for our layout file in
109
00:06:09,860 --> 00:06:12,110
here I'm just going to add two more
110
00:06:12,110 --> 00:06:17,480
first of all let's say cart corner
111
00:06:14,949 --> 00:06:21,860
please mount cart corner radius
112
00:06:17,480 --> 00:06:25,970
let's pass 7 DP beside that let's add a
113
00:06:21,860 --> 00:06:29,750
cart elevation once again I'm going to
114
00:06:25,970 --> 00:06:32,150
say 7 DP in here you can see that we are
115
00:06:29,750 --> 00:06:34,610
only showing the image view and also the
116
00:06:32,149 --> 00:06:37,310
book name but if you remember when we
117
00:06:34,610 --> 00:06:39,830
have created our book model we had more
118
00:06:37,310 --> 00:06:41,899
information we are going to show those
119
00:06:39,829 --> 00:06:44,209
information in two different places in
120
00:06:41,899 --> 00:06:46,459
our application first of all by clicking
121
00:06:44,209 --> 00:06:49,879
on every book we are going to navigate
122
00:06:46,459 --> 00:06:52,219
the user to another activity and beside
123
00:06:49,879 --> 00:06:54,949
that we are going to show lesser
124
00:06:52,220 --> 00:06:58,070
information when the user clicks on some
125
00:06:54,949 --> 00:07:00,139
arrow button on our cart view to be
126
00:06:58,069 --> 00:07:03,709
precise later on we are going to create
127
00:07:00,139 --> 00:07:05,509
an expandable card view which means that
128
00:07:03,709 --> 00:07:07,459
for the first time that the user sees
129
00:07:05,509 --> 00:07:10,279
this activity we are going to show only
130
00:07:07,459 --> 00:07:12,199
the image and the book name but if the
131
00:07:10,279 --> 00:07:14,599
user wants to see some more information
132
00:07:12,199 --> 00:07:17,659
he or she can click on some arrow button
133
00:07:14,600 --> 00:07:20,689
in here and expand our card view later
134
00:07:17,660 --> 00:07:22,550
on we will create that also I forgot to
135
00:07:20,689 --> 00:07:26,240
add a margin in here let's quickly do
136
00:07:22,550 --> 00:07:28,400
that let's say margin and I believe 5 DP
137
00:07:26,240 --> 00:07:30,560
would be fine ok now that we have
138
00:07:30,560 --> 00:07:36,470
initialize our UI elements inside this
139
00:07:33,500 --> 00:07:39,110
view holder class for that in here I'm
140
00:07:36,470 --> 00:07:43,280
going to say private card view for the
141
00:07:39,110 --> 00:07:46,400
parent let's name it parent beside that
142
00:07:46,399 --> 00:07:53,299
once again I'm going to name is IMG book
143
00:07:49,699 --> 00:07:57,180
and also let's say private text view
144
00:07:53,300 --> 00:07:59,129
let's say txt name I believe we did not
145
00:07:57,180 --> 00:08:01,759
define an ID for this text view that's
146
00:08:02,060 --> 00:08:11,280
so in here for this text view let's pass
147
00:08:05,009 --> 00:08:14,848
on ID let's say txt book me okay back in
148
00:08:11,279 --> 00:08:17,489
our adapter class inside the constructor
149
00:08:14,848 --> 00:08:20,188
of this view holder class after the
150
00:08:17,490 --> 00:08:22,439
super statement let's initialize our UI
151
00:08:20,189 --> 00:08:25,409
elements we have done this before
152
00:08:22,439 --> 00:08:26,990
we can say parent is equal to item view
153
00:08:26,990 --> 00:08:34,639
let's pass our dot ID does parent
154
00:08:38,879 --> 00:08:44,099
so after creating this inner class we
155
00:08:41,759 --> 00:08:47,610
can extend the recyclerview class in
156
00:08:44,099 --> 00:08:50,759
here and we can pass this view holder as
157
00:08:47,610 --> 00:08:54,570
the datatype of our adapter so I can say
158
00:08:50,759 --> 00:08:57,629
recycler view dot adapter and I can pass
159
00:08:54,570 --> 00:08:59,340
my view holder class make sure to import
160
00:08:57,629 --> 00:09:01,889
the one that comes from your package
161
00:08:59,340 --> 00:09:05,190
work that may put that my library dot
162
00:09:01,889 --> 00:09:07,019
block recycler view adapting you'll know
163
00:09:05,190 --> 00:09:07,530
that in here right now we need three
164
00:09:07,529 --> 00:09:14,339
let's press ctrl + v and let's import
165
00:09:10,710 --> 00:09:16,410
our methods before doing anything inside
166
00:09:14,340 --> 00:09:19,110
these methods first of all above in here
167
00:09:16,409 --> 00:09:22,100
I'm going to define an array list let's
168
00:09:19,110 --> 00:09:25,289
say private ArrayList of different books
169
00:09:22,100 --> 00:09:28,710
let's name this array list books is
170
00:09:25,289 --> 00:09:30,750
equal to new ArrayList so this array
171
00:09:28,710 --> 00:09:32,490
list is going to be the list of all of
172
00:09:30,750 --> 00:09:35,039
the books that we are going to show in
173
00:09:32,490 --> 00:09:36,750
our activity beside these books
174
00:09:35,039 --> 00:09:39,059
ArrayList I'm also going to need a
175
00:09:36,750 --> 00:09:41,570
context because if you remember when we
176
00:09:39,059 --> 00:09:44,339
are going to use glide in our project
177
00:09:41,570 --> 00:09:46,920
client library needed the context to
178
00:09:44,340 --> 00:09:52,530
show the image so let's say private
179
00:09:46,919 --> 00:09:55,889
context let's name it in context after
180
00:09:52,529 --> 00:09:57,809
that let's create our constructor in
181
00:09:55,889 --> 00:10:00,449
here I'm going to receive only the
182
00:09:57,809 --> 00:10:03,449
context for the books aerialist we are
183
00:10:00,450 --> 00:10:06,420
going to create a setter method let's
184
00:10:03,450 --> 00:10:08,970
create that method down in here by
185
00:10:06,419 --> 00:10:11,789
pressing Alt + insert once again but
186
00:10:08,970 --> 00:10:13,649
select setter and let's create a setter
187
00:10:11,789 --> 00:10:15,899
method for our books are released you
188
00:10:13,649 --> 00:10:18,000
know that when you set your books this
189
00:10:15,899 --> 00:10:20,909
way you also need to add a method in
190
00:10:18,000 --> 00:10:23,429
here and that method is notify data set
191
00:10:20,909 --> 00:10:25,620
changed we are adding this method
192
00:10:23,429 --> 00:10:28,949
because we are going to refresh the data
193
00:10:25,620 --> 00:10:30,690
in our recycler view okay let's move on
194
00:10:28,950 --> 00:10:33,090
from this part and let's start working
195
00:10:30,690 --> 00:10:34,680
on this get item count method but before
196
00:10:33,090 --> 00:10:37,379
that I'm going to minimize this view
197
00:10:34,679 --> 00:10:39,839
holder class this get item count method
198
00:10:37,379 --> 00:10:42,600
as I said before is just returning the
199
00:10:39,840 --> 00:10:45,600
size of items or the size of least in
200
00:10:42,600 --> 00:10:47,480
our recycler view so in here i can say
201
00:10:47,480 --> 00:10:51,970
nothing special is going to happen
202
00:10:51,970 --> 00:10:57,040
inside this uncreate view holder method
203
00:10:54,639 --> 00:10:59,460
we need to create an instance of our
204
00:10:57,039 --> 00:11:01,929
view holder and we need to return that
205
00:10:59,460 --> 00:11:03,730
probably all the times the code inside
206
00:11:01,929 --> 00:11:06,519
this on create view holder method is
207
00:11:03,730 --> 00:11:08,529
going to be the same in all cases so you
208
00:11:06,519 --> 00:11:11,590
can save the copy and paste but I'm
209
00:11:08,529 --> 00:11:14,529
writing in here so I can save you
210
00:11:11,590 --> 00:11:17,320
let's name it view is equal to layout
211
00:11:14,529 --> 00:11:19,870
inflator if you remember let's say that
212
00:11:17,320 --> 00:11:21,910
from we need to pass a context in here
213
00:11:19,870 --> 00:11:24,909
and we can pass the context by using
214
00:11:21,909 --> 00:11:28,179
this view group let's say parents that
215
00:11:24,909 --> 00:11:30,730
get context after that we can call the
216
00:11:28,179 --> 00:11:33,669
Tottenham flight method in which first
217
00:11:30,730 --> 00:11:36,840
of all we need to pass our layout I can
218
00:11:33,669 --> 00:11:39,429
say our that layout dot list item book
219
00:11:36,840 --> 00:11:42,129
after that we need the view group itself
220
00:11:39,429 --> 00:11:45,219
in order to attach our layout file this
221
00:11:42,129 --> 00:11:47,320
list item block to its parent and after
222
00:11:45,220 --> 00:11:51,610
that I am going to pass false in order
223
00:11:47,320 --> 00:11:53,920
to avoid redundancy after creating this
224
00:11:51,610 --> 00:11:57,370
view object you can create your view
225
00:11:53,919 --> 00:12:00,669
holder quest let's say view holder let's
226
00:11:57,370 --> 00:12:04,379
name it holder is equal to new view
227
00:12:00,669 --> 00:12:08,529
holder and let's pass our view object
228
00:12:04,379 --> 00:12:10,559
after that I can return my holder also
229
00:12:08,529 --> 00:12:14,019
this method in here can be simplified
230
00:12:10,559 --> 00:12:17,079
right now you can see that this local
231
00:12:14,019 --> 00:12:19,210
variable is redundant it means that you
232
00:12:17,080 --> 00:12:21,129
can directly return it instead of
233
00:12:19,210 --> 00:12:23,500
creating an instance of that holder
234
00:12:21,129 --> 00:12:27,700
class so in here what I can say is that
235
00:12:23,500 --> 00:12:30,490
I can say return new view holder and I
236
00:12:27,700 --> 00:12:33,370
can pass my view once again in most
237
00:12:30,490 --> 00:12:35,230
cases this is exactly the code that you
238
00:12:33,370 --> 00:12:38,049
need to put inside this one create new
239
00:12:35,230 --> 00:12:40,210
holder method after that down below
240
00:12:38,049 --> 00:12:42,719
inside this unbound view holder method
241
00:12:40,210 --> 00:12:44,769
first of all I'm going to lock something
242
00:12:42,720 --> 00:12:47,410
indicating that this method has been
243
00:12:44,769 --> 00:12:49,059
called in order to add a lock a bug in
244
00:12:47,409 --> 00:12:52,600
here first of all I need to add a
245
00:12:49,059 --> 00:12:54,959
constant after that inside on point view
246
00:12:52,600 --> 00:12:59,080
holder method I'm going to say lock D
247
00:12:54,960 --> 00:13:01,240
let's just say called first of all let's
248
00:12:59,080 --> 00:13:05,790
set the name for our book I'm going to
249
00:13:01,240 --> 00:13:09,070
say holder dot txt name that's at
250
00:13:05,789 --> 00:13:14,259
let's say books that get let's fast
251
00:13:09,070 --> 00:13:16,570
position let's say that get named after
252
00:13:14,259 --> 00:13:19,689
that we need to show our image in which
253
00:13:16,570 --> 00:13:21,190
for that we need to collide library for
254
00:13:19,690 --> 00:13:24,340
that I'm going to search the internet
255
00:13:21,190 --> 00:13:26,500
for Glide dependency the first link
256
00:13:24,340 --> 00:13:28,700
which is a github link is probably our
257
00:13:33,110 --> 00:13:39,899
first of all let's add these two
258
00:13:35,220 --> 00:13:42,840
dependencies in our project inside
259
00:13:39,899 --> 00:13:46,709
grading scripts inside this built at
260
00:13:42,840 --> 00:13:50,278
Gradle modular inside these dependencies
261
00:13:46,710 --> 00:13:53,400
I can paste them let's also check that
262
00:13:50,278 --> 00:13:56,129
if we have this maven central and Google
263
00:13:53,399 --> 00:13:59,639
repositories in our built at grader
264
00:13:56,129 --> 00:14:01,860
project one it seems like we need to add
265
00:13:59,639 --> 00:14:06,000
the maven repositories let's copy it
266
00:14:01,860 --> 00:14:07,519
from here maven central and let's paste
267
00:14:07,519 --> 00:14:13,110
ok let's sync our project ok it seems
268
00:14:13,110 --> 00:14:17,970
dependency successfully let's switch
269
00:14:15,750 --> 00:14:20,429
back to our adapter class and inside
270
00:14:17,970 --> 00:14:24,810
this unbound view holder method I'm
271
00:14:20,429 --> 00:14:26,939
going to say flight dot with here we
272
00:14:24,809 --> 00:14:30,469
need our context which was named in
273
00:14:26,940 --> 00:14:34,200
context after that let's say as bitmap
274
00:14:30,470 --> 00:14:36,810
dot load we need an image URL in here
275
00:14:34,200 --> 00:14:39,960
which I'm going to say it pops that yet
276
00:14:36,809 --> 00:14:42,869
let's pass our position let's say that
277
00:14:39,960 --> 00:14:45,680
get image run and after that we need our
278
00:14:42,870 --> 00:14:51,929
image view let's say that into our
279
00:14:45,679 --> 00:14:54,779
holder dot my mg book ok this way we can
280
00:14:51,929 --> 00:14:57,029
show the name and image of our book I'm
281
00:14:54,779 --> 00:14:59,610
also going to set an onclicklistener for
282
00:14:57,029 --> 00:15:01,379
the card view parent for the time being
283
00:14:59,610 --> 00:15:04,470
by clicking on this card view we are
284
00:15:01,379 --> 00:15:06,750
going toast message but later on we are
285
00:15:04,470 --> 00:15:08,490
going to create a book activity and we
286
00:15:06,750 --> 00:15:12,870
are going to navigate the user to that
287
00:15:08,490 --> 00:15:18,240
activity so for now let's say holder dot
288
00:15:12,870 --> 00:15:21,450
parent dot set on click listener let's
289
00:15:18,240 --> 00:15:26,519
say in the onclick listener and let's
290
00:15:21,450 --> 00:15:28,980
show our toast message let's receive the
291
00:15:26,519 --> 00:15:33,480
name of our book I'm going to say oops
292
00:15:28,980 --> 00:15:38,690
that get let's pass our position that
293
00:15:38,750 --> 00:15:43,710
okay I believe that's all we need for
294
00:15:41,250 --> 00:15:45,509
now inside this book recyclerview
295
00:15:43,710 --> 00:15:47,850
adapter later on we are going to change
296
00:15:45,509 --> 00:15:50,250
this a lot but for now let's initialize
297
00:15:47,850 --> 00:15:53,129
it inside our all books activity and
298
00:15:50,250 --> 00:15:56,039
let's set it as the adapter for this box
299
00:15:53,129 --> 00:15:57,750
recyclerview I'm going to define the
300
00:15:56,039 --> 00:16:00,659
adapter above in here as a member
301
00:15:57,750 --> 00:16:02,639
valuable so that we can have access to
302
00:16:00,659 --> 00:16:05,279
this method inside different methods I
303
00:16:02,639 --> 00:16:08,490
think we are going to need that let's
304
00:16:05,279 --> 00:16:12,659
say private books recyclable your
305
00:16:08,490 --> 00:16:14,759
adapter let's name it adapter down in
306
00:16:12,659 --> 00:16:17,009
here before initializing our recycler
307
00:16:14,759 --> 00:16:20,250
view adapter I'm going to say adapter is
308
00:16:17,009 --> 00:16:23,399
equal to new books recycler view adapter
309
00:16:20,250 --> 00:16:25,289
and let's pass our context once again
310
00:16:23,399 --> 00:16:28,409
because we are inside an activity we can
311
00:16:25,289 --> 00:16:30,449
pass this after that I'm going to set
312
00:16:28,409 --> 00:16:33,329
this adapter as the adapter of my
313
00:16:30,450 --> 00:16:36,360
recycler view let's say books recycler
314
00:16:33,330 --> 00:16:39,840
view dad set adapter let's pass our
315
00:16:36,360 --> 00:16:42,409
adapter also for the layout manager I'm
316
00:16:39,840 --> 00:16:45,600
going to pass a grid layout manager
317
00:16:42,409 --> 00:16:49,799
let's say box recycler view that set
318
00:16:45,600 --> 00:16:52,290
layout manager new grid layout manager
319
00:16:49,799 --> 00:16:54,959
this one first of all we need the
320
00:16:52,289 --> 00:16:56,579
context let's pass this after that we
321
00:16:54,960 --> 00:16:58,980
need the number of columns which I'm
322
00:16:56,580 --> 00:17:01,500
going to say to after setting the
323
00:16:58,980 --> 00:17:04,650
adapter we need to set the data I mean
324
00:17:01,500 --> 00:17:07,170
the books area list for the time being
325
00:17:04,650 --> 00:17:09,420
for testing purposes let's just create a
326
00:17:07,170 --> 00:17:12,209
dummy ArrayList and let's pass it to
327
00:17:09,420 --> 00:17:17,130
this adapter let's say array list of
328
00:17:12,209 --> 00:17:21,630
different books let's name it pops is
329
00:17:17,130 --> 00:17:24,950
equal to new ArrayList after that let's
330
00:17:21,630 --> 00:17:28,860
say books that add and let's add a book
331
00:17:24,950 --> 00:17:31,410
let's say new book for the idea of this
332
00:17:28,859 --> 00:17:38,029
book I'm going to save on for the name
333
00:17:31,410 --> 00:17:44,070
let's say 1q84 for the author let's say
334
00:17:38,029 --> 00:17:45,660
Harlequin Murakami after that let's
335
00:17:45,660 --> 00:17:53,759
I believe it's 1350 pages let's quickly
336
00:17:51,029 --> 00:18:02,789
copy some image URL let's search for
337
00:17:53,759 --> 00:18:05,549
1q84 and I think this one is good let's
338
00:18:02,789 --> 00:18:08,220
paste it in here just make sure that
339
00:18:05,549 --> 00:18:12,149
your images and weights that jpg or dot
340
00:18:08,220 --> 00:18:14,160
PNG let's go to the next line let's see
341
00:18:12,150 --> 00:18:16,340
what else do we need we need a short
342
00:18:14,160 --> 00:18:19,890
description and also a long description
343
00:18:16,339 --> 00:18:22,079
for the short description I'm going to
344
00:18:19,890 --> 00:18:24,240
say a work of madelung variants
345
00:18:22,079 --> 00:18:27,679
I believe it's about the Time magazine
346
00:18:28,160 --> 00:18:32,870
for the long description I'm just going
347
00:18:30,829 --> 00:18:35,929
to pass along description because we are
348
00:18:32,869 --> 00:18:38,589
not going to show that yet okay after
349
00:18:35,930 --> 00:18:42,350
adding this book I'm going to say
350
00:18:38,589 --> 00:18:45,079
adapter that sets books let's pass our
351
00:18:42,349 --> 00:18:46,699
books ArrayList before testing the
352
00:18:45,079 --> 00:18:48,649
application let's quickly add the
353
00:18:46,700 --> 00:18:50,720
internet permission because we are going
354
00:18:48,650 --> 00:18:54,490
to load the images from Internet we need
355
00:18:50,720 --> 00:18:57,380
that permission in our manifest file
356
00:18:54,490 --> 00:19:00,289
above the application tag I can say
357
00:18:57,380 --> 00:19:02,450
users permission and I can pass internet
358
00:19:00,289 --> 00:19:04,369
permission okay let's test our
359
00:19:02,450 --> 00:19:08,720
application and let's see if we can see
360
00:19:04,369 --> 00:19:12,469
this put in our activity let's click on
361
00:19:08,720 --> 00:19:14,779
this see all box button as you can see
362
00:19:12,470 --> 00:19:17,120
we are getting a card view for our book
363
00:19:14,779 --> 00:19:19,039
but we are not seeing the image if you
364
00:19:17,119 --> 00:19:21,349
remember I mentioned this problem in
365
00:19:19,039 --> 00:19:23,539
previous videos the reason that we are
366
00:19:21,349 --> 00:19:26,869
not seeing this image is because we have
367
00:19:23,539 --> 00:19:28,460
changed our manifest file we have added
368
00:19:26,869 --> 00:19:30,199
the permission and because we have
369
00:19:28,460 --> 00:19:32,360
changed our manifest we need to
370
00:19:30,200 --> 00:19:34,700
uninstall the application and install it
371
00:19:32,359 --> 00:19:36,709
once again we will do that in a minute
372
00:19:34,700 --> 00:19:39,590
but before that you can see that we have
373
00:19:36,710 --> 00:19:41,779
this ugly background in here I'm going
374
00:19:39,589 --> 00:19:43,909
to get rid of that and beside that I'm
375
00:19:41,779 --> 00:19:46,910
going to add a padding for my recycler
376
00:19:43,910 --> 00:19:49,850
view right now discard view is too close
377
00:19:46,910 --> 00:19:53,720
to the edges of our screen let's quickly
378
00:19:49,849 --> 00:19:55,159
fix those issues so inside our activity
379
00:19:55,160 --> 00:19:59,810
first of all let's delete this
380
00:19:56,960 --> 00:20:02,509
background color after that in our
381
00:19:59,809 --> 00:20:05,960
recycler view item I'm going to add a
382
00:20:02,509 --> 00:20:08,509
margin similarly you can add the padding
383
00:20:05,960 --> 00:20:10,190
on your constraint layers I'm just going
384
00:20:08,509 --> 00:20:10,879
to add the margin in my recycler view
385
00:20:10,880 --> 00:20:16,580
let's pass 15 I believe that's good okay
386
00:20:14,869 --> 00:20:19,939
before testing the application I'm going
387
00:20:16,579 --> 00:20:23,240
to uninstall it from the device so if we
388
00:20:23,240 --> 00:20:31,159
in the apps and notification we can see
389
00:20:28,460 --> 00:20:36,230
this my library application let's
390
00:20:31,159 --> 00:20:39,528
uninstall it and let's run our
391
00:20:36,230 --> 00:20:43,429
application once again this time if we
392
00:20:39,528 --> 00:20:45,648
click on this CL box button after a time
393
00:20:43,429 --> 00:20:47,630
we should see our image it takes some
394
00:20:45,648 --> 00:20:50,239
time to load the image but after all we
395
00:20:47,630 --> 00:20:51,049
can see that let's also check the
396
00:20:51,048 --> 00:20:55,129
on our card here so if we click on our
397
00:20:53,179 --> 00:20:57,259
card view you can see that we are seeing
398
00:20:55,130 --> 00:20:59,899
this toast message which seems to be
399
00:20:57,259 --> 00:21:01,849
working fine okay I think that's enough
400
00:20:59,898 --> 00:21:04,609
for this video in the next video we are
401
00:21:01,849 --> 00:21:07,038
going to work on that expandable card
402
00:21:04,609 --> 00:21:09,229
view that I was talking about so
403
00:21:07,038 --> 00:21:12,230
basically right now we are only seeing
404
00:21:09,230 --> 00:21:14,058
the name and image of this book in the
405
00:21:12,230 --> 00:21:16,700
next video we are going to add a little
406
00:21:14,058 --> 00:21:18,678
arrow button in here in which by
407
00:21:16,700 --> 00:21:21,590
clicking on that the user can see more
408
00:21:18,679 --> 00:21:23,179
details about our book just before I
409
00:21:21,589 --> 00:21:25,158
finish off this video once again I'm
410
00:21:23,179 --> 00:21:27,350
going to say that if for any reason you
411
00:21:25,159 --> 00:21:29,179
need to check the source code I will
412
00:21:27,349 --> 00:21:31,398
upload the source code at the links that
413
00:21:29,179 --> 00:21:33,559
you can see on the screen at make up dot
414
00:21:31,398 --> 00:21:35,449
or feel free to check that if you need
415
00:21:33,558 --> 00:21:37,509
and also I would love to hear your
416
00:21:35,450 --> 00:21:41,409
feedback on the code that I just write
417
00:21:43,500 --> 00:21:49,378
in this video we are going to work on
418
00:21:46,339 --> 00:21:51,599
expandable card view that means that we
419
00:21:49,378 --> 00:21:54,240
are going to show this simple card view
420
00:21:51,599 --> 00:21:56,939
plus an arrow button in here an arrow
421
00:21:54,240 --> 00:21:59,399
icon in which if the user clicks on this
422
00:21:56,940 --> 00:22:01,379
arrow we are going to expand our card
423
00:21:59,398 --> 00:22:03,928
view and we are going to show some more
424
00:22:01,378 --> 00:22:05,878
information for example in this case we
425
00:22:03,929 --> 00:22:08,548
are going to show the name of the author
426
00:22:05,878 --> 00:22:10,589
of this book mas we are going to show
427
00:22:08,548 --> 00:22:12,628
the description the short description of
428
00:22:10,589 --> 00:22:15,148
this book in this video we are going to
429
00:22:12,628 --> 00:22:17,449
see how we can implement that but I need
430
00:22:15,148 --> 00:22:19,678
to say that this way of implementing and
431
00:22:17,450 --> 00:22:20,519
expandable card view inside our
432
00:22:20,519 --> 00:22:25,230
is not going to work with our grid
433
00:22:22,859 --> 00:22:27,569
layouts manager it works perfect with
434
00:22:25,230 --> 00:22:29,159
linear layout manager but for grid
435
00:22:27,569 --> 00:22:31,319
layout manager you need some more
436
00:22:29,159 --> 00:22:33,899
information we will talk about how to
437
00:22:31,319 --> 00:22:36,028
implement an expandable card view in
438
00:22:33,898 --> 00:22:38,158
grid layout manager later on in the
439
00:22:36,028 --> 00:22:41,038
course so because of that first of all
440
00:22:38,159 --> 00:22:43,049
inside my own books activity I'm going
441
00:22:41,038 --> 00:22:45,990
to change the layout manager for my
442
00:22:43,048 --> 00:22:48,298
recycler view to a linear layout manager
443
00:22:45,990 --> 00:22:51,450
and also I am going to increase the size
444
00:22:48,298 --> 00:22:54,599
of this card view so let's switch to all
445
00:22:51,450 --> 00:22:56,370
books activity this one and then in here
446
00:22:54,599 --> 00:22:58,740
you can see that we are using a grid
447
00:22:56,369 --> 00:23:01,439
layout manager let's quickly change that
448
00:22:58,740 --> 00:23:03,298
to linear layout manager we need a
449
00:23:01,440 --> 00:23:05,639
context which I'm going to pass this
450
00:23:03,298 --> 00:23:07,558
let's close this file for now we will be
451
00:23:05,638 --> 00:23:10,048
coming back to this file and let's
452
00:23:07,558 --> 00:23:12,808
switch to a split view and let's write
453
00:23:10,048 --> 00:23:14,668
expandable view for this card view so
454
00:23:12,808 --> 00:23:16,619
here is what we are going to do we are
455
00:23:14,669 --> 00:23:19,110
going to create another relative layout
456
00:23:16,619 --> 00:23:20,849
then below this one that we already have
457
00:23:19,109 --> 00:23:23,339
and we are going to change its
458
00:23:20,849 --> 00:23:25,980
visibility to run later on in the code
459
00:23:23,339 --> 00:23:28,470
inside the recyclerview adapter when the
460
00:23:25,980 --> 00:23:30,569
user clicks on our arrow bottom we are
461
00:23:28,470 --> 00:23:33,179
going to change the visibility of our
462
00:23:30,569 --> 00:23:35,579
relative layout to visible plus we will
463
00:23:33,179 --> 00:23:37,769
add some animation for adding another
464
00:23:35,579 --> 00:23:41,128
relative layout in here I am going to
465
00:23:37,769 --> 00:23:43,319
add one above in here as a single child
466
00:23:41,128 --> 00:23:45,509
of this court view and I'm going to put
467
00:23:43,319 --> 00:23:48,388
this relative layout that we currently
468
00:23:45,509 --> 00:23:51,360
have inside that so let's say relative
469
00:23:48,388 --> 00:23:53,788
layout for its bits I'm going to say 200
470
00:23:51,359 --> 00:23:56,158
DP and for the height I'm going to say
471
00:23:53,788 --> 00:23:57,329
wrap content also I'm going to change
472
00:23:57,329 --> 00:24:02,699
imageview to 200 TP if you remember I
473
00:24:00,299 --> 00:24:05,039
said that because we are no longer using
474
00:24:02,700 --> 00:24:07,110
a great layout manager I'm going to
475
00:24:05,039 --> 00:24:09,569
change the size of this card here so
476
00:24:07,109 --> 00:24:14,009
let's say 200 DP and for the height
477
00:24:09,569 --> 00:24:15,869
let's say 220 I believe is fine now we
478
00:24:15,869 --> 00:24:21,089
let's finish creating our relative
479
00:24:17,579 --> 00:24:23,849
layout and let's move this one to inside
480
00:24:21,089 --> 00:24:25,889
the first relative layout so I'm going
481
00:24:23,849 --> 00:24:27,779
to copy everything but I think it's
482
00:24:25,890 --> 00:24:30,780
better to minimize this relative layout
483
00:24:27,779 --> 00:24:33,599
and copy everything or cut everything to
484
00:24:30,779 --> 00:24:35,609
be precise and place living here you can
485
00:24:33,599 --> 00:24:38,250
see that now our chord view has this
486
00:24:35,609 --> 00:24:40,589
strange shape that we can fix that so if
487
00:24:38,250 --> 00:24:42,750
we open this relative layout you can see
488
00:24:40,589 --> 00:24:44,699
that for the height we have said match
489
00:24:42,750 --> 00:24:47,190
parent I'm going to change that to wrap
490
00:24:44,700 --> 00:24:49,410
wanted as soon as I do that you can see
491
00:24:47,190 --> 00:24:50,789
in the preview that the height has been
492
00:24:50,789 --> 00:24:55,259
okay let's minimize this one after this
493
00:24:53,279 --> 00:24:57,269
relative layout I'm going to create
494
00:24:55,259 --> 00:24:59,970
another relative layout which is going
495
00:24:57,269 --> 00:25:02,639
to be the expanded version of our chord
496
00:24:59,970 --> 00:25:04,319
view so let's say relative layout for
497
00:25:02,640 --> 00:25:06,600
the width I'm going to say match parent
498
00:25:04,319 --> 00:25:09,210
for the height let's say wrap content
499
00:25:06,599 --> 00:25:11,399
I'm going to move it to below the first
500
00:25:09,210 --> 00:25:14,370
relative layout so let's give an ID to
501
00:25:11,400 --> 00:25:17,820
our first relative layout let's name
502
00:25:14,369 --> 00:25:20,429
this bond collapsed relative layout once
503
00:25:17,819 --> 00:25:23,849
again let's minimize it now in here I
504
00:25:20,430 --> 00:25:26,460
can say below our collapsed relative
505
00:25:23,849 --> 00:25:28,589
layout inside this relative layout as I
506
00:25:26,460 --> 00:25:30,840
said I'm going to define some text views
507
00:25:28,589 --> 00:25:33,929
I'm going to show the name of the author
508
00:25:30,839 --> 00:25:36,359
of this book plus I'm going to show the
509
00:25:33,930 --> 00:25:38,970
short description so first of all let's
510
00:25:36,359 --> 00:25:42,169
say text view wrap content and wrap
511
00:25:38,970 --> 00:25:46,920
content for its text I'm going to say
512
00:25:42,170 --> 00:25:50,100
author let's give it an ID let's just
513
00:25:46,920 --> 00:25:52,800
say author text I'm not going to change
514
00:25:50,099 --> 00:25:55,259
the style or anything after that let's
515
00:25:52,799 --> 00:25:57,599
and define another text view for the
516
00:25:55,259 --> 00:26:00,960
Viets that's a wrap content similarly
517
00:25:57,599 --> 00:26:02,819
for the height wrap content for its text
518
00:26:00,960 --> 00:26:05,789
I'm going to put the name I'm going to
519
00:26:02,819 --> 00:26:08,309
put my name for its ID I am going to say
520
00:26:05,789 --> 00:26:10,480
TX the author this is the one that we
521
00:26:08,309 --> 00:26:13,509
are going to change later on in the code
522
00:26:10,480 --> 00:26:17,950
let's move it below our author text
523
00:26:13,509 --> 00:26:20,890
let's say layout below text author or it
524
00:26:17,950 --> 00:26:24,340
was called author text let's add another
525
00:26:20,890 --> 00:26:28,179
text view in here text view wrap content
526
00:26:24,339 --> 00:26:31,449
and web content for its text I'm going
527
00:26:28,179 --> 00:26:33,970
to save short description and let's also
528
00:26:31,450 --> 00:26:37,330
give it an ID that's a txt short
529
00:26:33,970 --> 00:26:40,289
description that's also move it to below
530
00:26:37,329 --> 00:26:43,779
our author name let's say layout below
531
00:26:40,289 --> 00:26:47,740
TX the author I think it's better to add
532
00:26:43,779 --> 00:26:49,839
a margin let's say margin top I'm also
533
00:26:47,740 --> 00:26:52,210
going to need two icons let's quickly
534
00:26:49,839 --> 00:26:54,548
add them in our project and we'll see
535
00:26:52,210 --> 00:26:57,490
why I'm adding these two so in our
536
00:26:54,548 --> 00:26:58,179
driver folder we can say a new image
537
00:26:58,179 --> 00:27:03,400
let's select action bar and have icons
538
00:27:01,029 --> 00:27:06,308
for the icons I'm going to search for
539
00:27:03,400 --> 00:27:08,950
arrow the first one I'm going to add
540
00:27:06,308 --> 00:27:12,700
this one this down arrow let's change
541
00:27:08,950 --> 00:27:15,210
its name to I see down arrow and also
542
00:27:12,700 --> 00:27:18,910
let's change its color to a black color
543
00:27:15,210 --> 00:27:21,519
let's add another one new image acid
544
00:27:18,910 --> 00:27:24,700
once again this time I'm going to search
545
00:27:21,519 --> 00:27:27,460
for an up arrow this one in here I think
546
00:27:24,700 --> 00:27:31,750
is fine let's change its name to up
547
00:27:27,460 --> 00:27:34,750
arrow by CEO arrow and let's add it into
548
00:27:31,750 --> 00:27:37,480
our project now in here after this
549
00:27:34,750 --> 00:27:40,599
description text I'm going to add my up
550
00:27:37,480 --> 00:27:43,120
arrow so if the user decides to collapse
551
00:27:40,599 --> 00:27:45,490
this current view your she would be able
552
00:27:43,119 --> 00:27:48,579
to do that by clicking on our up arrow
553
00:27:45,490 --> 00:27:50,950
so let's say image view graph content
554
00:27:48,579 --> 00:27:52,149
and wrap content for its source let's
555
00:27:52,150 --> 00:27:57,730
up arrow this one let's move it to below
556
00:27:55,419 --> 00:28:00,220
our description text to X the
557
00:27:57,730 --> 00:28:02,950
description and also let's move it to
558
00:28:00,220 --> 00:28:05,500
the end of our card here for that we can
559
00:28:02,950 --> 00:28:08,740
say alloy in finance and and we can pass
560
00:28:05,500 --> 00:28:11,890
through let's give it an ID let's say DT
561
00:28:08,740 --> 00:28:14,740
an up arrow okay that's it for my
562
00:28:11,890 --> 00:28:17,559
expanded view now that I have defined it
563
00:28:14,740 --> 00:28:19,779
I'm going to change its visibility to
564
00:28:17,558 --> 00:28:21,819
gone but before that I'm going to give
565
00:28:19,779 --> 00:28:22,750
an ID to this relativelayout because we
566
00:28:22,750 --> 00:28:28,299
our adapter let's say ID this time I'm
567
00:28:26,170 --> 00:28:31,140
going to name it expanded relativelayout
568
00:28:28,299 --> 00:28:34,480
and let's change its visibility
569
00:28:31,140 --> 00:28:36,880
visibility to gone also let's minimize
570
00:28:34,480 --> 00:28:38,740
this relative layout so now you can see
571
00:28:36,880 --> 00:28:41,440
that we have two relative layouts the
572
00:28:38,740 --> 00:28:43,509
first one is the collapsed relative
573
00:28:41,440 --> 00:28:46,900
layout which the user is going to see
574
00:28:43,509 --> 00:28:49,210
when he or she opens our activity and if
575
00:28:46,900 --> 00:28:51,490
the user clicks on the arrow that I'm
576
00:28:49,210 --> 00:28:53,319
going to add in a minute we are going to
577
00:28:51,490 --> 00:28:56,440
show this second relative layout
578
00:28:53,319 --> 00:28:59,529
let's quickly add that arrow button so
579
00:28:56,440 --> 00:29:01,750
down in here I'm going to say image view
580
00:28:59,529 --> 00:29:05,139
wrap content and wrap content parse
581
00:29:01,750 --> 00:29:07,809
again for the source let's say down
582
00:29:05,140 --> 00:29:09,970
arrow this time I see down arrow let's
583
00:29:07,809 --> 00:29:13,899
move it to below our image that's a
584
00:29:09,970 --> 00:29:16,299
layout below IMG block also I'm going to
585
00:29:13,900 --> 00:29:18,940
add the same margin that I added for
586
00:29:16,299 --> 00:29:22,329
this text name so let's say margin top
587
00:29:18,940 --> 00:29:25,180
and let's pass 70 P you can see that for
588
00:29:22,329 --> 00:29:28,539
this textview we have the 70 PS back ok
589
00:29:25,180 --> 00:29:29,039
let's give it an ID let's say BTN down
590
00:29:29,039 --> 00:29:35,019
let's also move it to the end of our
591
00:29:31,930 --> 00:29:37,570
layout online parent and let's say
592
00:29:35,019 --> 00:29:39,789
through I think it's better to change
593
00:29:37,569 --> 00:29:41,829
the position of name text to the
594
00:29:39,789 --> 00:29:44,049
beginning of our card view now that we
595
00:29:41,829 --> 00:29:46,480
have added this icon let's quickly do
596
00:29:44,049 --> 00:29:48,609
that for this text view I'm going to
597
00:29:46,480 --> 00:29:50,920
remove this Center horizontal attribute
598
00:29:48,609 --> 00:29:54,009
I don't think we need anything else
599
00:29:50,920 --> 00:29:56,950
let's switch to our adapter and let's
600
00:29:54,009 --> 00:29:59,200
see how we can work on this down and up
601
00:29:56,950 --> 00:30:01,420
arrow buttons before everything before I
602
00:29:59,200 --> 00:30:04,660
go to my adapter I am going to open my
603
00:30:01,420 --> 00:30:07,090
model my book model and I am going to
604
00:30:04,660 --> 00:30:09,580
add another field so inside our package
605
00:30:07,089 --> 00:30:11,799
we had a book class if you remember I'm
606
00:30:09,579 --> 00:30:14,859
going to add another field in here let's
607
00:30:11,799 --> 00:30:18,009
say private Bruneian let's name it is
608
00:30:14,859 --> 00:30:20,349
expanded I'm not going to receive this
609
00:30:18,009 --> 00:30:23,049
boolean via the constructor instead
610
00:30:20,349 --> 00:30:25,750
inside the constructor initially I'm
611
00:30:23,049 --> 00:30:28,690
going to set it to false so whenever we
612
00:30:25,750 --> 00:30:30,700
create our book object I'm going to set
613
00:30:28,690 --> 00:30:33,250
this value to false let's say is
614
00:30:30,700 --> 00:30:35,440
expanded is Dakota farms let's also
615
00:30:33,250 --> 00:30:36,349
create a getter and setter for this is
616
00:30:36,349 --> 00:30:41,119
we are going to need them getter and
617
00:30:38,058 --> 00:30:43,250
setter let's create them okay now let's
618
00:30:41,119 --> 00:30:45,709
switch to our adapter class and let's
619
00:30:43,250 --> 00:30:48,319
see how we can implement this logic poke
620
00:30:45,710 --> 00:30:50,419
recycle every adapter first of all
621
00:30:48,319 --> 00:30:53,210
inside this inner viewholder class
622
00:30:50,419 --> 00:30:55,280
inside the constructor I'm going to set
623
00:30:53,210 --> 00:30:57,500
an onclicklistener for that and down
624
00:30:55,279 --> 00:30:59,450
arrow button but in order to have access
625
00:30:57,500 --> 00:31:02,119
to that I need to initialize that in
626
00:30:59,450 --> 00:31:05,808
here so let's say private image view
627
00:31:02,119 --> 00:31:08,269
down arrow and pop arrow let's also
628
00:31:05,808 --> 00:31:10,940
define the other UI elements for example
629
00:31:08,269 --> 00:31:13,460
we had a relative layout let's say
630
00:31:10,940 --> 00:31:16,548
private relative layout expanded
631
00:31:13,460 --> 00:31:20,298
relative layout we had two new text
632
00:31:16,548 --> 00:31:23,480
views private text view and TX the
633
00:31:20,298 --> 00:31:27,109
author and txt description let's quickly
634
00:31:23,480 --> 00:31:29,298
initialize them in our constructor now
635
00:31:27,109 --> 00:31:31,129
that we have initialized these items I
636
00:31:29,298 --> 00:31:33,259
am going to set an onclick listener for
637
00:31:31,130 --> 00:31:36,289
this down arrow button let's say down
638
00:31:33,259 --> 00:31:39,079
arrow that's set onclicklistener neon
639
00:31:36,288 --> 00:31:41,329
click listener inside this unclick
640
00:31:39,079 --> 00:31:43,639
method first of all I'm going to get the
641
00:31:41,329 --> 00:31:45,710
current book that we are looking into in
642
00:31:43,640 --> 00:31:48,470
previous videos we have seen how we can
643
00:31:45,710 --> 00:31:49,970
get that book inside unbind view holder
644
00:31:48,470 --> 00:31:53,058
method with the help of that position
645
00:31:49,970 --> 00:31:55,190
but it is also possible to get it inside
646
00:31:53,058 --> 00:31:58,129
this view holder class we can get it
647
00:31:55,190 --> 00:32:01,070
like this we can say work let's name it
648
00:31:58,130 --> 00:32:03,980
Talk is equal to our books ArrayList
649
00:32:01,069 --> 00:32:07,308
that get this time for the position I
650
00:32:03,980 --> 00:32:09,620
can pass get adapter position so this
651
00:32:07,308 --> 00:32:11,960
way we are going to get the book that we
652
00:32:09,619 --> 00:32:13,969
are currently creating a view holder for
653
00:32:11,960 --> 00:32:16,400
that after getting this book we are
654
00:32:13,970 --> 00:32:18,288
going to change the field that we just
655
00:32:16,400 --> 00:32:20,900
defined I'm talking about that is
656
00:32:18,288 --> 00:32:23,538
expanded boolean so whenever the user
657
00:32:20,900 --> 00:32:26,030
clicks on this down arrow we are going
658
00:32:23,538 --> 00:32:29,690
to change that is expanded field of our
659
00:32:26,029 --> 00:32:32,779
book I'm going to say book dot set
660
00:32:29,690 --> 00:32:36,798
expanded let's say the inverted value of
661
00:32:32,779 --> 00:32:39,619
our book dot get expanded or I believe
662
00:32:36,798 --> 00:32:41,779
it was is expanded instead of this line
663
00:32:39,619 --> 00:32:44,329
of code in here and you can write an if
664
00:32:41,779 --> 00:32:46,460
statement but I've simplified my code to
665
00:32:44,329 --> 00:32:49,409
this way so basically we are inverting
666
00:32:46,460 --> 00:32:50,970
the is expanded value of airport
667
00:32:49,410 --> 00:32:53,250
there is just one last thing that we
668
00:32:50,970 --> 00:32:55,620
need to do in here and that is to tell
669
00:32:53,250 --> 00:32:58,410
the adapter that we have changed some
670
00:32:55,619 --> 00:33:01,049
item in our dataset in previous videos
671
00:32:58,410 --> 00:33:03,750
we have seen at this notified data set
672
00:33:01,049 --> 00:33:05,970
this one but in here because I'm only
673
00:33:03,750 --> 00:33:09,059
changing one item I'm going to say
674
00:33:05,970 --> 00:33:10,740
notify item changed and of course in
675
00:33:09,059 --> 00:33:12,809
here once again I need the position
676
00:33:10,740 --> 00:33:14,910
which I can pass this get adapter
677
00:33:12,809 --> 00:33:17,819
position so this way we are going to
678
00:33:14,910 --> 00:33:19,890
update our recyclerview adapter later on
679
00:33:17,819 --> 00:33:22,529
in our on point view holder method we
680
00:33:19,890 --> 00:33:25,290
are going to take care of the expanding
681
00:33:22,529 --> 00:33:27,149
and collapsing our cart view beside this
682
00:33:27,150 --> 00:33:31,560
onclicklistener for this off arrow let's
683
00:33:29,460 --> 00:33:34,410
quickly write that as well let's say off
684
00:33:31,559 --> 00:33:36,929
arrow dot set one click listener me on
685
00:33:34,410 --> 00:33:38,820
click listener and in here the logic is
686
00:33:36,930 --> 00:33:41,670
the same once again we are going to
687
00:33:38,819 --> 00:33:44,220
invert the value of our books is
688
00:33:41,670 --> 00:33:45,779
expanded field so basically I can copy
689
00:33:44,220 --> 00:33:48,269
and paste these three lines of code
690
00:33:45,779 --> 00:33:51,450
let's face them in here so by clicking
691
00:33:48,269 --> 00:33:54,269
on our down arrow or off arrow we are
692
00:33:51,450 --> 00:33:56,130
inverting this is expanded field and
693
00:33:54,269 --> 00:33:57,990
that's all we need to do inside this
694
00:33:56,130 --> 00:34:00,390
view holder class let's see what do we
695
00:33:57,990 --> 00:34:02,789
need to do inside on brined view holder
696
00:34:00,390 --> 00:34:05,940
method so in here first of all I'm going
697
00:34:02,789 --> 00:34:09,779
to check that if these expanded is true
698
00:34:05,940 --> 00:34:13,409
or not let's say if Bob start get let's
699
00:34:09,780 --> 00:34:15,780
pass our position but is expanded it
700
00:34:13,409 --> 00:34:17,819
means that if we do need to expand our
701
00:34:15,780 --> 00:34:20,310
card view then we are going to do that
702
00:34:17,820 --> 00:34:23,100
and we can do that like this we can say
703
00:34:20,309 --> 00:34:26,250
holder that expanded relative layout
704
00:34:23,099 --> 00:34:28,860
that set visibility let's change it to
705
00:34:26,250 --> 00:34:32,190
visible we also need to make our down
706
00:34:28,860 --> 00:34:35,010
arrow icon invisible for that I can say
707
00:34:32,190 --> 00:34:36,840
holder dot down arrow that set
708
00:34:36,840 --> 00:34:42,630
set visibility let's say gone let's also
709
00:34:40,110 --> 00:34:44,280
write the n space in the else case we
710
00:34:42,630 --> 00:34:46,619
are going to change the visibility of
711
00:34:44,280 --> 00:34:50,250
this expanded relative layout to gone
712
00:34:46,619 --> 00:34:52,168
and this down arrow to visible so let's
713
00:34:50,250 --> 00:34:55,320
copy these two lines of code and let's
714
00:34:52,168 --> 00:34:57,389
change their values this in here is
715
00:34:55,320 --> 00:34:59,400
going to work fine but if you remember I
716
00:34:57,389 --> 00:35:02,039
said that we are going to also add some
717
00:34:59,400 --> 00:35:02,880
sort of animation to this expanding and
718
00:35:02,880 --> 00:35:07,410
for that before changing the visibility
719
00:35:05,070 --> 00:35:10,320
of our UI elements I'm going to call
720
00:35:07,409 --> 00:35:12,210
this transition manager I'm not sure
721
00:35:10,320 --> 00:35:14,940
that if you have noticed but it's coming
722
00:35:12,210 --> 00:35:17,099
from this Android extra transition make
723
00:35:14,940 --> 00:35:19,950
sure to import the right one let's say
724
00:35:17,099 --> 00:35:22,199
dot begin delayed transition for this
725
00:35:19,949 --> 00:35:24,779
method in here we need to pass our route
726
00:35:22,199 --> 00:35:27,779
in this case the route is our card view
727
00:35:24,780 --> 00:35:30,030
so we can say holder dot parent if you
728
00:35:27,780 --> 00:35:32,400
remember we gave an ID to our card view
729
00:35:30,030 --> 00:35:33,890
which was parent and that's all we need
730
00:35:32,400 --> 00:35:37,740
to do let's also do the same thing
731
00:35:33,889 --> 00:35:39,569
inside the else case so by this point we
732
00:35:37,739 --> 00:35:42,000
have changed the visibility of our
733
00:35:39,570 --> 00:35:45,120
relative layout but also we need to set
734
00:35:42,000 --> 00:35:47,400
the data for the author's name and also
735
00:35:45,119 --> 00:35:49,769
for the short description I can do that
736
00:35:47,400 --> 00:35:54,079
before this leaf case I can say holder
737
00:35:49,769 --> 00:35:58,380
dot txt author dot set text two books
738
00:35:54,079 --> 00:36:00,360
but yet let's pass position don't get
739
00:35:58,380 --> 00:36:03,000
author similarly for the short
740
00:36:00,360 --> 00:36:05,220
description let's run the application
741
00:36:05,219 --> 00:36:11,309
expandable card view let's go to our
742
00:36:07,800 --> 00:36:13,620
outputs activity you can see that right
743
00:36:11,309 --> 00:36:16,380
now we are seeing the collapsed version
744
00:36:13,619 --> 00:36:19,079
of our card view also the size is bigger
745
00:36:16,380 --> 00:36:21,360
we also need to move this recycler view
746
00:36:19,079 --> 00:36:23,730
discord view to the center of our layout
747
00:36:21,360 --> 00:36:26,579
we will fix that but right now if we
748
00:36:23,730 --> 00:36:28,530
click on this down arrow in here you can
749
00:36:26,579 --> 00:36:31,079
see that we are seeing the expanded
750
00:36:28,530 --> 00:36:33,990
version of our card we once again if we
751
00:36:31,079 --> 00:36:36,509
click on this up arrow we can see the
752
00:36:33,989 --> 00:36:38,489
collapsed version of our card view it
753
00:36:36,510 --> 00:36:40,770
seems like our logic is working fine
754
00:36:38,489 --> 00:36:43,019
let's quickly Center discord view and
755
00:36:40,769 --> 00:36:43,769
also let's add another item into our
756
00:36:43,769 --> 00:36:48,539
and let's see if they're collapsing and
757
00:36:46,019 --> 00:36:50,489
expanding is working the same or not so
758
00:36:48,539 --> 00:36:53,190
first of all I'm going to go to the
759
00:36:50,489 --> 00:36:56,219
layout of my old books activity in my
760
00:36:53,190 --> 00:36:59,309
app folder inside the resources layout
761
00:36:56,219 --> 00:37:01,619
activity all books that XML I'm going to
762
00:36:59,309 --> 00:37:04,829
change it sweets to wrap content and
763
00:37:01,619 --> 00:37:07,079
also I'm going to Center it horizontally
764
00:37:04,829 --> 00:37:09,389
but in here we are using this constraint
765
00:37:07,079 --> 00:37:11,940
layout so for that I need to constraint
766
00:37:11,940 --> 00:37:15,990
that seems better let's quickly add one
767
00:37:15,989 --> 00:37:22,108
in our java file in our books activity
768
00:37:19,739 --> 00:37:24,328
go to Java file down in here I'm going
769
00:37:22,108 --> 00:37:26,880
to add another book I'm going to cut the
770
00:37:24,329 --> 00:37:28,530
process of adding a new book okay now
771
00:37:26,880 --> 00:37:30,210
that I've added another book let's
772
00:37:28,530 --> 00:37:32,430
quickly run the application and let's
773
00:37:30,210 --> 00:37:35,099
see if our expandable card view is
774
00:37:32,429 --> 00:37:37,858
working the same let's go to our books
775
00:37:35,099 --> 00:37:40,109
activity this time you can see that we
776
00:37:37,858 --> 00:37:42,659
are seeing two books if I click on the
777
00:37:40,108 --> 00:37:44,219
down arrow of the first one you can see
778
00:37:42,659 --> 00:37:47,009
that we are seeing the short description
779
00:37:44,219 --> 00:37:49,259
and also the author name but the second
780
00:37:47,010 --> 00:37:51,780
book is still in the collapsed version
781
00:37:49,260 --> 00:37:54,720
we can do that for the second book as
782
00:37:51,780 --> 00:37:56,819
well let's quickly change the linear
783
00:37:54,719 --> 00:37:58,739
layout manager to a grid layout manager
784
00:37:56,818 --> 00:38:00,808
and show the problem with grid layout
785
00:37:58,739 --> 00:38:02,699
manager so in here we need to pass a
786
00:38:00,809 --> 00:38:04,769
column number which I'm going to fast
787
00:38:02,699 --> 00:38:07,588
too let's run the application once again
788
00:38:04,769 --> 00:38:10,440
so in here we have two books in our
789
00:38:07,588 --> 00:38:12,420
layout file in our recycler view if I
790
00:38:10,440 --> 00:38:15,269
click on this down arrow which you can
791
00:38:12,420 --> 00:38:17,309
hardly see we can see that the layout
792
00:38:15,269 --> 00:38:20,130
file for both of these card views
793
00:38:17,309 --> 00:38:22,589
changed so this way of implementing an
794
00:38:20,130 --> 00:38:25,200
expandable card view is not going to
795
00:38:22,588 --> 00:38:27,630
work for our grid layout manager for
796
00:38:25,199 --> 00:38:30,028
implementing the expanded court view in
797
00:38:27,630 --> 00:38:32,068
our grid layout manager we need to know
798
00:38:30,028 --> 00:38:34,108
a bit more about the circular views for
799
00:38:32,068 --> 00:38:37,079
example we need to know that in
800
00:38:34,108 --> 00:38:39,778
recyclable adapter we can have multiple
801
00:38:37,079 --> 00:38:41,730
view holder classes and handling two
802
00:38:39,778 --> 00:38:44,010
different view holders in recycler view
803
00:38:41,730 --> 00:38:46,230
adapter is out of the scope of this
804
00:38:44,010 --> 00:38:47,880
section we will cover that later on in
805
00:38:46,230 --> 00:38:51,240
the course but for now we are just going
806
00:38:47,880 --> 00:38:53,760
to stay with a linear layout manager our
807
00:38:51,239 --> 00:38:56,009
work with expandable card views are not
808
00:38:53,760 --> 00:38:59,099
done yet later on in the course we will
809
00:38:56,010 --> 00:39:01,380
add some action to this expandable view
810
00:38:59,099 --> 00:39:03,660
for example some buttons to delete this
811
00:39:01,380 --> 00:39:05,849
book from a specific list in our
812
00:39:03,659 --> 00:39:07,949
application but for now I think that's
813
00:39:05,849 --> 00:39:10,019
enough and also I think that's enough
814
00:39:07,949 --> 00:39:12,328
for this video in the next video we are
815
00:39:10,019 --> 00:39:14,400
going to create our book activity in
816
00:39:12,329 --> 00:39:16,260
which if we click on one of these card
817
00:39:14,400 --> 00:39:17,970
views instead of showing this toast
818
00:39:16,260 --> 00:39:20,490
message we are going to navigate the
819
00:39:17,969 --> 00:39:22,558
user to another activity in order to
820
00:39:20,489 --> 00:39:25,139
show some more detail about our book and
821
00:39:22,559 --> 00:39:25,710
also beside in a showing more details we
822
00:39:25,710 --> 00:39:30,750
to give the user some options for
823
00:39:27,539 --> 00:39:32,550
example to add book to some of the lists
824
00:39:30,750 --> 00:39:35,619
okay see you in the next video
825
00:39:36,130 --> 00:39:41,110
in this video we are going to create a
826
00:39:38,920 --> 00:39:43,930
book activity and we are going to
827
00:39:41,110 --> 00:39:46,570
navigate the user when he or she clicks
828
00:39:43,929 --> 00:39:49,389
on one of our books in our recyclerview
829
00:39:46,570 --> 00:39:52,690
for that in my package I can right click
830
00:39:49,389 --> 00:39:56,109
once again by selecting new empty
831
00:39:52,690 --> 00:39:59,650
activity I can create my activity let's
832
00:39:56,110 --> 00:40:01,840
name this one book activity I am going
833
00:39:59,650 --> 00:40:03,760
to generate a layout file so I'm going
834
00:40:01,840 --> 00:40:05,800
to leave this checkbox checked
835
00:40:03,760 --> 00:40:08,410
let's close this drama file and let's
836
00:40:05,800 --> 00:40:10,570
start working on our layout so our
837
00:40:08,409 --> 00:40:12,759
layout is right now a constraint layout
838
00:40:10,570 --> 00:40:16,000
first of all I'm going to add an image
839
00:40:12,760 --> 00:40:18,190
viewing here for the image of my book
840
00:40:16,000 --> 00:40:20,920
for the sample data let's select an
841
00:40:18,190 --> 00:40:23,440
avatar after that I'm going to add four
842
00:40:20,920 --> 00:40:26,139
buttons in here we will talk about the
843
00:40:23,440 --> 00:40:29,559
purpose of these buttons for now let's
844
00:40:26,139 --> 00:40:32,589
just add them after that I'm going to
845
00:40:29,559 --> 00:40:36,039
add some text views in here for the name
846
00:40:32,590 --> 00:40:38,019
author and description of my book I'm
847
00:40:36,039 --> 00:40:40,239
going to give some ID to these UI
848
00:40:38,019 --> 00:40:42,670
elements and beside that I'm going to
849
00:40:40,239 --> 00:40:44,559
set some initial data for them because
850
00:40:42,670 --> 00:40:47,110
we have done this before I'm going to
851
00:40:44,559 --> 00:40:49,329
record the process of doing that I've
852
00:40:47,110 --> 00:40:52,570
added the initial data for each one of
853
00:40:49,329 --> 00:40:54,429
these items plus I gave them some ID you
854
00:40:52,570 --> 00:40:56,769
can see the ID for example for this
855
00:40:54,429 --> 00:40:59,589
first button which is a bt an add to
856
00:40:56,769 --> 00:41:01,809
currently reading list so basically by
857
00:40:59,590 --> 00:41:04,329
clicking on this button I'm going to add
858
00:41:01,809 --> 00:41:06,369
this book to the currently reading list
859
00:41:04,329 --> 00:41:08,590
it means that I'm currently reading it
860
00:41:06,369 --> 00:41:11,139
you can guess the others this is for
861
00:41:08,590 --> 00:41:13,420
adding to the visual is this is for the
862
00:41:11,139 --> 00:41:15,489
books that I already read and the last
863
00:41:13,420 --> 00:41:17,980
one is for adding two favorite books
864
00:41:15,489 --> 00:41:21,339
also down in here we can see the books
865
00:41:17,980 --> 00:41:24,099
name books author books pages and also
866
00:41:21,340 --> 00:41:26,410
the books description and this image is
867
00:41:24,099 --> 00:41:28,239
going to be the image of our book okay
868
00:41:26,409 --> 00:41:30,609
now let's quickly add some constraints
869
00:41:28,239 --> 00:41:33,609
for this one I am going to constraint it
870
00:41:30,610 --> 00:41:36,039
to top of my screen and also to the left
871
00:41:33,610 --> 00:41:38,500
of my screen beside that I'm going to
872
00:41:36,039 --> 00:41:40,869
add a vertical guideline in here that's
873
00:41:38,500 --> 00:41:43,659
right click amperes add vertical
874
00:41:40,869 --> 00:41:46,269
guideline and let's move it to somewhere
875
00:41:43,659 --> 00:41:47,889
around here and let's constraint our
876
00:41:49,838 --> 00:41:56,528
I think 50 would be fine let's quickly
877
00:41:53,108 --> 00:41:59,248
constraint our buttons for this one I'm
878
00:41:56,528 --> 00:42:03,130
going to constraint it to top let's say
879
00:41:59,248 --> 00:42:06,368
15 as the margin top or 50 let's quickly
880
00:42:03,130 --> 00:42:08,798
constraint it to the edge of our screen
881
00:42:06,369 --> 00:42:10,960
and also this vertical guideline I'm
882
00:42:08,798 --> 00:42:14,139
going to do the same thing for my
883
00:42:10,960 --> 00:42:15,999
buttons for the other buttons just for
884
00:42:14,139 --> 00:42:20,288
the margin top I think I'm going to stay
885
00:42:15,998 --> 00:42:22,598
with 24 let's add a horizontal guideline
886
00:42:20,289 --> 00:42:25,390
and let's constraint our text views to
887
00:42:22,599 --> 00:42:27,609
that horizontal guideline so let's say
888
00:42:25,389 --> 00:42:29,528
add horizontal guideline let's move it
889
00:42:27,608 --> 00:42:31,690
to down below somewhere around here
890
00:42:29,528 --> 00:42:34,119
let's also add another vertical
891
00:42:31,690 --> 00:42:36,219
guideline we will see its usage in a
892
00:42:34,119 --> 00:42:39,068
minute add vertical guideline
893
00:42:36,219 --> 00:42:41,079
I think it's place is fine and I'm going
894
00:42:39,068 --> 00:42:44,318
to constraint these text views to this
895
00:42:41,079 --> 00:42:47,000
guideline in here let's do the same
896
00:42:44,318 --> 00:42:49,769
thing for the other text views
897
00:42:47,000 --> 00:42:52,440
also I'm going to add another vertical
898
00:42:49,769 --> 00:42:54,539
guideline let's say add vertical point
899
00:42:54,539 --> 00:42:58,139
let's move this vertical guideline to
900
00:42:56,309 --> 00:42:59,789
somewhere around here and let's
901
00:42:58,139 --> 00:43:01,858
constraint these three texts to this
902
00:42:59,789 --> 00:43:04,650
vertical guideline you can see that
903
00:43:01,858 --> 00:43:07,159
guidelines are extremely useful when you
904
00:43:04,650 --> 00:43:09,780
are designing your layout files with
905
00:43:07,159 --> 00:43:11,759
constraint layout for the top of this
906
00:43:09,780 --> 00:43:14,519
text view I'm going to constraint it to
907
00:43:11,760 --> 00:43:16,680
the top of my book name also the same
908
00:43:14,519 --> 00:43:19,079
thing for the button you can also use
909
00:43:16,679 --> 00:43:22,949
the baseline but in here I've used the
910
00:43:19,079 --> 00:43:24,719
top and bottom constraints okay I think
911
00:43:22,949 --> 00:43:27,659
that's all of the constraints that I
912
00:43:24,719 --> 00:43:29,489
need I just want to change the width and
913
00:43:27,659 --> 00:43:32,670
height of this image view to somewhere
914
00:43:29,489 --> 00:43:35,089
around 150 DP because different books
915
00:43:32,670 --> 00:43:37,769
can have different widths and height
916
00:43:35,090 --> 00:43:40,230
okay now let's quickly initialize all of
917
00:43:37,769 --> 00:43:42,150
these items in our Java file let's
918
00:43:40,230 --> 00:43:44,849
switch to report activity that's Java
919
00:43:42,150 --> 00:43:48,230
file and let's initialize that I'm going
920
00:43:49,190 --> 00:43:54,710
as you can see I've initialized all of
921
00:43:51,800 --> 00:43:57,019
my UI elements now it's time to set some
922
00:43:54,710 --> 00:43:58,760
values for each one of these books for
923
00:43:57,019 --> 00:44:01,219
now I'm just going to create a simple
924
00:43:58,760 --> 00:44:03,770
plug-in here and after that depending on
925
00:44:01,219 --> 00:44:06,769
the books value I'm going to change the
926
00:44:03,769 --> 00:44:08,838
value of all of these UI elements but we
927
00:44:06,769 --> 00:44:11,300
shouldn't do it this way because we are
928
00:44:08,838 --> 00:44:14,029
going to change the values of these UI
929
00:44:11,300 --> 00:44:16,579
elements depending on the item that we
930
00:44:14,030 --> 00:44:19,069
click on our recyclerview we will see
931
00:44:16,579 --> 00:44:21,289
that how we can get item that we have
932
00:44:19,068 --> 00:44:24,349
clicked on later on but in here just to
933
00:44:21,289 --> 00:44:26,659
test our UI I'm going to create a book I
934
00:44:24,349 --> 00:44:28,670
think I have a book in my old books
935
00:44:26,659 --> 00:44:32,389
activity so I'm going to copy it from
936
00:44:28,670 --> 00:44:34,700
there after creating this book I'm going
937
00:44:32,389 --> 00:44:38,299
to create another method let's name it
938
00:44:34,699 --> 00:44:41,210
set data also I'm going to pass my book
939
00:44:38,300 --> 00:44:43,700
object to this method let's quickly
940
00:44:41,210 --> 00:44:47,858
create this method let's say private
941
00:44:43,699 --> 00:44:50,358
void set data and let's receive a book
942
00:44:47,858 --> 00:44:53,179
before I do anything inside this method
943
00:44:50,358 --> 00:44:55,818
I am going to add a to doing here so
944
00:44:53,179 --> 00:44:59,449
that we don't forget to get the incoming
945
00:44:55,818 --> 00:45:02,509
data from the recycler view okay inside
946
00:44:59,449 --> 00:45:06,469
the set data method I'm going to say txd
947
00:45:02,510 --> 00:45:10,369
botany that set text let's say book that
948
00:45:06,469 --> 00:45:13,489
get me and similarly for the other three
949
00:45:10,369 --> 00:45:15,890
text views for these pages in here
950
00:45:13,489 --> 00:45:18,379
because we have set the pages as an
951
00:45:15,889 --> 00:45:21,199
integer in our book model we need to
952
00:45:18,380 --> 00:45:23,420
cast it into a string in here and here
953
00:45:21,199 --> 00:45:26,960
is how we can do that I can say a string
954
00:45:23,420 --> 00:45:30,650
with capital S dot value of let's say
955
00:45:26,960 --> 00:45:33,139
book dot pages or that get pages this
956
00:45:30,650 --> 00:45:35,389
way we can cast this integer to a string
957
00:45:33,139 --> 00:45:37,549
and after that we can pass it to this
958
00:45:35,389 --> 00:45:39,949
set text method for the description
959
00:45:37,550 --> 00:45:42,789
let's do the same let's say that's a
960
00:45:39,949 --> 00:45:45,769
text book that get knowing description
961
00:45:42,789 --> 00:45:49,309
let's also show our image I'm going to
962
00:45:45,769 --> 00:45:51,349
use glide collide that with this is an
963
00:45:49,309 --> 00:45:55,789
activity so I'm going to pass this as
964
00:45:51,349 --> 00:46:00,500
bitmap dot load book that image URL or
965
00:45:55,789 --> 00:46:03,009
get image URL dot into our pot image so
966
00:46:00,500 --> 00:46:04,809
this way we can set the data in our you
967
00:46:03,010 --> 00:46:06,730
elements in order to test this
968
00:46:04,809 --> 00:46:09,460
application I'm going to go to my
969
00:46:06,730 --> 00:46:11,980
recyclerview adapter and from there I'm
970
00:46:09,460 --> 00:46:14,289
going to create an intent so right now
971
00:46:11,980 --> 00:46:16,059
inside this folder that parents
972
00:46:14,289 --> 00:46:18,070
onclicklistener we are sharing a toast
973
00:46:16,059 --> 00:46:19,889
message and let's remove this toast
974
00:46:18,070 --> 00:46:22,870
message and let's create an intent
975
00:46:19,889 --> 00:46:25,000
intent is the call to mere intent for
976
00:46:22,869 --> 00:46:26,589
the context in here if you remember we
977
00:46:25,000 --> 00:46:29,320
are receiving a context where the
978
00:46:26,590 --> 00:46:32,289
constructor of this class so I can use
979
00:46:29,320 --> 00:46:35,440
that I'm going to say M context for the
980
00:46:32,289 --> 00:46:37,809
destination that's a book activity dot
981
00:46:35,440 --> 00:46:39,760
class after that usually if we were
982
00:46:37,809 --> 00:46:41,889
inside an activity we could have used a
983
00:46:39,760 --> 00:46:43,690
start activity method but in here you
984
00:46:41,889 --> 00:46:45,969
can see that we don't have that option
985
00:46:43,690 --> 00:46:49,059
because this start activity method is
986
00:46:45,969 --> 00:46:52,089
specific to activities if I want to use
987
00:46:49,059 --> 00:46:55,239
that I can say M context dot start
988
00:46:52,090 --> 00:46:57,430
activity so with the help of our context
989
00:46:55,239 --> 00:46:58,989
we can have this start activity method
990
00:46:57,429 --> 00:47:01,329
and after that we need to pass our
991
00:46:58,989 --> 00:47:03,699
intent so right now no matter on what
992
00:47:01,329 --> 00:47:06,219
book we click we are going to navigate
993
00:47:03,699 --> 00:47:08,829
to book activity and in there we are
994
00:47:06,219 --> 00:47:11,649
going to show the details of this 1q84
995
00:47:08,829 --> 00:47:14,349
book I'm doing this because I'm going to
996
00:47:11,650 --> 00:47:16,539
test my UI let's run the application and
997
00:47:14,349 --> 00:47:19,420
let's see if everything works fine let's
998
00:47:16,539 --> 00:47:21,610
go to our all books activity and in here
999
00:47:19,420 --> 00:47:23,200
if we click on this book for example you
1000
00:47:21,610 --> 00:47:25,360
can see that we are seeing the details
1001
00:47:23,199 --> 00:47:28,179
of this book but right now our layout
1002
00:47:25,360 --> 00:47:30,880
has some problems for example we need to
1003
00:47:28,179 --> 00:47:33,069
increase the width of our buttons
1004
00:47:30,880 --> 00:47:36,340
because they don't fit in one line right
1005
00:47:33,070 --> 00:47:38,410
now and also I'm going to increase the
1006
00:47:36,340 --> 00:47:40,900
size of this image view let's quickly
1007
00:47:38,409 --> 00:47:44,259
fix these two issues in our activity
1008
00:47:40,900 --> 00:47:46,869
book if I click on this book image I'm
1009
00:47:44,260 --> 00:47:50,230
going to change this font this width and
1010
00:47:46,869 --> 00:47:53,099
height to 200 T P answer for these
1011
00:47:50,230 --> 00:47:58,179
buttons let's increase the beats from
1012
00:47:53,099 --> 00:48:00,039
150 to I believe 170 would be fine let's
1013
00:47:58,179 --> 00:48:03,059
run the application one more time and
1014
00:48:00,039 --> 00:48:06,429
once again let's go to our book activity
1015
00:48:03,059 --> 00:48:08,049
this time it's somehow better also we
1016
00:48:06,429 --> 00:48:09,730
need to be careful about this long
1017
00:48:09,730 --> 00:48:14,199
because if this description don't fit on
1018
00:48:12,369 --> 00:48:16,009
the screen and be probably and I
1019
00:48:16,010 --> 00:48:20,120
that I'm going to add a scrollview into
1020
00:48:18,199 --> 00:48:22,909
my layout fight we haven't seen a
1021
00:48:20,119 --> 00:48:25,639
scrollview but its purpose is to create
1022
00:48:22,909 --> 00:48:27,170
a view that we can scroll let's quickly
1023
00:48:25,639 --> 00:48:29,569
see how we can add that in our
1024
00:48:27,170 --> 00:48:31,700
constraint layout so basically what I'm
1025
00:48:29,570 --> 00:48:34,370
going to do is that I'm going to change
1026
00:48:31,699 --> 00:48:36,919
these parents to a relative layout after
1027
00:48:34,369 --> 00:48:39,409
that I'm going to create a scroll view
1028
00:48:36,920 --> 00:48:41,840
inside that scroll view I'm going to
1029
00:48:39,409 --> 00:48:43,849
create a constraint layout and I'm going
1030
00:48:41,840 --> 00:48:45,829
to move all of these items into that
1031
00:48:43,849 --> 00:48:46,519
constraint layout let's see what I'm
1032
00:48:46,519 --> 00:48:50,750
so as I said I'm going to create a
1033
00:48:48,769 --> 00:48:53,360
scroll view for the width and height
1034
00:48:50,750 --> 00:48:55,219
let's say match parent inside this
1035
00:48:53,360 --> 00:48:57,380
scroll view I'm going to create a
1036
00:48:55,219 --> 00:48:59,049
constraint layout once again for the
1037
00:48:57,380 --> 00:49:01,820
vision height let's say match parent
1038
00:48:59,050 --> 00:49:04,039
after that I'm going to move all of my
1039
00:49:01,820 --> 00:49:05,930
elements to inside this constraint
1040
00:49:04,039 --> 00:49:07,519
layout and after everything I'm going to
1041
00:49:05,929 --> 00:49:09,589
change this constraint layer to a
1042
00:49:07,519 --> 00:49:13,309
relative layout so let's select all of
1043
00:49:09,590 --> 00:49:15,440
these items and after everything as I
1044
00:49:13,309 --> 00:49:18,650
said let's change the parent to a
1045
00:49:15,440 --> 00:49:20,360
relative layer let's enable the split
1046
00:49:18,650 --> 00:49:22,490
view and let's see if we have a good
1047
00:49:20,360 --> 00:49:25,190
layout it seems like we have done a good
1048
00:49:22,489 --> 00:49:28,579
job let's run our application let's go
1049
00:49:25,190 --> 00:49:30,920
to our book activity and we can see the
1050
00:49:28,579 --> 00:49:32,900
same result let's quickly add a longer
1051
00:49:30,920 --> 00:49:35,599
description and that's if you can scroll
1052
00:49:32,900 --> 00:49:39,200
our view I've copied the text in my book
1053
00:49:35,599 --> 00:49:41,179
activity I'm going to set that text as
1054
00:49:39,199 --> 00:49:43,189
the long description of this book but
1055
00:49:41,179 --> 00:49:46,789
before that I'm going to create a string
1056
00:49:43,190 --> 00:49:49,039
in here let's say long description is
1057
00:49:46,789 --> 00:49:50,380
equal to this text that I'm going to
1058
00:49:50,380 --> 00:49:55,200
now that we have this text let's set it
1059
00:49:52,599 --> 00:49:57,759
as the long description of our book
1060
00:49:55,199 --> 00:49:59,529
let's run the application once again and
1061
00:49:57,760 --> 00:50:03,070
let's see if we can scroll our view
1062
00:49:59,530 --> 00:50:04,540
let's go to block activity and in here
1063
00:50:03,070 --> 00:50:06,519
you can see that you have a long
1064
00:50:04,539 --> 00:50:09,340
description that does not fit on our
1065
00:50:06,519 --> 00:50:11,530
screen but as you can see we can scroll
1066
00:50:09,340 --> 00:50:13,630
this view ok I think that's enough for
1067
00:50:11,530 --> 00:50:15,820
this video this was a short video just
1068
00:50:13,630 --> 00:50:18,099
to create a layout file for our book
1069
00:50:15,820 --> 00:50:20,890
activity in the next video we will see
1070
00:50:18,099 --> 00:50:22,869
that how we can pass our book from our
1071
00:50:20,889 --> 00:50:25,299
recycler view to this activity and
1072
00:50:22,869 --> 00:50:29,489
beside that we will work on the logic of
1073
00:50:25,300 --> 00:50:29,490
these buttons see you in the next video
1074
00:50:31,528 --> 00:50:37,028
in this video we are going to write the
1075
00:50:34,539 --> 00:50:38,890
logic for these buttons we are going to
1076
00:50:37,028 --> 00:50:41,469
add our books two different categories
1077
00:50:38,889 --> 00:50:44,139
by clicking on each one of these buttons
1078
00:50:41,469 --> 00:50:46,929
but before I do that I need a data
1079
00:50:44,139 --> 00:50:49,688
storage to save these books to different
1080
00:50:46,929 --> 00:50:51,818
lists in a normal application in this
1081
00:50:49,688 --> 00:50:55,239
situation you may want to use a database
1082
00:50:51,818 --> 00:50:58,389
a database is a place that you persist
1083
00:50:55,239 --> 00:51:00,759
your data it can be a local database on
1084
00:50:58,389 --> 00:51:03,788
your smart phone or it can be an online
1085
00:51:00,759 --> 00:51:05,889
database on a web server in here we
1086
00:51:03,789 --> 00:51:08,859
haven't talked about any of those we
1087
00:51:05,889 --> 00:51:10,688
haven't talked about databases yet we
1088
00:51:08,858 --> 00:51:12,548
are going to talk about them later on in
1089
00:51:10,688 --> 00:51:15,759
the course in fact we have a section
1090
00:51:12,548 --> 00:51:17,798
dedicated to databases but in here we
1091
00:51:15,759 --> 00:51:20,259
are going to use an alternative we are
1092
00:51:17,798 --> 00:51:23,559
going to use some of the capabilities of
1093
00:51:20,259 --> 00:51:25,958
java language in previous videos in java
1094
00:51:23,559 --> 00:51:28,419
section if you remember I talked about a
1095
00:51:25,958 --> 00:51:31,028
static keyword I said that when you
1096
00:51:28,418 --> 00:51:33,699
define a variable or an object as a
1097
00:51:31,028 --> 00:51:35,768
static that variable will have the same
1098
00:51:33,699 --> 00:51:38,259
value in all of your application
1099
00:51:35,768 --> 00:51:40,268
regardless of where you have initialized
1100
00:51:38,259 --> 00:51:42,248
it in here we are going to take
1101
00:51:40,268 --> 00:51:45,368
advantage of that and we are going to
1102
00:51:42,248 --> 00:51:48,518
define our different lists of books as
1103
00:51:45,369 --> 00:51:50,588
static variables this way we have the
1104
00:51:48,518 --> 00:51:52,808
same lists when we are working with our
1105
00:51:50,588 --> 00:51:55,599
application in different activities but
1106
00:51:52,809 --> 00:51:59,139
there is a downside to this way of using
1107
00:51:55,599 --> 00:52:01,269
a static values your data would not be
1108
00:51:59,139 --> 00:52:03,249
persisted it means that if you close
1109
00:52:01,268 --> 00:52:06,038
your application you lose all of your
1110
00:52:03,248 --> 00:52:08,438
data at the end of this section I will
1111
00:52:06,039 --> 00:52:10,899
introduce another alternative in which
1112
00:52:08,438 --> 00:52:12,938
you can use to produce your data but in
1113
00:52:10,898 --> 00:52:16,088
here for now let's just use a static
1114
00:52:12,938 --> 00:52:18,489
variables for that I am going to create
1115
00:52:16,088 --> 00:52:20,528
a utility class in my package and we
1116
00:52:18,489 --> 00:52:23,349
will see in action why I am creating
1117
00:52:20,528 --> 00:52:26,409
this class so in my package let's
1118
00:52:23,349 --> 00:52:30,759
right-click new Java class I'm going to
1119
00:52:26,409 --> 00:52:33,338
name it utils in a real world
1120
00:52:30,759 --> 00:52:35,559
application this utils class is probably
1121
00:52:33,338 --> 00:52:37,748
your database class but of course the
1122
00:52:35,559 --> 00:52:40,179
name should be different but in here we
1123
00:52:37,748 --> 00:52:42,818
are not using databases so I named it
1124
00:52:40,179 --> 00:52:44,769
utils the first thing that I'm going to
1125
00:52:42,818 --> 00:52:47,500
do inside this class is that
1126
00:52:44,769 --> 00:52:49,840
to make this class Singleton so I'm
1127
00:52:47,500 --> 00:52:52,119
going to implement singleton pattern in
1128
00:52:49,840 --> 00:52:54,010
here inside this class if you remember
1129
00:52:52,119 --> 00:52:55,929
from the Java section whenever we
1130
00:52:54,010 --> 00:52:59,230
implement a singleton pattern for a
1131
00:52:55,929 --> 00:53:02,109
class we can have only one instance of
1132
00:52:59,230 --> 00:53:04,329
that class in our entire application I'm
1133
00:53:02,110 --> 00:53:06,360
making this class singleton because I
1134
00:53:04,329 --> 00:53:08,710
want only one instance of this class
1135
00:53:06,360 --> 00:53:10,750
basically this is the class that we are
1136
00:53:08,710 --> 00:53:11,440
going to interact with our aesthetic
1137
00:53:11,440 --> 00:53:15,820
and for that I am going to be sure that
1138
00:53:13,900 --> 00:53:17,619
I have only one instance of this class
1139
00:53:17,619 --> 00:53:22,239
ok let's quickly see how we can
1140
00:53:19,510 --> 00:53:24,100
implement singleton pattern first of all
1141
00:53:22,239 --> 00:53:27,309
I'm going to create a constructor for
1142
00:53:24,099 --> 00:53:29,829
this class it's an empty constructor and
1143
00:53:27,309 --> 00:53:31,509
right now we don't have anything after
1144
00:53:29,829 --> 00:53:34,569
that I am going to define a static
1145
00:53:31,510 --> 00:53:39,150
instance of this class let's say private
1146
00:53:34,570 --> 00:53:43,809
a static utils the type of our class
1147
00:53:39,150 --> 00:53:46,829
let's name it instance beside that I'm
1148
00:53:43,809 --> 00:53:49,449
going to need a getter for this instance
1149
00:53:46,829 --> 00:53:52,360
you remember all of these from the Java
1150
00:53:49,449 --> 00:53:55,089
section so I'm not explaining them let's
1151
00:53:52,360 --> 00:53:57,130
say getter for the instance first thing
1152
00:53:55,090 --> 00:54:00,519
I am going to change the modifier of
1153
00:53:57,130 --> 00:54:03,309
this constructor to a private let's do
1154
00:54:00,519 --> 00:54:05,050
that and inside this get instance method
1155
00:54:03,309 --> 00:54:07,869
I am going to write the logic to make
1156
00:54:05,050 --> 00:54:11,970
this class a singleton so I'm going to
1157
00:54:07,869 --> 00:54:17,619
say if now is not equal to my instance
1158
00:54:11,969 --> 00:54:20,199
then return the instance but in the else
1159
00:54:17,619 --> 00:54:24,819
case in case if the instance is now
1160
00:54:20,199 --> 00:54:28,719
let's say instance is equal to new you
1161
00:54:24,820 --> 00:54:31,590
tools and after that we can return our
1162
00:54:28,719 --> 00:54:34,389
instance let's say I return the instance
1163
00:54:31,590 --> 00:54:37,150
because we are returning in each one of
1164
00:54:34,389 --> 00:54:39,759
these cases we no longer need this
1165
00:54:37,150 --> 00:54:41,950
returned instance down in here in the
1166
00:54:39,760 --> 00:54:44,470
Java section we also have used the
1167
00:54:41,949 --> 00:54:46,029
synchronized keyboard if you remember we
1168
00:54:46,030 --> 00:54:50,980
in there I said that the synchronized
1169
00:54:48,250 --> 00:54:53,500
keyboard will make your method to be
1170
00:54:50,980 --> 00:54:55,809
thread safe it means that if different
1171
00:54:53,500 --> 00:54:58,539
threads at the same time call this
1172
00:54:55,809 --> 00:55:00,579
method this synchronized the keyboard
1173
00:54:58,539 --> 00:55:03,250
will cause them to call this method one
1174
00:55:00,579 --> 00:55:05,019
by one and not at the same time but in
1175
00:55:03,250 --> 00:55:07,300
this application we are not going to use
1176
00:55:05,019 --> 00:55:09,639
threading we are going to have only one
1177
00:55:07,300 --> 00:55:11,980
thread called the main thread so for
1178
00:55:09,639 --> 00:55:13,900
that I'm not worried about trading issue
1179
00:55:11,980 --> 00:55:16,840
in here and I can safely delete this
1180
00:55:13,900 --> 00:55:19,420
synchronized keyboard so by now this
1181
00:55:16,840 --> 00:55:23,079
utils class is a singleton class now we
1182
00:55:19,420 --> 00:55:27,240
can create our aesthetic lists so for
1183
00:55:23,079 --> 00:55:31,349
example in here I can say private static
1184
00:55:27,239 --> 00:55:35,079
let's say ArrayList of different books
1185
00:55:31,349 --> 00:55:36,819
let's call this phone all books as you
1186
00:55:35,079 --> 00:55:40,029
can guess this one is going to represent
1187
00:55:36,820 --> 00:55:42,190
all of our books in our application but
1188
00:55:40,030 --> 00:55:44,800
where do we initialize this all books
1189
00:55:42,190 --> 00:55:47,230
ArrayList we know for sure that when we
1190
00:55:44,800 --> 00:55:49,900
create an instance of our utyos' class
1191
00:55:47,230 --> 00:55:52,360
we are going to call this constructor so
1192
00:55:49,900 --> 00:55:54,369
the perfect place to initialize these
1193
00:55:52,360 --> 00:55:57,370
all books ArrayList is inside this
1194
00:55:54,369 --> 00:55:59,679
constructor let's move it to down below
1195
00:55:57,369 --> 00:56:04,420
this all book so that we can follow the
1196
00:55:59,679 --> 00:56:08,019
logic better and inside this constructor
1197
00:56:04,420 --> 00:56:08,889
let's say if null is not equal to our
1198
00:56:08,889 --> 00:56:13,089
we don't want to reinitialize our
1199
00:56:11,079 --> 00:56:15,449
ArrayList we just want to initialize it
1200
00:56:13,090 --> 00:56:18,670
one time when we create our application
1201
00:56:15,449 --> 00:56:22,029
or better than that would be to say if
1202
00:56:18,670 --> 00:56:23,920
null is equal to our old books I'm going
1203
00:56:22,030 --> 00:56:26,860
to say all books is equal to new
1204
00:56:23,920 --> 00:56:29,079
ArrayList and after that I'm going to
1205
00:56:26,860 --> 00:56:31,360
create another method in order to add
1206
00:56:29,079 --> 00:56:36,819
some initial data to this all books
1207
00:56:31,360 --> 00:56:39,670
ArrayList so let's say in its data let's
1208
00:56:36,820 --> 00:56:42,580
go to create this method by pressing Alt
1209
00:56:39,670 --> 00:56:44,349
+ Enter you can create your method for
1210
00:56:42,579 --> 00:56:46,119
now I'm just going to add a to doing
1211
00:56:44,349 --> 00:56:51,549
here and later on we will complete this
1212
00:56:46,119 --> 00:56:53,409
method let's say add initial data in
1213
00:56:51,550 --> 00:56:55,750
case if you have forgot about these two
1214
00:56:53,409 --> 00:56:57,940
do's and these are some sort of comments
1215
00:56:55,750 --> 00:56:59,980
that you live for yourself or for your
1216
00:56:57,940 --> 00:57:02,530
colleagues so that we don't forget
1217
00:56:59,980 --> 00:57:05,349
anything later on and when you want to
1218
00:57:02,530 --> 00:57:07,298
go in production you can check these two
1219
00:57:07,298 --> 00:57:12,608
and you can see the works that you left
1220
00:57:09,608 --> 00:57:15,068
for the future okay let's move on from
1221
00:57:12,608 --> 00:57:17,768
this part beside all books are released
1222
00:57:15,068 --> 00:57:18,518
I'm also going to define other ArrayList
1223
00:57:18,518 --> 00:57:27,008
let's say private a static array list of
1224
00:57:22,898 --> 00:57:31,748
different book let's name it already
1225
00:57:27,009 --> 00:57:34,358
read book let's define three more
1226
00:57:31,748 --> 00:57:36,788
one for currently reading books one for
1227
00:57:34,358 --> 00:57:41,369
one to reading books or wish list books
1228
00:57:36,789 --> 00:57:41,369
and another one for favorite books
1229
00:57:49,519 --> 00:57:54,630
similar to our old books aerialist we
1230
00:57:52,440 --> 00:57:57,570
need to initialize this ArrayList inside
1231
00:57:54,630 --> 00:58:00,329
our constructor as well so down in here
1232
00:57:57,570 --> 00:58:04,349
once again I can say if null is equal to
1233
00:58:00,329 --> 00:58:06,299
my already read books then I'm going to
1234
00:58:04,349 --> 00:58:09,420
initialize it let's say already read
1235
00:58:06,300 --> 00:58:11,160
books is equal to new ArrayList but I'm
1236
00:58:09,420 --> 00:58:12,690
not going to add any initial data
1237
00:58:11,159 --> 00:58:15,149
because we are going to leave that
1238
00:58:12,690 --> 00:58:17,789
option for the user later on when he or
1239
00:58:15,150 --> 00:58:19,380
she uses the application let's do the
1240
00:58:17,789 --> 00:58:21,800
same thing for the other three array
1241
00:58:33,010 --> 00:58:39,140
we now have initialized all of our lists
1242
00:58:36,230 --> 00:58:42,769
now let's see how we can get the values
1243
00:58:39,139 --> 00:58:44,839
or the items from our lists for that I'm
1244
00:58:42,769 --> 00:58:47,480
going to create get our methods for
1245
00:58:44,840 --> 00:58:49,519
example for this all books I released if
1246
00:58:47,480 --> 00:58:52,429
you want you can create a getter let's
1247
00:58:49,519 --> 00:58:54,619
quickly create that down in here by
1248
00:58:52,429 --> 00:58:58,549
pressing Alt + insert you can create
1249
00:58:54,619 --> 00:59:00,829
getters for all of your lists let's add
1250
00:58:58,550 --> 00:59:03,170
some initial data to our all books
1251
00:59:00,829 --> 00:59:04,789
ArrayList and that's an test this UTS
1252
00:59:03,170 --> 00:59:07,639
class and let's see if everything works
1253
00:59:04,789 --> 00:59:11,000
fine so if you remember in all box
1254
00:59:07,639 --> 00:59:13,940
activity we have created this array list
1255
00:59:11,000 --> 00:59:16,880
manually after that we have passed these
1256
00:59:13,940 --> 00:59:19,159
energies to our recyclerview adapter I'm
1257
00:59:16,880 --> 00:59:22,369
going to cut the initializing of our
1258
00:59:19,159 --> 00:59:24,440
array list from here and I'm going to
1259
00:59:22,369 --> 00:59:28,069
move it to my utils class right now we
1260
00:59:24,440 --> 00:59:30,380
have an error we will fix that so inside
1261
00:59:28,070 --> 00:59:33,769
utils class inside this in its data
1262
00:59:30,380 --> 00:59:37,700
method after this to do I'm going to
1263
00:59:33,769 --> 00:59:39,590
paste my ArrayList this time instead of
1264
00:59:37,699 --> 00:59:41,689
saying books that add which is this
1265
00:59:39,590 --> 00:59:45,380
array list I'm going to say all books
1266
00:59:41,690 --> 00:59:47,630
that add this one in here so this way we
1267
00:59:45,380 --> 00:59:49,970
are adding two books to our all books
1268
00:59:47,630 --> 00:59:53,240
ArrayList I can safely delete this one
1269
00:59:49,969 --> 00:59:55,730
as well remember that we are calling
1270
00:59:53,239 --> 00:59:58,309
this init data method from inside our
1271
00:59:55,730 --> 00:59:59,300
constructor when we are creating our all
1272
00:59:59,300 --> 01:00:05,300
so whenever we run our application and
1273
01:00:02,090 --> 01:00:08,269
we call this utils class this utils that
1274
01:00:05,300 --> 01:00:11,240
get instance method we have some data in
1275
01:00:08,269 --> 01:00:13,809
our all books ArrayList now that we have
1276
01:00:11,239 --> 01:00:17,209
some data in our all books activity
1277
01:00:13,809 --> 01:00:20,799
instead of these books we can say utils
1278
01:00:17,210 --> 01:00:24,789
with this capsule you don't get instance
1279
01:00:24,789 --> 01:00:30,559
if you run our application if everything
1280
01:00:27,889 --> 01:00:32,599
inside our util class works fine we
1281
01:00:30,559 --> 01:00:36,590
should see two books in our all books
1282
01:00:32,599 --> 01:00:39,500
activity let's quickly test that if we
1283
01:00:36,590 --> 01:00:42,050
go to our all books activity you can see
1284
01:00:39,500 --> 01:00:45,170
that we are seeing two books it seems
1285
01:00:42,050 --> 01:00:46,130
like our users class is working fine we
1286
01:00:46,130 --> 01:00:51,380
ton of more codes inside this UTS class
1287
01:00:48,559 --> 01:00:53,960
but more on that later on for now let's
1288
01:00:51,380 --> 01:00:55,789
see how we can pass a book from our
1289
01:00:53,960 --> 01:00:58,519
recyclerview adapter to the book
1290
01:00:55,789 --> 01:01:02,089
activity for example right now if I
1291
01:00:58,518 --> 01:01:05,328
click on this the myth of sisyphus you
1292
01:01:02,088 --> 01:01:07,880
can see that we are seeing this 1q84 it
1293
01:01:05,329 --> 01:01:10,640
means that we didn't pass our book to
1294
01:01:07,880 --> 01:01:13,039
this book activity in fact in our book
1295
01:01:10,639 --> 01:01:15,500
activity we are defining the book itself
1296
01:01:13,039 --> 01:01:18,259
and we are not getting any data from the
1297
01:01:15,500 --> 01:01:20,929
recyclerview let's see how we can pass a
1298
01:01:18,259 --> 01:01:23,809
book from our recyclerview to this book
1299
01:01:20,929 --> 01:01:26,949
activity so if you remember inside the
1300
01:01:23,809 --> 01:01:29,150
book recyclerview adapter inside this
1301
01:01:26,949 --> 01:01:31,608
holder dot parent thoughts at
1302
01:01:29,150 --> 01:01:34,130
onclicklistener inside the onclick
1303
01:01:31,608 --> 01:01:36,259
method we have created this intent the
1304
01:01:34,130 --> 01:01:38,869
use of this intent is to navigate the
1305
01:01:36,259 --> 01:01:40,909
user to the book activity the good thing
1306
01:01:38,869 --> 01:01:43,849
is that with this intent you can also
1307
01:01:40,909 --> 01:01:46,909
pass some sort of data let's quickly see
1308
01:01:43,849 --> 01:01:51,019
that as well so for example in here I
1309
01:01:46,909 --> 01:01:52,879
can say intent dot put extra you can see
1310
01:01:51,018 --> 01:01:55,459
that we have a ton of these different
1311
01:01:52,880 --> 01:01:58,400
methods for all sort of variables and
1312
01:01:55,460 --> 01:02:01,400
all sorts of data let's use one of them
1313
01:01:58,400 --> 01:02:03,588
for example I can pass the book ID in
1314
01:02:01,400 --> 01:02:05,930
here you can see that in here we need
1315
01:02:03,588 --> 01:02:09,170
two arguments a string and after that
1316
01:02:05,929 --> 01:02:12,259
data that we want the string is always
1317
01:02:09,170 --> 01:02:16,548
the key or the name of your value in
1318
01:02:12,259 --> 01:02:19,099
here for example if I say book ID later
1319
01:02:16,548 --> 01:02:22,699
on inside my book activity with this
1320
01:02:19,099 --> 01:02:24,890
book ID I can get the book ID so the
1321
01:02:22,699 --> 01:02:27,649
values inside your intents are key value
1322
01:02:24,889 --> 01:02:30,469
pairs for the idea of this book I can
1323
01:02:27,650 --> 01:02:33,380
use this books I release that we have
1324
01:02:30,469 --> 01:02:37,788
inside this adapter I can say books that
1325
01:02:33,380 --> 01:02:41,660
get let's pass position let's say target
1326
01:02:37,789 --> 01:02:44,269
ID so this way we are passing the ID of
1327
01:02:41,659 --> 01:02:47,118
our book - the book activity later on in
1328
01:02:44,268 --> 01:02:49,518
our book activity we will get our book
1329
01:02:47,119 --> 01:02:51,858
by its ID if you remember I said that
1330
01:02:49,518 --> 01:02:54,469
the ID for each book is going to be
1331
01:02:51,858 --> 01:02:56,838
unique it's worth mentioning that you
1332
01:02:54,469 --> 01:02:58,489
can also pass the book itself you can
1333
01:02:58,489 --> 01:03:03,919
that instead of passing an integer we
1334
01:03:01,730 --> 01:03:06,019
can pass a course a little bit let's
1335
01:03:03,920 --> 01:03:09,170
quickly see that you can say intents
1336
01:03:06,019 --> 01:03:12,530
that put extra and then in here if you
1337
01:03:09,170 --> 01:03:14,630
take a look one of the arguments in here
1338
01:03:12,530 --> 01:03:16,430
is this part of the bill we will talk
1339
01:03:14,630 --> 01:03:18,410
about cars available later on in the
1340
01:03:16,429 --> 01:03:21,829
course but basically it's an interface
1341
01:03:18,409 --> 01:03:23,809
that we will not serialize your class at
1342
01:03:21,829 --> 01:03:26,659
the time of transferring it from one
1343
01:03:23,809 --> 01:03:28,579
activity to another activity and at the
1344
01:03:28,579 --> 01:03:32,989
deserialize your object don't worry
1345
01:03:31,309 --> 01:03:35,690
about these two words that I am using
1346
01:03:32,989 --> 01:03:38,059
basically using parsable is really easy
1347
01:03:35,690 --> 01:03:39,740
we will take a look at that later on in
1348
01:03:38,059 --> 01:03:42,949
the course but for now we are just going
1349
01:03:39,739 --> 01:03:46,129
to pass an integer beside that you can
1350
01:03:42,949 --> 01:03:48,019
also set multiple extras for your intent
1351
01:03:46,130 --> 01:03:49,970
for example if I want to pass the book
1352
01:03:48,019 --> 01:03:53,179
name in here once again I can say that
1353
01:03:49,969 --> 01:03:56,079
put extra for the key I'm going to say
1354
01:03:53,179 --> 01:04:03,259
for the name and if I want I can say
1355
01:03:56,079 --> 01:04:04,849
oops that get position do not get me of
1356
01:04:03,260 --> 01:04:07,310
course we are not going to need this in
1357
01:04:04,849 --> 01:04:09,769
here but I just wanted to say that you
1358
01:04:07,309 --> 01:04:12,739
can pass multiple extras with your
1359
01:04:09,769 --> 01:04:15,199
intent okay now that we are passing some
1360
01:04:12,739 --> 01:04:18,289
data with our intent how we can retrieve
1361
01:04:15,199 --> 01:04:20,449
that data in our book activity before
1362
01:04:18,289 --> 01:04:22,460
that let's quickly remove this one to
1363
01:04:20,449 --> 01:04:25,639
have a reviewing here first of all we
1364
01:04:22,460 --> 01:04:27,800
are creating our intent the context is
1365
01:04:25,639 --> 01:04:30,710
this M context which we are receiving
1366
01:04:27,800 --> 01:04:33,200
with the constructor of this adapter the
1367
01:04:30,710 --> 01:04:35,990
destination of this intent is book
1368
01:04:33,199 --> 01:04:38,629
activity dot class we are calling this
1369
01:04:35,989 --> 01:04:41,059
pot extra method on our intent and with
1370
01:04:38,630 --> 01:04:43,490
that we are passing some integer in this
1371
01:04:41,059 --> 01:04:45,949
case we are passing the book ID after
1372
01:04:43,489 --> 01:04:48,019
that with the help of our context we are
1373
01:04:45,949 --> 01:04:51,108
starting to activity which in this case
1374
01:04:48,019 --> 01:04:53,690
is this pub activity dot class so now we
1375
01:04:51,108 --> 01:04:56,079
can continue our code from inside the
1376
01:04:53,690 --> 01:05:00,230
book activity inside on create method
1377
01:04:56,079 --> 01:05:02,900
let's close this one also I'm going to
1378
01:05:00,230 --> 01:05:07,400
close this one utils class my layout
1379
01:05:02,900 --> 01:05:10,068
file and let's open book activity
1380
01:05:07,400 --> 01:05:12,499
so inside this on create method in here
1381
01:05:10,068 --> 01:05:14,690
if you remember we are creating a book
1382
01:05:12,498 --> 01:05:17,149
and we are setting its value to our UI
1383
01:05:14,690 --> 01:05:19,519
elements you can see that we also have a
1384
01:05:17,150 --> 01:05:21,889
to-do in here get the data from circular
1385
01:05:19,518 --> 01:05:24,858
view in here so if we want to get the
1386
01:05:21,889 --> 01:05:27,259
data in this case the book ID from our
1387
01:05:24,858 --> 01:05:32,088
recyclerview we can say something like
1388
01:05:27,259 --> 01:05:35,480
this we can say intent let's call it
1389
01:05:32,088 --> 01:05:38,268
intent is equal to this time instead of
1390
01:05:35,480 --> 01:05:41,028
saying new intent I can say get intent
1391
01:05:38,268 --> 01:05:43,489
so if you use this get intent method you
1392
01:05:41,028 --> 01:05:46,190
are going to receive the incoming intent
1393
01:05:43,489 --> 01:05:48,709
the intent that caused this activity to
1394
01:05:46,190 --> 01:05:51,440
be launched but you also need to be
1395
01:05:48,710 --> 01:05:53,659
careful about non values of this intent
1396
01:05:51,440 --> 01:05:56,599
because this intent can be null at some
1397
01:05:53,659 --> 01:05:59,929
times so for that I can say if null is
1398
01:05:56,599 --> 01:06:02,420
not equal to my intent I'm going to
1399
01:05:59,929 --> 01:06:05,659
continue in here after that I'm going to
1400
01:06:02,420 --> 01:06:11,630
receive the book ID I'm going to say int
1401
01:06:05,659 --> 01:06:14,778
book ID is equal to intent dot get int
1402
01:06:11,630 --> 01:06:16,880
extra you can see that we have a lot of
1403
01:06:14,778 --> 01:06:19,670
this get extras method for different
1404
01:06:16,880 --> 01:06:21,680
kind of data for example if you are
1405
01:06:19,670 --> 01:06:24,139
going to get an integer we can call this
1406
01:06:21,679 --> 01:06:26,088
get into extra we can see that the
1407
01:06:24,139 --> 01:06:28,098
method in here is waiting for two things
1408
01:06:26,088 --> 01:06:30,440
you can press down the control key and
1409
01:06:28,099 --> 01:06:32,150
you can see the documentation first of
1410
01:06:30,440 --> 01:06:35,210
all we need the name of our variable
1411
01:06:32,150 --> 01:06:38,480
which if you remember was book ID and
1412
01:06:35,210 --> 01:06:41,119
the second one is a default value so in
1413
01:06:38,480 --> 01:06:43,969
case if for any reason this get into
1414
01:06:41,119 --> 01:06:46,009
extra wouldn't be able to get any data
1415
01:06:43,969 --> 01:06:48,558
from our intent we are going to assign a
1416
01:06:46,009 --> 01:06:52,909
default value for the name let's pass
1417
01:06:48,559 --> 01:06:55,249
pop ID and for the default value I'm
1418
01:06:52,909 --> 01:06:57,259
going to pass negative one because I
1419
01:06:55,248 --> 01:06:59,179
know for sure that and none of my books
1420
01:06:57,259 --> 01:07:02,088
in my list are going to have negative
1421
01:06:59,179 --> 01:07:04,639
one as their ID also about this name
1422
01:07:02,088 --> 01:07:07,038
this key t spoke ID in here you need to
1423
01:07:04,639 --> 01:07:09,199
be extra careful about this the
1424
01:07:07,039 --> 01:07:12,499
characters the upper cases and their
1425
01:07:09,199 --> 01:07:14,659
cases need to be exactly the same if you
1426
01:07:12,498 --> 01:07:16,818
put anything wrong in here you are not
1427
01:07:14,659 --> 01:07:19,578
going to retrieve your data there is a
1428
01:07:16,818 --> 01:07:20,590
better option than hard-coding your keys
1429
01:07:20,590 --> 01:07:25,630
passing your kids manually you can
1430
01:07:22,659 --> 01:07:33,839
create constants for example above in
1431
01:07:25,630 --> 01:07:37,950
here I can say public static final
1432
01:07:33,840 --> 01:07:40,780
string the convention is to name your
1433
01:07:37,949 --> 01:07:44,710
constants in upper cases for example in
1434
01:07:40,780 --> 01:07:47,320
here I can say book ID key I can also
1435
01:07:44,710 --> 01:07:50,769
assign a value to this one for example I
1436
01:07:47,320 --> 01:07:54,340
can say book ID now that I have defined
1437
01:07:50,769 --> 01:07:56,920
this constant in here I can pass it in
1438
01:07:54,340 --> 01:08:00,910
two places for example the first time I
1439
01:07:56,920 --> 01:08:04,530
can pass it as a key I can say book ID
1440
01:08:00,909 --> 01:08:08,190
key and also inside my adapter class
1441
01:08:04,530 --> 01:08:12,900
instead of hard-coding the key in here I
1442
01:08:12,929 --> 01:08:18,659
you can see that we need to import this
1443
01:08:15,599 --> 01:08:20,699
by pressing Alt + insert we can import
1444
01:08:18,659 --> 01:08:23,809
this constant into our class if you take
1445
01:08:20,698 --> 01:08:26,818
a look at above in here in the imports
1446
01:08:23,810 --> 01:08:29,969
we are importing this constant into this
1447
01:08:26,819 --> 01:08:32,520
class so this way by using different
1448
01:08:29,969 --> 01:08:34,730
constants you make sure that the keys
1449
01:08:32,520 --> 01:08:36,839
are the same in two different places
1450
01:08:34,729 --> 01:08:40,649
okay let's switch back to our book
1451
01:08:36,838 --> 01:08:43,259
activity so by this time after this line
1452
01:08:40,649 --> 01:08:46,409
of code we either have a negative one
1453
01:08:43,259 --> 01:08:48,539
value or we have the book ID we need to
1454
01:08:46,409 --> 01:08:53,488
create an if statement for this negative
1455
01:08:48,539 --> 01:08:56,698
one value let's say if our work ID is
1456
01:08:53,488 --> 01:08:58,979
equal to negative one or the better
1457
01:08:56,698 --> 01:09:01,798
logic would be - if it's not equal to
1458
01:08:58,979 --> 01:09:04,108
negative one let's pursue the code so by
1459
01:09:01,798 --> 01:09:07,109
this time inside this if statement we
1460
01:09:04,109 --> 01:09:09,630
have our plot ID how do we get the POC
1461
01:09:07,109 --> 01:09:11,579
by its ID if you remember at the
1462
01:09:09,630 --> 01:09:13,469
beginning of this video I said that we
1463
01:09:13,469 --> 01:09:18,569
interactions with our lists inside the
1464
01:09:15,899 --> 01:09:20,818
UTS class so for that once again I'm
1465
01:09:18,569 --> 01:09:23,039
going to go to my utils class I'm
1466
01:09:20,819 --> 01:09:24,469
pressing double shift in order to pop up
1467
01:09:23,039 --> 01:09:27,238
this search menu if you are wondering
1468
01:09:24,469 --> 01:09:29,759
anywhere in Android studio you can press
1469
01:09:27,238 --> 01:09:32,399
shift two times and you can get this
1470
01:09:29,759 --> 01:09:34,979
menu in which you can easily type and go
1471
01:09:32,399 --> 01:09:37,948
to your class for example inside this
1472
01:09:34,979 --> 01:09:40,468
utils class after everything I'm going
1473
01:09:37,948 --> 01:09:43,198
to create a method I'm going to say
1474
01:09:40,469 --> 01:09:46,679
public book is going to be the return
1475
01:09:43,198 --> 01:09:51,659
type of this method let's say get book
1476
01:09:46,679 --> 01:09:55,859
by ID we also need to get the ID let's
1477
01:09:51,659 --> 01:09:58,349
say int ID after that inside this method
1478
01:09:55,859 --> 01:10:01,319
I'm going to login to my all books
1479
01:09:58,350 --> 01:10:04,500
activity and I'm going to return the pot
1480
01:10:01,319 --> 01:10:06,899
by its ID for that I'm going to create a
1481
01:10:04,500 --> 01:10:11,279
for loop for each loop to be precise
1482
01:10:06,899 --> 01:10:15,929
let's say for book be inside our all
1483
01:10:11,279 --> 01:10:20,238
books are released in case if B dot get
1484
01:10:15,929 --> 01:10:23,880
ID with equal to the ID that we received
1485
01:10:20,238 --> 01:10:26,339
then we are going to return B
1486
01:10:23,880 --> 01:10:28,409
so if we have a book with this idea we
1487
01:10:26,340 --> 01:10:31,560
are going to return it but after the
1488
01:10:28,409 --> 01:10:35,849
four do if we didn't return anything we
1489
01:10:31,560 --> 01:10:37,770
are going to return now by returning
1490
01:10:35,850 --> 01:10:40,800
null in here we are acknowledging that
1491
01:10:37,770 --> 01:10:43,800
we may not found a book with this ID in
1492
01:10:40,800 --> 01:10:46,079
our list so whenever we call this get
1493
01:10:43,800 --> 01:10:48,659
put by ID method we also need to be
1494
01:10:46,079 --> 01:10:51,180
careful about the null values because
1495
01:10:48,659 --> 01:10:54,479
the result can be known for example
1496
01:10:51,180 --> 01:10:57,810
inside the pot activity in here I'm
1497
01:10:54,479 --> 01:11:03,569
going to say book let's name it
1498
01:10:57,810 --> 01:11:08,789
incoming work is equal to our utils
1499
01:11:03,569 --> 01:11:11,759
class that get instance first of all dot
1500
01:11:08,789 --> 01:11:15,390
let's say get book by ID after that we
1501
01:11:11,760 --> 01:11:16,890
can pass our book ID after this line of
1502
01:11:15,390 --> 01:11:19,980
code we need to make sure that this
1503
01:11:16,890 --> 01:11:23,610
incoming book is not known so let's say
1504
01:11:19,979 --> 01:11:27,569
if null is not equal to our incoming
1505
01:11:23,609 --> 01:11:29,489
book then we can call our set data
1506
01:11:27,569 --> 01:11:33,149
method which is this method I can
1507
01:11:29,489 --> 01:11:35,579
account this and I can paste it inside
1508
01:11:33,149 --> 01:11:37,649
this if statement you can see that
1509
01:11:35,579 --> 01:11:40,470
before getting our book and before
1510
01:11:37,649 --> 01:11:42,599
passing it to this set data method we
1511
01:11:40,470 --> 01:11:44,640
are doing three security checks first of
1512
01:11:42,600 --> 01:11:47,340
all we are checking that our intent is
1513
01:11:44,640 --> 01:11:49,530
not now after that we are making sure
1514
01:11:47,340 --> 01:11:50,159
that we have received some data from our
1515
01:11:50,159 --> 01:11:54,510
after that we are checking that if we
1516
01:11:52,380 --> 01:11:57,480
have such a book with this ID in our
1517
01:11:54,510 --> 01:11:58,890
list in a normal scenario in a good
1518
01:11:57,479 --> 01:12:02,219
situation none of this would be
1519
01:11:58,890 --> 01:12:04,560
necessary and you can simply call these
1520
01:12:02,220 --> 01:12:07,199
get books by ID method and you can get
1521
01:12:04,560 --> 01:12:09,930
your book but a lot of things can happen
1522
01:12:07,199 --> 01:12:12,539
when you call your activity and when you
1523
01:12:09,930 --> 01:12:14,250
pass your data your activity may be
1524
01:12:12,539 --> 01:12:16,769
destroyed your activity may be
1525
01:12:14,250 --> 01:12:19,199
interrupted by some call that user
1526
01:12:16,770 --> 01:12:21,690
receives your activity also may be
1527
01:12:19,199 --> 01:12:24,059
called from different places and also
1528
01:12:21,689 --> 01:12:26,699
for other security reasons you always
1529
01:12:24,060 --> 01:12:29,520
need to check for the intent for the
1530
01:12:26,699 --> 01:12:32,789
incoming data and for the data itself
1531
01:12:29,520 --> 01:12:34,920
inside your data storage sorry I need to
1532
01:12:32,789 --> 01:12:37,680
change this book to incoming booking
1533
01:12:37,680 --> 01:12:43,110
in there okay now that we are setting
1534
01:12:40,439 --> 01:12:46,139
our incoming book we can safely delete
1535
01:12:43,109 --> 01:12:52,199
the spot above in here let's comment all
1536
01:12:46,140 --> 01:12:53,490
of this let's test our application and
1537
01:12:52,199 --> 01:12:56,039
let's see if we can successfully
1538
01:12:53,489 --> 01:12:59,880
navigate the user to book activity and
1539
01:12:56,039 --> 01:13:04,079
show the appropriate book let's go to
1540
01:12:59,880 --> 01:13:08,510
all books activity 1q84 we are saying
1541
01:13:04,079 --> 01:13:11,159
1q84 if we click on the myth of sisyphus
1542
01:13:08,510 --> 01:13:13,050
you can see that now we are seeing the
1543
01:13:11,159 --> 01:13:16,109
meetups is the first it seems like we
1544
01:13:13,050 --> 01:13:18,510
are passing the data from our recycler
1545
01:13:16,109 --> 01:13:22,019
view from inside the all books activity
1546
01:13:18,510 --> 01:13:24,000
to the bot activity successfully okay I
1547
01:13:22,020 --> 01:13:25,830
think that's enough for this video I did
1548
01:13:24,000 --> 01:13:28,020
want to talk about the logic for these
1549
01:13:25,829 --> 01:13:31,319
buttons but I think that's better to be
1550
01:13:28,020 --> 01:13:33,950
left off for the next video okay see you
1551
01:13:38,989 --> 01:13:42,559
going to take care of these buttons we
1552
01:13:40,819 --> 01:13:44,659
are going to add the book to different
1553
01:13:42,560 --> 01:13:47,570
lists by clicking on each one of these
1554
01:13:44,659 --> 01:13:49,519
buttons beside that we are going to
1555
01:13:47,569 --> 01:13:52,699
disable the button if the book already
1556
01:13:49,520 --> 01:13:54,620
exists in one of these lists for example
1557
01:13:52,699 --> 01:13:57,109
if the book exists in the users wish
1558
01:13:54,619 --> 01:13:59,809
list we are going to disable this one to
1559
01:13:57,109 --> 01:14:02,389
read button let's go to book activity
1560
01:13:59,810 --> 01:14:04,640
and let's see how we can do that so
1561
01:14:02,390 --> 01:14:07,369
inside this book activity insight is on
1562
01:14:04,640 --> 01:14:10,340
create method I am going to call another
1563
01:14:07,369 --> 01:14:12,710
method but I am going to do that inside
1564
01:14:10,340 --> 01:14:15,440
this if statement after I made sure that
1565
01:14:12,710 --> 01:14:19,789
I have an incoming book so let's name
1566
01:14:15,439 --> 01:14:22,939
this method and a handle already read
1567
01:14:19,789 --> 01:14:28,250
I'm also going to pass the incoming book
1568
01:14:22,939 --> 01:14:32,710
itself let's quickly create this method
1569
01:14:28,250 --> 01:14:34,369
down in here let's say private void and
1570
01:14:34,369 --> 01:14:42,229
let's also receive a book inside this
1571
01:14:40,460 --> 01:14:44,720
method first of all I'm going to check
1572
01:14:42,229 --> 01:14:47,839
that if this incoming book exists in our
1573
01:14:44,720 --> 01:14:51,470
already read books so for that I'm going
1574
01:14:47,840 --> 01:14:54,789
to say ArrayList of book let's name it
1575
01:14:55,439 --> 01:15:03,948
is equal to you Till's not get instance
1576
01:15:03,948 --> 01:15:09,869
this method after that I'm going to
1577
01:15:07,380 --> 01:15:15,710
create a for each loop let's say for
1578
01:15:09,869 --> 01:15:18,539
book be inside our already read books
1579
01:15:15,710 --> 01:15:20,579
also before this for loop I'm going to
1580
01:15:18,539 --> 01:15:21,779
define a boolean and its purpose will be
1581
01:15:21,779 --> 01:15:28,340
so that's a boolean let's name it exist
1582
01:15:28,609 --> 01:15:34,289
let's initialize it to false down in
1583
01:15:32,039 --> 01:15:38,340
here inside the for-loop I'm going to
1584
01:15:34,289 --> 01:15:41,850
say that if B that get ID is equal to
1585
01:15:38,340 --> 01:15:43,650
our incoming pour target ID if that's
1586
01:15:41,850 --> 01:15:46,650
the case we are going to change the
1587
01:15:43,649 --> 01:15:49,069
value of this boolean let's say exists
1588
01:15:46,649 --> 01:15:52,049
in already read books is equal to true
1589
01:15:49,069 --> 01:15:54,359
so after this for loop we know that if
1590
01:15:52,050 --> 01:15:56,970
the pop exist in our already read books
1591
01:15:54,359 --> 01:15:59,699
ArrayList and we can use this program we
1592
01:15:56,970 --> 01:16:02,640
can say if existing already read books
1593
01:15:59,699 --> 01:16:05,039
is equal to true then we are going to
1594
01:16:02,640 --> 01:16:07,140
disable our button because we don't want
1595
01:16:05,039 --> 01:16:09,869
to add this book one more time in the
1596
01:16:07,140 --> 01:16:12,930
already read books ArrayList so let's
1597
01:16:09,869 --> 01:16:15,989
say BTN already read or between add to
1598
01:16:12,930 --> 01:16:20,159
already read that set enabled this
1599
01:16:15,989 --> 01:16:24,079
method and let's pass false so this way
1600
01:16:20,159 --> 01:16:26,880
we can disable a button in the else case
1601
01:16:24,079 --> 01:16:28,920
I'm going to set an onclicklistener for
1602
01:16:26,880 --> 01:16:31,739
this button and I'm going to add it to
1603
01:16:28,920 --> 01:16:34,260
my already read books ArrayList so let's
1604
01:16:31,739 --> 01:16:36,239
say B thean add to already read that set
1605
01:16:36,239 --> 01:16:42,179
onclicklistener and inside this onclick
1606
01:16:39,300 --> 01:16:44,220
method we need to add it to our list but
1607
01:16:42,180 --> 01:16:46,680
because I'm going to keep all of my
1608
01:16:44,220 --> 01:16:49,140
interactions to my lists inside the
1609
01:16:46,680 --> 01:16:51,570
utils class I'm going to create that
1610
01:16:49,140 --> 01:16:54,480
method inside the utils class so let's
1611
01:16:51,569 --> 01:16:56,960
go to utils class and let's minimize all
1612
01:16:54,479 --> 01:17:01,829
the extra unnecessary method for now
1613
01:16:56,960 --> 01:17:03,480
down in here I'm going to say public for
1614
01:17:01,829 --> 01:17:05,729
the return type of this method I am
1615
01:17:03,479 --> 01:17:11,669
going to say boolean and we will see why
1616
01:17:05,729 --> 01:17:17,309
public boolean bad to already read let's
1617
01:17:11,670 --> 01:17:20,460
also receive a book and inside this
1618
01:17:17,310 --> 01:17:24,480
method let's say return already read
1619
01:17:20,460 --> 01:17:28,289
list already read books dot add and
1620
01:17:24,479 --> 01:17:30,989
let's pass our book so if you remember
1621
01:17:28,289 --> 01:17:33,779
from the Java section when we use this
1622
01:17:30,989 --> 01:17:36,389
add method on our ArrayList this add
1623
01:17:33,779 --> 01:17:38,279
method is going to return a boolean the
1624
01:17:36,390 --> 01:17:40,200
boolean is going to be the indicator
1625
01:17:38,279 --> 01:17:41,789
that if we have added the book
1626
01:17:41,789 --> 01:17:45,390
if you first down the control key or if
1627
01:17:43,619 --> 01:17:48,239
you are on a Mac system if you press
1628
01:17:45,390 --> 01:17:51,420
down the command key by clicking on this
1629
01:17:48,239 --> 01:17:54,300
ad you can see the documentation in here
1630
01:17:51,420 --> 01:17:56,640
you can see that if we successfully add
1631
01:17:54,300 --> 01:17:59,489
this element which is the generic data
1632
01:17:56,640 --> 01:18:02,160
type in Java at the end of this method
1633
01:17:59,489 --> 01:18:04,439
we are returning true it means that we
1634
01:18:02,159 --> 01:18:07,409
have added elements into our an
1635
01:18:04,439 --> 01:18:10,319
ArrayList successfully so in here we are
1636
01:18:07,409 --> 01:18:12,930
returning death boolean electron in our
1637
01:18:10,319 --> 01:18:14,549
book activity we are going to check for
1638
01:18:12,930 --> 01:18:17,280
this boolean and we are going to make
1639
01:18:14,550 --> 01:18:20,039
sure that we have added this block item
1640
01:18:17,279 --> 01:18:21,809
into our list successfully that's all we
1641
01:18:20,039 --> 01:18:23,819
need to do inside this ad to already
1642
01:18:21,810 --> 01:18:26,610
read and we can switch back to our book
1643
01:18:23,819 --> 01:18:28,679
activity so once again inside this
1644
01:18:26,609 --> 01:18:30,630
onclick method of this BTN add to
1645
01:18:28,680 --> 01:18:35,789
already read we are going to check that
1646
01:18:30,630 --> 01:18:40,319
if you teams target instance dot add to
1647
01:18:35,789 --> 01:18:42,449
already read with the incoming book if
1648
01:18:40,319 --> 01:18:50,159
that's true we are going to show a toast
1649
01:18:42,449 --> 01:18:51,750
message let's draw a book added but in
1650
01:18:50,159 --> 01:18:56,430
the else case I am going to show a
1651
01:18:51,750 --> 01:18:58,619
different toast message let's just say
1652
01:18:56,430 --> 01:19:00,829
something wrong happened try one more
1653
01:19:02,090 --> 01:19:07,349
also in the if case in case if we add
1654
01:19:05,429 --> 01:19:10,199
the book successfully I'm going to
1655
01:19:07,349 --> 01:19:12,270
navigate the user to another activity to
1656
01:19:10,198 --> 01:19:14,479
be precise I am going to create an
1657
01:19:12,270 --> 01:19:17,250
activity called already read books and
1658
01:19:14,479 --> 01:19:19,169
in that activity we are going to show
1659
01:19:17,250 --> 01:19:21,328
the list of books that the user has
1660
01:19:19,170 --> 01:19:23,639
already read but first of all I need to
1661
01:19:21,328 --> 01:19:27,448
create that activity in here I'm just
1662
01:19:23,639 --> 01:19:32,069
going to put a to do right now so let's
1663
01:19:27,448 --> 01:19:33,629
say navigate the user once again let's
1664
01:19:32,069 --> 01:19:36,058
review what we are doing inside this
1665
01:19:33,630 --> 01:19:38,309
method first of all we are getting there
1666
01:19:36,059 --> 01:19:41,369
already read books from this utils class
1667
01:19:38,309 --> 01:19:43,440
after that we are checking that if our
1668
01:19:41,368 --> 01:19:46,170
book exists inside this already read
1669
01:19:43,439 --> 01:19:49,109
books if it does we are disabling our
1670
01:19:46,170 --> 01:19:51,449
button but if it doesn't we are setting
1671
01:19:49,109 --> 01:19:53,698
an onclicklistener for this button in
1672
01:19:51,448 --> 01:19:55,710
which by clicking on that button we are
1673
01:19:53,698 --> 01:19:58,710
adding the book to already read books
1674
01:19:55,710 --> 01:20:00,359
ArrayList if that process goes well we
1675
01:19:58,710 --> 01:20:02,130
are going to show a toast message and
1676
01:20:00,359 --> 01:20:05,279
after that we are going to navigate the
1677
01:20:02,130 --> 01:20:07,020
user to already read book activity but
1678
01:20:05,279 --> 01:20:08,368
in case if something wrong happens we
1679
01:20:07,020 --> 01:20:11,219
are just going to show a toast message
1680
01:20:08,368 --> 01:20:13,649
this else case would never happen but I
1681
01:20:11,219 --> 01:20:15,569
just put it for the security reason we
1682
01:20:13,649 --> 01:20:18,299
don't want to gamble on anything that
1683
01:20:15,569 --> 01:20:19,889
can happen in our application ok by now
1684
01:20:19,889 --> 01:20:23,550
application and check if we can
1685
01:20:21,899 --> 01:20:26,098
successfully add a book to our already
1686
01:20:23,550 --> 01:20:29,699
read book ArrayList let's run the
1687
01:20:26,099 --> 01:20:32,010
application let's go to our book
1688
01:20:29,698 --> 01:20:35,488
activity by clicking on one of these
1689
01:20:32,010 --> 01:20:37,679
books and in here you can see that this
1690
01:20:35,488 --> 01:20:40,049
button is not disabled and that's
1691
01:20:37,679 --> 01:20:42,929
because this book does not exist in our
1692
01:20:40,050 --> 01:20:45,570
already read book ArrayList if we click
1693
01:20:42,929 --> 01:20:47,550
on this already read button you can see
1694
01:20:45,569 --> 01:20:50,488
that the book has been added to our
1695
01:20:47,550 --> 01:20:52,500
ArrayList successfully I said that after
1696
01:20:50,488 --> 01:20:55,408
this we need to navigate the user to
1697
01:20:52,500 --> 01:20:58,679
already read book activity but for now
1698
01:20:55,408 --> 01:21:01,109
let's go back to levels and once again
1699
01:20:58,679 --> 01:21:03,000
let's go to our book activity and let's
1700
01:21:01,109 --> 01:21:06,238
see if that button is still available
1701
01:21:03,000 --> 01:21:08,819
which is not it seems like we have wrote
1702
01:21:06,238 --> 01:21:11,399
the logic perfectly ok now let's quickly
1703
01:21:08,819 --> 01:21:13,788
create the already read book activity
1704
01:21:11,399 --> 01:21:16,009
and let's navigate the user there
1705
01:21:13,788 --> 01:21:18,229
but before that I'm just going to warn
1706
01:21:16,010 --> 01:21:21,019
you about something I don't usually
1707
01:21:18,229 --> 01:21:23,988
comment my coat and that's because I'm
1708
01:21:21,019 --> 01:21:26,630
lazy I had that son execuse but you
1709
01:21:23,988 --> 01:21:29,089
don't follow this behavior you put
1710
01:21:26,630 --> 01:21:31,279
comments wherever you feel necessary in
1711
01:21:29,090 --> 01:21:33,590
your code for example before the
1712
01:21:31,279 --> 01:21:37,189
declaration of this method we can put a
1713
01:21:33,590 --> 01:21:40,159
comment and in here we can specify the
1714
01:21:37,189 --> 01:21:44,529
purpose of this method for example I'm
1715
01:21:40,158 --> 01:21:44,529
going to say enable and disable button
1716
01:21:45,000 --> 01:21:50,729
besides that we are going to add the
1717
01:21:51,880 --> 01:21:57,500
using comments in your code might seem
1718
01:21:54,889 --> 01:21:59,590
some minor thing but believe me if you
1719
01:21:57,500 --> 01:22:03,139
come back to your code one month later
1720
01:21:59,590 --> 01:22:05,449
probably you don't remember any aspect
1721
01:22:03,139 --> 01:22:07,460
of your code and only thing that you
1722
01:22:05,448 --> 01:22:10,428
have that will help you to understand
1723
01:22:07,460 --> 01:22:12,020
your code are these comments also beside
1724
01:22:10,429 --> 01:22:13,880
that you may work with a team on a
1725
01:22:12,020 --> 01:22:14,989
project and these comments can be
1726
01:22:14,988 --> 01:22:20,868
so not only at the declaration of your
1727
01:22:17,750 --> 01:22:23,618
methods but wherever else you feel like
1728
01:22:20,868 --> 01:22:26,029
you need comments please do use comments
1729
01:22:23,618 --> 01:22:28,038
ok let's move on from this part and
1730
01:22:26,029 --> 01:22:33,380
let's create our already read book
1731
01:22:28,038 --> 01:22:35,779
activity so in my project I can right
1732
01:22:33,380 --> 01:22:38,750
click on the package and by saying new
1733
01:22:35,779 --> 01:22:41,509
activity empty activity we can create
1734
01:22:38,750 --> 01:22:45,250
our activity I'm going to name this one
1735
01:22:47,630 --> 01:22:53,029
to generate the layout fine so let's
1736
01:22:49,399 --> 01:22:55,099
leave this checkbox and I checked the
1737
01:22:53,029 --> 01:22:56,779
layout file for this activity is going
1738
01:22:55,100 --> 01:22:59,929
to be really simple basically we just
1739
01:22:56,779 --> 01:23:02,779
need a recycler view in that recycler
1740
01:22:59,929 --> 01:23:04,520
view we are going to show our books so
1741
01:23:02,779 --> 01:23:08,920
let's switch to our layout file and
1742
01:23:04,520 --> 01:23:11,389
let's drag a recycler view in our layout
1743
01:23:08,920 --> 01:23:16,100
for the vid some height I am going to
1744
01:23:11,389 --> 01:23:19,130
say match parent and also let's give it
1745
01:23:16,100 --> 01:23:23,630
an ID I'm going to say pork recycle of
1746
01:23:19,130 --> 01:23:25,520
you beside that let's add some margin in
1747
01:23:23,630 --> 01:23:30,440
our split view I believe that would be
1748
01:23:25,520 --> 01:23:32,750
better let's add a margin in here margin
1749
01:23:30,439 --> 01:23:35,750
I believe that NDP would be fine okay
1750
01:23:32,750 --> 01:23:38,869
now back in our Java file we can
1751
01:23:35,750 --> 01:23:41,569
initialize our recycle view for example
1752
01:23:38,869 --> 01:23:44,599
down in here I'm going to say recycler
1753
01:23:41,569 --> 01:23:47,630
view let's name it recycler view is
1754
01:23:44,600 --> 01:23:50,989
equal to find view by ID our that ID
1755
01:23:47,630 --> 01:23:53,510
that books recycle view I don't think we
1756
01:23:50,988 --> 01:23:56,899
had s let's remove that so that we don't
1757
01:23:53,510 --> 01:24:00,230
get a nullpointerexception after that
1758
01:23:56,899 --> 01:24:02,359
I'm going to create my adapter and here
1759
01:24:00,229 --> 01:24:04,638
is where the recycler view is coming
1760
01:24:02,359 --> 01:24:06,738
very handy we have created a book
1761
01:24:04,639 --> 01:24:09,199
recycler view adapter in our project
1762
01:24:06,738 --> 01:24:11,839
previously and the good thing is that we
1763
01:24:09,198 --> 01:24:14,719
can reuse our adapter as many times as
1764
01:24:11,840 --> 01:24:17,719
we want so once we have used that in our
1765
01:24:14,719 --> 01:24:21,289
all books activity we can also use it in
1766
01:24:17,719 --> 01:24:24,380
here for example I can say box recycler
1767
01:24:21,289 --> 01:24:27,109
view adapter let's name it adapter is
1768
01:24:24,380 --> 01:24:30,969
equal to new box recycler view adapter
1769
01:24:27,109 --> 01:24:33,559
we also needed a context let's pass this
1770
01:24:30,969 --> 01:24:36,050
let's say recycler view touch set
1771
01:24:33,560 --> 01:24:39,170
adapter and let's pass our adapter
1772
01:24:36,050 --> 01:24:41,779
beside that we can set a layout manager
1773
01:24:39,170 --> 01:24:44,060
for our recycler view I'm going to say
1774
01:24:41,779 --> 01:24:46,340
recycler view that set layout manager
1775
01:24:44,060 --> 01:24:49,370
once again I'm going to pass linear
1776
01:24:46,340 --> 01:24:53,420
layout manager let's pass our context
1777
01:24:49,369 --> 01:24:57,158
for the data I am going to say adapter
1778
01:24:53,420 --> 01:25:00,469
set box I'm going to pass newton's
1779
01:24:57,158 --> 01:25:01,469
target instance that get already read
1780
01:25:01,469 --> 01:25:06,550
this method in here also we are keep
1781
01:25:04,630 --> 01:25:09,100
seeing this highlighting here please
1782
01:25:06,550 --> 01:25:11,579
highlight says that you can also use
1783
01:25:09,100 --> 01:25:14,860
this get already red box method without
1784
01:25:11,579 --> 01:25:16,988
instantiating your UTS class let's do
1785
01:25:14,859 --> 01:25:19,210
that we can do this because this get
1786
01:25:16,988 --> 01:25:22,059
already red box method is a static
1787
01:25:19,210 --> 01:25:24,699
method so for example before getting an
1788
01:25:22,060 --> 01:25:26,200
instance I can say that get already red
1789
01:25:24,699 --> 01:25:27,130
box you can see that it's working
1790
01:25:27,130 --> 01:25:31,930
but there is a potential bug in here
1791
01:25:29,590 --> 01:25:34,180
right now the first place that we are
1792
01:25:31,930 --> 01:25:36,909
calling our greetings class is inside
1793
01:25:34,180 --> 01:25:39,940
the all Box activity I'm talking about
1794
01:25:36,909 --> 01:25:42,069
that UTS that get instance method so
1795
01:25:39,939 --> 01:25:44,738
before that we don't have any instance
1796
01:25:42,069 --> 01:25:48,099
of this utils class in our application
1797
01:25:44,738 --> 01:25:50,319
so before going to add all Box activity
1798
01:25:48,100 --> 01:25:52,480
we don't have any ArrayList called
1799
01:25:50,319 --> 01:25:55,210
already red box because if you remember
1800
01:25:52,479 --> 01:25:57,399
we are initializing our array lists
1801
01:25:55,210 --> 01:25:59,800
inside the constructor of this utils
1802
01:25:57,399 --> 01:26:02,289
class what happens if the user decides
1803
01:25:59,800 --> 01:26:04,659
to come to this already read books
1804
01:26:02,289 --> 01:26:07,269
activity first and don't go to the out
1805
01:26:04,659 --> 01:26:09,130
box activity I mean that hits this gate
1806
01:26:07,270 --> 01:26:11,350
already red box method is going to
1807
01:26:09,130 --> 01:26:13,510
return null and that's where the
1808
01:26:11,350 --> 01:26:16,210
potential bug can happen inside the
1809
01:26:13,510 --> 01:26:18,250
adapter of our recycle of view we are
1810
01:26:16,210 --> 01:26:20,350
calling some functions on our books
1811
01:26:18,250 --> 01:26:22,719
ArrayList and we know that calling a
1812
01:26:20,350 --> 01:26:25,329
function on a null reference can cause
1813
01:26:22,719 --> 01:26:28,090
null pointer exceptions what can we do
1814
01:26:25,329 --> 01:26:30,430
to avoid this now enter exception we can
1815
01:26:28,090 --> 01:26:32,710
call youtube's target instance inside
1816
01:26:30,430 --> 01:26:35,260
the main activity we don't meet any
1817
01:26:32,710 --> 01:26:37,390
functionalities from UTS class in main
1818
01:26:35,260 --> 01:26:39,340
activity but we are just going to do
1819
01:26:37,390 --> 01:26:42,160
that in order to avoid null pointer
1820
01:26:39,340 --> 01:26:45,960
exceptions and to initialize all of our
1821
01:26:42,159 --> 01:26:48,569
lists so let's go to main activity and
1822
01:26:48,569 --> 01:26:55,479
initializing all of our buttons I'm
1823
01:26:51,550 --> 01:26:57,640
going to say utils target instance this
1824
01:26:55,479 --> 01:26:59,799
way we are calling the constructor of
1825
01:26:57,640 --> 01:27:02,469
this utils class and we are initializing
1826
01:26:59,800 --> 01:27:04,480
our lists also now that we are here
1827
01:27:02,469 --> 01:27:07,000
let's quickly set an onclicklistener for
1828
01:27:04,479 --> 01:27:09,609
this beauty and already read I'm going
1829
01:27:07,000 --> 01:27:12,359
to say BTN already read that's at
1830
01:27:09,609 --> 01:27:14,710
onclicklistener me onclick listener and
1831
01:27:14,710 --> 01:27:19,569
the user to this activity to already
1832
01:27:16,689 --> 01:27:23,139
read books activity so let's create an
1833
01:27:19,569 --> 01:27:25,329
intent intent is equal to new intent for
1834
01:27:23,140 --> 01:27:27,789
the context let's pass main activity
1835
01:27:25,329 --> 01:27:30,960
that this and for the destination
1836
01:27:27,789 --> 01:27:33,939
already read book activity third class
1837
01:27:30,960 --> 01:27:36,730
after that we can say start activity and
1838
01:27:33,939 --> 01:27:38,649
we can pass our intent there is one more
1839
01:27:36,729 --> 01:27:40,479
place that we need to navigate the user
1840
01:27:38,649 --> 01:27:42,670
to already read books activity and
1841
01:27:40,479 --> 01:27:45,069
that's where we have added the book into
1842
01:27:42,670 --> 01:27:47,529
our already read books list let's copy
1843
01:27:45,069 --> 01:27:50,439
this intent and let's go to our book
1844
01:27:47,529 --> 01:27:52,988
activity if you remember we had a to-do
1845
01:27:50,439 --> 01:27:55,809
somewhere down in here in which we are
1846
01:27:52,988 --> 01:27:58,299
saying to navigate the user after this
1847
01:27:55,810 --> 01:28:00,700
to do I'm going to paste my intent but
1848
01:27:58,300 --> 01:28:04,060
of course I need to change this context
1849
01:28:00,699 --> 01:28:05,679
let's change it to this or because we
1850
01:28:04,060 --> 01:28:10,960
are inside this interface we need to
1851
01:28:05,680 --> 01:28:12,550
pass book activity that this now that we
1852
01:28:10,960 --> 01:28:15,279
are navigating the user we no longer
1853
01:28:12,550 --> 01:28:17,380
need these to do let's remove that and
1854
01:28:15,279 --> 01:28:19,199
let's run our application once again and
1855
01:28:17,380 --> 01:28:21,699
let's see if everything works perfect
1856
01:28:19,199 --> 01:28:24,250
first of all let's go to already read
1857
01:28:21,699 --> 01:28:26,380
books activity we can see that right now
1858
01:28:24,250 --> 01:28:28,029
it's empty it's also better to show
1859
01:28:26,380 --> 01:28:30,909
something in case if we don't have
1860
01:28:28,029 --> 01:28:32,649
anything in our list we will take care
1861
01:28:30,909 --> 01:28:34,569
of that in future videos but for now
1862
01:28:32,649 --> 01:28:37,229
let's go back and let's go to our book
1863
01:28:37,380 --> 01:28:42,420
you can see that this already red box
1864
01:28:40,050 --> 01:28:44,000
button is enabled you may be wondering
1865
01:28:42,420 --> 01:28:46,560
why this one is enabled because
1866
01:28:44,000 --> 01:28:49,079
previously we have added this book into
1867
01:28:46,560 --> 01:28:51,090
our already read books ArrayList well
1868
01:28:49,079 --> 01:28:53,880
that's because we are not persisting our
1869
01:28:51,090 --> 01:28:55,710
data we are not using any database or
1870
01:28:53,880 --> 01:28:59,010
anything we are just simply using a
1871
01:28:55,710 --> 01:29:01,319
static array lists because of that the
1872
01:28:59,010 --> 01:29:04,560
life of our data storage is only
1873
01:29:01,319 --> 01:29:06,329
whenever we close our application in
1874
01:29:04,560 --> 01:29:09,289
future videos in this section we will
1875
01:29:06,329 --> 01:29:11,880
use another option to persist our data
1876
01:29:09,289 --> 01:29:14,310
but for now we just lose our data
1877
01:29:11,880 --> 01:29:16,590
whenever we close our application
1878
01:29:14,310 --> 01:29:18,690
ok let's click on this already red pop
1879
01:29:18,689 --> 01:29:24,109
successfully navigating the user to
1880
01:29:20,789 --> 01:29:26,609
already read book activity if we go back
1881
01:29:24,109 --> 01:29:29,039
we are once again inside the book
1882
01:29:26,609 --> 01:29:32,009
activity but still this already red
1883
01:29:29,039 --> 01:29:34,439
button is enabled this is because of an
1884
01:29:32,010 --> 01:29:37,320
entirely new concept that's because of
1885
01:29:34,439 --> 01:29:40,049
the activity lifecycle whenever we add
1886
01:29:37,319 --> 01:29:42,929
this book to our already read book list
1887
01:29:40,050 --> 01:29:45,420
and we navigate the user to already read
1888
01:29:42,929 --> 01:29:47,730
book activity and from there when we
1889
01:29:45,420 --> 01:29:50,039
press this back button we are not
1890
01:29:47,729 --> 01:29:52,289
calling the oncreate method of our
1891
01:29:50,039 --> 01:29:54,149
activity we are calling some other
1892
01:29:52,289 --> 01:29:56,488
methods in which we are going to talk
1893
01:29:54,149 --> 01:29:59,158
about them in future videos in activity
1894
01:29:56,488 --> 01:30:01,019
and fragment section so we are not going
1895
01:29:59,158 --> 01:30:03,569
to talk about this problem right now but
1896
01:30:01,020 --> 01:30:06,989
if we press this back button once again
1897
01:30:03,569 --> 01:30:08,908
and if we go to our book activity you
1898
01:30:06,988 --> 01:30:11,669
can see that now it is already read and
1899
01:30:08,908 --> 01:30:13,229
button is disabled but the thing that we
1900
01:30:11,670 --> 01:30:15,420
are going to talk about in here is that
1901
01:30:13,229 --> 01:30:18,388
whenever we add a book to our already
1902
01:30:15,420 --> 01:30:21,119
read book I released and whenever we
1903
01:30:18,389 --> 01:30:23,579
navigate the user to and already read
1904
01:30:21,119 --> 01:30:25,439
book activity by pressing this back
1905
01:30:23,579 --> 01:30:27,929
button we are going to navigate the user
1906
01:30:25,439 --> 01:30:30,479
back to the main activity and not this
1907
01:30:27,929 --> 01:30:33,149
pop activity we are going to talk about
1908
01:30:30,479 --> 01:30:35,279
how we can fix that for example if I go
1909
01:30:33,149 --> 01:30:37,799
back and add this other book to my
1910
01:30:35,279 --> 01:30:40,139
already read book array list let's
1911
01:30:37,800 --> 01:30:42,360
quickly do that whenever we are
1912
01:30:40,139 --> 01:30:45,150
navigated to this already read book
1913
01:30:42,359 --> 01:30:46,948
activity by pressing this back button we
1914
01:30:45,149 --> 01:30:48,899
are going to navigate the user back to
1915
01:30:46,948 --> 01:30:51,269
main activity and not to the book
1916
01:30:48,899 --> 01:30:53,670
activity we will talk about that
1917
01:30:51,270 --> 01:30:57,480
later on let's also go back to main
1918
01:30:53,670 --> 01:31:00,090
activity and from there let's click on
1919
01:30:57,479 --> 01:31:02,429
this already read books once again you
1920
01:31:00,090 --> 01:31:05,130
can see that we have two books in our
1921
01:31:02,430 --> 01:31:07,110
already read books ArrayList there is
1922
01:31:05,130 --> 01:31:09,659
just one minor problem in here and that
1923
01:31:07,109 --> 01:31:12,420
we need to Center our recycler we will
1924
01:31:09,659 --> 01:31:14,159
fix that ok let's fix these problems one
1925
01:31:12,420 --> 01:31:16,500
by one first of all let's enter this
1926
01:31:14,159 --> 01:31:18,869
recyclerview and after that let's take
1927
01:31:16,500 --> 01:31:21,319
care of this back button so for this
1928
01:31:18,869 --> 01:31:25,800
recycler view I can go to my layout file
1929
01:31:21,319 --> 01:31:28,199
activity already read book and in here I
1930
01:31:25,800 --> 01:31:33,600
can change the width and height to wrap
1931
01:31:28,199 --> 01:31:36,869
content and after that I can constraint
1932
01:31:33,600 --> 01:31:42,300
my recycle review because we are inside
1933
01:31:36,869 --> 01:31:44,369
a constraint layout or I think this
1934
01:31:42,300 --> 01:31:47,270
button constraint wouldn't be necessary
1935
01:31:48,029 --> 01:31:54,460
okay it seems like fix this let's go to
1936
01:31:51,850 --> 01:31:56,470
our already read book activity that Java
1937
01:31:54,460 --> 01:31:59,380
fine and let's see how we can take care
1938
01:31:56,470 --> 01:32:01,989
of the black button for the back button
1939
01:31:59,380 --> 01:32:04,480
we have few options the easiest one is
1940
01:32:01,988 --> 01:32:07,029
to override some method called on back
1941
01:32:04,479 --> 01:32:10,569
pressed if you press ctrl o somewhere
1942
01:32:07,029 --> 01:32:16,329
inside your activity if you search for
1943
01:32:10,569 --> 01:32:18,130
on back pressed we can see this method
1944
01:32:16,329 --> 01:32:21,430
in here we are going to override this
1945
01:32:18,130 --> 01:32:23,680
method this method is going to be
1946
01:32:21,430 --> 01:32:26,079
triggered whenever the user click on the
1947
01:32:23,680 --> 01:32:28,060
back button so inside this method
1948
01:32:26,079 --> 01:32:31,238
instead of the super statement we can
1949
01:32:28,060 --> 01:32:33,640
simply create an intent and navigate the
1950
01:32:31,238 --> 01:32:36,189
user back to main activity let's see how
1951
01:32:33,640 --> 01:32:39,190
we can do that we can say intent intent
1952
01:32:36,189 --> 01:32:41,649
is equal to new intent let's pass this
1953
01:32:39,189 --> 01:32:45,159
as the context and main activity that
1954
01:32:41,649 --> 01:32:48,579
class as the destination after that
1955
01:32:45,159 --> 01:32:50,319
let's say start activity and let's pass
1956
01:32:50,319 --> 01:32:54,488
let's run the application and let's see
1957
01:32:52,840 --> 01:32:57,699
if we are going to navigate the user
1958
01:32:54,488 --> 01:32:59,829
successfully back to main activity let's
1959
01:32:57,699 --> 01:33:03,279
add one book to our already read books
1960
01:32:59,829 --> 01:33:05,559
are in list for example this one we are
1961
01:33:03,279 --> 01:33:09,189
navigating the user to already read book
1962
01:33:05,560 --> 01:33:12,100
activity if we press back you can see
1963
01:33:09,189 --> 01:33:15,189
that now we are inside the main activity
1964
01:33:12,100 --> 01:33:17,650
but there is one more problem in here if
1965
01:33:15,189 --> 01:33:19,659
you press this back button we will be
1966
01:33:17,649 --> 01:33:22,000
navigated back to already read books
1967
01:33:19,659 --> 01:33:24,909
activity and that's because of something
1968
01:33:22,000 --> 01:33:27,390
called back snack in programming so
1969
01:33:24,909 --> 01:33:29,949
whenever you are going to an activity
1970
01:33:27,390 --> 01:33:32,350
some snack will be added to your
1971
01:33:29,949 --> 01:33:34,539
application basically the hundred system
1972
01:33:32,350 --> 01:33:37,720
is going to keep a history of where the
1973
01:33:34,539 --> 01:33:40,090
user visits in your application whenever
1974
01:33:37,720 --> 01:33:42,400
you go to a new activity in you a stack
1975
01:33:40,090 --> 01:33:44,920
or to be personalized a new task will be
1976
01:33:42,399 --> 01:33:46,629
added to your back stack you can deal
1977
01:33:44,920 --> 01:33:49,029
with that back stack if you want for
1978
01:33:46,630 --> 01:33:52,180
example you can clear that back a stack
1979
01:33:49,029 --> 01:33:54,429
or whenever you are defining a new job
1980
01:33:52,180 --> 01:33:56,770
for example whenever you are firing an
1981
01:33:54,430 --> 01:33:59,320
intent we can say that this is an
1982
01:33:56,770 --> 01:34:01,540
entirely new task and you don't want to
1983
01:34:01,539 --> 01:34:06,699
visit in your application in order to
1984
01:34:04,119 --> 01:34:09,069
define your intent as a new task you can
1985
01:34:06,699 --> 01:34:11,679
add some flags to your intent for
1986
01:34:09,069 --> 01:34:15,219
example after defining your intent you
1987
01:34:11,680 --> 01:34:17,680
can say intent set flags this method in
1988
01:34:15,220 --> 01:34:22,930
here and you can pass two flags you can
1989
01:34:17,680 --> 01:34:25,360
say intent dot let's say clear task you
1990
01:34:22,930 --> 01:34:28,210
can see this flag activity clear tasks
1991
01:34:25,359 --> 01:34:30,969
in here and also I'm going to add one
1992
01:34:28,210 --> 01:34:35,199
more flag you can add one more by using
1993
01:34:30,970 --> 01:34:38,260
this pipeline let's say intent dot new
1994
01:34:35,199 --> 01:34:40,869
task you have this flag activity new
1995
01:34:38,260 --> 01:34:42,880
task so by using these two flags on your
1996
01:34:40,869 --> 01:34:45,579
intent you are saying that we want to
1997
01:34:42,880 --> 01:34:48,550
clear your back stack and also you are
1998
01:34:45,579 --> 01:34:52,390
defining this intent as a new task so
1999
01:34:48,550 --> 01:34:54,310
now if we run our application if we add
2000
01:34:52,390 --> 01:34:59,320
a book to our already read books
2001
01:34:54,310 --> 01:35:01,030
ArrayList for example this one now if I
2002
01:34:59,319 --> 01:35:03,699
press this back button I will be
2003
01:35:01,029 --> 01:35:05,859
navigated to the main activity but my
2004
01:35:03,699 --> 01:35:08,170
back slack is now clear it means that if
2005
01:35:05,859 --> 01:35:10,509
I press this back button we are going to
2006
01:35:08,170 --> 01:35:12,699
quit the application so this way by
2007
01:35:10,510 --> 01:35:15,489
using these flags and you can define a
2008
01:35:12,699 --> 01:35:17,529
new task ok let's move on from this part
2009
01:35:15,489 --> 01:35:20,380
and let's work on the other buttons in
2010
01:35:17,529 --> 01:35:24,189
our POC activity if you remember we had
2011
01:35:20,380 --> 01:35:28,090
three more buttons so once again I'm
2012
01:35:24,189 --> 01:35:30,579
going to go to the uncreate method after
2013
01:35:28,090 --> 01:35:33,369
getting the incoming book I'm going to
2014
01:35:30,579 --> 01:35:35,850
call another method called handle one to
2015
01:35:36,689 --> 01:35:42,149
once again I am going to pass my
2016
01:35:38,850 --> 01:35:43,920
incoming book the logic for this button
2017
01:35:42,149 --> 01:35:46,170
and the other two buttons are going to
2018
01:35:43,920 --> 01:35:48,480
be exactly the same so I'm going to call
2019
01:35:46,170 --> 01:35:50,250
two more methods in here hand our
2020
01:35:48,479 --> 01:35:52,908
currently reading book and handle
2021
01:35:56,689 --> 01:36:01,239
let's quickly create these methods
2022
01:36:05,579 --> 01:36:09,329
the logic from inside this method let's
2023
01:36:07,529 --> 01:36:11,489
copy them and we will change them if it
2024
01:36:09,329 --> 01:36:17,550
was necessary I'm going to copy this
2025
01:36:11,489 --> 01:36:22,170
whole method and I'm going to paste it
2026
01:36:17,550 --> 01:36:24,029
inside this handle one two reports we
2027
01:36:22,170 --> 01:36:27,000
need to change if you think first of all
2028
01:36:24,029 --> 01:36:29,489
we need to make this book final because
2029
01:36:27,000 --> 01:36:32,250
we are using it inside this onclick
2030
01:36:29,489 --> 01:36:34,289
listener after that I'm going to change
2031
01:36:32,250 --> 01:36:36,630
the name of this already read books
2032
01:36:34,289 --> 01:36:38,670
ArrayList I'm not sure if I talked about
2033
01:36:36,630 --> 01:36:41,100
this previously but basically whenever
2034
01:36:38,670 --> 01:36:43,409
you want to change the name of a
2035
01:36:41,100 --> 01:36:45,630
variable or some object in your
2036
01:36:43,409 --> 01:36:48,809
application that you are using in
2037
01:36:45,630 --> 01:36:52,470
multiple places you can press Shift + f6
2038
01:36:48,810 --> 01:36:55,230
and in here you can refactor the name of
2039
01:36:52,470 --> 01:36:58,260
your variable for example in here I am
2040
01:36:55,229 --> 01:36:59,909
going to save one to read books you can
2041
01:36:58,260 --> 01:37:02,699
see that when I change the name of this
2042
01:36:59,909 --> 01:37:05,189
array list it will be changed in all of
2043
01:37:02,699 --> 01:37:08,340
its usages so let's say I want to read
2044
01:37:08,340 --> 01:37:14,840
I also need to change this method in
2045
01:37:11,039 --> 01:37:17,470
here let's say get one to read books I
2046
01:37:14,840 --> 01:37:20,449
need to change the name of this boolean
2047
01:37:20,449 --> 01:37:26,670
after that I need to disable another
2048
01:37:23,189 --> 01:37:28,949
button beaten add to one to read this
2049
01:37:28,949 --> 01:37:36,449
onclicklistener for this with an ativan
2050
01:37:30,960 --> 01:37:38,640
to read so let's change that I also need
2051
01:37:36,449 --> 01:37:41,159
to create another method inside my UTS
2052
01:37:38,640 --> 01:37:46,320
class so that I add this book to my
2053
01:37:41,159 --> 01:37:50,720
wishlist so let's go to utils and then
2054
01:37:46,319 --> 01:37:50,719
in here let's create a similar method
2055
01:37:51,590 --> 01:37:56,329
you can see that the method is basically
2056
01:37:53,899 --> 01:37:58,250
the same we are returning a boolean once
2057
01:37:56,329 --> 01:38:00,979
again and we are adding the book into
2058
01:37:58,250 --> 01:38:04,010
our bond to read books ArrayList now
2059
01:38:00,979 --> 01:38:06,259
inside our book activity instead of this
2060
01:38:04,010 --> 01:38:09,289
add to already read book I can say add
2061
01:38:06,260 --> 01:38:11,150
to want to read there is just one more
2062
01:38:09,289 --> 01:38:13,849
thing that I need to take care in here
2063
01:38:11,149 --> 01:38:16,189
and that's navigating the user to want
2064
01:38:13,849 --> 01:38:18,529
to read books activity and not already
2065
01:38:16,189 --> 01:38:21,799
read book activity so let's quickly
2066
01:38:18,529 --> 01:38:25,429
create that other activity once again in
2067
01:38:21,800 --> 01:38:28,329
our package we can say new activity
2068
01:38:29,359 --> 01:38:33,679
the layout file is going to be exactly
2069
01:38:32,029 --> 01:38:38,050
the same so I'm going to fast forward
2070
01:38:33,680 --> 01:38:38,050
the process of adding the recyclerview
2071
01:38:46,529 --> 01:38:50,439
don't worry if you need to check the
2072
01:38:48,819 --> 01:38:52,269
source code I will upload the source
2073
01:38:50,439 --> 01:38:54,519
code at the end of every video but
2074
01:38:52,270 --> 01:38:57,250
basically these are and just copy and
2075
01:38:54,520 --> 01:38:59,200
pasting okay let's switch back to our
2076
01:38:57,250 --> 01:39:01,899
one to report activity and let's
2077
01:38:59,199 --> 01:39:03,880
initialize our recycling once again I
2078
01:39:01,899 --> 01:39:07,899
think I can copy some of the logic from
2079
01:39:03,880 --> 01:39:10,470
the already read web activity let's copy
2080
01:39:11,539 --> 01:39:16,260
but this time instead of this get
2081
01:39:14,100 --> 01:39:19,469
already read books I'm going to say get
2082
01:39:16,260 --> 01:39:23,400
one to read works this one let's also
2083
01:39:19,469 --> 01:39:26,310
take care of the back stack I'm going to
2084
01:39:23,399 --> 01:39:28,769
copy this whole method from the already
2085
01:39:26,310 --> 01:39:31,620
read pot activity you may be wondering
2086
01:39:28,770 --> 01:39:34,290
why I am copying and pasting why I have
2087
01:39:31,619 --> 01:39:35,969
created four different lists later on we
2088
01:39:34,289 --> 01:39:39,060
will see some minor differences between
2089
01:39:35,969 --> 01:39:40,890
these four different lists okay now that
2090
01:39:39,060 --> 01:39:43,080
we have created this activity let's
2091
01:39:40,890 --> 01:39:47,539
navigate the user to want to read
2092
01:39:43,079 --> 01:39:47,539
activity from inside our POC activity
2093
01:39:48,079 --> 01:39:53,488
that all we need to do inside this
2094
01:39:50,430 --> 01:39:56,190
handle want to read box method let's
2095
01:39:53,488 --> 01:39:58,049
quickly create the other tool in order
2096
01:39:56,189 --> 01:40:00,539
to save your time because it files just
2097
01:39:58,050 --> 01:40:03,119
copy and pasting I cut a part that I
2098
01:40:00,539 --> 01:40:05,519
wrote these two methods but let's
2099
01:40:03,119 --> 01:40:07,439
quickly take a look at them so first of
2100
01:40:05,520 --> 01:40:09,180
all this handle favorite books you can
2101
01:40:07,439 --> 01:40:11,460
see that the book is final we are
2102
01:40:09,180 --> 01:40:13,619
getting the ArrayList we are checking
2103
01:40:11,460 --> 01:40:16,590
that this book exists in our favorite
2104
01:40:13,619 --> 01:40:19,199
books after that if it does exist we are
2105
01:40:16,590 --> 01:40:21,060
going to deactivate our button but if it
2106
01:40:21,060 --> 01:40:26,520
onclicklistener if adding the book into
2107
01:40:23,760 --> 01:40:28,350
our favorites ArrayList is successful we
2108
01:40:26,520 --> 01:40:30,840
are showing a toast message and we are
2109
01:40:28,350 --> 01:40:32,039
navigating the user to favorite activity
2110
01:40:32,039 --> 01:40:36,238
I have ensured that in a minute but in
2111
01:40:34,680 --> 01:40:38,610
case if something wrong happens we are
2112
01:40:36,238 --> 01:40:40,889
sharing a toast message just like we did
2113
01:40:38,609 --> 01:40:42,719
for already read books beside that and
2114
01:40:40,890 --> 01:40:45,420
the same thing happens inside this
2115
01:40:42,719 --> 01:40:47,130
handle currently reading book you can
2116
01:40:45,420 --> 01:40:49,770
see that basically the logic is the same
2117
01:40:47,130 --> 01:40:51,750
we just changed the name also beside
2118
01:40:49,770 --> 01:40:54,210
that I've added two more methods inside
2119
01:40:51,750 --> 01:40:57,329
my utils class this add two currently
2120
01:40:54,210 --> 01:40:58,739
reading book and add to favorite once
2121
01:40:57,329 --> 01:41:01,559
again you can see that we are returning
2122
01:40:58,738 --> 01:41:03,539
a boolean beside that I've created two
2123
01:41:01,560 --> 01:41:05,610
new activities this currently reading
2124
01:41:03,539 --> 01:41:07,649
activity which once again we are
2125
01:41:05,609 --> 01:41:10,109
initializing every circle view and it's
2126
01:41:07,649 --> 01:41:12,899
adapter and we are setting the data in
2127
01:41:10,109 --> 01:41:15,029
our adapter by using utils that that
2128
01:41:12,899 --> 01:41:17,789
method that we have in our utils class
2129
01:41:15,029 --> 01:41:20,909
we are also taking care of this unpack
2130
01:41:17,789 --> 01:41:23,010
first button beside that we have created
2131
01:41:20,909 --> 01:41:24,988
this favorite activity which you can see
2132
01:41:23,010 --> 01:41:27,840
the code is a lot like each other
2133
01:41:24,988 --> 01:41:29,578
and also for the layout fonts for these
2134
01:41:27,840 --> 01:41:32,279
two activities if you take a look at
2135
01:41:29,578 --> 01:41:35,130
them I only have a recyclerview in each
2136
01:41:32,279 --> 01:41:36,868
one of them I just caught the process to
2137
01:41:35,130 --> 01:41:38,969
save your time but if you want to check
2138
01:41:36,868 --> 01:41:40,558
the source code please do that I will
2139
01:41:38,969 --> 01:41:42,868
upload the source code at the end of
2140
01:41:40,559 --> 01:41:45,538
every video in this section on the links
2141
01:41:42,868 --> 01:41:47,098
that you can see on the screen so feel
2142
01:41:45,538 --> 01:41:48,509
free to check that if you need but in
2143
01:41:47,099 --> 01:41:51,650
here let's quickly run our application
2144
01:41:48,510 --> 01:41:56,730
and let's see if everything works fine
2145
01:41:51,649 --> 01:41:59,189
let's go to our block activity and let's
2146
01:41:56,729 --> 01:42:00,839
add this book to one of our array lists
2147
01:41:59,189 --> 01:42:04,018
for example let's add this one to our
2148
01:42:00,840 --> 01:42:06,748
favorites the book has been added we are
2149
01:42:04,019 --> 01:42:08,219
navigating to the favorite activity if
2150
01:42:06,748 --> 01:42:10,679
you press this back button we are
2151
01:42:08,219 --> 01:42:12,989
navigating back to the main activity
2152
01:42:10,679 --> 01:42:15,269
let's see our favorites from here
2153
01:42:12,988 --> 01:42:17,788
but I didn't set down quick listeners
2154
01:42:15,269 --> 01:42:20,820
for these buttons I will do that let's
2155
01:42:17,788 --> 01:42:24,210
see our books once again and let's add
2156
01:42:20,819 --> 01:42:26,729
this 1q84 to our I don't know currently
2157
01:42:24,210 --> 01:42:28,279
reading books it seems like we have
2158
01:42:28,279 --> 01:42:32,670
okay I think that's enough for this
2159
01:42:30,510 --> 01:42:35,579
video in the next video we are going to
2160
01:42:32,670 --> 01:42:37,609
work on showing our card views I'm
2161
01:42:35,578 --> 01:42:40,710
talking about this book card view
2162
01:42:37,609 --> 01:42:42,479
differently in different activities so
2163
01:42:40,710 --> 01:42:45,210
for example inside this all books
2164
01:42:42,479 --> 01:42:48,058
activity we can see this card view we
2165
01:42:45,210 --> 01:42:50,069
can expand that in different lists for
2166
01:42:48,059 --> 01:42:52,440
example inside the favorite books list
2167
01:42:50,069 --> 01:42:54,868
we are going to add some actions for
2168
01:42:52,439 --> 01:42:57,839
example two text views so that by
2169
01:42:54,868 --> 01:43:00,210
clicking on them we remove the book from
2170
01:42:57,840 --> 01:43:02,639
the list we are going to show that for
2171
01:43:00,210 --> 01:43:05,368
the books that are inside our lists but
2172
01:43:02,639 --> 01:43:08,578
we are not going to show that inside all
2173
01:43:05,368 --> 01:43:11,189
books activity and at the same time we
2174
01:43:08,578 --> 01:43:12,689
are going to use only one adapter so
2175
01:43:11,189 --> 01:43:13,768
that's one thing that we are going to
2176
01:43:13,769 --> 01:43:19,170
inside that if you had time and we will
2177
01:43:16,198 --> 01:43:20,609
work on this about in here basically we
2178
01:43:19,170 --> 01:43:23,449
are going to show some dialog message
2179
01:43:20,609 --> 01:43:27,408
and we will see how we can show a dialog
2180
01:43:23,448 --> 01:43:27,408
okay see you in the next video
2181
01:43:29,460 --> 01:43:33,960
in this video we are going to create a
2182
01:43:32,130 --> 01:43:36,300
delete button in our current view
2183
01:43:33,960 --> 01:43:39,180
English will be available in all
2184
01:43:36,300 --> 01:43:41,340
activities beside the old books activity
2185
01:43:39,180 --> 01:43:43,680
let's see how we can implement that
2186
01:43:41,340 --> 01:43:45,779
functionality I'm going to add my delete
2187
01:43:43,680 --> 01:43:47,880
button inside this expanded version
2188
01:43:45,779 --> 01:43:50,849
inside the second relativelayout inside
2189
01:43:47,880 --> 01:43:52,890
the list item pop that XML file so if I
2190
01:43:50,850 --> 01:43:55,740
expand this relative layout and change
2191
01:43:52,890 --> 01:43:57,800
its visibility to visible for now I'm
2192
01:43:55,739 --> 01:44:01,319
going to add the delete button somewhere
2193
01:43:57,800 --> 01:44:03,630
beside this up arrow I'm going to place
2194
01:44:01,319 --> 01:44:05,880
it in here so for that down in here
2195
01:44:03,630 --> 01:44:08,569
after my image view after this bitten
2196
01:44:05,880 --> 01:44:11,310
off arrow I am going to say text view
2197
01:44:08,569 --> 01:44:13,859
wrap content and wrap content for the
2198
01:44:11,310 --> 01:44:16,890
width and height for the text I'm going
2199
01:44:13,859 --> 01:44:19,559
to say delete let's move it to below our
2200
01:44:16,890 --> 01:44:22,800
short description let's say layout below
2201
01:44:19,560 --> 01:44:25,140
and let's address our txt short
2202
01:44:22,800 --> 01:44:27,480
description after that I'm going to move
2203
01:44:25,140 --> 01:44:32,310
it to the left of this up arrow button
2204
01:44:27,479 --> 01:44:35,250
so let's say to start off I DBT and our
2205
01:44:32,310 --> 01:44:38,250
pyro let's quickly add a margin let's
2206
01:44:35,250 --> 01:44:40,800
say margin end and I believe 70 P would
2207
01:44:38,250 --> 01:44:43,350
be fine let's also change its color to a
2208
01:44:40,800 --> 01:44:46,050
red color let's quickly define a color
2209
01:44:43,350 --> 01:44:48,600
in our color resources inside this color
2210
01:44:46,050 --> 01:44:51,090
resources let's copy this one and let's
2211
01:44:48,600 --> 01:44:54,329
create a new one I'm going to change its
2212
01:44:51,090 --> 01:44:55,680
color to red and for its value and let's
2213
01:44:54,329 --> 01:44:57,600
select one of these two I'm going to
2214
01:44:55,680 --> 01:44:59,520
select this one but I think this one is
2215
01:44:57,600 --> 01:45:02,970
a pink color so let's change the color
2216
01:44:59,520 --> 01:45:05,850
to pink next in our list item book that
2217
01:45:02,970 --> 01:45:08,909
XML file in our text view I'm going to
2218
01:45:05,850 --> 01:45:11,340
say text color and I'm going to change
2219
01:45:08,909 --> 01:45:14,300
it to my pink color let's also give it
2220
01:45:11,340 --> 01:45:17,069
an ID I'm going to say BT and delete
2221
01:45:14,300 --> 01:45:20,909
beside that let's change its visibility
2222
01:45:17,069 --> 01:45:22,949
to argon later on in our adapter we will
2223
01:45:20,909 --> 01:45:25,050
change this visibility if it was
2224
01:45:22,949 --> 01:45:27,869
necessary okay we are almost done with
2225
01:45:25,050 --> 01:45:30,360
our card view let's just change the
2226
01:45:27,869 --> 01:45:32,670
visibility of this expanded view to gone
2227
01:45:30,359 --> 01:45:34,979
once again so in here I'm going to
2228
01:45:32,670 --> 01:45:37,770
change this one to gone and we are done
2229
01:45:34,979 --> 01:45:40,469
with our layout file let's go to our
2230
01:45:37,770 --> 01:45:43,300
adapter and let's pursue the code from
2231
01:45:40,470 --> 01:45:46,240
there so in our books recycle we are
2232
01:45:43,300 --> 01:45:48,039
if you remember inside on point
2233
01:45:46,239 --> 01:45:50,529
viewholder method we are checking that
2234
01:45:48,039 --> 01:45:52,449
if you should expand the card view or
2235
01:45:50,529 --> 01:45:53,259
not I'm talking about this if statement
2236
01:45:53,260 --> 01:45:59,079
if pops get that is expanded so inside
2237
01:45:56,949 --> 01:46:02,590
is if case I'm going to check that if
2238
01:45:59,079 --> 01:46:04,720
I'm inside all box activity or not if I
2239
01:46:02,590 --> 01:46:06,159
am inside the all box activity I'm not
2240
01:46:04,720 --> 01:46:08,320
going to show the delete button
2241
01:46:06,159 --> 01:46:10,449
but in other activities I am going to
2242
01:46:08,319 --> 01:46:12,670
show that for that I'm going to add one
2243
01:46:10,449 --> 01:46:15,460
more variable inside this adapter class
2244
01:46:12,670 --> 01:46:18,069
above in here after the context I am
2245
01:46:15,460 --> 01:46:20,319
going to add a string let's say private
2246
01:46:18,069 --> 01:46:23,500
a string I'm going to name this string
2247
01:46:20,319 --> 01:46:25,539
parent activity I'm going to receive
2248
01:46:23,500 --> 01:46:27,250
this string by the constructor so I'm
2249
01:46:25,539 --> 01:46:30,130
going to delete this constructor and
2250
01:46:27,250 --> 01:46:32,529
create it once again this time let's
2251
01:46:30,130 --> 01:46:34,510
select the context and this drink at the
2252
01:46:32,529 --> 01:46:37,059
time of initializing my recyclerview
2253
01:46:34,510 --> 01:46:39,280
adapter in different activities I'm
2254
01:46:37,060 --> 01:46:41,800
going to say that which activity is
2255
01:46:39,279 --> 01:46:44,199
calling this adapter for example if it's
2256
01:46:41,800 --> 01:46:46,779
the old books activity I'm going to pass
2257
01:46:44,199 --> 01:46:49,179
all work if it's others I am going to
2258
01:46:46,779 --> 01:46:51,340
pass the correspondent text after
2259
01:46:49,180 --> 01:46:53,260
receiving this string down in here
2260
01:46:51,340 --> 01:46:56,230
inside the unbound view holder method
2261
01:46:53,260 --> 01:46:58,570
I'm talking about this if case in here
2262
01:46:56,229 --> 01:47:01,149
I'm going to check that what that text
2263
01:46:58,569 --> 01:47:04,359
is so I'm going to say if parent
2264
01:47:01,149 --> 01:47:06,609
activity dot equals let's pass some text
2265
01:47:04,359 --> 01:47:09,460
in here for example let's say all books
2266
01:47:06,609 --> 01:47:11,589
it's better to use constants in here but
2267
01:47:09,460 --> 01:47:14,289
just for the sake of simplicity I'm
2268
01:47:11,590 --> 01:47:16,329
going to pass my text if the parent
2269
01:47:14,289 --> 01:47:18,550
activity that calling this adapter is
2270
01:47:16,329 --> 01:47:20,829
the all box activity we are going to
2271
01:47:18,550 --> 01:47:24,279
change the visibility of our delete text
2272
01:47:20,829 --> 01:47:26,319
to gone so let's say holder but I
2273
01:47:24,279 --> 01:47:28,479
believe we have it instantiated our
2274
01:47:26,319 --> 01:47:31,059
tillu text view in our view holder class
2275
01:47:28,479 --> 01:47:33,609
let's quickly do that so down in here
2276
01:47:31,060 --> 01:47:35,620
inside this view holder I'm going to
2277
01:47:33,609 --> 01:47:38,859
define my daily text so let's say
2278
01:47:35,619 --> 01:47:41,859
private text view let's name it VT and
2279
01:47:38,859 --> 01:47:44,229
delete and also after that inside the
2280
01:47:41,859 --> 01:47:46,059
constructor let's instantiate it for
2281
01:47:44,229 --> 01:47:49,689
example down in here I'm going to say
2282
01:47:46,060 --> 01:47:50,920
BTN delete is equal to item view dot
2283
01:47:50,920 --> 01:47:56,289
ordered ID dot retain delete now that we
2284
01:47:54,279 --> 01:47:57,279
have this element in our view holder
2285
01:47:57,279 --> 01:48:02,349
have access to it inside OnPoint
2286
01:47:59,770 --> 01:48:04,780
viewholder method so in our if statement
2287
01:48:02,350 --> 01:48:06,940
I am going to say holder dot BT and
2288
01:48:06,939 --> 01:48:13,299
let's icon let's write the other cases
2289
01:48:09,850 --> 01:48:16,990
for example let's say else if if our
2290
01:48:13,300 --> 01:48:20,409
parent activity is equal to already read
2291
01:48:16,989 --> 01:48:22,809
books if that's the case we are going to
2292
01:48:20,409 --> 01:48:24,729
delete this book from the already read
2293
01:48:22,810 --> 01:48:26,530
ArrayList instead of this if statement
2294
01:48:24,729 --> 01:48:28,929
you can also create a switch statement
2295
01:48:26,529 --> 01:48:30,969
first of all I'm going to write the
2296
01:48:28,930 --> 01:48:33,670
whole if statement and after that we
2297
01:48:30,970 --> 01:48:36,840
will write the logic for each case let's
2298
01:48:33,670 --> 01:48:40,600
say else if and activity that equals
2299
01:48:36,840 --> 01:48:45,250
let's say one to read the other case
2300
01:48:40,600 --> 01:48:49,210
would be as if and activity is equal to
2301
01:48:45,250 --> 01:48:52,210
currently reading we have one more case
2302
01:48:49,210 --> 01:48:54,699
let's say else the else case would be in
2303
01:48:52,210 --> 01:48:56,890
a favorite activity now let's write the
2304
01:48:54,699 --> 01:48:58,960
logic for each one of these cases for
2305
01:48:56,890 --> 01:49:00,610
example if it's the already read pop
2306
01:49:00,609 --> 01:49:06,489
onclicklistener for this bit intimate so
2307
01:49:03,310 --> 01:49:09,280
let's say holder that BTN delete dot set
2308
01:49:06,489 --> 01:49:11,679
on click listener let's say me on click
2309
01:49:09,279 --> 01:49:13,929
listener and inside this onclick method
2310
01:49:11,680 --> 01:49:16,450
I need to delete the poop from my
2311
01:49:13,930 --> 01:49:18,250
ArrayList once again I'm going to keep
2312
01:49:16,449 --> 01:49:21,309
all my interactions to my aesthetic
2313
01:49:18,250 --> 01:49:23,350
array lists inside the utils class so
2314
01:49:21,310 --> 01:49:25,300
I'm going to write another method inside
2315
01:49:23,350 --> 01:49:27,640
that with us class let's quickly go to
2316
01:49:25,300 --> 01:49:30,970
that class and down in here after
2317
01:49:27,640 --> 01:49:32,560
everything let's say public boolean once
2318
01:49:30,970 --> 01:49:34,510
again you can see that the return type
2319
01:49:32,560 --> 01:49:35,680
of this method is a boolean I will talk
2320
01:49:35,680 --> 01:49:42,909
let's say remove from already read let's
2321
01:49:40,000 --> 01:49:44,050
also receive a book and after that
2322
01:49:44,050 --> 01:49:49,510
let's return already read puts dot
2323
01:49:46,510 --> 01:49:52,150
remove and let's pass our book like the
2324
01:49:49,510 --> 01:49:54,789
add method on our ArrayList this remove
2325
01:49:52,149 --> 01:49:56,409
will also return a boolean if you want
2326
01:49:54,789 --> 01:49:57,850
you can check the documentation by
2327
01:49:56,409 --> 01:50:00,039
pressing down the control key and
2328
01:49:57,850 --> 01:50:02,590
clicking on this remove you can see the
2329
01:50:00,039 --> 01:50:04,569
guideline in case if we remove this item
2330
01:50:02,590 --> 01:50:06,699
from our array list successfully we are
2331
01:50:04,569 --> 01:50:09,609
returning true but otherwise we are
2332
01:50:06,699 --> 01:50:11,139
returning false we can use this boolean
2333
01:50:11,140 --> 01:50:16,060
remove the book successfully let's go
2334
01:50:13,449 --> 01:50:19,420
back to our adapter and in here let's
2335
01:50:16,060 --> 01:50:22,150
say if you teams that get instance to
2336
01:50:19,420 --> 01:50:24,940
add remove from already red book which
2337
01:50:22,149 --> 01:50:27,429
we need to pass our report by saying
2338
01:50:24,939 --> 01:50:29,769
boots target position if that was
2339
01:50:27,430 --> 01:50:32,560
successful we are going to show a toast
2340
01:50:29,770 --> 01:50:34,660
message let's say book removed but
2341
01:50:32,560 --> 01:50:37,240
instead of the book I'm going to pass
2342
01:50:34,659 --> 01:50:41,769
the name of the book which I can say box
2343
01:50:37,239 --> 01:50:44,859
that get position target name let's save
2344
01:50:41,770 --> 01:50:46,450
close removed also after that we need to
2345
01:50:44,859 --> 01:50:48,670
notify that the data set has been
2346
01:50:46,449 --> 01:50:51,309
changed because we want to refresh our
2347
01:50:48,670 --> 01:50:55,060
recyclerview so we can say notify data
2348
01:50:51,310 --> 01:50:58,270
set changed but in the else case let's
2349
01:50:55,060 --> 01:50:59,980
just show a toast message let's say
2350
01:50:58,270 --> 01:51:03,370
something wrong happened clear sorry
2351
01:50:59,979 --> 01:51:05,469
again we have write the logic for
2352
01:51:03,369 --> 01:51:08,079
removing a book in case if the planet
2353
01:51:05,470 --> 01:51:09,820
activity is already read but now that we
2354
01:51:08,079 --> 01:51:11,949
have changed the constructor of this
2355
01:51:09,819 --> 01:51:14,409
adapter probably we are going to see
2356
01:51:11,949 --> 01:51:17,349
some errors in our application wherever
2357
01:51:14,409 --> 01:51:19,180
we have instantiated this adapter we are
2358
01:51:17,350 --> 01:51:21,460
going to see some read errors for
2359
01:51:19,180 --> 01:51:23,770
example if we go to our all books
2360
01:51:21,460 --> 01:51:26,199
activity you can see that in here we
2361
01:51:23,770 --> 01:51:28,480
have an error and that's because now our
2362
01:51:26,199 --> 01:51:31,090
constructor needs two elements the
2363
01:51:28,479 --> 01:51:33,309
context and also the parent activity
2364
01:51:31,090 --> 01:51:35,529
which is a string for example inside
2365
01:51:33,310 --> 01:51:38,410
this all works activity I can say all
2366
01:51:35,529 --> 01:51:40,539
works let's see other places that we
2367
01:51:38,409 --> 01:51:43,619
have instantiated our adapter for
2368
01:51:40,539 --> 01:51:46,510
example already read books activity
2369
01:51:46,510 --> 01:51:50,469
notice that these strings should be
2370
01:51:48,550 --> 01:51:53,710
exactly the strings that you have passed
2371
01:51:50,469 --> 01:51:56,590
inside your if cases okay let's go to
2372
01:51:53,710 --> 01:51:59,618
currently reading activity and let's
2373
01:51:56,590 --> 01:52:00,819
pass one in here as well let's go to do
2374
01:51:59,618 --> 01:52:03,359
the same thing for the other two
2375
01:52:03,359 --> 01:52:08,099
ok let's close all of these extra files
2376
01:52:06,060 --> 01:52:09,960
and let's test our application and
2377
01:52:08,100 --> 01:52:12,470
that's if we can successfully to meet
2378
01:52:09,960 --> 01:52:15,329
the books from different activities
2379
01:52:12,470 --> 01:52:17,460
remember that we have written the case
2380
01:52:15,329 --> 01:52:19,500
only for this already read and the
2381
01:52:17,460 --> 01:52:21,239
others shouldn't work before I test my
2382
01:52:19,500 --> 01:52:23,460
application I'm going to add one more
2383
01:52:21,239 --> 01:52:25,829
line in here because it seems like I
2384
01:52:23,460 --> 01:52:28,319
have forgot something so in case if the
2385
01:52:25,829 --> 01:52:30,390
parent activity is already read activity
2386
01:52:28,319 --> 01:52:32,969
first of all we need to change the
2387
01:52:30,390 --> 01:52:35,250
visibility of our BTN delete I can say
2388
01:52:32,970 --> 01:52:37,350
holder that between delete let's say
2389
01:52:35,250 --> 01:52:40,470
that set visibility and let's pass
2390
01:52:37,350 --> 01:52:43,289
visible let's run our application let's
2391
01:52:40,470 --> 01:52:45,329
go to our all works activity in here if
2392
01:52:43,289 --> 01:52:48,060
we click on this down arrow we shouldn't
2393
01:52:45,329 --> 01:52:49,739
see this delete text let's try that as
2394
01:52:48,060 --> 01:52:51,990
you can see we cannot see any delete
2395
01:52:49,739 --> 01:52:54,689
that seems to be good let's go to our
2396
01:52:51,989 --> 01:52:57,689
activity and let's try adding this book
2397
01:52:54,689 --> 01:52:59,579
to our already read list it seems like
2398
01:52:57,689 --> 01:53:01,439
it has been added successfully if we
2399
01:52:59,579 --> 01:53:03,409
click on this drop down we can see that
2400
01:53:01,439 --> 01:53:07,229
this time we can see the delete button
2401
01:53:03,409 --> 01:53:09,210
let's try clicking on that it seems like
2402
01:53:07,229 --> 01:53:11,629
we are getting a crash let's open our
2403
01:53:09,210 --> 01:53:14,460
locket and let's see what the crash is
2404
01:53:11,630 --> 01:53:16,650
it seems like I've lost the error let's
2405
01:53:14,460 --> 01:53:18,689
run the application once again and let's
2406
01:53:16,649 --> 01:53:21,989
try everything one more time see all
2407
01:53:18,689 --> 01:53:24,269
boats put activity add to already read
2408
01:53:21,989 --> 01:53:26,819
list and let's try deleting it once
2409
01:53:24,270 --> 01:53:30,510
again it seems like the air is happening
2410
01:53:26,819 --> 01:53:33,329
online 78 of our recyclerview adapter
2411
01:53:30,510 --> 01:53:35,579
yes the problem is that first of all we
2412
01:53:33,329 --> 01:53:38,670
are removing this book from our list and
2413
01:53:35,579 --> 01:53:40,920
after that we are trying to get the book
2414
01:53:38,670 --> 01:53:43,409
from our list for that we are getting an
2415
01:53:40,920 --> 01:53:45,510
index out-of-band exception because this
2416
01:53:43,409 --> 01:53:47,939
book no longer exists in our books
2417
01:53:45,510 --> 01:53:50,850
ArrayList what I can do is that I can
2418
01:53:47,939 --> 01:53:52,639
save the name of book before this button
2419
01:53:50,850 --> 01:53:54,810
before this include listener or
2420
01:53:52,640 --> 01:53:58,650
alternatively in here I'm just going to
2421
01:53:54,810 --> 01:54:00,840
say port removed but still it is and in
2422
01:53:58,649 --> 01:54:02,279
here let's say broke removed let's try
2423
01:54:00,840 --> 01:54:03,930
running the application one more time
2424
01:54:02,279 --> 01:54:07,769
and let's see if you still see the
2425
01:54:03,930 --> 01:54:10,800
exception all box activity book activity
2426
01:54:07,770 --> 01:54:13,110
to already read list this time let's try
2427
01:54:10,800 --> 01:54:15,150
to leting this book it seems like we
2428
01:54:13,109 --> 01:54:17,158
have removed the book successfully also
2429
01:54:15,149 --> 01:54:19,619
we have refreshed our recycler
2430
01:54:17,158 --> 01:54:21,988
this empty screen is not a good user
2431
01:54:19,619 --> 01:54:24,000
experience we probably should show some
2432
01:54:21,988 --> 01:54:26,459
text message in case if we don't have
2433
01:54:24,000 --> 01:54:28,649
any book in our list we will fix that
2434
01:54:26,460 --> 01:54:31,380
later on in future videos but for now
2435
01:54:28,649 --> 01:54:34,319
let's go back I also don't like this
2436
01:54:31,380 --> 01:54:36,929
behavior that we are instantly removing
2437
01:54:34,319 --> 01:54:39,479
the book for example in here if we try
2438
01:54:36,929 --> 01:54:42,210
to add a book the user might press this
2439
01:54:39,479 --> 01:54:44,519
delete unwanted leaf for example by
2440
01:54:42,210 --> 01:54:46,679
accident before deleting the book we
2441
01:54:44,520 --> 01:54:48,929
also need to get some confirmation from
2442
01:54:46,679 --> 01:54:51,630
the user I think that creates a better
2443
01:54:48,929 --> 01:54:53,730
user experience so in here after
2444
01:54:51,630 --> 01:54:56,429
clicking on this delete button I'm going
2445
01:54:53,729 --> 01:54:59,339
to show a dialog message to the user and
2446
01:54:56,429 --> 01:55:01,408
I'm going to ask that if he or she is
2447
01:54:59,340 --> 01:55:03,980
sure of deleting this book let's see how
2448
01:55:01,408 --> 01:55:06,179
we can create a dialog so in here before
2449
01:55:07,170 --> 01:55:11,699
I'm going to delete this whole if
2450
01:55:08,969 --> 01:55:14,010
statement and here is how you can create
2451
01:55:11,698 --> 01:55:16,138
the simplest alert dialog you can say
2452
01:55:14,010 --> 01:55:19,079
alert dialog this one that comes from
2453
01:55:16,139 --> 01:55:22,829
and with x-dot app compat let's say that
2454
01:55:19,079 --> 01:55:25,050
builder let's name this builder is equal
2455
01:55:22,829 --> 01:55:27,359
to new other dialogue that builder this
2456
01:55:25,050 --> 01:55:30,960
builder needs a context in which I can't
2457
01:55:27,359 --> 01:55:32,729
ask my am context after that I can set
2458
01:55:30,960 --> 01:55:34,800
some options for this builder for
2459
01:55:32,729 --> 01:55:37,829
example I can set the text let's say
2460
01:55:34,800 --> 01:55:40,560
builder that set message this option and
2461
01:55:37,829 --> 01:55:43,139
in here we need to provide some message
2462
01:55:40,560 --> 01:55:46,289
for example let's say are you sure you
2463
01:55:43,139 --> 01:55:48,270
want to delete this book after that I
2464
01:55:46,289 --> 01:55:51,269
can also set some buttons for my other
2465
01:55:48,270 --> 01:55:53,940
Tyler for example I can say builder that
2466
01:55:51,270 --> 01:55:56,489
set positive button you can see that we
2467
01:55:53,939 --> 01:55:58,710
have negative button and positive button
2468
01:55:56,488 --> 01:56:00,928
for example for the positive button
2469
01:55:58,710 --> 01:56:03,359
that's a yes we also need an onclick
2470
01:56:00,929 --> 01:56:05,399
listener let's say new unclick the snap
2471
01:56:03,359 --> 01:56:07,679
this dialog interface that on click
2472
01:56:05,399 --> 01:56:10,079
listener and what would happen if the
2473
01:56:07,679 --> 01:56:11,699
user press on this yes and here is the
2474
01:56:10,079 --> 01:56:14,698
place that we need to remove the pot
2475
01:56:11,698 --> 01:56:17,698
from our ArrayList I can say if UTL
2476
01:56:14,698 --> 01:56:20,009
start get instance that remove from
2477
01:56:17,698 --> 01:56:22,319
already read let's also pass our book
2478
01:56:20,010 --> 01:56:25,050
groups that get with an index of
2479
01:56:22,319 --> 01:56:27,630
position if that was successful let's
2480
01:56:25,050 --> 01:56:28,670
show a toast message let's say Pope
2481
01:56:28,670 --> 01:56:33,529
after this toast message we also need to
2482
01:56:31,359 --> 01:56:35,929
notify that the data set has been
2483
01:56:33,529 --> 01:56:38,119
changed let's also set a negative button
2484
01:56:35,930 --> 01:56:41,450
for our dialog for example I can say
2485
01:56:38,119 --> 01:56:43,369
builder that set negative button let's
2486
01:56:43,369 --> 01:56:46,550
onclicklistener dialog interface that
2487
01:56:46,550 --> 01:56:50,930
inside this onclick method I am NOT
2488
01:56:48,920 --> 01:56:52,940
going to do anything because I want to
2489
01:56:50,930 --> 01:56:54,079
dismiss the dialog in case if the user
2490
01:56:54,079 --> 01:56:58,100
so we don't need to do anything we just
2491
01:56:56,000 --> 01:57:00,199
need to override this one click method
2492
01:56:58,100 --> 01:57:02,690
let's finish setting a negative button
2493
01:57:00,199 --> 01:57:04,579
after creating your builder after
2494
01:57:02,689 --> 01:57:07,339
setting the message the positive and
2495
01:57:04,579 --> 01:57:09,079
negative button you can create and show
2496
01:57:07,340 --> 01:57:12,440
your builder for example you can say
2497
01:57:09,079 --> 01:57:13,789
builder dot create dot show let's test
2498
01:57:12,439 --> 01:57:15,979
the application and let's see if
2499
01:57:13,789 --> 01:57:18,800
everything works fine let's go to our
2500
01:57:15,979 --> 01:57:21,379
all Box activity let's add a book to our
2501
01:57:18,800 --> 01:57:23,810
already read list and let's try removing
2502
01:57:21,380 --> 01:57:25,699
this book so if I press on this delete
2503
01:57:23,810 --> 01:57:27,710
you can see that we are seeing this
2504
01:57:25,699 --> 01:57:31,069
alert dialog are you sure you want to
2505
01:57:27,710 --> 01:57:32,960
delete 1q84 let's say no as you can see
2506
01:57:31,069 --> 01:57:35,000
even though we didn't write any code
2507
01:57:32,960 --> 01:57:37,460
inside this on click method we have
2508
01:57:35,000 --> 01:57:40,039
dismissed the dialog successfully let's
2509
01:57:37,460 --> 01:57:42,230
press the delete once again and let's
2510
01:57:40,039 --> 01:57:44,449
say yes this time as you can see the
2511
01:57:42,229 --> 01:57:46,579
book has been removed successfully that
2512
01:57:44,449 --> 01:57:49,579
alert Allah creates a much more better
2513
01:57:46,579 --> 01:57:52,130
user experience ok now that we have
2514
01:57:49,579 --> 01:57:54,439
rightt logic for already read books list
2515
01:57:52,130 --> 01:57:56,390
and let's quickly write for the others I
2516
01:57:54,439 --> 01:57:58,399
think I can copy and paste a lot of
2517
01:57:56,390 --> 01:58:00,560
these codes before copying and pasting
2518
01:57:58,399 --> 01:58:03,769
we need to go to our you to its class
2519
01:58:00,560 --> 01:58:06,320
and add some methods for example for
2520
01:58:03,770 --> 01:58:10,030
removing from different lists let's say
2521
01:58:06,319 --> 01:58:13,579
public boolean remove from one to read
2522
01:58:10,029 --> 01:58:17,029
let's also receive a book you can see
2523
01:58:13,579 --> 01:58:19,130
that the logic is exactly the same I'm
2524
01:58:17,029 --> 01:58:21,439
going to cut the process of writing the
2525
01:58:19,130 --> 01:58:23,779
logic for the other two lists you can
2526
01:58:21,439 --> 01:58:26,299
see that it's exactly the same ok now
2527
01:58:23,779 --> 01:58:28,729
let's go back to our adapter class and
2528
01:58:26,300 --> 01:58:32,510
let's copy the logic for T's already
2529
01:58:28,729 --> 01:58:34,428
read case I'm going to paste it for the
2530
01:58:34,429 --> 01:58:38,899
as you can see the code is exactly the
2531
01:58:36,529 --> 01:58:39,559
same we just changed the name of this
2532
01:58:39,560 --> 01:58:45,469
remove from favorites remove from
2533
01:58:42,529 --> 01:58:47,840
currently reading and remove from one to
2534
01:58:45,469 --> 01:58:50,658
read beside that I'm going to create an
2535
01:58:47,840 --> 01:58:53,329
onclicklistener for my different buttons
2536
01:58:50,658 --> 01:58:54,979
in main activity because I'm going to
2537
01:58:53,329 --> 01:58:57,519
navigate the user to each one of the
2538
01:58:54,979 --> 01:59:00,769
activities by clicking on the buttons
2539
01:58:57,520 --> 01:59:03,380
okay let's test our application let's go
2540
01:59:00,770 --> 01:59:05,690
to our all box activity let's add this
2541
01:59:03,380 --> 01:59:07,850
one to a currently reading list we are
2542
01:59:05,689 --> 01:59:10,189
navigating to the currently reading list
2543
01:59:07,850 --> 01:59:12,230
let's try removing this let's say delete
2544
01:59:10,189 --> 01:59:14,479
once again you can see that we are
2545
01:59:12,229 --> 01:59:16,789
seeing the dialogue let's say no this
2546
01:59:14,479 --> 01:59:18,859
time let's say yes it seems like the
2547
01:59:16,789 --> 01:59:21,198
book has been removed successfully if we
2548
01:59:18,859 --> 01:59:23,059
go back and if we check out currently
2549
01:59:21,198 --> 01:59:25,369
reading books you can see that the list
2550
01:59:23,060 --> 01:59:29,020
is a still empty let's quickly try for
2551
01:59:25,369 --> 01:59:32,329
others one to read added successfully
2552
01:59:29,020 --> 01:59:35,270
delete sorry I clicked on the current
2553
01:59:32,329 --> 01:59:38,600
view and not on the delete button let's
2554
01:59:35,270 --> 01:59:40,820
go back and let's try deleting it yes it
2555
01:59:38,600 --> 01:59:43,219
has been deleted successfully see all
2556
01:59:40,819 --> 01:59:46,698
books let's add it to our favorites
2557
01:59:43,219 --> 01:59:49,158
let's try to looking it let's say yes it
2558
01:59:46,698 --> 01:59:51,469
seems like we have an error when we try
2559
01:59:49,158 --> 01:59:54,019
to delete a book from our favorite lists
2560
01:59:51,469 --> 01:59:55,969
if we open our locket you can see that
2561
01:59:54,020 --> 01:59:59,900
something wrong is happening inside our
2562
01:59:55,969 --> 02:00:02,600
UTS class at 9 116 and yes this is the
2563
01:59:59,899 --> 02:00:04,908
error in here instead of removing the
2564
02:00:04,908 --> 02:00:10,279
I have recalled this method sorry about
2565
02:00:07,460 --> 02:00:13,429
that let's say favorites don't remove
2566
02:00:10,279 --> 02:00:16,519
let's try it once again let's add a book
2567
02:00:13,429 --> 02:00:19,908
to our favorites list and let's try
2568
02:00:16,520 --> 02:00:22,190
removing it let's say yes it seems like
2569
02:00:19,908 --> 02:00:23,929
it has been deleted successfully okay I
2570
02:00:22,189 --> 02:00:25,669
think that's enough for this video in
2571
02:00:23,929 --> 02:00:27,710
the next video we are going to see how
2572
02:00:25,670 --> 02:00:29,960
we can show a website in Android
2573
02:00:27,710 --> 02:00:32,079
applications ok see you in the next
2574
02:00:34,109 --> 02:00:38,459
in this video we are going to work on
2575
02:00:36,479 --> 02:00:39,749
this about button by clicking on this
2576
02:00:38,458 --> 02:00:42,328
button we are going to show some
2577
02:00:39,748 --> 02:00:44,309
dialogue in which inside that dialogue
2578
02:00:42,328 --> 02:00:46,408
we are going to show some detail about
2579
02:00:44,309 --> 02:00:48,659
the developer of this application and
2580
02:00:46,408 --> 02:00:51,509
also the application itself beside that
2581
02:00:48,658 --> 02:00:53,938
we are going to give the offer to check
2582
02:00:51,510 --> 02:00:56,099
our website by clicking on a button the
2583
02:00:53,939 --> 02:00:57,809
user will be navigated to our website
2584
02:00:56,099 --> 02:01:00,328
let's quickly see how we can implement
2585
02:00:57,809 --> 02:01:02,099
that for showing the dialog like the
2586
02:01:00,328 --> 02:01:04,408
previous video we can use the alert
2587
02:01:02,099 --> 02:01:06,628
dialog we are going to use that in here
2588
02:01:04,408 --> 02:01:08,788
but I also need to say that you have
2589
02:01:06,628 --> 02:01:11,849
other options as well for example you
2590
02:01:08,788 --> 02:01:13,800
can create your own customized dialog we
2591
02:01:11,849 --> 02:01:15,149
will talk about customized dialogue
2592
02:01:13,800 --> 02:01:17,609
later on in the course when we talk
2593
02:01:15,149 --> 02:01:20,039
about fragments but in here we are just
2594
02:01:17,609 --> 02:01:21,809
going to show a simple alert dialog okay
2595
02:01:20,038 --> 02:01:23,788
let's go to main activity and let's
2596
02:01:21,809 --> 02:01:26,939
implement that functionality that I was
2597
02:01:23,788 --> 02:01:29,158
just talking about so down in here
2598
02:01:26,939 --> 02:01:31,109
inside on create method I can say
2599
02:01:32,069 --> 02:01:37,408
let's say neon click listener we need to
2600
02:01:35,338 --> 02:01:39,958
create our alert dialog that builder
2601
02:01:37,408 --> 02:01:42,448
object in here once again I'm using the
2602
02:01:39,958 --> 02:01:45,208
Android X artifacts so import the right
2603
02:01:42,448 --> 02:01:48,478
one let's say other dialog dot builder
2604
02:01:45,208 --> 02:01:50,668
let's name it builder is equal to neon a
2605
02:01:48,479 --> 02:01:52,530
dialog that builder you know that we
2606
02:01:50,668 --> 02:01:54,238
need to pass a context in here because
2607
02:01:52,529 --> 02:01:56,578
we are inside the main activity inside
2608
02:01:54,238 --> 02:01:57,178
this interface we can pass main activity
2609
02:01:57,179 --> 02:02:02,309
after that we can set a title for our
2610
02:01:59,878 --> 02:02:05,368
other dialogue builder we can say
2611
02:02:02,309 --> 02:02:07,439
builder dot set title I believe is the
2612
02:02:05,368 --> 02:02:09,509
name of the method let's pass the name
2613
02:02:07,439 --> 02:02:12,780
of our application I can say get the
2614
02:02:09,510 --> 02:02:15,510
strings let's say our dot string dot add
2615
02:02:12,779 --> 02:02:19,099
name after that I can say builder touch
2616
02:02:15,510 --> 02:02:21,958
set message and let's provide a message
2617
02:02:19,099 --> 02:02:23,788
that's going to be our text and after
2618
02:02:21,958 --> 02:02:26,729
that we are going to set two buttons for
2619
02:02:23,788 --> 02:02:29,518
our dialog so let's say builder that's
2620
02:02:26,729 --> 02:02:31,760
at negative button for the negative
2621
02:02:29,519 --> 02:02:33,958
button I am going to say dismiss and
2622
02:02:31,760 --> 02:02:36,958
after that we need an onclick listener
2623
02:02:33,958 --> 02:02:38,479
so I have a toy point here let's say
2624
02:02:38,479 --> 02:02:43,409
dialog interface that include listener
2625
02:02:40,979 --> 02:02:44,878
once again inside this onclick method we
2626
02:02:43,408 --> 02:02:47,038
are not going to do anything because we
2627
02:02:44,878 --> 02:02:47,609
are going to dismiss the dialog we just
2628
02:02:47,609 --> 02:02:51,539
implement this onclick method after that
2629
02:02:49,800 --> 02:02:53,909
let's set a positive button for our
2630
02:02:51,539 --> 02:02:57,600
dialog let's say builder that said
2631
02:02:53,908 --> 02:03:00,448
positive button let's say visit neon
2632
02:02:57,600 --> 02:03:02,550
click listener and by clicking on this
2633
02:03:00,448 --> 02:03:05,368
visit text we are going to navigate the
2634
02:03:02,550 --> 02:03:07,079
user to our website for now let's just
2635
02:03:05,368 --> 02:03:11,009
add it to do in here we will do that
2636
02:03:07,079 --> 02:03:13,050
later on after creating the dialog we
2637
02:03:11,010 --> 02:03:16,350
can show it we can say Bueller that
2638
02:03:13,050 --> 02:03:18,360
creates that job also before I run my
2639
02:03:16,350 --> 02:03:20,219
application I am going to say that you
2640
02:03:18,359 --> 02:03:21,899
have all sorts of functionalities with
2641
02:03:20,219 --> 02:03:24,000
this builder for example if you take a
2642
02:03:21,899 --> 02:03:25,618
look at the available methods you can
2643
02:03:24,000 --> 02:03:28,770
see that you have all sorts of options
2644
02:03:25,618 --> 02:03:32,519
for example you can set an icon for your
2645
02:03:28,770 --> 02:03:34,889
dialog beside that you can set that if
2646
02:03:32,520 --> 02:03:37,290
your dialogue is cancelable or not by
2647
02:03:34,889 --> 02:03:39,389
saying set cancelable let's say that
2648
02:03:37,289 --> 02:03:41,279
cancelable this one you can pass a
2649
02:03:39,389 --> 02:03:43,770
boolean if the dialogue is not
2650
02:03:41,279 --> 02:03:45,988
cancelable the user cannot dismiss the
2651
02:03:43,770 --> 02:03:48,389
dialog unless and he or she clicks on
2652
02:03:45,988 --> 02:03:50,399
one of our buttons I'm not going to talk
2653
02:03:48,389 --> 02:03:53,130
more about these functionalities in here
2654
02:03:50,399 --> 02:03:54,750
because when we talk about customized
2655
02:03:53,130 --> 02:03:56,100
dialogue later on in the course you can
2656
02:03:56,100 --> 02:03:59,789
functionalities ok let's run the
2657
02:03:58,198 --> 02:04:02,250
application and let's see if we can see
2658
02:03:59,789 --> 02:04:04,889
this toyline let's click on this about
2659
02:04:02,250 --> 02:04:06,840
button right now I can only see this
2660
02:04:04,889 --> 02:04:09,090
visit button and that's because I've
2661
02:04:06,840 --> 02:04:11,250
made a mistake in here both of my
2662
02:04:09,090 --> 02:04:13,350
unclick listeners are for this set
2663
02:04:11,250 --> 02:04:16,590
negative button I need to change this
2664
02:04:13,350 --> 02:04:18,329
one to set positive button sorry about
2665
02:04:16,590 --> 02:04:20,310
that let's run the application one more
2666
02:04:18,329 --> 02:04:22,590
time once again let's click on this
2667
02:04:20,310 --> 02:04:25,050
about button this time you can see both
2668
02:04:22,590 --> 02:04:28,020
of the options also if you don't get my
2669
02:04:25,050 --> 02:04:30,150
point about being cancelable cancelable
2670
02:04:28,020 --> 02:04:32,310
means that if you click on anywhere
2671
02:04:30,149 --> 02:04:35,039
outside of the dialog for example in
2672
02:04:32,310 --> 02:04:36,840
here your dialogue will be cancelled if
2673
02:04:35,039 --> 02:04:39,329
you set your dialogue to not to be
2674
02:04:36,840 --> 02:04:41,819
cancelable you cannot cancel it by
2675
02:04:39,329 --> 02:04:43,859
clicking on anywhere on the screen you
2676
02:04:41,819 --> 02:04:46,229
just need to click on the dismiss button
2677
02:04:43,859 --> 02:04:48,658
ok let's also try this dismiss in here
2678
02:04:46,229 --> 02:04:50,939
we can dismiss our dialogue successfully
2679
02:04:48,658 --> 02:04:53,339
and by clicking on this visit button
2680
02:04:50,939 --> 02:04:54,988
because right now we don't have any code
2681
02:04:53,340 --> 02:04:55,529
once again our dialogue should be
2682
02:04:55,529 --> 02:05:00,840
ok let's write the code to navigate the
2683
02:04:58,260 --> 02:05:02,699
user to our website in order to navigate
2684
02:05:00,840 --> 02:05:05,369
the user to my website I'm going to
2685
02:05:02,699 --> 02:05:08,250
create another activity in my package in
2686
02:05:05,369 --> 02:05:11,670
Java folder in my package let's say new
2687
02:05:08,250 --> 02:05:15,060
activity empty activity let's name this
2688
02:05:11,670 --> 02:05:17,670
activity website activity in the layout
2689
02:05:15,060 --> 02:05:20,310
file of this activity I am going to put
2690
02:05:17,670 --> 02:05:22,199
only one element and that element is
2691
02:05:20,310 --> 02:05:24,600
going to be a webview let's search for
2692
02:05:22,199 --> 02:05:27,000
webview in here you can see that we have
2693
02:05:24,600 --> 02:05:29,220
this webview option let's drag that and
2694
02:05:27,000 --> 02:05:32,189
let's change its bits and height to a
2695
02:05:29,220 --> 02:05:35,000
match parent let's also give it an ID
2696
02:05:32,189 --> 02:05:37,439
I'm going to simply call it webview
2697
02:05:35,000 --> 02:05:39,989
that's all we need in here let's switch
2698
02:05:37,439 --> 02:05:42,839
back to our Java file and in here let's
2699
02:05:39,989 --> 02:05:45,269
initialize our webview I'm going to
2700
02:05:42,840 --> 02:05:47,850
define my web view as a member variable
2701
02:05:45,270 --> 02:05:50,310
as a private member variable inside this
2702
02:05:47,850 --> 02:05:54,660
activity and you will see why I am doing
2703
02:05:50,310 --> 02:05:57,210
this let's say private that view let's
2704
02:05:54,659 --> 02:05:58,889
name it web view down in here inside on
2705
02:05:57,210 --> 02:06:01,649
create method let's initialize that
2706
02:05:58,890 --> 02:06:05,910
let's say webview is equal to find V by
2707
02:06:01,649 --> 02:06:08,489
ID or that ID dot webview after that we
2708
02:06:05,909 --> 02:06:10,920
can pass a URL to this web view for
2709
02:06:08,489 --> 02:06:14,519
example if we want to show Google we can
2710
02:06:10,920 --> 02:06:17,399
save web view dot load load URL and we
2711
02:06:14,520 --> 02:06:21,180
can pass our URL let's pass the URL of
2712
02:06:17,399 --> 02:06:23,219
google.com and from the positive button
2713
02:06:21,180 --> 02:06:25,500
of our dialog let's navigate to this
2714
02:06:23,220 --> 02:06:29,550
website activity in here I can say
2715
02:06:25,500 --> 02:06:31,560
intent intent is equal to new intent for
2716
02:06:29,550 --> 02:06:33,930
the context let's fast main activity
2717
02:06:31,560 --> 02:06:36,810
that this for the destination website
2718
02:06:33,930 --> 02:06:38,909
activity dot class and we don't meet any
2719
02:06:36,810 --> 02:06:42,150
flag in here let's just say start
2720
02:06:38,909 --> 02:06:43,979
activity and let's pass our intent let's
2721
02:06:42,149 --> 02:06:46,710
run the application and that's if we can
2722
02:06:43,979 --> 02:06:48,779
load Google successfully let's click on
2723
02:06:46,710 --> 02:06:51,090
this visit as you can see we are
2724
02:06:48,779 --> 02:06:53,309
navigating to another activity but we
2725
02:06:51,090 --> 02:06:56,369
are not seeing google.com and that's
2726
02:06:53,310 --> 02:06:59,460
because in the URL we need to say HTTPS
2727
02:06:56,369 --> 02:07:01,769
because Google has SSL certification so
2728
02:06:59,460 --> 02:07:04,439
let's quickly modify our URL in our
2729
02:07:01,770 --> 02:07:06,720
website activity instead of HTTP I'm
2730
02:07:04,439 --> 02:07:07,979
going to say HTTPS let's run the
2731
02:07:07,979 --> 02:07:12,099
let's click on this about let's try
2732
02:07:12,100 --> 02:07:16,390
as you can see another application has
2733
02:07:14,260 --> 02:07:18,670
been opened in this case we are opening
2734
02:07:16,390 --> 02:07:21,190
Chrome because Chrome is the default
2735
02:07:18,670 --> 02:07:23,079
browser in this emulator this is good
2736
02:07:21,189 --> 02:07:25,029
but you can do better you can open the
2737
02:07:23,079 --> 02:07:27,159
website in your own application and
2738
02:07:25,029 --> 02:07:29,739
don't send the user to another browser
2739
02:07:27,159 --> 02:07:32,319
in order to do that you need to set a
2740
02:07:29,739 --> 02:07:34,239
webview client on your webview let's
2741
02:07:32,319 --> 02:07:37,059
quickly see how we can do that so in
2742
02:07:34,239 --> 02:07:39,880
here I can save fu that's that webview
2743
02:07:37,060 --> 02:07:43,090
client this one and we need to pass a
2744
02:07:39,880 --> 02:07:45,880
new webview client near webview client
2745
02:07:43,090 --> 02:07:48,279
this time if we run our application we
2746
02:07:45,880 --> 02:07:50,109
should open the google.com in our
2747
02:07:48,279 --> 02:07:54,189
application and not in another browser
2748
02:07:50,109 --> 02:07:56,229
about visit you can see that this time
2749
02:07:54,189 --> 02:07:58,089
we are inside our own application you
2750
02:07:56,229 --> 02:08:00,579
can see the name of application above in
2751
02:07:58,090 --> 02:08:02,710
here let's try searching something in
2752
02:08:00,579 --> 02:08:06,250
here for example let's try searching for
2753
02:08:02,710 --> 02:08:08,319
Android if we try to go back one page
2754
02:08:06,250 --> 02:08:10,659
right now if you press on this back
2755
02:08:08,319 --> 02:08:12,819
button we are going to go back to the
2756
02:08:10,659 --> 02:08:15,250
main activity this is not a good user
2757
02:08:12,819 --> 02:08:18,189
experience you may want to navigate the
2758
02:08:15,250 --> 02:08:20,140
user one page back and not destroy the
2759
02:08:18,189 --> 02:08:22,149
whole activity if you want to do that
2760
02:08:20,140 --> 02:08:24,400
you can overwrite the on back rest
2761
02:08:22,149 --> 02:08:27,369
method in here by pressing ctrl or and
2762
02:08:24,399 --> 02:08:28,929
searching for on back press we have seen
2763
02:08:27,369 --> 02:08:30,729
this method in previous videos
2764
02:08:28,930 --> 02:08:33,010
let's overwrite that and we need to do
2765
02:08:30,729 --> 02:08:35,169
some modifications in here and here is
2766
02:08:33,010 --> 02:08:37,630
the reason why I've defined this webview
2767
02:08:35,170 --> 02:08:39,699
as a member variable because I want to
2768
02:08:37,630 --> 02:08:41,890
have access to this method inside both
2769
02:08:39,699 --> 02:08:44,019
on back press method and also on create
2770
02:08:41,890 --> 02:08:48,369
method so what I can do in here is that
2771
02:08:44,020 --> 02:08:50,380
I can say if webview dot can go back
2772
02:08:48,369 --> 02:08:53,109
this method you can see that the return
2773
02:08:50,380 --> 02:08:57,100
type is a boolean if our web you can go
2774
02:08:53,109 --> 02:08:59,289
back let's say webview dot go back but
2775
02:08:57,100 --> 02:09:01,329
in the else case we are going to do the
2776
02:08:59,289 --> 02:09:03,880
super statement so I'm going to cut this
2777
02:09:01,329 --> 02:09:05,949
one and I'm going to put it inside this
2778
02:09:03,880 --> 02:09:07,960
else case this in here means that
2779
02:09:05,949 --> 02:09:11,529
whenever we are pressing the back button
2780
02:09:07,960 --> 02:09:14,050
if our web you can go back one page then
2781
02:09:11,529 --> 02:09:16,000
go back but if not do whatever you are
2782
02:09:14,050 --> 02:09:18,310
doing with your back button for example
2783
02:09:16,000 --> 02:09:21,760
destroyed activity and go to your main
2784
02:09:18,310 --> 02:09:23,480
activity let's try this let's visit
2785
02:09:23,479 --> 02:09:28,779
and let's search for something for
2786
02:09:25,729 --> 02:09:31,699
example may code this time if we go back
2787
02:09:28,779 --> 02:09:33,738
you can see that we are going back one
2788
02:09:31,699 --> 02:09:35,869
page and we are not destroying the whole
2789
02:09:33,738 --> 02:09:38,419
activity there is also one more thing
2790
02:09:35,869 --> 02:09:40,460
that you can enable on your webview you
2791
02:09:38,420 --> 02:09:42,649
can enable JavaScript if you want on
2792
02:09:40,460 --> 02:09:44,810
your webview as well most modern web
2793
02:09:42,649 --> 02:09:47,299
sites use javascript and you can enable
2794
02:09:44,810 --> 02:09:51,560
it in here if you want you can save web
2795
02:09:47,300 --> 02:09:53,960
view dot get settings this one dot set
2796
02:09:51,560 --> 02:09:56,030
JavaScript enabled this method you can
2797
02:09:53,960 --> 02:09:58,100
pass true or false in here for example
2798
02:09:56,029 --> 02:10:00,079
let's pass true but you can see that as
2799
02:09:58,100 --> 02:10:02,600
soon as I pass through I'm getting a
2800
02:10:00,079 --> 02:10:05,269
warning the warning says that enabling
2801
02:10:02,600 --> 02:10:07,100
JavaScript is a security issue and it
2802
02:10:05,270 --> 02:10:10,010
can cause vulnerabilities to your
2803
02:10:07,100 --> 02:10:11,810
application so enable it carefully okay
2804
02:10:10,010 --> 02:10:13,699
now that we have enabled JavaScript
2805
02:10:11,810 --> 02:10:15,410
let's try running our application one
2806
02:10:13,699 --> 02:10:17,090
more time and let's see if we can see
2807
02:10:15,409 --> 02:10:20,359
any difference we shouldn't see any
2808
02:10:17,090 --> 02:10:21,980
difference about visit you can see
2809
02:10:20,359 --> 02:10:24,079
Google in here and you can search for
2810
02:10:21,979 --> 02:10:26,329
whatever you want when you are using
2811
02:10:24,079 --> 02:10:28,488
webview in your application you have all
2812
02:10:26,329 --> 02:10:31,100
sorts of functionalities in fact a lot
2813
02:10:28,488 --> 02:10:33,559
of applications are based on web view
2814
02:10:31,100 --> 02:10:35,090
they are basically some website and they
2815
02:10:33,560 --> 02:10:37,310
are showing some webview in their
2816
02:10:35,090 --> 02:10:39,739
application so if you want to dig into
2817
02:10:37,310 --> 02:10:41,420
that area make sure to learn webview
2818
02:10:39,738 --> 02:10:43,639
well you'll have all sorts of options
2819
02:10:41,420 --> 02:10:45,529
when you are working with webview but in
2820
02:10:43,640 --> 02:10:47,390
this course we are going to use a web
2821
02:10:45,529 --> 02:10:50,090
view this much and we are not going to
2822
02:10:47,390 --> 02:10:52,850
go further in here I'm going to make my
2823
02:10:50,090 --> 02:10:55,039
website activity reusable because I may
2824
02:10:52,850 --> 02:10:57,380
want to show different websites in my
2825
02:10:55,039 --> 02:10:59,390
application for that I'm going to get an
2826
02:10:57,380 --> 02:11:02,270
intent in here and I'm going to receive
2827
02:10:59,390 --> 02:11:04,369
the URL with that intent so that I can
2828
02:11:02,270 --> 02:11:05,870
show multiple websites so before
2829
02:11:05,869 --> 02:11:11,510
instantiating it let's get the intent
2830
02:11:08,350 --> 02:11:12,920
let's say intent is equal to get intent
2831
02:11:12,920 --> 02:11:17,750
after that let's make sure that our
2832
02:11:14,960 --> 02:11:21,050
intent is not null so let's say if not
2833
02:11:17,750 --> 02:11:24,380
is not equal to our intent let's receive
2834
02:11:21,050 --> 02:11:28,190
the URL let's say a string URL is equal
2835
02:11:24,380 --> 02:11:30,619
to intent that get a string extra this
2836
02:11:28,189 --> 02:11:33,349
method and let's pass a key for example
2837
02:11:30,619 --> 02:11:35,920
let's say URL let's move this logic to
2838
02:11:35,920 --> 02:11:40,750
then I'm going to pass this URL to this
2839
02:11:38,529 --> 02:11:43,210
load URL method so instead of this
2840
02:11:40,750 --> 02:11:45,189
hard-coded text I'm going to pass URL
2841
02:11:43,210 --> 02:11:48,520
next in different part of my application
2842
02:11:45,189 --> 02:11:50,859
when I create an intent and navigate the
2843
02:11:48,520 --> 02:11:53,650
user to this website activity I am going
2844
02:11:50,859 --> 02:11:55,719
to also provide a URL for example in
2845
02:11:53,649 --> 02:11:58,119
here inside this onclick method of our
2846
02:11:55,719 --> 02:12:01,480
dialog before starting the activity I'm
2847
02:11:58,119 --> 02:12:03,849
going to say intent dot set extra or put
2848
02:12:01,479 --> 02:12:07,589
extra was the name of the method let's
2849
02:12:03,850 --> 02:12:10,870
say URL for the key and let's pass URL
2850
02:12:07,590 --> 02:12:13,029
let's remove this to do from here as a
2851
02:12:10,869 --> 02:12:15,909
suggestion in your application in your
2852
02:12:13,029 --> 02:12:17,920
blog activity you may want to provide a
2853
02:12:15,909 --> 02:12:20,738
link for more information about your
2854
02:12:17,920 --> 02:12:23,230
book let's quickly go to activity block
2855
02:12:20,738 --> 02:12:25,119
dot XML for example somewhere in this
2856
02:12:23,229 --> 02:12:27,099
layout you may provide a link for your
2857
02:12:25,119 --> 02:12:29,679
book for that you also need to change
2858
02:12:27,100 --> 02:12:32,440
the model of your book and provide a URL
2859
02:12:29,679 --> 02:12:34,179
for that and navigate the user to some
2860
02:12:32,439 --> 02:12:36,399
website if you want to give the user
2861
02:12:34,179 --> 02:12:37,600
some more functionalities but we are not
2862
02:12:36,399 --> 02:12:39,670
going to do that in here together
2863
02:12:37,600 --> 02:12:41,770
because that's really simple and I
2864
02:12:39,670 --> 02:12:43,449
believe you can do it by yourself ok I
2865
02:12:41,770 --> 02:12:45,940
think that's enough for this video it
2866
02:12:43,448 --> 02:12:47,799
was a relatively short video in the next
2867
02:12:45,939 --> 02:12:50,289
video we are going to see how we can
2868
02:12:47,800 --> 02:12:52,079
define some animations for example right
2869
02:12:50,289 --> 02:12:55,600
now when we navigate between different
2870
02:12:52,079 --> 02:12:57,939
activities we only have a basic pop-up
2871
02:12:55,600 --> 02:12:59,469
animation in the next video we are going
2872
02:12:57,939 --> 02:13:01,389
to see how we can create a better
2873
02:12:59,469 --> 02:13:03,850
animation for navigating between
2874
02:13:01,390 --> 02:13:04,130
different activities see you in the next
2875
02:13:09,988 --> 02:13:14,308
talk about animations in Android and
2876
02:13:12,179 --> 02:13:16,800
also beside that we will talk about how
2877
02:13:14,309 --> 02:13:19,260
to enable the UP button to be honest
2878
02:13:16,800 --> 02:13:21,510
with you we are not going to focus on
2879
02:13:19,260 --> 02:13:23,639
animations that much yet in the course
2880
02:13:21,510 --> 02:13:25,349
and after this video you will know my
2881
02:13:23,639 --> 02:13:27,420
reason okay let's see how we can
2882
02:13:25,349 --> 02:13:29,760
implement a simple animation in our
2883
02:13:27,420 --> 02:13:31,859
application for navigating between
2884
02:13:29,760 --> 02:13:34,380
different activities in order to create
2885
02:13:31,859 --> 02:13:36,960
a simple animation file in our project
2886
02:13:34,380 --> 02:13:38,969
inside app folder inside the resources
2887
02:13:36,960 --> 02:13:41,158
folder we can create any resources
2888
02:13:38,969 --> 02:13:43,498
directory by clicking on this new
2889
02:13:41,158 --> 02:13:45,988
Android resource directory from this
2890
02:13:43,498 --> 02:13:48,210
resource type we can select any the
2891
02:13:45,988 --> 02:13:50,038
first option in our list let's keep the
2892
02:13:48,210 --> 02:13:52,019
name anning and let's create our
2893
02:13:50,038 --> 02:13:53,849
resource directory now if you take a
2894
02:13:52,019 --> 02:13:55,889
look at your resources you can see this
2895
02:13:53,849 --> 02:13:58,170
einem folder by right-clicking on that
2896
02:13:55,889 --> 02:14:00,300
you can create a new animation resource
2897
02:13:58,170 --> 02:14:03,868
file I'm going to name this file a
2898
02:14:00,300 --> 02:14:05,849
slide-in let's create our file you can
2899
02:14:03,868 --> 02:14:08,429
see that the root element right now is
2900
02:14:05,849 --> 02:14:10,889
this set basically set means a set of
2901
02:14:08,429 --> 02:14:13,230
different animations for example you may
2902
02:14:10,889 --> 02:14:15,210
have a horizontal animation beside that
2903
02:14:13,229 --> 02:14:17,218
you may want to have a rotation
2904
02:14:15,210 --> 02:14:19,529
animation you can include them all
2905
02:14:17,219 --> 02:14:21,929
inside this set but in here we are only
2906
02:14:19,529 --> 02:14:24,059
going to implement one animation and
2907
02:14:21,929 --> 02:14:26,069
because of that I'm going to change this
2908
02:14:24,059 --> 02:14:28,829
root element I'm going to change it to
2909
02:14:26,069 --> 02:14:31,498
translate whenever you want to have a
2910
02:14:28,828 --> 02:14:33,538
simple horizontal or vertical animation
2911
02:14:31,498 --> 02:14:35,998
you can use this translate in this
2912
02:14:33,538 --> 02:14:37,889
application we are going to slide our
2913
02:14:35,998 --> 02:14:39,868
activity to the next activity
2914
02:14:37,889 --> 02:14:41,670
so in here we need a horizontal
2915
02:14:39,868 --> 02:14:44,248
animation let's see some of the
2916
02:14:41,670 --> 02:14:45,960
attributes on this translate element the
2917
02:14:44,248 --> 02:14:49,469
first one that I'm going to talk about
2918
02:14:45,960 --> 02:14:51,448
in here is called from X Delta this one
2919
02:14:49,469 --> 02:14:53,788
you can see that similar to that we have
2920
02:14:51,448 --> 02:14:55,649
this from void lttle you can guess the
2921
02:14:53,788 --> 02:14:58,288
meaning of each one of these when we use
2922
02:14:55,649 --> 02:15:00,359
the first one from X Delta it means that
2923
02:14:58,288 --> 02:15:02,639
we are going to define the horizontal
2924
02:15:00,359 --> 02:15:04,799
place of our animation where do we want
2925
02:15:02,639 --> 02:15:08,099
to start our animation in a horizontal
2926
02:15:04,800 --> 02:15:10,079
axis so let's say from X Delta in here
2927
02:15:08,099 --> 02:15:12,659
you need to define the first horizontal
2928
02:15:10,078 --> 02:15:15,538
place of your application for example
2929
02:15:12,658 --> 02:15:17,518
you can pass 0 pixel this is just a
2930
02:15:15,538 --> 02:15:19,228
normal pixel and it's going to be
2931
02:15:17,519 --> 02:15:22,860
started from the beginning of your
2932
02:15:19,229 --> 02:15:23,880
screen besides 0 you can pass 0% which
2933
02:15:23,880 --> 02:15:28,409
from the beginning of your element from
2934
02:15:26,729 --> 02:15:29,039
the beginning of the beats of your
2935
02:15:29,039 --> 02:15:33,029
so this percent in here means relative
2936
02:15:33,029 --> 02:15:38,460
if you pass percent P you are going to
2937
02:15:35,670 --> 02:15:40,920
start your animation from the zero pixel
2938
02:15:38,460 --> 02:15:43,020
relative to the parent of your element
2939
02:15:40,920 --> 02:15:45,180
not to the Viets of the element so for
2940
02:15:43,020 --> 02:15:47,280
example if we have a button that we are
2941
02:15:45,180 --> 02:15:49,710
going to apply this animation on that
2942
02:15:47,279 --> 02:15:52,199
this zero percent P in here means that
2943
02:15:49,710 --> 02:15:54,960
we are going to start our animation from
2944
02:15:52,199 --> 02:15:56,939
the beginning of its parent layout you
2945
02:15:54,960 --> 02:15:59,880
can enter any number that you want in
2946
02:15:56,939 --> 02:16:02,039
here from 0 to 100 beside that you can
2947
02:15:59,880 --> 02:16:04,739
also enter negative numbers for example
2948
02:16:02,039 --> 02:16:06,689
in here I am going to say negative 100
2949
02:16:04,739 --> 02:16:09,149
the next attribute that we are going to
2950
02:16:06,689 --> 02:16:11,159
take a look at in here is called 2x
2951
02:16:09,149 --> 02:16:13,859
Delta once again you can see that we
2952
02:16:11,159 --> 02:16:15,989
have two attributes 2x Delta and two Y
2953
02:16:13,859 --> 02:16:18,989
Delta you probably can guess their
2954
02:16:15,989 --> 02:16:21,899
meaning 2x Delta means the destination
2955
02:16:18,989 --> 02:16:24,300
in the x axis and two Y Delta is the
2956
02:16:21,899 --> 02:16:26,939
destination in the y axis mean here we
2957
02:16:24,300 --> 02:16:29,460
are just going to slide our activity so
2958
02:16:26,939 --> 02:16:31,500
we are going to use this 2x Delta you
2959
02:16:29,460 --> 02:16:35,309
can put whatever number that you want in
2960
02:16:31,500 --> 02:16:37,799
here but I'm going to say 0% P beside
2961
02:16:35,309 --> 02:16:40,019
these two you can also define a duration
2962
02:16:37,799 --> 02:16:43,109
for your animation as well for example
2963
02:16:40,020 --> 02:16:45,030
in here we can say duration you can see
2964
02:16:43,110 --> 02:16:47,310
that it's not working you can type it
2965
02:16:45,030 --> 02:16:51,120
manually you can say Android column
2966
02:16:47,309 --> 02:16:53,638
duration that's is equal to and we need
2967
02:16:51,120 --> 02:16:55,679
to pass our duration in milliseconds
2968
02:16:53,638 --> 02:16:57,750
inside these double quotations for
2969
02:16:55,679 --> 02:17:00,659
example I want to set the duration of my
2970
02:16:57,750 --> 02:17:02,370
animation to 1000 milliseconds so to
2971
02:17:00,659 --> 02:17:04,829
have a quick review in here our
2972
02:17:02,370 --> 02:17:07,679
animation is going to start from the
2973
02:17:04,829 --> 02:17:10,379
negative 100 pixel relative to the
2974
02:17:07,679 --> 02:17:13,138
parent layout and we are going to end in
2975
02:17:10,379 --> 02:17:15,509
the zero percent relative to the parent
2976
02:17:13,138 --> 02:17:17,699
inside the x-axis and the whole
2977
02:17:15,510 --> 02:17:19,649
animation is going to take one second
2978
02:17:17,700 --> 02:17:21,840
let's quickly create another animation
2979
02:17:19,649 --> 02:17:23,909
as well once again by right-clicking on
2980
02:17:21,840 --> 02:17:26,159
our animation folder that's a new
2981
02:17:23,909 --> 02:17:28,299
animation resource file let's name this
2982
02:17:28,299 --> 02:17:31,988
I think we can change the root element
2983
02:17:30,068 --> 02:17:34,299
from here and smell let's change this
2984
02:17:31,988 --> 02:17:37,090
one to translate and let's create our
2985
02:17:34,299 --> 02:17:39,368
XML file for this translate element I'm
2986
02:17:37,090 --> 02:17:41,228
going to define the same attributes but
2987
02:17:39,369 --> 02:17:43,510
I'm going to change their values for
2988
02:17:41,228 --> 02:17:47,228
example I'm going to say from X Delta
2989
02:17:43,510 --> 02:17:50,170
this time I'm going to pass 0% P let's
2990
02:17:47,228 --> 02:17:54,010
say 2x Delta this time let's pass
2991
02:17:50,170 --> 02:17:55,960
negative 100% DP or 100% peace sorry
2992
02:17:54,010 --> 02:17:59,710
about that and let's also define the
2993
02:17:55,959 --> 02:18:01,988
duration and rate column duration once
2994
02:17:59,709 --> 02:18:04,509
again let's say 1000 milliseconds okay
2995
02:18:01,988 --> 02:18:06,908
now we have two different XML files for
2996
02:18:04,510 --> 02:18:09,369
our animations how do we implement them
2997
02:18:06,908 --> 02:18:11,260
in our activities here is how you can do
2998
02:18:09,369 --> 02:18:14,170
that for example let's go to our all
2999
02:18:11,260 --> 02:18:16,478
books activity inside the oncreate
3000
02:18:14,170 --> 02:18:18,638
method of this activity before
3001
02:18:16,478 --> 02:18:20,738
everything we can say overwrite pending
3002
02:18:18,638 --> 02:18:23,318
transition you can see that this is an
3003
02:18:20,738 --> 02:18:26,019
inner method inside every activity this
3004
02:18:23,318 --> 02:18:28,269
method requires two animation files the
3005
02:18:26,019 --> 02:18:30,789
first one is the inter animation and the
3006
02:18:28,269 --> 02:18:32,800
second one is the exit animation let's
3007
02:18:30,789 --> 02:18:35,649
provide them for the first one I'm going
3008
02:18:32,799 --> 02:18:38,318
to say our thoughts annum dot let's say
3009
02:18:35,648 --> 02:18:41,978
slide in for the second one I'm going to
3010
02:18:38,318 --> 02:18:43,840
say our that einem dot slide out let's
3011
02:18:41,978 --> 02:18:46,448
run our application and let's see what
3012
02:18:43,840 --> 02:18:48,849
our animation looks like if we try to go
3013
02:18:46,449 --> 02:18:51,729
to all box activity you should see the
3014
02:18:48,849 --> 02:18:54,068
animation it's not that pretty but it is
3015
02:18:51,728 --> 02:18:56,198
what we created but in here if I try to
3016
02:18:54,068 --> 02:18:58,179
go back for example by pressing this
3017
02:18:56,199 --> 02:19:00,789
back button you can see that we are
3018
02:18:58,179 --> 02:19:03,250
still seeing the default animation if we
3019
02:19:00,789 --> 02:19:05,439
want to apply our own animation we can
3020
02:19:03,250 --> 02:19:07,599
do something like this in our activity
3021
02:19:05,439 --> 02:19:10,719
we can override a method by pressing
3022
02:19:07,599 --> 02:19:12,609
ctrl + o or alternatively by typing the
3023
02:19:10,718 --> 02:19:14,589
name of the method we can override that
3024
02:19:12,609 --> 02:19:16,719
method the name of this method is
3025
02:19:14,590 --> 02:19:18,609
finished so this method is going to be
3026
02:19:16,718 --> 02:19:21,728
called whenever we are going to finish
3027
02:19:18,609 --> 02:19:23,949
our activity let's call that after the
3028
02:19:21,728 --> 02:19:26,288
super statement once again we can use
3029
02:19:23,949 --> 02:19:28,420
this override pending transition let's
3030
02:19:26,289 --> 02:19:30,159
say overwrite pending transition this
3031
02:19:28,420 --> 02:19:32,289
time I am going to switch these two
3032
02:19:30,158 --> 02:19:34,599
animations for example for the first one
3033
02:19:32,289 --> 02:19:36,159
I'm going to pass a slide out and for
3034
02:19:34,599 --> 02:19:38,619
the second one I'm going to pass it
3035
02:19:36,158 --> 02:19:41,618
slightly so let's say our thoughts and
3036
02:19:38,619 --> 02:19:42,190
you dot slide out and for the second one
3037
02:19:42,190 --> 02:19:46,899
and if that slightly let's run the
3038
02:19:44,829 --> 02:19:50,049
application once again and let's go to
3039
02:19:46,899 --> 02:19:53,109
our old books activity this time if we
3040
02:19:50,049 --> 02:19:55,149
try this back button you can see that we
3041
02:19:53,110 --> 02:19:57,280
have some sort of animation it's not
3042
02:19:55,149 --> 02:19:59,799
perfect but it is what we have created
3043
02:19:57,280 --> 02:20:02,200
honestly I'm not a designer I am not
3044
02:19:59,799 --> 02:20:04,270
good at animating my applications but
3045
02:20:02,200 --> 02:20:06,159
probably you can do better than me just
3046
02:20:04,271 --> 02:20:08,351
play around with these numbers inside
3047
02:20:06,159 --> 02:20:10,659
your XML files and you will find
3048
02:20:08,351 --> 02:20:12,641
animations that you are looking for but
3049
02:20:10,659 --> 02:20:15,190
right now if we try to go to another
3050
02:20:12,640 --> 02:20:17,229
activity for example this already Redbox
3051
02:20:15,190 --> 02:20:19,780
activity you can see that we are still
3052
02:20:17,229 --> 02:20:21,879
seeing the default animation if you want
3053
02:20:19,780 --> 02:20:24,521
to apply your animation on this activity
3054
02:20:21,879 --> 02:20:26,829
as well once again inside this activity
3055
02:20:24,521 --> 02:20:29,141
you can overwrite the pending transition
3056
02:20:26,829 --> 02:20:31,479
or alternatively if you want to apply
3057
02:20:29,140 --> 02:20:33,940
the animation on your entire application
3058
02:20:31,479 --> 02:20:36,159
you can change the style let's quickly
3059
02:20:33,940 --> 02:20:38,700
see how we can change our style so
3060
02:20:36,159 --> 02:20:41,140
inside our values folder inside
3061
02:20:38,700 --> 02:20:43,210
styles.xml in here I am going to create
3062
02:20:41,140 --> 02:20:45,459
another animation sorry I'm going to
3063
02:20:43,209 --> 02:20:47,829
create another style let's say it style
3064
02:20:45,459 --> 02:20:51,339
I'm going to name my style custom
3065
02:20:47,829 --> 02:20:54,819
animation and for its parent I'm going
3066
02:20:51,340 --> 02:20:59,799
to say at Android column style forward
3067
02:20:54,819 --> 02:21:02,319
slash animation dot activity so this is
3068
02:20:59,799 --> 02:21:04,629
going to be our parent inside this style
3069
02:21:02,319 --> 02:21:06,610
file I'm going to define some items for
3070
02:21:04,629 --> 02:21:09,279
example for the first one I'm going to
3071
02:21:06,610 --> 02:21:11,891
name it activity open inter animation
3072
02:21:09,280 --> 02:21:14,021
this one and for its value I'm going to
3073
02:21:11,890 --> 02:21:17,049
pass my own animation I'm going to pass
3074
02:21:14,021 --> 02:21:20,290
this slightly I can say that any slide
3075
02:21:17,049 --> 02:21:22,959
in I need to create three more items the
3076
02:21:20,290 --> 02:21:25,811
next one is going to be activity open
3077
02:21:22,959 --> 02:21:28,419
exit animation this one this time for
3078
02:21:25,810 --> 02:21:30,789
its value I'm going to say add and slide
3079
02:21:28,420 --> 02:21:34,390
out let's also create the exit
3080
02:21:30,790 --> 02:21:37,030
animations item activity close inter
3081
02:21:34,390 --> 02:21:39,430
animation this one let's pass a slide
3082
02:21:37,030 --> 02:21:42,159
out once again at Panama slide out
3083
02:21:39,430 --> 02:21:44,620
another item activity close exit
3084
02:21:42,159 --> 02:21:47,829
animation this time let's pass our slide
3085
02:21:44,620 --> 02:21:50,561
in now that I have created this style I
3086
02:21:47,829 --> 02:21:53,379
can pass it as an item inside this app
3087
02:21:50,560 --> 02:21:56,049
theme style so in here inside this F
3088
02:21:53,379 --> 02:21:58,209
theme style I can say item for its name
3089
02:21:56,049 --> 02:22:00,640
I'm going to say Android column window
3090
02:21:58,209 --> 02:22:03,100
animation style this one and for its
3091
02:22:00,640 --> 02:22:05,469
value I'm going to address this file I'm
3092
02:22:03,101 --> 02:22:08,351
going to say add style forward slash
3093
02:22:05,469 --> 02:22:10,840
constant animation now that we have
3094
02:22:08,351 --> 02:22:13,060
changed our app theme style we can
3095
02:22:10,840 --> 02:22:15,040
delete that overwrite pending transition
3096
02:22:13,060 --> 02:22:17,079
method from inside our Albert's
3097
02:22:15,040 --> 02:22:19,240
activity so let's delete this one and
3098
02:22:17,079 --> 02:22:20,771
also beside that let's delete this whole
3099
02:22:19,239 --> 02:22:23,170
and finish method let's run our
3100
02:22:20,771 --> 02:22:24,851
application one more time and let's try
3101
02:22:23,170 --> 02:22:27,460
going to different activities for
3102
02:22:24,851 --> 02:22:29,170
example this currently reading books you
3103
02:22:27,459 --> 02:22:31,419
can see that we are seeing some sort of
3104
02:22:29,170 --> 02:22:35,170
animations let's go to this see your
3105
02:22:31,420 --> 02:22:37,299
favorites animation my emulator is low
3106
02:22:35,170 --> 02:22:40,329
on speed so for that you can see some
3107
02:22:37,299 --> 02:22:42,340
frames let's go to our all books once
3108
02:22:40,329 --> 02:22:44,829
again we can see the animation to our
3109
02:22:42,340 --> 02:22:47,069
book activity it seems like our
3110
02:22:44,829 --> 02:22:49,629
animation have been applied successfully
3111
02:22:47,069 --> 02:22:51,520
there are much more concepts and
3112
02:22:49,629 --> 02:22:54,069
elements when creating different
3113
02:22:51,521 --> 02:22:56,650
animations you can probably and design a
3114
02:22:54,069 --> 02:22:58,959
simple game with Android studio by just
3115
02:22:56,649 --> 02:23:00,789
using these animations but I'm not going
3116
02:22:58,959 --> 02:23:02,560
to talk about them in here the reason
3117
02:23:00,790 --> 02:23:04,690
that I'm not going to talk about them in
3118
02:23:02,560 --> 02:23:06,879
here is that because the Android team
3119
02:23:04,690 --> 02:23:09,040
are releasing a much better solution for
3120
02:23:06,879 --> 02:23:11,619
animations that solution is called
3121
02:23:09,040 --> 02:23:12,950
motion layout and right now it's in beta
3122
02:23:12,950 --> 02:23:17,210
we'll be released in a few monsters
3123
02:23:14,390 --> 02:23:19,760
probably in the spring of this year in
3124
02:23:17,209 --> 02:23:21,409
the Google i/o conference or later on
3125
02:23:19,760 --> 02:23:23,479
this year in Android developers
3126
02:23:21,409 --> 02:23:26,030
conference either way when it's released
3127
02:23:23,479 --> 02:23:28,069
on a stable Channel I will create one or
3128
02:23:26,030 --> 02:23:29,840
more videos about that I've seen and
3129
02:23:28,069 --> 02:23:31,959
I've heard a lot of good things about
3130
02:23:29,840 --> 02:23:35,030
that let me quickly show you some links
3131
02:23:31,959 --> 02:23:37,279
if you come to this web page at Android
3132
02:23:35,030 --> 02:23:39,650
developers official website you can see
3133
02:23:37,280 --> 02:23:42,440
some of the features of motion layout
3134
02:23:39,649 --> 02:23:44,479
together with the motion editor you have
3135
02:23:42,440 --> 02:23:46,640
all sorts of functionalities and all
3136
02:23:44,479 --> 02:23:49,010
sort of easiness when you are designing
3137
02:23:46,640 --> 02:23:51,350
your animations honestly I think that
3138
02:23:49,010 --> 02:23:53,750
they are drinking After Effects inside
3139
02:23:51,351 --> 02:23:56,181
Android studio so for that I'm not going
3140
02:23:53,750 --> 02:23:58,729
to talk about animations in here instead
3141
02:23:56,181 --> 02:24:00,909
I'm going to wait for the motion layout
3142
02:23:58,729 --> 02:24:03,680
motion layout is going to compete
3143
02:24:00,909 --> 02:24:05,569
constraint layout 2.0 and that
3144
02:24:03,681 --> 02:24:07,640
constraint layout is still in beta
3145
02:24:05,569 --> 02:24:09,890
phases we just need to wait a few more
3146
02:24:07,640 --> 02:24:11,750
months ok let's move on from animations
3147
02:24:09,890 --> 02:24:14,299
the next thing that I'm going to do
3148
02:24:11,750 --> 02:24:16,760
inside my application is that I'm going
3149
02:24:14,299 --> 02:24:19,159
to enable an UP button in my activities
3150
02:24:16,760 --> 02:24:21,319
for example inside this all works
3151
02:24:19,159 --> 02:24:23,209
activity but before I do that I'm going
3152
02:24:21,319 --> 02:24:25,219
to delete my animation because I don't
3153
02:24:23,209 --> 02:24:27,739
like it let's just comment this line and
3154
02:24:25,219 --> 02:24:30,079
let's close all of these extra points so
3155
02:24:27,739 --> 02:24:32,449
in order to activate your off button
3156
02:24:30,079 --> 02:24:35,030
inside on create method of your activity
3157
02:24:32,450 --> 02:24:38,120
you can say get action bar or to refer
3158
02:24:35,030 --> 02:24:40,820
circuit support action bar dot set
3159
02:24:38,120 --> 02:24:42,440
display home op enabled please option in
3160
02:24:40,819 --> 02:24:45,170
here if you pass through we will
3161
02:24:42,440 --> 02:24:46,760
activate your op button let's run the
3162
02:24:45,170 --> 02:24:49,489
application and let's see what does that
3163
02:24:46,760 --> 02:24:52,250
look like if we go to our all box
3164
02:24:49,489 --> 02:24:55,190
activity in here you can see this back
3165
02:24:52,250 --> 02:24:57,110
arrow which is our off button right now
3166
02:24:55,190 --> 02:24:59,450
it's not going to do anything because we
3167
02:24:57,110 --> 02:25:01,460
haven't defined the functionality but if
3168
02:24:59,450 --> 02:25:03,320
we want to navigate the user back to the
3169
02:25:01,459 --> 02:25:06,079
main activity we can do something like
3170
02:25:03,319 --> 02:25:08,149
this we can overwrite the on option item
3171
02:25:06,079 --> 02:25:10,310
selected method like this I'm talking
3172
02:25:08,149 --> 02:25:12,590
about this method you can see that we
3173
02:25:10,310 --> 02:25:14,779
are getting a menu item and we can use
3174
02:25:12,590 --> 02:25:17,659
that item in here we can create a switch
3175
02:25:14,780 --> 02:25:20,931
statement let's say switch on item dot
3176
02:25:17,659 --> 02:25:23,869
get item ID and let's create our cases
3177
02:25:20,931 --> 02:25:26,640
let's say in case it's Android that our
3178
02:25:23,870 --> 02:25:28,590
that ID at home which means that
3179
02:25:26,639 --> 02:25:31,228
you are going to click on our up button
3180
02:25:28,590 --> 02:25:33,120
this is the idea of that button we are
3181
02:25:31,228 --> 02:25:35,099
going to navigate the user back to the
3182
02:25:33,120 --> 02:25:37,290
main activity and here I have two
3183
02:25:35,100 --> 02:25:38,729
options I can create an intent and
3184
02:25:37,290 --> 02:25:41,790
navigate the user back to the main
3185
02:25:38,728 --> 02:25:44,278
activity or I can call the on backrest
3186
02:25:41,790 --> 02:25:45,960
method let's call that so this in here
3187
02:25:44,279 --> 02:25:48,390
means that do whatever you are doing
3188
02:25:45,959 --> 02:25:50,669
when the user clicks on the back button
3189
02:25:48,389 --> 02:25:52,469
basically the up button and the back
3190
02:25:50,670 --> 02:25:54,420
button in here are going to have the
3191
02:25:52,469 --> 02:25:55,829
same functionality but of course you can
3192
02:25:54,420 --> 02:25:58,318
do whatever you want you can navigate
3193
02:25:55,829 --> 02:26:00,329
the user to another activity let's also
3194
02:25:58,318 --> 02:26:02,309
add a break in here and let's create a
3195
02:26:00,329 --> 02:26:03,898
default case in the default case I am
3196
02:26:02,309 --> 02:26:05,250
NOT going to do anything I'm just going
3197
02:26:03,898 --> 02:26:07,559
to break out of the switch statement
3198
02:26:05,250 --> 02:26:09,478
let's run our application and that's if
3199
02:26:07,559 --> 02:26:12,389
it's going to work so if we go to our
3200
02:26:09,478 --> 02:26:14,488
all books activity if we click on this
3201
02:26:12,389 --> 02:26:16,799
up button you can see that we are
3202
02:26:14,488 --> 02:26:18,689
navigating back to the main activity I'm
3203
02:26:16,799 --> 02:26:20,728
not going to enable it in other
3204
02:26:18,689 --> 02:26:23,040
activities I just wanted to show you how
3205
02:26:20,728 --> 02:26:24,898
you can implement this out button okay
3206
02:26:23,040 --> 02:26:27,210
the next minor thing that I'm going to
3207
02:26:24,898 --> 02:26:29,760
do in here is that to change the name of
3208
02:26:27,209 --> 02:26:31,919
my application this title in here in
3209
02:26:29,760 --> 02:26:33,600
different activities for example I'm
3210
02:26:31,920 --> 02:26:36,238
going to change it inside these are
3211
02:26:33,600 --> 02:26:38,279
books activity to all books in order to
3212
02:26:36,238 --> 02:26:41,459
do that you can go to your manifest file
3213
02:26:38,279 --> 02:26:44,069
and in here for different activities you
3214
02:26:41,459 --> 02:26:46,469
can define different labels but I'm
3215
02:26:44,068 --> 02:26:49,019
going to create my labels inside the
3216
02:26:46,469 --> 02:26:52,079
string resources so inside my values
3217
02:26:49,020 --> 02:26:54,390
folder inside strings.xml I'm going to
3218
02:26:52,079 --> 02:26:56,939
define a few more strings the first one
3219
02:26:54,389 --> 02:27:00,349
is going to be named activity all books
3220
02:26:56,939 --> 02:27:03,450
and its value is going to be all books
3221
02:27:03,450 --> 02:27:08,610
after defining these strings you can go
3222
02:27:06,360 --> 02:27:11,310
back to your manifest file and inside
3223
02:27:08,610 --> 02:27:13,290
every activity tag you can set a label
3224
02:27:11,309 --> 02:27:16,079
attribute for example for this favorite
3225
02:27:13,290 --> 02:27:18,540
activity we can say label let's search
3226
02:27:16,079 --> 02:27:21,809
for favorite activity let's do the same
3227
02:27:18,540 --> 02:27:23,490
thing for the other activities let's run
3228
02:27:21,809 --> 02:27:25,949
our application and let's see if you
3229
02:27:23,489 --> 02:27:27,930
have changed the labels successfully in
3230
02:27:25,950 --> 02:27:30,570
the main activity we are still seeing
3231
02:27:27,930 --> 02:27:32,970
this my library which is the name of our
3232
02:27:30,569 --> 02:27:35,189
application let's go to our all books
3233
02:27:32,969 --> 02:27:36,959
activity you can see that the title has
3234
02:27:35,189 --> 02:27:39,210
been changed if we go to our book
3235
02:27:36,959 --> 02:27:42,449
activity you can see the pop details
3236
02:27:39,209 --> 02:27:43,919
let's go to already read activity once
3237
02:27:42,450 --> 02:27:46,110
again you can see the title has been
3238
02:27:43,920 --> 02:27:48,600
changed it seems like we have changed
3239
02:27:46,110 --> 02:27:50,400
the labels in all of our activities okay
3240
02:27:48,600 --> 02:27:52,260
I think that's enough for this video in
3241
02:27:50,399 --> 02:27:54,779
the next video we are going to work on
3242
02:27:52,260 --> 02:27:57,478
our utils class right now we are using a
3243
02:27:54,780 --> 02:28:00,210
static array lists for our data which is
3244
02:27:57,478 --> 02:28:02,309
not resisted over the life cycle of our
3245
02:28:00,209 --> 02:28:04,079
application in the next video we are
3246
02:28:02,309 --> 02:28:07,409
going to see my simple solution for
3247
02:28:04,079 --> 02:28:09,780
persisting data even if we restart our
3248
02:28:07,409 --> 02:28:11,430
device it is probably the last video of
3249
02:28:09,780 --> 02:28:13,439
this section of the course so make sure
3250
02:28:11,430 --> 02:28:15,770
to don't miss that ok see you in the
3251
02:28:17,729 --> 02:28:22,629
in this video we are going to solve our
3252
02:28:20,620 --> 02:28:25,660
problems with our data not being
3253
02:28:22,629 --> 02:28:27,729
persistent right now the problem is that
3254
02:28:25,659 --> 02:28:30,940
we are using static variables for our
3255
02:28:27,729 --> 02:28:33,489
data for example when they add one block
3256
02:28:30,940 --> 02:28:36,340
to one of these lists that book will be
3257
02:28:33,489 --> 02:28:39,219
added but when we close our application
3258
02:28:36,340 --> 02:28:41,110
these ArrayList will be cleared in this
3259
02:28:39,219 --> 02:28:43,840
video we are going to solve that we are
3260
02:28:41,110 --> 02:28:46,060
going to persist our data after an
3261
02:28:43,840 --> 02:28:48,809
application is closed and also for that
3262
02:28:46,059 --> 02:28:51,459
matter after the device is rebooted
3263
02:28:48,809 --> 02:28:53,799
usually in a real world application you
3264
02:28:51,459 --> 02:28:56,019
may want to use databases for situations
3265
02:28:53,799 --> 02:28:58,659
like this they have been designed
3266
02:28:56,020 --> 02:29:01,360
exactly for this problem and they have
3267
02:28:58,659 --> 02:29:03,459
been designed to persist our data but we
3268
02:29:01,360 --> 02:29:05,140
don't know anything about databases yet
3269
02:29:03,459 --> 02:29:07,629
later on in the course we will talk
3270
02:29:05,139 --> 02:29:10,629
about databases specifically we will
3271
02:29:07,629 --> 02:29:13,839
talk about SQLite database and also its
3272
02:29:10,629 --> 02:29:15,969
wrapper room database but we also have
3273
02:29:13,840 --> 02:29:18,579
another option that we are going to use
3274
02:29:15,969 --> 02:29:21,369
in here that option is called shared
3275
02:29:18,579 --> 02:29:24,010
preferences the purpose of shared
3276
02:29:21,370 --> 02:29:26,920
preferences is that to produce the data
3277
02:29:24,010 --> 02:29:29,350
that is not a structured they are being
3278
02:29:26,920 --> 02:29:32,290
void to use for the Preferences of the
3279
02:29:29,350 --> 02:29:34,540
user in your application for example if
3280
02:29:32,290 --> 02:29:35,740
the user decides to use the dark theme
3281
02:29:35,739 --> 02:29:41,049
you can save that preference in your
3282
02:29:38,350 --> 02:29:42,970
shared preferences but that's not all of
3283
02:29:41,049 --> 02:29:45,039
the purpose of the shared preferences as
3284
02:29:42,969 --> 02:29:48,189
I said you can save all of the on
3285
02:29:45,040 --> 02:29:50,530
structured data in shared preferences in
3286
02:29:48,190 --> 02:29:52,960
here in our application our data is a
3287
02:29:50,530 --> 02:29:55,420
structured we have a model called book
3288
02:29:52,959 --> 02:29:58,449
beside that we have all of these array
3289
02:29:55,420 --> 02:30:00,430
lists but we are going to manipulate our
3290
02:29:58,450 --> 02:30:03,010
data and we are going to save them
3291
02:30:00,430 --> 02:30:04,899
inside the shared preferences by
3292
02:30:03,010 --> 02:30:07,510
manipulate I mean we are going to
3293
02:30:04,899 --> 02:30:08,590
convert our Java classes and array lists
3294
02:30:08,590 --> 02:30:13,899
and after that we are going to save them
3295
02:30:11,200 --> 02:30:15,940
inside the shared references in another
3296
02:30:13,899 --> 02:30:18,909
word we are going to serialize our
3297
02:30:15,940 --> 02:30:21,310
objects and later on when we get our
3298
02:30:18,909 --> 02:30:23,559
data from the shared preferences we are
3299
02:30:21,309 --> 02:30:26,469
going to convert those strings to these
3300
02:30:23,559 --> 02:30:29,559
array lists and books that process is
3301
02:30:26,469 --> 02:30:31,170
called deserializing okay enough talking
3302
02:30:31,170 --> 02:30:35,639
shared preferences so if you remember
3303
02:30:33,299 --> 02:30:38,340
from the previous videos I have done all
3304
02:30:35,639 --> 02:30:41,459
of my interactions with Maya arraylists
3305
02:30:38,340 --> 02:30:43,799
inside this utils class and I've done
3306
02:30:41,459 --> 02:30:45,989
that because of this exact reason I'm
3307
02:30:43,799 --> 02:30:48,119
going to delete all of my array lists
3308
02:30:45,989 --> 02:30:50,879
and I am going to use shared references
3309
02:30:48,120 --> 02:30:53,850
so most of our changes are going to be
3310
02:30:50,879 --> 02:30:56,129
inside this utils class first of all I'm
3311
02:30:53,850 --> 02:30:58,530
going to define my shared preferences as
3312
02:30:56,129 --> 02:31:01,228
a member variable inside this utils
3313
02:30:58,530 --> 02:31:03,659
class for example down in here I'm going
3314
02:31:01,228 --> 02:31:05,938
to say private shared preferences you
3315
02:31:03,659 --> 02:31:09,450
can see that this is an interface that
3316
02:31:05,939 --> 02:31:12,420
comes from Android content package let's
3317
02:31:09,450 --> 02:31:14,400
name it shared preferences after that
3318
02:31:12,420 --> 02:31:17,489
I'm going to initialize it inside my
3319
02:31:14,399 --> 02:31:20,090
constructor inside these UTS before
3320
02:31:17,489 --> 02:31:23,579
everything let's say shared preferences
3321
02:31:20,090 --> 02:31:25,530
is equal to get shared preferences but
3322
02:31:23,579 --> 02:31:28,049
we cannot use this method because for
3323
02:31:25,530 --> 02:31:29,939
that we need a context for that reason
3324
02:31:28,049 --> 02:31:32,699
I'm going to receive a context via the
3325
02:31:29,939 --> 02:31:34,500
constructor of this class but notice
3326
02:31:32,700 --> 02:31:36,810
that and because I'm going to receive a
3327
02:31:34,500 --> 02:31:39,600
context in here I need to change a lot
3328
02:31:36,809 --> 02:31:41,939
of codes in my application wherever we
3329
02:31:39,600 --> 02:31:44,670
have used this constructor or for that
3330
02:31:41,939 --> 02:31:47,100
matter this instance and its method get
3331
02:31:44,670 --> 02:31:49,860
instance method we also need to pass a
3332
02:31:47,100 --> 02:31:52,800
context we will do that later on
3333
02:31:49,860 --> 02:31:55,530
so let's receive a context let's say
3334
02:31:52,799 --> 02:31:58,049
context and down in here let's say
3335
02:31:55,530 --> 02:32:02,100
shared preferences is equal to context
3336
02:31:58,049 --> 02:32:04,139
dot get shared preferences you can see
3337
02:32:02,100 --> 02:32:06,270
that in here we need a name this string
3338
02:32:04,139 --> 02:32:08,549
is going to be the key for our shared
3339
02:32:06,270 --> 02:32:12,270
preferences let's pass a name for
3340
02:32:08,549 --> 02:32:15,209
example let's say alternate divi divi S
3341
02:32:12,270 --> 02:32:17,310
stands for database after that after the
3342
02:32:15,209 --> 02:32:19,169
key you also need to pass a mod for
3343
02:32:17,309 --> 02:32:21,659
example the mode that I'm going to pass
3344
02:32:19,170 --> 02:32:23,670
in here is this mod private we have
3345
02:32:21,659 --> 02:32:25,770
other modes as well but if you want your
3346
02:32:23,670 --> 02:32:28,469
shared preferences to be specific to
3347
02:32:25,770 --> 02:32:31,470
your application only you can use this
3348
02:32:28,469 --> 02:32:33,959
mod private or to be precise context
3349
02:32:31,469 --> 02:32:36,420
that mod private now you have an
3350
02:32:33,959 --> 02:32:38,339
instance of your shared preferences you
3351
02:32:36,420 --> 02:32:40,350
can use it however you want you can put
3352
02:32:38,340 --> 02:32:42,270
some data into it or you can get
3353
02:32:40,350 --> 02:32:44,520
existing data from your shared
3354
02:32:42,270 --> 02:32:45,101
preferences but right now because I've
3355
02:32:45,101 --> 02:32:49,420
is an a constructor we should probably
3356
02:32:47,079 --> 02:32:51,789
see some error inside to get instance
3357
02:32:49,420 --> 02:32:54,489
method because if you remember in here
3358
02:32:51,790 --> 02:32:56,650
we are calling our constructor for that
3359
02:32:54,489 --> 02:32:59,979
inside this get instance method I'm
3360
02:32:56,649 --> 02:33:03,420
going to also receive a context and I'm
3361
02:32:59,979 --> 02:33:07,899
going to pass it to this constructor
3362
02:33:03,420 --> 02:33:11,200
that will fix our error for now next I'm
3363
02:33:07,899 --> 02:33:13,779
going to change this init data method in
3364
02:33:11,200 --> 02:33:15,940
here right now we are saving our books
3365
02:33:13,780 --> 02:33:19,120
inside these all books array list which
3366
02:33:15,940 --> 02:33:21,700
is a static array list but let's see how
3367
02:33:19,120 --> 02:33:23,561
we can use shared references so in here
3368
02:33:21,700 --> 02:33:27,601
first of all I'm going to define a new
3369
02:33:23,560 --> 02:33:31,119
array list let's say array list of books
3370
02:33:27,601 --> 02:33:34,480
let's call it books is equal to new
3371
02:33:31,120 --> 02:33:36,851
array list and after that I'm going to
3372
02:33:34,479 --> 02:33:39,699
add my books to this new ArrayList and
3373
02:33:36,851 --> 02:33:42,700
not to the static ArrayList so let's say
3374
02:33:39,700 --> 02:33:46,659
books that add and similarly for the
3375
02:33:42,700 --> 02:33:48,641
second book now let's see how we can add
3376
02:33:46,659 --> 02:33:51,280
these books I released into our shared
3377
02:33:48,640 --> 02:33:54,699
preferences so down in here I can say
3378
02:33:51,280 --> 02:33:57,790
editor this interface shared preferences
3379
02:33:54,700 --> 02:34:00,880
that editor let's name it editor is
3380
02:33:57,790 --> 02:34:03,940
equal to our shared preferences instance
3381
02:34:00,879 --> 02:34:07,390
dot edit you can see that this edit
3382
02:34:03,940 --> 02:34:09,670
method returns an editor instance after
3383
02:34:07,390 --> 02:34:12,789
that with the help of this editor we can
3384
02:34:09,670 --> 02:34:15,700
say editor dot for example put a stream
3385
02:34:12,790 --> 02:34:19,090
you can see that our options in here are
3386
02:34:15,700 --> 02:34:21,971
very limited we can only store primitive
3387
02:34:19,090 --> 02:34:24,790
datatypes plus the string but how do we
3388
02:34:21,970 --> 02:34:26,829
store our Java classes for example this
3389
02:34:24,790 --> 02:34:28,870
book class and similar to that our
3390
02:34:26,829 --> 02:34:31,511
ArrayList inside these shared
3391
02:34:28,870 --> 02:34:34,120
preferences I said that we are going to
3392
02:34:31,511 --> 02:34:37,601
convert our books I read list into a
3393
02:34:34,120 --> 02:34:40,420
string let's see how we can do that the
3394
02:34:37,601 --> 02:34:43,569
best option is to convert your Java
3395
02:34:40,420 --> 02:34:46,329
classes and array lists into a JSON file
3396
02:34:43,569 --> 02:34:48,851
if you don't know anything about JSON
3397
02:34:46,329 --> 02:34:50,771
don't worry we are going to talk about
3398
02:34:48,851 --> 02:34:52,780
that later on in the course specifically
3399
02:34:50,771 --> 02:34:56,079
we will talk about it in the networking
3400
02:34:52,780 --> 02:34:57,641
section basically JSON is a way of
3401
02:34:56,079 --> 02:34:59,020
passing data between different
3402
02:34:59,020 --> 02:35:03,399
godless of the language I mean here we
3403
02:35:01,478 --> 02:35:05,528
are not going to talk further about JSON
3404
02:35:03,398 --> 02:35:07,868
we are not going to work with JSON files
3405
02:35:05,529 --> 02:35:10,988
we are going to handle the job to a
3406
02:35:07,869 --> 02:35:13,359
third-party library so basically we are
3407
02:35:10,988 --> 02:35:15,578
going to serialize and deserialize our
3408
02:35:13,359 --> 02:35:17,979
objects with the help of another library
3409
02:35:15,578 --> 02:35:20,199
let's quickly implement that library
3410
02:35:17,978 --> 02:35:23,590
into our project the name of this
3411
02:35:20,199 --> 02:35:25,390
library is JSON if you search for JSON
3412
02:35:23,590 --> 02:35:28,750
you can see that the first thing from
3413
02:35:25,389 --> 02:35:30,578
github is the link of this library as
3414
02:35:28,750 --> 02:35:33,250
you can see above in here it has been
3415
02:35:30,578 --> 02:35:35,158
developed by Google down in here
3416
02:35:33,250 --> 02:35:38,529
somewhere we should see the dependencies
3417
02:35:35,158 --> 02:35:41,889
we are using Gradle not maven so we can
3418
02:35:38,529 --> 02:35:45,939
copy the dependencies from here let's
3419
02:35:41,889 --> 02:35:48,698
add it into our project inside build
3420
02:35:45,939 --> 02:35:51,479
that Gradle module app let's add it
3421
02:35:48,699 --> 02:35:54,399
somewhere and let's sink our project
3422
02:35:51,478 --> 02:35:56,709
after adding it in our routines class
3423
02:35:54,398 --> 02:36:00,549
first of all let's create an instance of
3424
02:35:56,709 --> 02:36:02,408
this JSON object we can say Giza you can
3425
02:36:00,549 --> 02:36:05,318
see that it's coming from countered who
3426
02:36:02,408 --> 02:36:09,340
built it Doosan package let's name it
3427
02:36:05,318 --> 02:36:12,129
JSON is equal to new JSON after that if
3428
02:36:09,340 --> 02:36:14,078
you want to convert an object to JSON
3429
02:36:12,129 --> 02:36:17,799
and you can say something like this you
3430
02:36:14,078 --> 02:36:20,170
can say geez on dot to JSON we have
3431
02:36:17,799 --> 02:36:22,148
multiple versions of this to JSON method
3432
02:36:20,170 --> 02:36:24,879
you can see that each one of these
3433
02:36:22,148 --> 02:36:28,868
versions receive different arguments for
3434
02:36:24,879 --> 02:36:31,988
example we can simply pass our books so
3435
02:36:28,869 --> 02:36:35,260
this way we can have a string let's
3436
02:36:31,988 --> 02:36:39,038
simply name it text is equal to json dot
3437
02:36:35,260 --> 02:36:41,170
to json so this way we can serialize our
3438
02:36:39,039 --> 02:36:43,539
books object with the help of this
3439
02:36:41,170 --> 02:36:46,539
reason we have converted our ArrayList
3440
02:36:43,539 --> 02:36:48,670
into a JSON file now let's see how we
3441
02:36:46,539 --> 02:36:50,770
can add this text into our shared
3442
02:36:48,670 --> 02:36:53,469
preferences I'm going to delete this one
3443
02:36:50,770 --> 02:36:55,720
I'm going to say editor that put the
3444
02:36:53,469 --> 02:36:57,578
string first of all we need the key I'm
3445
02:36:55,719 --> 02:37:00,368
going to use constants for different
3446
02:36:57,578 --> 02:37:03,728
keys and I'm going to define them above
3447
02:37:00,369 --> 02:37:07,971
in here as member variables let's say
3448
02:37:03,728 --> 02:37:14,119
private static find out the string
3449
02:37:07,970 --> 02:37:18,109
let's name it all box key let's
3450
02:37:14,120 --> 02:37:20,301
initialize it to all books after that
3451
02:37:18,110 --> 02:37:22,851
down in here inside this put a string
3452
02:37:20,300 --> 02:37:25,909
method we can pass that key let's say
3453
02:37:22,851 --> 02:37:28,971
all works key and after that we need our
3454
02:37:25,909 --> 02:37:32,780
value which I'm going to say jisan but
3455
02:37:28,970 --> 02:37:34,489
to JSON and let's pass our box object as
3456
02:37:32,780 --> 02:37:37,909
simple as that with the help of this
3457
02:37:34,489 --> 02:37:40,399
editor we can put this ArrayList into
3458
02:37:37,909 --> 02:37:42,409
our shared preferences but there is one
3459
02:37:40,399 --> 02:37:45,229
more step and we need to apply the
3460
02:37:42,409 --> 02:37:47,569
changes on this bed ĂȘtre for that we
3461
02:37:45,229 --> 02:37:50,779
have two options we can say editor dot
3462
02:37:47,569 --> 02:37:53,091
apply this method or the alternative
3463
02:37:50,780 --> 02:37:56,091
that we are going to use in here is dot
3464
02:37:53,091 --> 02:37:58,399
commit the difference between the apply
3465
02:37:56,091 --> 02:38:01,940
and commit is shown in here inside this
3466
02:37:58,399 --> 02:38:04,011
file and so whenever you use apply the
3467
02:38:01,940 --> 02:38:06,200
changes inside your shared preferences
3468
02:38:04,011 --> 02:38:09,171
will be applied in a background thread
3469
02:38:06,200 --> 02:38:11,960
and you will not block the main thread I
3470
02:38:09,171 --> 02:38:14,120
suggest that in most cases you use apply
3471
02:38:11,959 --> 02:38:16,159
because you don't want to block the user
3472
02:38:14,120 --> 02:38:19,011
from interacting with your application
3473
02:38:16,159 --> 02:38:20,989
but in here our data is really small and
3474
02:38:19,011 --> 02:38:23,569
we are not going to block our user
3475
02:38:20,989 --> 02:38:26,181
interface for long and beside that we
3476
02:38:23,569 --> 02:38:28,101
need the result of this applying
3477
02:38:26,181 --> 02:38:30,500
immediately for that I'm going to use
3478
02:38:28,101 --> 02:38:32,690
this comment later on we will see that
3479
02:38:30,500 --> 02:38:34,130
how we can use callbacks in order to
3480
02:38:32,690 --> 02:38:37,280
communicate between two different
3481
02:38:34,130 --> 02:38:38,899
threads and then we can use apply but in
3482
02:38:37,280 --> 02:38:40,909
here because we need the results
3483
02:38:38,899 --> 02:38:43,789
instantly and we haven't talked about
3484
02:38:40,909 --> 02:38:46,431
callbacks I'm just going to simply use
3485
02:38:43,790 --> 02:38:48,530
this comet method okay that's all that
3486
02:38:46,431 --> 02:38:51,801
we need to know in order to put some a
3487
02:38:48,530 --> 02:38:53,721
string into our shared preferences now
3488
02:38:51,800 --> 02:38:56,119
that we have successfully initialized
3489
02:38:53,720 --> 02:38:58,850
our data let's see how we can call this
3490
02:38:56,120 --> 02:39:00,950
in its data method so inside the
3491
02:38:58,851 --> 02:39:03,560
constructor if you remember in here we
3492
02:39:00,950 --> 02:39:05,570
are calling this in its data but before
3493
02:39:03,560 --> 02:39:08,181
that we are using these all books are
3494
02:39:05,569 --> 02:39:11,149
released in order to make sure that we
3495
02:39:08,181 --> 02:39:12,950
haven't defined outputs previously as I
3496
02:39:11,149 --> 02:39:15,261
said I'm going to delete all of these
3497
02:39:12,950 --> 02:39:17,570
array list so I shouldn't use these all
3498
02:39:15,261 --> 02:39:20,060
box ArrayList for that I'm going to
3499
02:39:17,569 --> 02:39:21,680
check my shared preferences and see if I
3500
02:39:21,680 --> 02:39:26,449
in the shared preferences or not if I
3501
02:39:24,379 --> 02:39:29,148
don't have any initial data I'm going to
3502
02:39:26,449 --> 02:39:31,340
call this in its data method but if I
3503
02:39:29,148 --> 02:39:33,648
don't I'm going to escape to the rest of
3504
02:39:31,340 --> 02:39:36,500
the code okay let's see how we can get
3505
02:39:33,648 --> 02:39:38,689
our data from our shared preferences the
3506
02:39:36,500 --> 02:39:41,478
right place to do that is inside the get
3507
02:39:38,689 --> 02:39:42,920
all box method let's quick answer for
3508
02:39:41,478 --> 02:39:44,959
that you can see that we have this
3509
02:39:42,920 --> 02:39:48,049
method in here and we are simply
3510
02:39:44,959 --> 02:39:50,299
returning all books ArrayList instead of
3511
02:39:48,049 --> 02:39:52,759
that I'm going to get the data from the
3512
02:39:50,299 --> 02:39:57,559
shared preferences let's say I really
3513
02:39:52,760 --> 02:40:00,738
stopped different book let's name it
3514
02:39:57,559 --> 02:40:02,659
books is equal to in here first of all
3515
02:40:00,738 --> 02:40:05,029
I'm going to get the text from the
3516
02:40:02,659 --> 02:40:07,250
shared preferences and after that with
3517
02:40:05,029 --> 02:40:10,550
the help of JSON library I'm going to
3518
02:40:07,250 --> 02:40:12,829
convert it to this books ArrayList so
3519
02:40:10,549 --> 02:40:15,259
before defining this ArrayList first of
3520
02:40:12,829 --> 02:40:18,559
all I need to create an instance of the
3521
02:40:15,260 --> 02:40:22,850
JSON so let's say juice on jihad is
3522
02:40:18,559 --> 02:40:28,850
equal to new JSON after that let's say I
3523
02:40:22,850 --> 02:40:32,988
really stuff different books is equal to
3524
02:40:28,850 --> 02:40:35,568
json dot from json this time we can see
3525
02:40:32,988 --> 02:40:38,448
that similar to to json we have these
3526
02:40:35,568 --> 02:40:40,609
from json as well in here first of all
3527
02:40:38,449 --> 02:40:43,670
we need the text itself which we are
3528
02:40:40,609 --> 02:40:45,979
going to get from shared preferences but
3529
02:40:43,670 --> 02:40:47,930
as you can see I'm not getting my shared
3530
02:40:45,978 --> 02:40:50,719
preferences and that's because when I've
3531
02:40:47,930 --> 02:40:53,000
defined my shared preferences I didn't
3532
02:40:50,719 --> 02:40:55,519
define it as a static variable and
3533
02:40:53,000 --> 02:40:58,430
because of that because we are trying to
3534
02:40:55,520 --> 02:41:01,040
have access to a non-static field if I'm
3535
02:40:58,430 --> 02:41:03,109
inside a static method we are getting
3536
02:41:01,040 --> 02:41:07,970
this morning let me type it completely
3537
02:41:03,109 --> 02:41:09,590
to see the error if you hover over these
3538
02:41:07,969 --> 02:41:11,840
shared references you can see that
3539
02:41:09,590 --> 02:41:15,228
non-static field cannot be referenced
3540
02:41:11,840 --> 02:41:17,270
from a static context for that I'm going
3541
02:41:15,228 --> 02:41:19,698
to delete this static keyboard from the
3542
02:41:17,270 --> 02:41:21,649
Declaration of this method we have used
3543
02:41:19,699 --> 02:41:24,319
it so far in order to have access to
3544
02:41:21,648 --> 02:41:26,599
this all books ArrayList but we no
3545
02:41:24,318 --> 02:41:29,090
longer need it so we can safely delete
3546
02:41:26,600 --> 02:41:31,189
it now that we have access to our shared
3547
02:41:29,090 --> 02:41:33,610
preferences I can say shared preferences
3548
02:41:33,610 --> 02:41:38,960
insightly's get a string method first of
3549
02:41:36,110 --> 02:41:42,590
all we need a key the key is going to be
3550
02:41:38,959 --> 02:41:45,529
our constant all books key this one and
3551
02:41:42,590 --> 02:41:48,560
after that we need a default value which
3552
02:41:45,530 --> 02:41:50,511
I am going to say not in this case so if
3553
02:41:48,560 --> 02:41:52,579
we did not get anything from the shared
3554
02:41:50,511 --> 02:41:56,060
preferences we are going to return null
3555
02:41:52,579 --> 02:41:57,979
as this string after that the next item
3556
02:41:56,060 --> 02:42:02,209
that we need an effort is from JSON
3557
02:41:57,979 --> 02:42:04,939
method is a type token the type token in
3558
02:42:02,209 --> 02:42:08,089
here defines that to what object we are
3559
02:42:04,940 --> 02:42:10,640
going to convert our JSON in this case
3560
02:42:08,090 --> 02:42:13,579
we are going to convert our JSON to an
3561
02:42:10,640 --> 02:42:16,970
array list of books so we need to create
3562
02:42:13,579 --> 02:42:20,060
a appropriate type so in here I can say
3563
02:42:16,970 --> 02:42:24,680
type you can see that it's an interface
3564
02:42:20,060 --> 02:42:28,011
let's name it type is equal to new type
3565
02:42:24,681 --> 02:42:30,380
token this one has the data type of this
3566
02:42:28,011 --> 02:42:33,431
type token inside the diamonds I'm going
3567
02:42:30,379 --> 02:42:36,379
to say array list of different books
3568
02:42:33,431 --> 02:42:38,899
after that we have a strange syntax in
3569
02:42:36,379 --> 02:42:42,109
here after the parentheses I'm going to
3570
02:42:38,899 --> 02:42:45,590
put a pair of curly braces after that a
3571
02:42:42,110 --> 02:42:47,480
dot and after that this gets type method
3572
02:42:45,590 --> 02:42:51,380
which you can see that will return a
3573
02:42:47,479 --> 02:42:53,989
type so let's use that this is fairly a
3574
02:42:51,379 --> 02:42:54,379
strange syntax and we haven't seen it so
3575
02:42:54,379 --> 02:42:58,609
you don't need to understand everything
3576
02:42:56,390 --> 02:43:01,459
in here we are just defining a new type
3577
02:42:58,610 --> 02:43:04,011
token you can copy and paste this one if
3578
02:43:01,459 --> 02:43:06,319
you need basically inside these type
3579
02:43:04,011 --> 02:43:09,380
token diamonds we are defining our
3580
02:43:06,319 --> 02:43:11,479
object kind and after that we are using
3581
02:43:09,379 --> 02:43:15,529
this dot get type method in order to
3582
02:43:11,479 --> 02:43:18,079
have a type after creating our type in
3583
02:43:15,530 --> 02:43:22,070
here inside this from json method we can
3584
02:43:18,079 --> 02:43:24,200
pass that now we are getting our books
3585
02:43:22,069 --> 02:43:27,440
from the shared preferences and we are
3586
02:43:24,200 --> 02:43:29,990
converting it to an ArrayList after that
3587
02:43:27,440 --> 02:43:33,110
we can safely return books instead of
3588
02:43:29,989 --> 02:43:35,601
all works so now that we have changed
3589
02:43:33,110 --> 02:43:39,050
this get out box method we can call it
3590
02:43:35,601 --> 02:43:42,530
from inside our constructor inside these
3591
02:43:39,049 --> 02:43:46,159
utils instead of using these all books
3592
02:43:42,530 --> 02:43:49,340
I'm going to say if null is equal to get
3593
02:43:46,159 --> 02:43:52,101
all books this method if you remember we
3594
02:43:49,340 --> 02:43:54,710
had a lot of non potentials inside to
3595
02:43:52,101 --> 02:43:57,950
get all box method let me quickly show
3596
02:43:54,709 --> 02:44:00,709
you one more time so for example if we
3597
02:43:57,950 --> 02:44:02,540
fail to retrieve this string from our
3598
02:44:00,709 --> 02:44:05,479
shared preferences we are going to get
3599
02:44:02,540 --> 02:44:08,090
known after that if our type doesn't
3600
02:44:05,479 --> 02:44:10,879
work we are going to get now which will
3601
02:44:08,090 --> 02:44:13,159
be produced by this JSON library so
3602
02:44:10,879 --> 02:44:16,010
there are a lot of potentially null
3603
02:44:13,159 --> 02:44:18,950
values so make sure to take care of them
3604
02:44:16,011 --> 02:44:20,690
whenever you call your methods so inside
3605
02:44:18,950 --> 02:44:23,659
this constructor I'm going to say if
3606
02:44:20,690 --> 02:44:25,909
null is equal to get all books I'm going
3607
02:44:23,659 --> 02:44:27,709
to call this in its data method let's
3608
02:44:25,909 --> 02:44:30,021
remove this line of code because it's no
3609
02:44:27,709 --> 02:44:32,479
longer necessary and if you want to have
3610
02:44:30,021 --> 02:44:36,021
a review inside this in its data method
3611
02:44:32,479 --> 02:44:38,149
we are initializing our data we are
3612
02:44:36,021 --> 02:44:39,800
creating these books ArrayList and we
3613
02:44:38,149 --> 02:44:42,379
are saving it inside the shared
3614
02:44:39,799 --> 02:44:44,840
preferences so the logic that we have
3615
02:44:42,379 --> 02:44:46,879
wrote so far means that if it's the
3616
02:44:44,840 --> 02:44:49,340
first time that the user is launching
3617
02:44:46,879 --> 02:44:51,079
our application if we don't have any
3618
02:44:49,340 --> 02:44:53,810
books saved inside our shared
3619
02:44:51,079 --> 02:44:56,569
preferences then call this in its title
3620
02:44:53,810 --> 02:44:58,340
method and save some ports but if it's
3621
02:44:56,569 --> 02:45:01,069
not the first time that the user is
3622
02:44:58,340 --> 02:45:03,950
launching our application just ignore
3623
02:45:01,069 --> 02:45:06,020
this if statement after initializing the
3624
02:45:06,021 --> 02:45:11,659
initialize these other array lists as
3625
02:45:08,750 --> 02:45:13,970
well because even if at the time of
3626
02:45:11,659 --> 02:45:16,729
installing our application these array
3627
02:45:13,970 --> 02:45:18,890
lists should be empty but we are using
3628
02:45:16,729 --> 02:45:21,439
them inside different activities and
3629
02:45:18,890 --> 02:45:25,220
based on them we are calling some
3630
02:45:21,440 --> 02:45:27,829
methods if these array lists are none we
3631
02:45:25,220 --> 02:45:29,869
are going to cause some exceptions for
3632
02:45:27,829 --> 02:45:33,170
that I am going to initialize all of
3633
02:45:29,870 --> 02:45:35,150
these with some empty array lists you
3634
02:45:33,170 --> 02:45:36,950
can see that basically inside these if
3635
02:45:35,149 --> 02:45:39,920
statements we are doing the same thing
3636
02:45:36,950 --> 02:45:41,601
for our aesthetic array lists this time
3637
02:45:39,920 --> 02:45:44,690
we are going to do it for our shared
3638
02:45:41,601 --> 02:45:46,670
preferences so I'm going to do the same
3639
02:45:44,690 --> 02:45:49,159
thing that I have done for my initial
3640
02:45:46,670 --> 02:45:51,590
data instead of these already read books
3641
02:45:49,159 --> 02:45:54,289
I'm going to use get already read books
3642
02:45:51,590 --> 02:45:57,110
if you remember we had such a method
3643
02:45:54,290 --> 02:45:59,180
down in here let's quickly find that we
3644
02:45:57,110 --> 02:46:02,270
have this get already read books
3645
02:45:59,180 --> 02:46:05,090
method and we are simply returning our
3646
02:46:02,270 --> 02:46:08,229
ArrayList this time let's see if we have
3647
02:46:05,090 --> 02:46:12,408
such a data in our shared references
3648
02:46:08,228 --> 02:46:15,948
once again I'm going to say jisan let's
3649
02:46:12,408 --> 02:46:18,918
say Tucson is equal to new JSON after
3650
02:46:15,949 --> 02:46:20,930
that let's define our type once again we
3651
02:46:18,918 --> 02:46:24,228
are using this interface which is coming
3652
02:46:20,930 --> 02:46:27,109
from the java packages so let's say type
3653
02:46:24,228 --> 02:46:30,019
once again let's name it type is equal
3654
02:46:27,109 --> 02:46:31,930
to I think I can copy some of the code
3655
02:46:30,020 --> 02:46:34,668
from inside this get out box method
3656
02:46:31,930 --> 02:46:38,020
let's copy everything we just need to
3657
02:46:38,359 --> 02:46:43,408
also we need to remove this a static
3658
02:46:41,398 --> 02:46:45,958
keyboard because we no longer need that
3659
02:46:43,408 --> 02:46:47,760
of course removing this static keyboard
3660
02:46:45,959 --> 02:46:51,060
is going to cause some problem in our
3661
02:46:47,760 --> 02:46:53,600
application for example inside already
3662
02:46:51,059 --> 02:46:56,398
read book activity in here without
3663
02:46:53,600 --> 02:46:58,738
initializing our utils we are trying to
3664
02:46:56,398 --> 02:47:01,469
call this method which was fine when we
3665
02:46:58,738 --> 02:47:03,958
have defined our method a static but
3666
02:47:01,469 --> 02:47:06,809
it's not going to work right now we will
3667
02:47:03,959 --> 02:47:09,050
fix this later on ok let's move on from
3668
02:47:06,809 --> 02:47:11,728
this part and let's go to our UTS class
3669
02:47:09,049 --> 02:47:13,920
inside this kit already read box method
3670
02:47:11,728 --> 02:47:16,858
when we are trying to get a string from
3671
02:47:13,920 --> 02:47:19,559
the shared preferences we need to put
3672
02:47:16,859 --> 02:47:23,149
another key in here let's quickly define
3673
02:47:36,060 --> 02:47:40,511
after defining these constants we can
3674
02:47:38,921 --> 02:47:42,700
pass them in different methods for
3675
02:47:40,511 --> 02:47:46,271
example for this gate already read books
3676
02:47:42,700 --> 02:47:48,909
method I can pass already read books and
3677
02:47:46,271 --> 02:47:51,700
constant now that we have changed this
3678
02:47:48,909 --> 02:47:55,810
gate already read books method inside
3679
02:47:51,700 --> 02:47:57,881
our constructor inside these utils when
3680
02:47:55,810 --> 02:48:00,190
we are going to initialize our already
3681
02:47:57,880 --> 02:48:02,890
read books we need to check that if it's
3682
02:48:00,190 --> 02:48:06,250
non or not let's say get already read
3683
02:48:02,890 --> 02:48:08,050
books to his method if it is not we are
3684
02:48:06,250 --> 02:48:10,569
going to initialize our shared
3685
02:48:08,050 --> 02:48:13,569
references because I am going to use my
3686
02:48:10,569 --> 02:48:16,000
editor in multiple places I'm going to
3687
02:48:13,569 --> 02:48:18,579
define that outside of these if
3688
02:48:16,000 --> 02:48:21,640
statements for example in here let's say
3689
02:48:18,579 --> 02:48:24,341
editor to be precise shared references
3690
02:48:21,640 --> 02:48:26,619
that editor let's name it editor is
3691
02:48:24,341 --> 02:48:29,649
equal to shared references that edit
3692
02:48:26,620 --> 02:48:32,021
then after that inside this if case we
3693
02:48:29,649 --> 02:48:36,489
are going to edit our shared references
3694
02:48:32,021 --> 02:48:38,950
I can say editor that put a string for
3695
02:48:36,489 --> 02:48:42,671
the key I am going to use my key from
3696
02:48:38,950 --> 02:48:45,521
above in here this one let's say I
3697
02:48:42,671 --> 02:48:48,069
already read books and for the values I
3698
02:48:45,521 --> 02:48:50,200
am going to pass an empty array list I'm
3699
02:48:48,069 --> 02:48:52,449
also going to use JSON libraries so
3700
02:48:50,200 --> 02:48:57,030
let's define our JSON above in here
3701
02:48:52,450 --> 02:49:00,131
let's say jisang is equal to a near json
3702
02:48:57,030 --> 02:49:05,440
after that inside this put a string
3703
02:49:00,130 --> 02:49:07,239
method let's say json dot to json and as
3704
02:49:05,440 --> 02:49:10,681
for the object I am going to say new
3705
02:49:12,101 --> 02:49:17,200
this way we are initializing our already
3706
02:49:14,290 --> 02:49:19,511
read books as an empty array list inside
3707
02:49:17,200 --> 02:49:21,700
our shared preferences we just need to
3708
02:49:19,511 --> 02:49:25,511
commit these changes we can say anything
3709
02:49:21,700 --> 02:49:28,090
commit let's do the same thing for the
3710
02:49:25,511 --> 02:49:30,431
other array lists as well for example
3711
02:49:28,090 --> 02:49:33,460
for this one to read books we need to
3712
02:49:30,431 --> 02:49:35,860
fix the get one to read books method if
3713
02:49:33,459 --> 02:49:38,859
you remember we had such a method down
3714
02:49:35,860 --> 02:49:41,280
in here let's copy everything from
3715
02:49:38,860 --> 02:49:45,851
inside this get already read box method
3716
02:49:41,280 --> 02:49:48,280
I'm going to copy everything and in here
3717
02:49:45,851 --> 02:49:50,710
let's paste them we just need to delete
3718
02:49:48,280 --> 02:49:56,170
this get a static keyboard and also
3719
02:49:50,709 --> 02:49:58,959
beside that use another key then after
3720
02:49:56,170 --> 02:50:00,879
that inside the constructor we need to
3721
02:49:58,959 --> 02:50:03,489
check that if this method is going to
3722
02:50:00,879 --> 02:50:06,640
return non or not let's say if not is
3723
02:50:03,489 --> 02:50:08,590
equal to get one to read books then we
3724
02:50:06,640 --> 02:50:10,359
are going to initialize our one to read
3725
02:50:08,590 --> 02:50:12,340
books ArrayList let's copy these two
3726
02:50:10,360 --> 02:50:16,630
line of code from here and let's paste
3727
02:50:12,340 --> 02:50:21,069
them in the second if case we just need
3728
02:50:16,629 --> 02:50:22,930
to change this constant similarly for
3729
02:50:21,069 --> 02:50:29,819
the currently reading book and favorite
3730
02:50:22,931 --> 02:50:32,590
books let's copy the logic from here and
3731
02:50:29,819 --> 02:50:36,940
paste them inside this gate currently
3732
02:50:32,590 --> 02:50:39,761
reading book method let's also delete
3733
02:50:36,940 --> 02:50:44,590
this a static keyboard and let's change
3734
02:50:39,761 --> 02:50:48,120
the constant let's do the same thing for
3735
02:50:44,590 --> 02:50:48,120
this gate favorite books method
3736
02:50:48,959 --> 02:50:55,839
delete the static keyboard and change
3737
02:50:51,909 --> 02:50:59,129
the constant let's minimize both of
3738
02:50:55,840 --> 02:51:02,409
these methods and let's go back to our
3739
02:50:59,129 --> 02:51:05,859
constructor let's say if null is equal
3740
02:51:02,409 --> 02:51:09,569
to get quietly reading books this one
3741
02:51:05,860 --> 02:51:15,340
let's copy these two line of code and
3742
02:51:09,569 --> 02:51:17,649
let's change the constant beside that in
3743
02:51:15,340 --> 02:51:20,021
here let's say if null is equal to get
3744
02:51:17,649 --> 02:51:22,779
favorite books once again let's paste
3745
02:51:20,021 --> 02:51:24,600
these two line of codes and also let's
3746
02:51:24,600 --> 02:51:28,899
okay now we have deal with our
3747
02:51:27,010 --> 02:51:31,719
constructor successful if we have
3748
02:51:28,898 --> 02:51:33,489
initialized all of our array lists let's
3749
02:51:31,719 --> 02:51:37,000
see what else do we have inside this
3750
02:51:33,489 --> 02:51:39,039
utils class we have fixed all of these
3751
02:51:37,000 --> 02:51:42,728
methods until down in here after this
3752
02:51:39,040 --> 02:51:45,399
get favorite books we also have this get
3753
02:51:42,728 --> 02:51:47,679
books by ID method let's quickly see
3754
02:51:45,398 --> 02:51:49,840
what will be having here so basically
3755
02:51:47,680 --> 02:51:52,090
once again we are using the all books
3756
02:51:49,840 --> 02:51:55,478
are released in order to get some pop by
3757
02:51:52,090 --> 02:51:58,120
its ID instead of that I'm going to get
3758
02:51:55,478 --> 02:51:59,829
the books from my shared preferences for
3759
02:51:58,120 --> 02:52:05,460
that I'm going to say array list of
3760
02:51:59,829 --> 02:52:08,939
books let's name it books is equal to
3761
02:52:05,459 --> 02:52:11,469
get all pubs I'm going to use my method
3762
02:52:08,939 --> 02:52:14,100
after that I'm going to check that if
3763
02:52:11,469 --> 02:52:17,398
these books are a list is null or not
3764
02:52:14,100 --> 02:52:20,380
let's say if null is not equal to books
3765
02:52:17,398 --> 02:52:25,269
then let's put our for loop inside that
3766
02:52:20,379 --> 02:52:29,409
if case and also let's iterate through
3767
02:52:25,270 --> 02:52:31,359
our books ArrayList that's all the
3768
02:52:29,409 --> 02:52:34,389
change we need to do inside this get put
3769
02:52:31,359 --> 02:52:36,640
by ID method now we are getting the book
3770
02:52:34,389 --> 02:52:39,608
from our shared preferences instead of
3771
02:52:36,639 --> 02:52:42,250
ArrayList after that we have these I had
3772
02:52:39,609 --> 02:52:46,149
two methods and is remove from method
3773
02:52:42,250 --> 02:52:49,148
let's quickly fix this as well inside
3774
02:52:46,148 --> 02:52:51,789
this method we are returning the result
3775
02:52:49,148 --> 02:52:54,219
of this dot add method which we have
3776
02:52:51,790 --> 02:52:56,200
called on our ArrayList this time I'm
3777
02:52:54,219 --> 02:52:59,108
going to connect my shared preferences
3778
02:52:56,200 --> 02:53:02,920
so I'm going to say negative stuff
3779
02:52:59,109 --> 02:53:05,890
different book let's name it books is
3780
02:53:02,920 --> 02:53:08,228
equal to let's say get already read
3781
02:53:05,889 --> 02:53:10,510
books if you remember above in here we
3782
02:53:08,228 --> 02:53:13,029
have fixed that method I'm talking about
3783
02:53:10,510 --> 02:53:15,670
this method in here and now instead of
3784
02:53:13,030 --> 02:53:18,460
using our ArrayList we are getting the
3785
02:53:15,670 --> 02:53:21,489
data from the shared references then
3786
02:53:18,459 --> 02:53:24,069
inside these two already read method we
3787
02:53:21,489 --> 02:53:25,840
are going to use that after that we need
3788
02:53:24,069 --> 02:53:28,750
to make sure that these books are a list
3789
02:53:25,840 --> 02:53:33,939
is not known let's say if not is not
3790
02:53:28,750 --> 02:53:37,430
equal to books after that let's say if
3791
02:53:33,939 --> 02:53:40,460
our books ArrayList that at
3792
02:53:37,430 --> 02:53:41,120
let's say book if the result of that is
3793
02:53:41,120 --> 02:53:46,311
then we are going to save these boats
3794
02:53:43,729 --> 02:53:49,129
are released into our shared preferences
3795
02:53:46,310 --> 02:53:51,319
as a reminder this add method will add
3796
02:53:49,129 --> 02:53:53,689
the book into our ArrayList and after
3797
02:53:51,319 --> 02:53:56,449
that we'll return through if something
3798
02:53:53,690 --> 02:53:58,670
wrong happens it will return false so
3799
02:53:56,450 --> 02:54:00,860
after this check in here inside this if
3800
02:53:58,670 --> 02:54:03,469
statement we have successfully added the
3801
02:54:00,860 --> 02:54:06,050
book into our list now we need to
3802
02:54:03,469 --> 02:54:08,539
convert this books ArrayList into a JSON
3803
02:54:06,049 --> 02:54:10,850
file and after that added to our shared
3804
02:54:08,540 --> 02:54:13,550
references for that I'm going to
3805
02:54:10,851 --> 02:54:16,700
instantiate address on in here and say
3806
02:54:13,549 --> 02:54:19,819
ji-sun is equal to new JSON after that
3807
02:54:16,700 --> 02:54:22,159
I'm going to instantiate my editor let's
3808
02:54:19,819 --> 02:54:25,310
name it editor is equal to shared
3809
02:54:22,159 --> 02:54:27,771
references that edit and after that I am
3810
02:54:25,310 --> 02:54:31,101
going to first of all remove the current
3811
02:54:27,771 --> 02:54:33,380
already read books and immediately after
3812
02:54:31,101 --> 02:54:36,829
that I'm going to put this new books
3813
02:54:33,379 --> 02:54:39,469
ArrayList so let's say editor dot remove
3814
02:54:36,829 --> 02:54:41,840
you can see that beside put a string and
3815
02:54:39,469 --> 02:54:43,879
get a string we have this remove as well
3816
02:54:41,840 --> 02:54:46,159
if you want to clear your shared
3817
02:54:43,879 --> 02:54:48,289
references you can use this clear method
3818
02:54:46,159 --> 02:54:50,899
which will remove all of the data inside
3819
02:54:48,290 --> 02:54:52,970
your shared references with the key that
3820
02:54:50,899 --> 02:54:56,029
you have provided above in here when you
3821
02:54:52,969 --> 02:54:57,829
have created your shared references I'm
3822
02:54:56,030 --> 02:55:00,771
talking about this key in here this
3823
02:54:57,829 --> 02:55:03,709
alternate TV it will clear all of the
3824
02:55:00,771 --> 02:55:05,480
data inside that shared preferences but
3825
02:55:03,709 --> 02:55:07,579
in here we are not going to clear all of
3826
02:55:05,479 --> 02:55:10,159
the data we are just going to clear our
3827
02:55:07,579 --> 02:55:13,069
already read books list and we are going
3828
02:55:10,159 --> 02:55:15,560
to update it with this new list so let's
3829
02:55:13,069 --> 02:55:18,440
use that remove method which requires a
3830
02:55:15,560 --> 02:55:21,739
key once again for the key I can pass my
3831
02:55:18,440 --> 02:55:23,930
constant already read books after that
3832
02:55:21,739 --> 02:55:26,420
let's say any third that put a string
3833
02:55:23,930 --> 02:55:29,120
for the key once again let's say already
3834
02:55:26,420 --> 02:55:32,719
read books and for the value let's say
3835
02:55:29,120 --> 02:55:36,200
Jason taught to JSON and let's pass our
3836
02:55:32,719 --> 02:55:39,229
books are released after everything we
3837
02:55:36,200 --> 02:55:41,450
just need to call that commit method if
3838
02:55:39,229 --> 02:55:44,000
we reach to this point we also need to
3839
02:55:41,450 --> 02:55:45,890
return true because as you can see the
3840
02:55:44,000 --> 02:55:48,409
return type of this method is abloom Ian
3841
02:55:45,889 --> 02:55:50,809
if we reach to this point it means that
3842
02:55:48,409 --> 02:55:53,648
we have successfully updated our share
3843
02:55:50,809 --> 02:55:56,809
preferences so we can safely return true
3844
02:55:53,648 --> 02:55:58,398
but in case if anything wrong happens in
3845
02:55:56,809 --> 02:56:00,170
this process we are going to return
3846
02:55:58,398 --> 02:56:03,408
false I'm going to do that after
3847
02:56:00,170 --> 02:56:05,510
everything let's say return false that's
3848
02:56:03,408 --> 02:56:07,879
all we need to do in order to add a new
3849
02:56:05,510 --> 02:56:10,639
book to our already read book list in
3850
02:56:07,879 --> 02:56:15,828
our shared preferences let's copy this
3851
02:56:10,639 --> 02:56:19,010
logic for the other methods for example
3852
02:56:15,828 --> 02:56:21,408
for this ad to want to read list let's
3853
02:56:19,010 --> 02:56:23,930
delete this return statement in here and
3854
02:56:21,408 --> 02:56:27,350
let's paste our logic we just need to
3855
02:56:23,930 --> 02:56:29,809
change this method let's say get one to
3856
02:56:27,350 --> 02:56:32,689
read books and after that we need to
3857
02:56:29,809 --> 02:56:35,988
change these constants as well once
3858
02:56:32,689 --> 02:56:38,689
again we want to read books ok let's do
3859
02:56:35,988 --> 02:56:43,430
the same thing for the other methods for
3860
02:56:38,689 --> 02:56:45,619
this currently reading let's change the
3861
02:56:43,430 --> 02:56:47,988
name of our method to get currently
3862
02:56:45,619 --> 02:56:51,949
reading books and after that let's
3863
02:56:47,988 --> 02:56:56,600
change our constant let's say currently
3864
02:56:51,949 --> 02:56:58,550
reading books let's minimize this method
3865
02:56:56,600 --> 02:57:01,029
and let's do the same thing for our last
3866
02:56:58,549 --> 02:57:05,448
method for this add to favorite method
3867
02:57:01,029 --> 02:57:09,670
let's say get favorite books and for the
3868
02:57:05,449 --> 02:57:09,670
constant let's say favorite books
3869
02:57:10,601 --> 02:57:14,710
okay I think that's enough for this
3870
02:57:12,761 --> 02:57:17,530
video this video is getting a little bit
3871
02:57:14,709 --> 02:57:19,359
long but we also have these remove
3872
02:57:17,530 --> 02:57:20,739
methods in which we are going to fix
3873
02:57:20,739 --> 02:57:24,640
beside that we have a lot of problems in
3874
02:57:23,500 --> 02:57:27,040
different part of our application
3875
02:57:24,640 --> 02:57:29,050
because first of all we have changed the
3876
02:57:27,040 --> 02:57:32,290
constructor of this you Tunes class and
3877
02:57:29,050 --> 02:57:34,000
also we have removed a static keyboard
3878
02:57:32,290 --> 02:57:36,700
from the Declaration of some of these
3879
02:57:34,000 --> 02:57:39,129
methods we will fix those problems in
3880
02:57:36,700 --> 02:57:41,730
the next video as well okay see you in
3881
02:57:44,189 --> 02:57:50,010
in the previous video we have rewrite at
3882
02:57:47,040 --> 02:57:52,050
this UTSA class up until these removed
3883
02:57:50,010 --> 02:57:54,360
methods in this video we are going to
3884
02:57:52,049 --> 02:57:56,849
change these remove methods in order to
3885
02:57:54,360 --> 02:57:59,909
get our data from the shared preferences
3886
02:57:56,850 --> 02:58:01,710
not static array lists beside that I
3887
02:57:59,909 --> 02:58:03,809
said that right now we have a lot of
3888
02:58:01,709 --> 02:58:06,599
problems in our application due to
3889
02:58:03,809 --> 02:58:08,489
changes in this utils class you can see
3890
02:58:06,600 --> 02:58:10,860
some red warnings above in here we are
3891
02:58:08,489 --> 02:58:13,199
going to fix them in this video as well
3892
02:58:10,860 --> 02:58:14,760
okay let's change this remove from
3893
02:58:14,760 --> 02:58:19,200
first of all let's delete this return
3894
02:58:16,559 --> 02:58:21,449
statement after that let's get already
3895
02:58:19,200 --> 02:58:23,880
read book let's say array list of
3896
02:58:23,879 --> 02:58:29,789
oops is the call to get already read
3897
02:58:27,540 --> 02:58:32,189
books after that I'm going to check that
3898
02:58:29,790 --> 02:58:35,729
if this array list is null or not let's
3899
02:58:32,189 --> 02:58:38,460
say if books or if not is not equal to
3900
02:58:35,728 --> 02:58:40,648
books if that's the case we are going to
3901
02:58:38,459 --> 02:58:42,239
remove the book from this list in here
3902
02:58:40,648 --> 02:58:44,760
you may think that you may write some
3903
02:58:42,239 --> 02:58:47,340
logic similar to these add methods for
3904
02:58:44,760 --> 02:58:49,739
example inside this add method after
3905
02:58:47,340 --> 02:58:51,898
checking that if our array is null or
3906
02:58:49,739 --> 02:58:53,939
not we are using this add method in
3907
02:58:51,898 --> 02:58:55,409
order to add our new book in here you
3908
02:58:53,939 --> 02:58:57,540
may want to do the same thing for
3909
02:58:55,409 --> 02:58:59,879
example you may want to say if books
3910
02:58:57,540 --> 02:59:01,740
taught remove the book that we are
3911
02:58:59,879 --> 02:59:04,049
receiving you may think that this is
3912
02:59:04,049 --> 02:59:08,188
I have tried that actually and the
3913
02:59:06,000 --> 02:59:10,079
reason for that is because this book
3914
02:59:08,189 --> 02:59:12,630
that you are passing to this method is
3915
02:59:10,079 --> 02:59:15,090
different from the book that is inside
3916
02:59:12,629 --> 02:59:17,549
your ArrayList the values are the same
3917
02:59:15,090 --> 02:59:19,469
for example the name IT description and
3918
02:59:17,549 --> 02:59:22,319
everything is the same for both of these
3919
02:59:19,469 --> 02:59:24,539
books but the reference is not for that
3920
02:59:22,319 --> 02:59:27,000
you cannot remove your book this way
3921
02:59:24,540 --> 02:59:30,840
instead I'm going to create a for each
3922
02:59:27,000 --> 02:59:34,260
loop let's say for pork let's name it be
3923
02:59:30,840 --> 02:59:37,170
inside our box ArrayList after that
3924
02:59:34,260 --> 02:59:40,800
inside the for loop let's say if B dot
3925
02:59:37,170 --> 02:59:44,520
ket PI D is equal to this incoming box
3926
02:59:40,799 --> 02:59:47,009
ID book target ID if that's the case
3927
02:59:44,520 --> 02:59:48,510
then we are going to remove this pot so
3928
02:59:47,010 --> 02:59:50,670
this way we are not checking the
3929
02:59:48,510 --> 02:59:53,130
reference of these two objects instead
3930
02:59:50,670 --> 02:59:55,860
we are checking their equality by their
3931
02:59:53,129 --> 02:59:57,209
ID so if that's the case we are going to
3932
02:59:57,209 --> 03:00:01,649
don't remove let's say be it's very
3933
02:59:59,430 --> 03:00:03,840
important to pass be in here and not
3934
03:00:01,649 --> 03:00:07,020
this incoming book or if you want to
3935
03:00:03,840 --> 03:00:10,020
have the boolean you can say if books
3936
03:00:07,020 --> 03:00:12,239
that remove let's pass P once again if
3937
03:00:10,020 --> 03:00:15,030
that's the case we are going to update
3938
03:00:12,239 --> 03:00:15,420
our shared preferences let's do that in
3939
03:00:15,420 --> 03:00:21,200
first of all we need an instance of our
3940
03:00:17,549 --> 03:00:24,478
JSON let's say is equal to new JSON
3941
03:00:21,200 --> 03:00:27,060
after that I can say editor let's name
3942
03:00:24,478 --> 03:00:28,639
it editor is equal to shared references
3943
03:00:28,639 --> 03:00:34,469
after that I can say editor dot removed
3944
03:00:32,430 --> 03:00:36,120
first of all we are going to remove this
3945
03:00:34,469 --> 03:00:38,309
already read book from our shared
3946
03:00:36,120 --> 03:00:40,950
preferences for that I need the key
3947
03:00:38,309 --> 03:00:43,228
that's math already read books after
3948
03:00:40,950 --> 03:00:46,050
that I'm going to put the new books
3949
03:00:43,228 --> 03:00:48,149
ArrayList let's say editor that put a
3950
03:00:46,049 --> 03:00:51,239
string or the key I'm going to say
3951
03:00:48,149 --> 03:00:54,869
already read books and for the value I'm
3952
03:00:51,239 --> 03:00:57,930
going to say json dot to json our books
3953
03:00:54,870 --> 03:01:00,030
are released after that lets say editor
3954
03:00:57,930 --> 03:01:02,190
dot commit in order to commit our
3955
03:01:00,030 --> 03:01:04,440
changes also the return type of this
3956
03:01:02,190 --> 03:01:06,690
method is a boolean so we need to pass
3957
03:01:04,440 --> 03:01:08,909
through in here after this editor that
3958
03:01:06,690 --> 03:01:10,739
commit if we reach to this point in our
3959
03:01:08,909 --> 03:01:12,478
code it means that we have successfully
3960
03:01:10,739 --> 03:01:14,909
removed a book from our shared
3961
03:01:12,478 --> 03:01:17,459
preferences so we can safely return true
3962
03:01:14,909 --> 03:01:19,889
but if anything wrong happens during
3963
03:01:17,459 --> 03:01:23,009
this process we need to return false
3964
03:01:19,889 --> 03:01:24,629
i'm going to do that after everything we
3965
03:01:23,010 --> 03:01:27,059
need to do the same thing for the other
3966
03:01:24,629 --> 03:01:29,219
three remove methods so let's copy all
3967
03:01:27,059 --> 03:01:32,129
of these and let's paste them inside
3968
03:01:29,219 --> 03:01:34,170
this remove from one to read we just
3969
03:01:32,129 --> 03:01:37,049
need to change the name of our method in
3970
03:01:34,170 --> 03:01:39,899
here to get one to read books and also
3971
03:01:39,899 --> 03:01:44,159
okay I think that's all the changes that
3972
03:01:42,120 --> 03:01:46,079
we need to do inside this utils class
3973
03:01:44,159 --> 03:01:48,030
that's where you can check everything we
3974
03:01:46,079 --> 03:01:50,370
have changed these remove methods we
3975
03:01:48,030 --> 03:01:52,920
have changed these add methods we also
3976
03:01:50,370 --> 03:01:55,230
have changed this get proper ID method
3977
03:01:52,920 --> 03:01:57,870
we change the gather methods for our
3978
03:01:55,229 --> 03:02:00,090
lists we also change this init data
3979
03:01:57,870 --> 03:02:02,851
method and after that we have changed
3980
03:02:00,090 --> 03:02:05,370
this constructor we no longer use these
3981
03:02:02,851 --> 03:02:07,920
array lists so I'm going to comment them
3982
03:02:05,370 --> 03:02:09,870
okay now let's fix our problems in our
3983
03:02:07,920 --> 03:02:12,659
application I'm going to check my
3984
03:02:09,870 --> 03:02:15,271
classes one by one so in the project
3985
03:02:12,659 --> 03:02:17,340
folder inside the package folder let's
3986
03:02:15,271 --> 03:02:20,040
check our classes one by one all books
3987
03:02:17,340 --> 03:02:22,139
activity first of all we have this error
3988
03:02:20,040 --> 03:02:24,450
in here we are using this get instance
3989
03:02:22,139 --> 03:02:27,149
if you remember this get instance now
3990
03:02:24,450 --> 03:02:29,190
requires a context which I'm going to
3991
03:02:27,149 --> 03:02:31,409
pass this you can see that we don't have
3992
03:02:29,190 --> 03:02:33,569
any much error inside this class let's
3993
03:02:31,409 --> 03:02:35,969
go to the next one I already read both
3994
03:02:33,569 --> 03:02:38,010
activity because we have removed a
3995
03:02:35,969 --> 03:02:40,409
static keyword from the Declaration of
3996
03:02:38,010 --> 03:02:42,540
this get already read books method I'm
3997
03:02:40,409 --> 03:02:44,851
going to fix that by calling to get
3998
03:02:42,540 --> 03:02:47,730
instance method let's say you tips that
3999
03:02:44,851 --> 03:02:50,130
get instance in which requires a context
4000
03:02:47,729 --> 03:02:51,750
in which I can pass this okay that's all
4001
03:02:50,129 --> 03:02:54,000
the fix that we need to do inside this
4002
03:02:51,750 --> 03:02:56,579
already read book activity let's go to
4003
03:02:54,000 --> 03:02:58,979
our book class because this is the model
4004
03:02:56,579 --> 03:03:00,870
and we haven't used anything from inside
4005
03:02:58,979 --> 03:03:03,899
the UTS class we don't need to change
4006
03:03:00,870 --> 03:03:06,240
this one inside the book activity we
4007
03:03:03,899 --> 03:03:08,579
have multiple errors you can click on
4008
03:03:06,239 --> 03:03:10,619
these errors from this left pane in here
4009
03:03:08,579 --> 03:03:12,120
in order to navigate to the errors for
4010
03:03:10,620 --> 03:03:14,970
example in here we need to pass a
4011
03:03:12,120 --> 03:03:17,640
context let's pass this let's check the
4012
03:03:14,969 --> 03:03:20,549
second one once again in here we need to
4013
03:03:17,639 --> 03:03:22,469
pass context the third error in here we
4014
03:03:20,549 --> 03:03:24,719
need to pass a context but because we
4015
03:03:22,469 --> 03:03:27,659
are inside this onclick listener we need
4016
03:03:24,719 --> 03:03:30,389
to pass group activity dot this instead
4017
03:03:27,659 --> 03:03:32,819
of this let's see others inside this
4018
03:03:30,389 --> 03:03:35,670
handle currently reading once again
4019
03:03:32,819 --> 03:03:37,229
that's passed this inside I click
4020
03:03:35,670 --> 03:03:39,420
listener of this between our two
4021
03:03:37,229 --> 03:03:42,210
currently reading I need to say book
4022
03:03:42,210 --> 03:03:47,699
in here we need to pass this also inside
4023
03:03:45,390 --> 03:03:50,100
this onclick listener of this BT an ad
4024
03:03:47,700 --> 03:03:52,950
to want to read let's say both activity
4025
03:03:50,101 --> 03:03:54,450
dot this that's probably all of the
4026
03:03:52,950 --> 03:03:56,280
changes that we need to do in our
4027
03:03:54,450 --> 03:03:58,860
application we just need to pass some
4028
03:03:56,280 --> 03:04:01,141
context to our get instance method let's
4029
03:03:58,860 --> 03:04:02,551
save this and let's check the last one
4030
03:04:03,479 --> 03:04:07,800
so let's say work activity that this I
4031
03:04:05,880 --> 03:04:10,050
think we have fixed all of the errors
4032
03:04:07,800 --> 03:04:12,630
inside this class let's check the others
4033
03:04:10,050 --> 03:04:14,430
inside the recyclerview adapter from the
4034
03:04:14,431 --> 03:04:19,171
onclicklistener of our positive button
4035
03:04:16,890 --> 03:04:21,479
of our alder toilet if you remember
4036
03:04:19,171 --> 03:04:24,030
inside this adapter we have received a
4037
03:04:21,479 --> 03:04:27,421
context where the constructor so I can
4038
03:04:24,030 --> 03:04:30,690
see damn context let's check others once
4039
03:04:27,421 --> 03:04:34,351
again let's pass in context in here as
4040
03:04:30,690 --> 03:04:37,081
well in context the last one that's here
4041
03:04:34,351 --> 03:04:38,581
let's say am context ok it seems like we
4042
03:04:37,081 --> 03:04:40,860
have fixed everything inside this
4043
03:04:38,581 --> 03:04:42,899
adapter let's switch to a currently
4044
03:04:40,860 --> 03:04:44,641
reading activity once again in here
4045
03:04:42,899 --> 03:04:46,380
because we have removed a static
4046
03:04:44,640 --> 03:04:49,020
keyboard first all we need to say get
4047
03:04:46,380 --> 03:04:51,421
instance and we need to pass our context
4048
03:04:49,021 --> 03:04:53,761
favorite activity let's say YouTube
4049
03:04:51,421 --> 03:04:56,190
start get instance and let's pass this
4050
03:04:53,761 --> 03:04:58,801
inside the main activity I believe we
4051
03:04:56,190 --> 03:05:01,530
have instantiated our routines let's
4052
03:04:58,800 --> 03:05:03,510
pass our context we have fixed the UTS
4053
03:05:01,530 --> 03:05:06,511
class we shouldn't see any error in here
4054
03:05:03,511 --> 03:05:08,489
let's go to one to read activity once
4055
03:05:06,511 --> 03:05:10,501
again we need to say gluten start get
4056
03:05:08,489 --> 03:05:12,630
instance and we need to pass this I
4057
03:05:10,501 --> 03:05:15,091
believe that was the last error in our
4058
03:05:12,630 --> 03:05:16,800
application let's also check the website
4059
03:05:15,091 --> 03:05:19,140
activity we don't need to change
4060
03:05:16,800 --> 03:05:21,331
anything inside this class ok now that
4061
03:05:19,140 --> 03:05:23,640
we have rewrite the logic for our
4062
03:05:21,331 --> 03:05:26,130
application let's test it and let's see
4063
03:05:23,640 --> 03:05:27,931
if everything works fine our application
4064
03:05:26,130 --> 03:05:30,689
is launching that's a good sign
4065
03:05:27,931 --> 03:05:32,791
let's go to our all books activity in
4066
03:05:30,690 --> 03:05:34,831
here we can see our books once again
4067
03:05:32,790 --> 03:05:36,870
that's a good sign let's see if we can
4068
03:05:34,831 --> 03:05:39,601
see the details of this book by clicking
4069
03:05:36,870 --> 03:05:42,810
on this button we are seeing them let's
4070
03:05:39,601 --> 03:05:44,521
also go to our book activity in here we
4071
03:05:42,810 --> 03:05:46,770
are seeing all of the details of our
4072
03:05:44,521 --> 03:05:48,931
book let's try adding this book to one
4073
03:05:46,771 --> 03:05:50,940
of our lists for example this one to
4074
03:05:48,931 --> 03:05:53,041
read it seems like we have added the
4075
03:05:50,940 --> 03:05:55,319
book successfully let's see if we can
4076
03:05:53,040 --> 03:05:55,890
see the details in here we can see them
4077
03:05:55,890 --> 03:05:59,640
we can see this delete water but here
4078
03:05:58,110 --> 03:06:02,251
comes the difference between using
4079
03:05:59,640 --> 03:06:04,560
aesthetic variables versus shared
4080
03:06:02,251 --> 03:06:07,171
preferences right now if we close our
4081
03:06:04,560 --> 03:06:09,390
application and run it once again we
4082
03:06:07,171 --> 03:06:09,841
should see this book still in our wish
4083
03:06:09,841 --> 03:06:13,261
let's close the application and let's
4084
03:06:11,761 --> 03:06:16,021
run it once again and let's see if we
4085
03:06:13,261 --> 03:06:18,360
can see this book in our wish list let's
4086
03:06:16,021 --> 03:06:21,030
run it once again let's go to our wish
4087
03:06:18,360 --> 03:06:23,791
list and as you can see we have our book
4088
03:06:21,030 --> 03:06:25,891
in our wish list now we have persisted
4089
03:06:23,790 --> 03:06:28,380
our data with the help of shared
4090
03:06:25,890 --> 03:06:30,359
preferences it seems to be great let's
4091
03:06:28,380 --> 03:06:31,020
also try to leting this book from our
4092
03:06:31,021 --> 03:06:35,521
I believe in here we should see a little
4093
03:06:32,790 --> 03:06:38,250
bug let's try deleting this book first
4094
03:06:35,521 --> 03:06:40,471
of all let's say no next time let's say
4095
03:06:38,251 --> 03:06:42,659
yes it seems like the book has been
4096
03:06:40,470 --> 03:06:45,029
removed successfully but we are seeing
4097
03:06:42,659 --> 03:06:47,251
the book inside our wish list I believe
4098
03:06:45,030 --> 03:06:49,860
the problem is that our recyclerview is
4099
03:06:47,251 --> 03:06:52,319
not refreshing if we go back to the main
4100
03:06:49,860 --> 03:06:54,541
activity and we open our wish list once
4101
03:06:52,319 --> 03:06:57,120
again you can see that the list is empty
4102
03:06:54,540 --> 03:07:00,120
but for some reason after deleting the
4103
03:06:57,120 --> 03:07:02,180
book the recyclerview does not refresh I
4104
03:07:00,120 --> 03:07:05,250
believe the reason for that is because
4105
03:07:02,181 --> 03:07:07,081
the process of deleting that book from
4106
03:07:05,251 --> 03:07:10,021
our recycler view takes too much time
4107
03:07:07,081 --> 03:07:11,610
and we have a trading issue in here if
4108
03:07:10,021 --> 03:07:13,891
you take a look at our recycler view
4109
03:07:11,610 --> 03:07:16,621
adapter this phonebooks recycler view
4110
03:07:13,890 --> 03:07:18,989
adapter you can see that after removing
4111
03:07:16,620 --> 03:07:20,939
the book from our lists immediately
4112
03:07:18,989 --> 03:07:23,251
after that we are calling these notify
4113
03:07:20,940 --> 03:07:25,110
data set changed we have seen the toast
4114
03:07:23,251 --> 03:07:27,601
message we have seen this book remove
4115
03:07:25,110 --> 03:07:29,761
text but it seems like this method in
4116
03:07:27,601 --> 03:07:31,980
here is not being called until this
4117
03:07:29,761 --> 03:07:34,021
point until calling this method we have
4118
03:07:31,979 --> 03:07:37,050
removed the book successfully from our
4119
03:07:34,021 --> 03:07:39,331
list but the process of updating the
4120
03:07:37,050 --> 03:07:41,850
process of making another connection to
4121
03:07:39,331 --> 03:07:44,130
the shared references inside for example
4122
03:07:41,851 --> 03:07:46,291
and I get favorites method takes too
4123
03:07:44,130 --> 03:07:48,479
much time and before that we have called
4124
03:07:46,290 --> 03:07:51,060
this method so we have called this
4125
03:07:48,479 --> 03:07:53,880
method before we get the new favorite
4126
03:07:51,060 --> 03:07:55,681
ports we can fix this we can create a
4127
03:07:53,880 --> 03:07:58,171
callback interface and create a
4128
03:07:55,681 --> 03:08:00,511
communication between this part of our
4129
03:07:58,171 --> 03:08:03,630
application between this on-click method
4130
03:08:00,511 --> 03:08:05,791
and for example favorite books activity
4131
03:08:03,630 --> 03:08:06,810
we can implement that callback interface
4132
03:08:06,810 --> 03:08:11,430
favorite books activities so that
4133
03:08:09,090 --> 03:08:14,579
whenever we remove some book inside this
4134
03:08:11,430 --> 03:08:16,770
on click method we update list of our
4135
03:08:14,579 --> 03:08:18,478
books but I'm not going to do that in
4136
03:08:16,770 --> 03:08:21,540
here because we haven't talked about
4137
03:08:18,478 --> 03:08:23,579
call back interfaces yet if you want as
4138
03:08:21,540 --> 03:08:25,740
a challenge for later videos you can
4139
03:08:23,579 --> 03:08:28,200
come back to this video and fix this
4140
03:08:25,739 --> 03:08:30,420
problem when we have talked about call
4141
03:08:28,200 --> 03:08:32,550
back interfaces I believe we will face
4142
03:08:30,420 --> 03:08:34,739
this problem a lot during the course and
4143
03:08:32,549 --> 03:08:37,139
we definitely will take a look at call
4144
03:08:34,739 --> 03:08:39,270
back interfaces and their usages in
4145
03:08:37,139 --> 03:08:41,430
situations like this so for that reason
4146
03:08:39,270 --> 03:08:43,530
I'm not going to talk about the solution
4147
03:08:41,430 --> 03:08:45,450
for that issue in this video let's
4148
03:08:43,530 --> 03:08:47,820
quickly check the other aspects of our
4149
03:08:45,450 --> 03:08:50,640
application for example let's add some
4150
03:08:47,819 --> 03:08:53,369
books to other lists let's try this book
4151
03:08:50,639 --> 03:08:56,369
let's say already read we have added the
4152
03:08:53,370 --> 03:08:58,439
book let's delete it let's say yes what
4153
03:08:56,370 --> 03:09:00,899
has been removed if we go back to main
4154
03:08:58,439 --> 03:09:03,239
activity and check our already read
4155
03:09:00,898 --> 03:09:05,579
books activity you can see that the list
4156
03:09:03,239 --> 03:09:07,770
is empty okay I think that's enough for
4157
03:09:05,579 --> 03:09:09,090
this video and for that matter for this
4158
03:09:07,770 --> 03:09:11,040
section of the course you have
4159
03:09:09,090 --> 03:09:13,559
successfully created your first
4160
03:09:11,040 --> 03:09:15,720
functional application as a reminder of
4161
03:09:13,559 --> 03:09:17,909
what we have done in this section I'm
4162
03:09:15,719 --> 03:09:20,670
going to say that we have practiced a
4163
03:09:17,909 --> 03:09:22,559
lot of our skill set beside that we have
4164
03:09:20,670 --> 03:09:24,930
learned how to show different dialogues
4165
03:09:22,559 --> 03:09:28,049
we have seen how to create a web view
4166
03:09:24,930 --> 03:09:30,450
and show our website beside that we have
4167
03:09:28,049 --> 03:09:33,029
seen how to create expandable record
4168
03:09:30,450 --> 03:09:33,810
views we have seen how to use aesthetic
4169
03:09:33,809 --> 03:09:38,189
beside that we have learned how to use
4170
03:09:35,939 --> 03:09:40,680
shared preferences we learned how to
4171
03:09:38,189 --> 03:09:43,680
enable this off button we learned how to
4172
03:09:40,680 --> 03:09:45,389
create animations for our activities we
4173
03:09:43,680 --> 03:09:47,850
also have learned how to change the
4174
03:09:45,389 --> 03:09:49,920
title of different activities I believe
4175
03:09:47,850 --> 03:09:51,120
overall this was a good section and I
4176
03:09:51,120 --> 03:09:55,290
hello everyone may Symes here this video
4177
03:09:53,489 --> 03:09:57,359
is about to reached its end but before
4178
03:09:55,290 --> 03:09:59,130
that I would like to say that it is
4179
03:09:57,359 --> 03:10:01,140
amazing that you have watched thus far
4180
03:09:59,129 --> 03:10:03,329
of the course make sure to have a little
4181
03:10:01,139 --> 03:10:05,250
party watching the entire course means
4182
03:10:03,329 --> 03:10:07,469
that you are serious about Android app
4183
03:10:05,250 --> 03:10:09,239
development because of that once again
4184
03:10:07,469 --> 03:10:11,039
I'm going to remind you that there is an
4185
03:10:09,239 --> 03:10:13,409
extended version of this course that you
4186
03:10:11,040 --> 03:10:15,030
can take there are more than 60 hours of
4187
03:10:13,409 --> 03:10:16,379
videos in that course and you will learn
4188
03:10:15,030 --> 03:10:19,200
everything that you need for a
4189
03:10:16,379 --> 03:10:20,939
successful career in Android app develop
4190
03:10:19,200 --> 03:10:23,101
by enrolling in the course you will have
4191
03:10:20,940 --> 03:10:25,290
lifetime access to all of the existing
4192
03:10:23,101 --> 03:10:27,360
videos and all of the new videos that
4193
03:10:25,290 --> 03:10:29,311
I'll add in the course you will have
4194
03:10:27,360 --> 03:10:30,989
access to the source code that I write
4195
03:10:29,310 --> 03:10:33,449
in the videos and you can ask your
4196
03:10:30,989 --> 03:10:35,789
questions directly from me and expect an
4197
03:10:33,450 --> 03:10:37,860
answer between hours above all you will
4198
03:10:35,790 --> 03:10:40,050
have 30 day money-back guarantee in case
4199
03:10:37,860 --> 03:10:42,360
if for any reason you changed your mind
4200
03:10:40,049 --> 03:10:44,699
click on the link in the description of
4201
03:10:42,360 --> 03:10:46,290
this video or go to Mako dot org for
4202
03:10:44,700 --> 03:10:48,750
more information about the course
4203
03:10:46,290 --> 03:10:51,990
remember that you can use free code camp
4204
03:10:48,750 --> 03:10:53,549
as the coupon code to get 20% discount I
4205
03:10:51,989 --> 03:10:57,829
hope you learned something in this
4206
03:10:53,549 --> 03:10:57,829
course take care and continue coding
311993
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.