We'll come back and this video, we are going to load the profile data off the user, so here we want
to display the data and yeah, let's just go ahead and built that.
So in order to do that in the my profile activity, I will need to call a function which is our fire
restore function.
So I'm just going to do it right here.
Fire store, class, dot sign in user and pass this activity.
So at this point, I think passing in the activity, my profile activity is not going to work.
Right.
So it doesn't understand what's going on.
But I'm also not very happy with the name of this function anymore.
So if we look at a function in our first class.
So an end user.
OK, I called it, I wrote it correctly.
But the thing is, we are not really signing in the user anymore when we update the navigation user
details.
So how I want to rename this function is I'm going to rename it to.
Load user data, so load user data.
I think this is going to be more descriptive because it's really just loading user data and one case
that's signing in the user and logging in the user done.
And the other one, it's updating the navigation user details.
And then the third one, which we had now is our my profile activity.
So in that case, what it should do is it should call a function from the profile activity.
And give it to user data.
All right.
So let's go out and create a new function here.
I'm going to create a new function called Set User Data in UI.
And Anita, a user here, and then I can go ahead and display the.
Image, first of all, so here I'm using the model's user, by the way.
So we are going to use the same function that we used before.
We're going to use this glide function now, this time with the profile activity.
We load the user image, we crop it.
Then alternatively, we used to use a placeholder and where do we want to use it?
Well, in our IVI user image.
Now, to make sure that this is the correct one.
Let's go to our profile XML file this one and see if we actually called the image IVI user image, just
to be sure.
So it's at the very top, I think inside of the card view.
So circle view, it's just one.
I have a user image inside of our activity in my profile.
Right.
So that's the one that I want to assign here.
This image to.
OK, so this is just one step, and of course, we also want to get the name of the user or set the
name of the user with the text of user name.
Then the email said text with user dot email.
And then if there is a user mobile number.
So user dot mobile is not equal now or zero has a long value, then also set the number so he t mobile
set text user dot mobile to string because otherwise it would look weird if just not a zero would be
entered there.
Right.
So if we look at it, if I zero would be the mobile number, I think this is not good.
So that's why we do this check here.
If zero is stored in the user object, which basically is what we get when we download the document.
So when we download this document, we get this mobile number, which is zero, and if it's zero, we
don't want to use it.
And that's what we do here.
So if it's not zero, then we want to use to number that is stored there.
All right, and that is the function that I want to use here, by the way, it's not an end user anymore.
Now it's called.
So store class that could not not got current user already, part load user data and I passan this activity.
OK, so now what we need to do is we need to run the code here, so activity that said user data in
UI with logged in user.
So you see we we here say, OK, activity, please call this function inside of our my profile activity.
But before that we say in my profile activity, please call this function, which then in turn calls
this function here, but then it also gives us the user name or not just the user name, but the whole
user object.
Right.
So that is the idea.
It's really we go from the my profile activity over to first class.
We call this function.
This function goes back to the activity, which is are my profile activity, and then calls the function
inside of this one.
But this time we get the user.
That's the huge difference.
Right.
So we just wanted to have the user.
And the thing is, we already have this class which gives us or this method even which gives us the
user that is currently locked in.
So why wouldn't we reuse it?
And that's exactly what we have this code for.
So by doing it this way, we save us so much code we would otherwise have to do this code or reuse this
code multiple times or copy and paste it multiple times.
So each time and the activity sign an activity then in the main activity then into my profile activity.
But the way we do it now is we just called this function.
It gives us the Lockton user.
We don't need to create extra code all the time.
I hope this makes sense, even though, of course, that would be probably a little easier to read if
we would not do it in one one place.
But on the other hand, if we do it in one place, it's just all there.
Right.
It's a little more obvious.
Well, it really depends on what you prefer.
OK, so let's just test it.
Let's see if we now get Homer with the image and his email address and potentially even his phone number.
So let's add a phone number of Homer Simpson.
I don't know what his number will be.
Five five five one, two, three, four, five, six, something like that.
That's updated.
And now the only thing that is still me is going to be the email address.
But other than that, it's going to be Homer Simpson.
So let's see.
Let's go to my profile.
And we can see there is Homer to name the email the mobile number five five five one, two, three,
four, five, six.
All right, at this point, we know how to load all the user data.
We, of course, still need to update user data.
So let's say we make changes to the mobile number or the name than we would, of course, want to be
able to update it.
Of course, our update button doesn't do anything as of now, but we will add functionality to our app
in the next video, of course.
So see you in the next one.