1
00:00:00,520 --> 00:00:01,340
Welcome back.

2
00:00:01,569 --> 00:00:06,180
Now that we have created the functionality to upload an image.

3
00:00:06,460 --> 00:00:13,570
Let's go ahead and pretty much update our user info as well, because just uploading the image is not

4
00:00:13,570 --> 00:00:14,120
going to be enough.

5
00:00:14,140 --> 00:00:19,960
We also need to make sure that the image is stored in the user database as well.

6
00:00:20,380 --> 00:00:20,790
All right.

7
00:00:20,800 --> 00:00:21,820
So let's go ahead.

8
00:00:21,820 --> 00:00:27,400
And first of all, create a little function here, which I'm going to call a profile update success,

9
00:00:27,910 --> 00:00:31,890
which will be called each time that our profile update is successful.

10
00:00:32,170 --> 00:00:35,320
And for now, we're just going to do the following.

11
00:00:35,320 --> 00:00:39,400
We're going to highlight the progress dialog and we're going to finish the current screen.

12
00:00:40,890 --> 00:00:45,180
Or activity, so we're closing the current activity with the finished statement here.

13
00:00:46,640 --> 00:00:52,070
So basically, when the user has updated, what we want to do is we want to close this activity and

14
00:00:52,070 --> 00:00:54,500
send the user back so he doesn't have to do it manually.

15
00:00:55,850 --> 00:01:01,230
Next, what I want to do is and that will be the coat that will be done in our fire store functionality.

16
00:01:01,520 --> 00:01:05,570
So let's go over to our forest or class.

17
00:01:06,850 --> 00:01:14,050
So here we will have another function which will take care of updating the user profile data so you

18
00:01:14,050 --> 00:01:20,050
can see this class is responsible for all of the database stuff, the other functions, they just do

19
00:01:20,050 --> 00:01:27,250
the code that has to be done inside of the class itself and which is not directly linked to the fire

20
00:01:27,310 --> 00:01:29,590
store or firebase functionality.

21
00:01:29,620 --> 00:01:33,450
So this is very useful when you want to make your app unmaintainable.

22
00:01:34,160 --> 00:01:41,470
OK, so fun update user profile data should be responsible of updating the user profile.

23
00:01:42,190 --> 00:01:49,960
OK, and here what I'm going to require is an activity of type, my profile activity.

24
00:01:52,490 --> 00:01:55,910
And a hash map, so let's look at this.

25
00:01:56,570 --> 00:02:04,370
I'm going to call this one user hash map and what we have to have hash map and now we need to define

26
00:02:04,550 --> 00:02:07,390
what variable types it will have.

27
00:02:07,670 --> 00:02:12,390
So as the key, it will have a string and as a value it will have any.

28
00:02:13,160 --> 00:02:18,210
OK, so this is what I was talking about in the last video.

29
00:02:18,770 --> 00:02:27,230
So basically the idea is that we will have the functionality that allows us to pass in the user as a

30
00:02:27,230 --> 00:02:30,890
hash map and I will show you why that is required in the second.

31
00:02:31,160 --> 00:02:35,860
So let's just start this fire store collection stuff, as we have done before.

32
00:02:35,870 --> 00:02:44,930
So we get to constant users, then we get to document for the current user ID and then now we don't

33
00:02:44,930 --> 00:02:48,110
want to get the data, but we want to update the data.

34
00:02:48,530 --> 00:02:50,510
Now, the thing is, if you want to update.

35
00:02:51,380 --> 00:02:55,160
So here, let's have a look at this update.

36
00:02:56,580 --> 00:03:03,900
It will offer you multiple options, so data field and field property or whatever, and the one that

37
00:03:03,900 --> 00:03:08,470
I want to use is the one that requires a user or a Hashmat.

38
00:03:08,940 --> 00:03:11,810
OK, so it requires a type of a Hashmat.

39
00:03:12,330 --> 00:03:18,270
If you look at this update function, you will see none nullable or non null map with a string, an

40
00:03:18,270 --> 00:03:18,810
object.

41
00:03:19,500 --> 00:03:22,800
So object is the class name and Java.

42
00:03:23,100 --> 00:03:27,750
And in Scotland it's called any and that's exactly the type that we have here.

43
00:03:27,780 --> 00:03:31,230
So instead of object, you have to use any in.

44
00:03:33,070 --> 00:03:36,790
Cotton and Kinzie object itself is not accepted.

45
00:03:36,940 --> 00:03:42,110
We need to use any here, it's the cotton in class, the base class, everything is built upon.

46
00:03:42,640 --> 00:03:48,220
So that's why we need to pass in a Hashmat instead of a user object, because it would have been easier,

47
00:03:48,220 --> 00:03:49,310
as we have done before.

48
00:03:49,310 --> 00:03:49,520
Right.

49
00:03:49,540 --> 00:03:54,220
Where we get the whole thing is user object, and then we make changes to the user object and then we

50
00:03:54,220 --> 00:03:55,770
just send it over and update it.

51
00:03:56,050 --> 00:03:59,570
But the thing is, it requires something of type, Hashmat.

52
00:03:59,590 --> 00:04:05,560
So we need to transform our user object into this specific Hashmat type.

53
00:04:07,580 --> 00:04:14,640
So whenever you call this update user profile data, you don't need to pass on activity and user Hashmat

54
00:04:15,020 --> 00:04:17,010
OK, and that will then update the collection.

55
00:04:17,630 --> 00:04:21,959
So then the next thing we want to do is we want to add an unsuccess listener.

56
00:04:22,550 --> 00:04:24,860
So we want to know if things went right.

57
00:04:25,100 --> 00:04:26,510
So what do we want to do there?

58
00:04:26,870 --> 00:04:33,200
Well, first of all, let's write a little luck entry here where we just say profile that update that

59
00:04:33,200 --> 00:04:34,060
successfully.

60
00:04:34,520 --> 00:04:35,930
Very basic log entry.

61
00:04:37,290 --> 00:04:43,950
Then we can make a little toast so that the user also knows that things have been updated, profile,

62
00:04:44,280 --> 00:04:52,200
updated successfully, and then we want to call activity that profile.

63
00:04:53,350 --> 00:05:00,880
Update success, so basically dysfunction that we just prepared before profile, update success.

64
00:05:03,350 --> 00:05:07,910
So what will happen if there is a failure, so add on failure.

65
00:05:08,060 --> 00:05:08,660
Listener.

66
00:05:09,960 --> 00:05:14,640
Well, what I'm going to do is I'm going to use that exception and.

67
00:05:15,540 --> 00:05:19,020
It was activity that I progress dialogue.

68
00:05:20,660 --> 00:05:29,290
Have a little log entry again, so error while creating a board and yeah, that's pretty much.

69
00:05:29,370 --> 00:05:32,980
We can also, of course, add a little toast here saying.

70
00:05:34,040 --> 00:05:35,510
Profile update's.

71
00:05:36,580 --> 00:05:43,810
Error or error when updating the profile?

72
00:05:44,990 --> 00:05:52,970
All right, and we can go back to our my profile activity and we will need two new variables here.

73
00:05:53,940 --> 00:06:00,690
Actually, we have one already, which is a powerful image, but we need another one which will be private

74
00:06:01,020 --> 00:06:07,170
late in it, variable and user details of type user.

75
00:06:09,290 --> 00:06:10,760
And we will initialize it.

76
00:06:11,920 --> 00:06:14,950
In said user data.

77
00:06:16,080 --> 00:06:21,010
UI updates function, where is it, said user data in UI.

78
00:06:21,900 --> 00:06:26,550
So that's what we're going to set up the user because that's where we get the user, right?

79
00:06:26,550 --> 00:06:33,630
So we get the user from the other class, from our Firestar class, and now we can set it so user details

80
00:06:33,630 --> 00:06:36,330
will be our user object at this pass to us.

81
00:06:37,910 --> 00:06:43,580
So what we're going to change is the image, the mobile and the name, and it makes sense to have these

82
00:06:43,580 --> 00:06:45,710
names, so to speak, as Constance.

83
00:06:46,840 --> 00:06:52,510
Because they are constant names inside of our database and we want to change values behind those key,

84
00:06:52,520 --> 00:06:57,190
so keys should always be used as constants, at least in this context.

85
00:06:57,190 --> 00:06:57,420
Right.

86
00:06:57,790 --> 00:07:00,940
So let's go ahead and go to our Constance again.

87
00:07:03,580 --> 00:07:10,730
So here you tale's Constance, so far, we only have to use this table as a constant.

88
00:07:10,900 --> 00:07:13,390
Actually, it's not the table, it's the whole document.

89
00:07:13,390 --> 00:07:13,750
Right.

90
00:07:14,440 --> 00:07:22,900
But what we want to have is we want to also have the image, the name and the mobile as Constance.

91
00:07:23,200 --> 00:07:23,590
All right.

92
00:07:23,600 --> 00:07:25,810
So these three variables here.

93
00:07:27,540 --> 00:07:34,020
All right, and now we can actually update the user profile data, so we have this function called update

94
00:07:34,020 --> 00:07:38,250
user profile data in our Firestar class.

95
00:07:39,850 --> 00:07:43,700
Now, let's create a function with the same name and our my profile activity.

96
00:07:44,380 --> 00:07:45,220
OK, so.

97
00:07:46,480 --> 00:07:49,480
It's also going to be called update user profile.

98
00:07:51,760 --> 00:07:58,240
Data and this time it doesn't need any specific data because the profile data is inside of this class

99
00:07:58,240 --> 00:07:58,660
already.

100
00:08:00,440 --> 00:08:03,980
So what we will do here is we'll create a user hash map.

101
00:08:04,400 --> 00:08:09,440
All right, you've probably already guessed that we will need it one at one point, right?

102
00:08:09,830 --> 00:08:12,920
So user hash map will be of type hash map.

103
00:08:14,400 --> 00:08:17,700
With a string and any as the.

104
00:08:18,600 --> 00:08:19,440
Key value pair.

105
00:08:22,220 --> 00:08:24,720
OK, now we can add values to that, Hashmat.

106
00:08:24,740 --> 00:08:29,570
So how do we add a value to a Hashmat and what are the values that we want to add to the Hashmat?

107
00:08:30,050 --> 00:08:32,240
Well, it's the image URL.

108
00:08:32,419 --> 00:08:36,169
It's the name of the user and it's the mobile number.

109
00:08:36,840 --> 00:08:39,520
It's the same three values that we have here as constants, right?

110
00:08:39,530 --> 00:08:40,669
Image, name and mobile.

111
00:08:41,720 --> 00:08:48,290
OK, so let's do that, let's add the image, first of all, we can check if my profile image, your

112
00:08:48,290 --> 00:08:49,730
URL is not empty.

113
00:08:50,680 --> 00:08:55,270
Because if it's empty, we shouldn't use it and image profile your URL.

114
00:08:56,350 --> 00:09:01,510
Is not the same as the image that we already use as the user details image.

115
00:09:01,750 --> 00:09:05,470
So, um, user details about image.

116
00:09:07,690 --> 00:09:14,170
So this is the one that is stored in the database, right, if it's exactly the same your URL, then

117
00:09:14,170 --> 00:09:15,460
we don't need to make any changes.

118
00:09:15,460 --> 00:09:17,790
But if it's not the same, then we want to make changes.

119
00:09:18,250 --> 00:09:23,580
So then we will just say user Hashmat at the position.

120
00:09:23,800 --> 00:09:24,730
So at the key.

121
00:09:25,860 --> 00:09:28,560
Constance, that image.

122
00:09:29,820 --> 00:09:33,660
He's going to be equal to him, profile image, Earl.

123
00:09:35,520 --> 00:09:38,670
So he was just saying he was a Hashmat at the position.

124
00:09:38,850 --> 00:09:47,910
That's the same as if we had used a hash map and here we pass an image, OK, because if you look at

125
00:09:47,910 --> 00:09:49,710
this, Constance is just image.

126
00:09:51,310 --> 00:09:58,000
So it's just a key, and if you want to get the value from something or from a Hashmat, you can just

127
00:09:58,000 --> 00:09:58,920
use the key like this.

128
00:09:58,930 --> 00:10:01,660
So this will then return whatever is behind image.

129
00:10:02,720 --> 00:10:06,500
In our case, it will be this jury will hear this disvalue.

130
00:10:07,570 --> 00:10:10,960
OK, so this upload Wikimedia work and so forth.

131
00:10:11,930 --> 00:10:15,200
And if you want to assign something to it, you just used to equal some.

132
00:10:16,180 --> 00:10:21,410
OK, so this is how we can update a Hashmat, how we can add values to the Hashmat.

133
00:10:21,670 --> 00:10:26,090
Now, the next thing we want to see if the user has changed the username.

134
00:10:26,110 --> 00:10:29,110
So if et on the screen name.

135
00:10:30,380 --> 00:10:37,670
To the text to string is going to be not equal the same as Muser.

136
00:10:38,650 --> 00:10:40,240
Details that name.

137
00:10:43,900 --> 00:10:46,870
Because if it's the same, there's no use in updating, right?

138
00:10:47,200 --> 00:10:52,870
So the idea is that we first check if the user has made any updates before you press the update button,

139
00:10:52,870 --> 00:10:57,250
because maybe he didn't make any changes and he still presses the update button.

140
00:10:57,440 --> 00:11:02,120
But if that's the case, we don't want to make another call to the database.

141
00:11:02,140 --> 00:11:03,100
It's not necessary.

142
00:11:03,560 --> 00:11:07,930
We don't want to make any changes in the database if there are no changes to be made.

143
00:11:08,470 --> 00:11:14,260
And that's why we check first if there are any changes, because we already know the data from the database

144
00:11:14,740 --> 00:11:17,380
and we can compare it to the data that the user has entered.

145
00:11:17,710 --> 00:11:19,960
And if there's no change, then don't do anything.

146
00:11:20,470 --> 00:11:26,020
OK, so here we're just changing the same thing for the name.

147
00:11:26,650 --> 00:11:32,200
So we're just saying hash map constants name is going to be.

148
00:11:33,580 --> 00:11:35,980
Equal to eat underscore name.

149
00:11:38,110 --> 00:11:40,360
Text to string.

150
00:11:43,420 --> 00:11:51,630
And then finally, we do the same thing with the mobile number, so Etty Mobile takes to strength,

151
00:11:52,180 --> 00:11:54,790
is it the same as the mobile value?

152
00:11:55,840 --> 00:11:58,060
Then we check that mobile.

153
00:11:59,360 --> 00:12:03,470
And here, mobile to string, of course.

154
00:12:05,380 --> 00:12:11,800
And then we say E.T. mobile text to string to.

155
00:12:13,030 --> 00:12:13,570
Long.

156
00:12:15,690 --> 00:12:19,260
Because they used the Hashmat expects a long value here.

157
00:12:21,300 --> 00:12:24,810
Because, of course, our phone number here is not a string, it's a long value.

158
00:12:26,530 --> 00:12:33,430
OK, and at that point, we have prepared everything and we can just say fire or.

159
00:12:35,440 --> 00:12:36,160
Class.

160
00:12:37,620 --> 00:12:38,940
Update user.

161
00:12:40,320 --> 00:12:41,970
Profile and here.

162
00:12:43,430 --> 00:12:52,010
It's this Firestar class, like this first class update user profile data with this activity and the

163
00:12:52,430 --> 00:12:57,560
user, Hashmat, has the hash map that we need to pass.

164
00:13:00,390 --> 00:13:04,950
Now, of course, as I said, if there are no changes, we would need to call this function so you could

165
00:13:04,950 --> 00:13:06,600
create a new variable here.

166
00:13:06,990 --> 00:13:13,370
So var any changes made is false.

167
00:13:13,980 --> 00:13:18,810
And then if that is the case, you could say any changes made equals true.

168
00:13:20,440 --> 00:13:24,040
And here, the same, any changes made equals true.

169
00:13:25,040 --> 00:13:27,160
And then finally here as well.

170
00:13:28,440 --> 00:13:37,950
Any changes made equals true and then check if any changes made equals true, no, not equals.

171
00:13:37,980 --> 00:13:43,980
Well, actually, just like this, if it's true, then just run the opposite profile data.

172
00:13:45,210 --> 00:13:51,000
OK, so this is how you could check it, if the user presses to button, either we want to update anything

173
00:13:51,000 --> 00:13:51,660
or we don't.

174
00:13:53,300 --> 00:13:56,360
But the thing is in our update, user profile.

175
00:13:58,190 --> 00:14:02,680
Do we do anything about hiding the progress dialogue where we are hiding the progress dialogue here?

176
00:14:03,020 --> 00:14:07,970
So in that case, what you would then of course, also have to do is to highlight the progress dialogue

177
00:14:07,970 --> 00:14:08,620
accordingly.

178
00:14:10,030 --> 00:14:16,780
All right, so I'm just going to get rid of this, if any changes made and so forth, you can use it

179
00:14:17,170 --> 00:14:18,280
now, you know how to do it.

180
00:14:18,280 --> 00:14:20,350
But I'm just going to keep it simple for now.

181
00:14:21,720 --> 00:14:26,310
OK, so we have the same name, right, we use the same name for both functions, update user profile

182
00:14:26,310 --> 00:14:30,900
data, one is inside of my profile activity and the other one is in our Firestar class.

183
00:14:31,230 --> 00:14:37,290
But the fire still needs the activity in which it should perform it and it needs the user hash map as

184
00:14:37,290 --> 00:14:37,610
well.

185
00:14:39,380 --> 00:14:49,250
All right, and at that point, we can modify our on update button click listener here, button updates

186
00:14:49,400 --> 00:14:56,060
on Click Listener, so now we can make changes to it because otherwise what we want to do is we want

187
00:14:56,060 --> 00:14:56,480
to.

188
00:14:58,000 --> 00:14:59,470
Showed a progress dialogue.

189
00:15:00,630 --> 00:15:06,660
I'm not the image chooser, but the progress dialogue with please wait.

190
00:15:08,610 --> 00:15:16,110
And then what we want to do is we want to update our profile data.

191
00:15:17,930 --> 00:15:26,240
So update user profile data now, this user profile data we have to do still, we added a little to

192
00:15:26,240 --> 00:15:27,920
do somewhere in our code.

193
00:15:28,930 --> 00:15:31,060
And actually, it's easier to find it like this.

194
00:15:31,570 --> 00:15:32,500
So here.

195
00:15:33,380 --> 00:15:38,900
We have this to do, hi, progress dialogue, so now instead of doing this, we can't call this optic

196
00:15:38,910 --> 00:15:44,240
user profile data function and that is inside of our upload user image.

197
00:15:44,630 --> 00:15:49,670
So the thing is, when we upload the user image now, we will also do is we will call the optic user

198
00:15:49,670 --> 00:15:52,100
profile data function, which will then.

199
00:15:53,330 --> 00:15:54,980
Trigger making changes.

200
00:15:57,560 --> 00:16:03,290
All right, now we can, of course, make this function private, and at this point we can test our

201
00:16:03,290 --> 00:16:07,610
application because we never use up the user profile data somewhere else.

202
00:16:08,450 --> 00:16:10,070
So it makes sense to.

203
00:16:11,000 --> 00:16:11,840
Make it private.

204
00:16:13,860 --> 00:16:15,210
All right, so let's test it.

205
00:16:15,960 --> 00:16:18,690
Let's see if any changes are going to be made.

206
00:16:21,020 --> 00:16:22,700
So let's go to my profile.

207
00:16:23,650 --> 00:16:25,540
Let's select the Holmer image here.

208
00:16:29,100 --> 00:16:36,750
OK, now it's uploaded, we can see Holmer well, let's change it to Homer Simpson.

209
00:16:38,330 --> 00:16:42,310
And the mobile phone number will have seven, eight, nine as well.

210
00:16:43,460 --> 00:16:46,620
OK, at that point, let's update just to see if anything's going to happen.

211
00:16:46,640 --> 00:16:52,610
OK, so the dialogue opens profile update successfully and we're sent back to our main activity.

212
00:16:53,620 --> 00:16:56,980
And now let's look at the database, let's see.

213
00:16:57,010 --> 00:17:02,470
OK, so the link has been changed, the link now, is this your URL here?

214
00:17:04,500 --> 00:17:10,710
Which is this almost instant image, perfect, and other than that, what else was changed?

215
00:17:11,160 --> 00:17:14,670
Well, the mobile number has been changed at the name also has been changed.

216
00:17:15,150 --> 00:17:16,950
OK, so now it works perfectly.

217
00:17:18,319 --> 00:17:24,950
You can see how you can update data in the database, not just create data, but also update data.

218
00:17:25,010 --> 00:17:29,090
Of course, also how to load data, because if you want to update something, you need to know what

219
00:17:29,090 --> 00:17:29,820
you want to update.

220
00:17:30,170 --> 00:17:35,520
So now you pretty much know everything you need to know to build the whole application, I'd say.

221
00:17:36,110 --> 00:17:41,630
Of course, there are functionalities where we need third party libraries still and where we need to

222
00:17:41,630 --> 00:17:42,840
look into it a little more.

223
00:17:42,860 --> 00:17:45,710
But overall, I think we're at a very good spot now.

224
00:17:46,880 --> 00:17:49,790
OK, so let's go over to the next video.

