1
00:00:00,210 --> 00:00:06,480
So now I'm going to pasting some lines of code here inside this class and then I'm going to explain

2
00:00:06,480 --> 00:00:07,930
to you what's going on here.

3
00:00:08,070 --> 00:00:13,050
So before the end in curly brace of this class here as you can see this is the end in equilibrate of

4
00:00:13,050 --> 00:00:13,710
this class.

5
00:00:13,710 --> 00:00:18,120
So before the end in curly braces this class I'm going to paste in these lines of code here.

6
00:00:18,240 --> 00:00:24,900
So as you can see here these are the lines of code that I pasted here and now I'm going to explain to

7
00:00:24,900 --> 00:00:26,810
you what's going on here.

8
00:00:26,850 --> 00:00:28,320
Exactly.

9
00:00:28,350 --> 00:00:30,540
So now let's actually look at this method.

10
00:00:30,540 --> 00:00:32,270
Here we have our method right.

11
00:00:32,400 --> 00:00:36,370
And now as you can see here the axis of this method is public.

12
00:00:36,660 --> 00:00:39,840
The return type of the Smurfette is void.

13
00:00:39,930 --> 00:00:44,580
The name of the Smurfit is modify animals guess Rose as you can see here.

14
00:00:44,910 --> 00:00:51,750
And this method actually accepts one argument of type shared preferences and the name of this argument

15
00:00:51,750 --> 00:00:53,210
is shared preferences.

16
00:00:53,220 --> 00:00:53,920
Right.

17
00:00:54,000 --> 00:00:59,550
So now as you can see here let's go inside the curly braces of the Smurfette And let's see what's going

18
00:00:59,550 --> 00:01:03,450
on here in line number three hundred and eighty nine as you can see.

19
00:01:03,570 --> 00:01:10,030
We have actually a constant and the name as he has here that data type of this constant is string.

20
00:01:10,260 --> 00:01:15,460
And the name of our constant is actually number of guest options.

21
00:01:15,690 --> 00:01:20,620
So here as you can see we have a constant that can hold of idea of type string.

22
00:01:20,640 --> 00:01:20,970
Right.

23
00:01:21,000 --> 00:01:24,030
So final strange number of options.

24
00:01:24,180 --> 00:01:31,230
Assignment operator and that I referred to the name of this actually to the name of this argument shared

25
00:01:31,230 --> 00:01:34,380
preferences that get strange.

26
00:01:34,630 --> 00:01:39,620
And now as you can see here I am actually referring to this guess as to this case is here.

27
00:01:39,780 --> 00:01:41,350
So this case is here.

28
00:01:41,430 --> 00:01:47,130
Actually first to this guess Chih that we have inside this main activity class.

29
00:01:47,280 --> 00:01:47,680
Right.

30
00:01:47,760 --> 00:01:51,020
So analysis I should go inside this main activity fragment that of a fight here.

31
00:01:51,030 --> 00:01:57,620
So now let's just type in main activity that classes are now in this.

32
00:01:57,690 --> 00:02:02,850
You can understand that we are referring to this this is key that we have inside this main activity

33
00:02:02,850 --> 00:02:04,130
that double wide.

34
00:02:04,140 --> 00:02:10,820
So this here this constant actually holds this key settings underline number of guesses.

35
00:02:10,830 --> 00:02:13,770
So now if we actually go inside.

36
00:02:14,040 --> 00:02:16,140
Actually let me show you the structure of the project.

37
00:02:16,140 --> 00:02:21,490
So just click on View and then tool windows and then click on Project.

38
00:02:21,720 --> 00:02:28,500
And now it's actually double click on this red folder and then let's go inside this values folder and

39
00:02:28,500 --> 00:02:34,680
here as you can see we have these XML files and now let's actually double click on this XML file here

40
00:02:34,710 --> 00:02:40,620
as you can see the DoubleClick and the xml folder and then double click and the squeeze underline preferences

41
00:02:40,620 --> 00:02:41,970
that exemplified.

42
00:02:42,420 --> 00:02:47,460
And now it's actually double click on this a tab here quis underlying preferences that exemplified in

43
00:02:47,460 --> 00:02:51,410
order to act in order to actually make it make this area Vider.

44
00:02:51,870 --> 00:02:56,530
So as you can see here inside this file we have actually a list preference right.

45
00:02:56,880 --> 00:03:01,680
And this is preferencial actually holds the number of guest list as you can see here.

46
00:03:02,010 --> 00:03:08,940
And the key is settings underline number of guesses and the title is as I see it as you can see here

47
00:03:09,150 --> 00:03:10,240
number of cases total.

48
00:03:10,260 --> 00:03:14,730
And if I actually hold up the comment the comment on my keyboard as you can see here and then click

49
00:03:14,730 --> 00:03:19,790
on the title here as you can see it's a number of guesses right inside strings that exemplified.

50
00:03:20,430 --> 00:03:25,260
And let's go back into our Q Is Underland preference is that exemplified and here as you can see the

51
00:03:25,260 --> 00:03:31,070
summary is this values Schu show two four or six gives options.

52
00:03:31,060 --> 00:03:37,650
And now if I show you the emulator and if I actually go inside the settings but activity here as you

53
00:03:37,650 --> 00:03:41,300
can see now if I actually click on this number of guesses here.

54
00:03:41,820 --> 00:03:46,350
Now it says that we have actually two four or six options.

55
00:03:46,350 --> 00:03:49,130
So here we have actually a typo number.

56
00:03:49,140 --> 00:03:53,180
So now let's actually hold the comment here on the keyboard.

57
00:03:53,190 --> 00:03:58,110
If you are using a Windows machine just hold the control on your keyboard and then click on this title

58
00:03:58,110 --> 00:03:58,730
here.

59
00:03:58,830 --> 00:04:02,410
As you can see we didn't actually put the are chelator here.

60
00:04:02,410 --> 00:04:06,660
So a number of guesses right now is actually on our project again.

61
00:04:07,860 --> 00:04:12,080
And now let's get you to go back into our quiz underlying preferences that examined by.

62
00:04:12,330 --> 00:04:17,640
So now as you can see we have this preference yet and a persistent is true.

63
00:04:17,760 --> 00:04:26,170
And this means that it can actually save our changes into their shared preferences file.

64
00:04:26,430 --> 00:04:30,100
Inside our Android device and the default value is number four.

65
00:04:30,360 --> 00:04:36,660
And this means that the default value of just options is four and we are going to have Fortius options

66
00:04:37,050 --> 00:04:41,170
for our quiz if we don't specify our value for this.

67
00:04:41,190 --> 00:04:42,870
Actually for this this preference.

68
00:04:42,870 --> 00:04:44,550
So now let me show you the emulator here.

69
00:04:44,550 --> 00:04:47,190
As you can see now it says number of guesses.

70
00:04:47,220 --> 00:04:54,170
And if I click on it now for example if I want to actually for example if I select is 6 here I want

71
00:04:54,180 --> 00:05:00,280
when I actually click on back button here I want to have for example says six gives options right.

72
00:05:00,330 --> 00:05:05,150
Now let's actually click on this setting's activity and this number of guesses here and here.

73
00:05:05,160 --> 00:05:10,350
If I actually click on this for example to here two number of cases and then click click on this patch

74
00:05:10,350 --> 00:05:11,190
with and here.

75
00:05:11,190 --> 00:05:12,850
Are you going to have two number of guesses.

76
00:05:12,870 --> 00:05:13,200
Right.

77
00:05:13,200 --> 00:05:14,580
Not six.

78
00:05:14,580 --> 00:05:17,540
So we need to actually provide some logic for this.

79
00:05:17,550 --> 00:05:19,510
So here we have this list preference.

80
00:05:19,680 --> 00:05:22,950
And the key is settings underline number of guesses.

81
00:05:23,100 --> 00:05:25,680
Inside is an activity of a fight as you can see here.

82
00:05:25,680 --> 00:05:32,650
We created this color this constant here in say this main activity class and the key is guesses.

83
00:05:32,820 --> 00:05:38,640
And then I put an assignment operator here and this this is actually the key settings on the number

84
00:05:38,640 --> 00:05:39,270
of cases.

85
00:05:39,270 --> 00:05:43,650
So we assigned this value to these constants so that we can actually refers to this constant in order

86
00:05:43,650 --> 00:05:45,270
to access this value.

87
00:05:45,540 --> 00:05:48,380
Inciters main activity affreightment our job here.

88
00:05:48,400 --> 00:05:56,280
I want to actually provide this actually this logic here in order to allow the user to actually specify

89
00:05:56,460 --> 00:06:00,700
the number of guest options that he or she wants to have inside the quiz.

90
00:06:01,110 --> 00:06:07,180
So now as you can see this method actually accepts an argument of type shirt preferences right.

91
00:06:07,320 --> 00:06:14,220
So has preferences that jet stream main activity so this if it gets through in here actually sits two

92
00:06:14,220 --> 00:06:15,180
arguments right.

93
00:06:15,180 --> 00:06:18,120
The first one is that actually the key.

94
00:06:18,370 --> 00:06:21,220
So main activity that just that guess is as you can see here.

95
00:06:21,230 --> 00:06:26,820
So in this way we can actually access this list preference that we have inside this quiz underlying

96
00:06:26,870 --> 00:06:32,180
preferences that is similar in this way by actually reading what is key that you specified here.

97
00:06:32,240 --> 00:06:39,840
We can actually access this this this list preference and then we can actually get the value that we

98
00:06:39,840 --> 00:06:42,750
get from this actually from these radio buttons.

99
00:06:42,750 --> 00:06:45,180
So as you can see here let me show you the emulator.

100
00:06:45,180 --> 00:06:51,000
So for example if I go inside this setting's activity here and then click on the number of guesses here.

101
00:06:51,150 --> 00:06:54,070
As you can see we have number two four or six.

102
00:06:54,300 --> 00:06:59,610
So when I say let's actually go back into our main activity fragment of a fight here.

103
00:06:59,640 --> 00:07:02,850
When I say share preferences that get strange.

104
00:07:02,880 --> 00:07:05,640
So it can actually give us a string value right.

105
00:07:05,880 --> 00:07:11,190
And now as you can see here in say this quiz underling preference is that exemplified the default value

106
00:07:11,190 --> 00:07:14,600
is number four right inside the double quotes as you can see here.

107
00:07:14,610 --> 00:07:15,040
Right.

108
00:07:15,180 --> 00:07:19,740
So this is going to be osting value right because this value is inside double quotes.

109
00:07:19,740 --> 00:07:24,640
So inside this way activity fragment that of a file when I say share preferences that gets three is

110
00:07:24,670 --> 00:07:26,280
going to give us a string value.

111
00:07:26,310 --> 00:07:28,430
First I need to specify the key.

112
00:07:28,620 --> 00:07:36,420
So the key is main activity that guesses right main activity that guesses and now the second argument

113
00:07:36,420 --> 00:07:36,870
is not.

114
00:07:36,870 --> 00:07:40,840
So now let me ask you to call this method here again in order to show you the second argument.

115
00:07:40,920 --> 00:07:44,450
So shares preferences that get strange

116
00:07:47,280 --> 00:07:50,370
and now as you can see here that's the first argument is key.

117
00:07:50,500 --> 00:07:53,320
And the second argument is the default value.

118
00:07:53,320 --> 00:07:54,180
Right.

119
00:07:54,670 --> 00:08:00,850
So here inside this quiz preference preferences that example I actually specified the default value

120
00:08:00,850 --> 00:08:01,350
here.

121
00:08:01,450 --> 00:08:04,920
So I don't need to provide a default value here again.

122
00:08:04,930 --> 00:08:08,690
So I actually assign the value null for the second argument.

123
00:08:08,710 --> 00:08:11,920
So let me read this line of code here.

124
00:08:11,950 --> 00:08:14,970
So now let's look at this line of code here again.

125
00:08:15,040 --> 00:08:20,680
So we have a constant the data type of this constant is strange the name of this constant is number

126
00:08:20,680 --> 00:08:21,920
of options.

127
00:08:21,940 --> 00:08:27,100
So this constant is going to hold the number of options that we use that actually specifies.

128
00:08:27,200 --> 00:08:30,310
So assignment operator shares preferences.

129
00:08:30,340 --> 00:08:33,850
So you can actually go inside the shared preferences that jet stream.

130
00:08:33,860 --> 00:08:39,630
So it's going to actually get a string value and then it's going to actually pass the CI.

131
00:08:39,700 --> 00:08:44,890
So because you want to actually get the number of just options as you can see here we need to pass the

132
00:08:44,890 --> 00:08:48,210
key the key of this actually list this reference.

133
00:08:48,220 --> 00:08:53,440
If I can say this squeeze Underland preferences that exemplified you can see that because I want to

134
00:08:53,440 --> 00:08:59,110
get the value of this this preference right because these are actually radio buttons in say the radio

135
00:08:59,120 --> 00:09:01,300
group we can only select one of them right.

136
00:09:01,390 --> 00:09:07,300
So when I say get strange is going to actually only give us one of these values to four or six.

137
00:09:07,360 --> 00:09:07,950
Right.

138
00:09:08,020 --> 00:09:15,550
So now if I go back into our main activity fragment of a file you can see that I passed this key in

139
00:09:15,550 --> 00:09:21,160
order to access that list preference and for the default value I passed the value null because inside

140
00:09:21,160 --> 00:09:26,500
this quiz Underland preferences that exemplified for this this preference here as you can see here for

141
00:09:26,500 --> 00:09:31,570
these key settings underline number of cases I specified a default value.

142
00:09:31,570 --> 00:09:32,620
Number four.

143
00:09:32,680 --> 00:09:36,510
So now let's actually go back into our main activity fragment out of a file.

144
00:09:36,910 --> 00:09:42,830
So here now this string constant actually holds the number of options.

145
00:09:42,880 --> 00:09:48,170
For example 2 4 or 6 because we are actually getting that value from these shared preferences.

146
00:09:48,370 --> 00:09:52,070
So if you look at this quiz Underland preferences are exemplified here.

147
00:09:52,090 --> 00:09:58,780
When we assign the value true to this persistent attribute of we actually said to the computer to our

148
00:09:58,840 --> 00:10:03,900
Android device to actually save those changes to the shared preferences.

149
00:10:03,910 --> 00:10:09,590
So when I actually referred to this shared preference I can't get that specific value right.

150
00:10:09,670 --> 00:10:16,240
So Shetterly that gets trencherman activity that us and for the second argument null and then in line

151
00:10:16,240 --> 00:10:21,670
number three hundred and ninety one as you can see here I actually referred to this valuable number

152
00:10:21,670 --> 00:10:23,340
of animals guestrooms.

153
00:10:23,350 --> 00:10:29,200
So now if I actually scroll to the top here inside this class as you can see we actually created this

154
00:10:29,200 --> 00:10:35,890
variable here in line number 55 and disvalue is actually that integer and the name is number of animals

155
00:10:35,890 --> 00:10:36,660
get throws.

156
00:10:36,790 --> 00:10:43,500
So this value is supposed to hold the number of guests throws that we are going to have in say the quiz.

157
00:10:43,510 --> 00:10:49,230
So now let's actually scroll down here and now as you can see here insight is actually inside the Smurfette

158
00:10:49,240 --> 00:10:51,980
modify animals guess throws.

159
00:10:52,030 --> 00:10:57,810
I am actually initialising despite the overall number of animals just throws assignment operator.

160
00:10:58,060 --> 00:11:04,150
So now as you can see here we need to actually convert because as you can see here we're actually getting

161
00:11:04,150 --> 00:11:06,510
this value as a string value right.

162
00:11:06,520 --> 00:11:10,900
We need to convert that value to an integer value so that we can actually use it.

163
00:11:10,900 --> 00:11:17,110
Inside our quiz so that we can actually tell the actual main activity here that we are going to have

164
00:11:17,110 --> 00:11:22,090
for example six throws or four guess throws or for example two guesses.

165
00:11:22,120 --> 00:11:22,640
That's bad.

166
00:11:22,640 --> 00:11:25,490
You must be an integer value right.

167
00:11:25,540 --> 00:11:31,810
So now as you can see because these values are actually string values when we want to get these values

168
00:11:31,810 --> 00:11:34,230
here we are actually getting them as a string to.

169
00:11:34,240 --> 00:11:36,660
For example two or four or six.

170
00:11:36,670 --> 00:11:37,960
We need to convert them.

171
00:11:37,960 --> 00:11:42,590
We need to convert those values actually to an integer value for example the value is too right.

172
00:11:42,640 --> 00:11:45,280
We need to convert that number to an integer value.

173
00:11:45,370 --> 00:11:47,190
So integer that parse.

174
00:11:47,210 --> 00:11:48,430
Int.

175
00:11:48,680 --> 00:11:52,880
And then we need to pass this thing value that you're going to convert it to actually to an integer

176
00:11:52,890 --> 00:11:57,130
reduce the number of options as you can see here divided by two.

177
00:11:57,140 --> 00:11:59,760
Why did I divide this value by two.

178
00:11:59,780 --> 00:12:00,650
Why do they do that.

179
00:12:00,650 --> 00:12:01,680
Just think about that.

180
00:12:01,730 --> 00:12:04,960
And then we're going to talk about this line of thought here.

