Now that we have the user class, we can go ahead and use user, so let's import user here, which is
our models.
So instead of models.
And not the user that we get from Firestorm.
It's important that we use the right one here.
So now what I want to do is I want to register the user right in this function, but what we need,
therefore, is our M store collection.
So I'm going to create a new collection, which is going to be called users.
OK, so it's going to be something like this or something like this.
But the thing is, I'm using a magic string here.
That's something that I shouldn't do.
I think it's better if I go ahead and create a new.
Class, which will be or new file, which will be Constance.
This will just be a constant object.
Which will for now just have one constant contact, all users string, which will be users.
All right, so now we can use this constant that we prepared.
So Constance thought user or users.
So this is just a cold way to do the same thing as if we just created a new collection here, which
is called Users.
OK, so here, creating a collection or start collection, and we called this one, for example, users,
and then we click next and now it becomes interesting because the document ID and all of the different
fields, that's what we do next in the code.
So we know go ahead and create a document, right, so that document.
And here we need to get the current user ID, so we want to create a new document for every single user
that we have because we want to store details about every single user.
Right.
So it would be good if we could get the user ID, which is this unique user I.D. So how do we get that?
Well, we need to function for that.
So let's create a new function, which is just going to give us the current user ID, get current user
I.D., which will return a string, which then will simply return firebase of.
Firebase Horth, get instant's current user.
You ID.
OK, so that will give us, as to current users, unique ID, which is.
This year, you ID this one here, so it's going to give us this one and we want to use that as the
document inside of our collection.
So we'll create a new collection, which we call users.
Then we have a new document which is going to be called this weird number or this weird add value that
we just saw for every single user.
So every user will have his own collection or the collection, but every user will have his own document.
OK, so we have collections in collections, we have documents and then we have all of those fields
and the fields will be the one that we have in our user class, which is ID, name, email, image for
mobile and so forth.
So we don't want to create all of that stuff manually, but we want to do it in a code.
That's exactly what we do now.
So now let's go ahead and pass in the user, the current user, so get current user ID, then we want
to set the user info to be set options Merche.
So it's going to merge the user info, whatever user info is passed to us.
And then we need to finally add in on success listener, so did it work, Ed, on success a listener
and if it did work, well, then we want to execute some code.
So we want to run the activity that is passed to this function, this registered user function, which
is to sign up activity.
And we dare want to call the user registered.
Success, so user registered success.
So it doesn't exist, so let's go over to the sign up activity and created.
For now, it's just going to be a new function user registered.
Success, which will show a toast, so let's see if we find a toast somewhere.
I'm just going to use this toast here and actually I want to do the same thing as I did here.
So where is it?
It's up here, so let's write this little toast without the name and the email you have successfully
registered.
Something like that.
And here.
We should also highlight the progress bar, so hide.
Progress.
Thilak.
So here, make tax, something is wrong with make text.
It still needs the length here.
So that's because I forgot to add a little quotation mark here.
So hi, progress dialogue at that point and then lock the user out.
By the way, if we now used to hide progress, dialogue, function here, we won't need it anymore in
our registered user because we also did that somewhere in here.
And that is right here, so we won't need it here anymore.
And now at that point, we need to make sure that when we are registering a user that we call the fast
or class function, which is called registry user.
So the thing is, we're registering the user on two levels.
Right.
So one is we actually create the new authentication entry for him.
And the other one is that we create a new entry in the collection of users, which is a new documentation
or a document.
Right.
And this will is a little abstract still, but it will make a lot more sense once we actually run the
code and we see what it does with our entry in the fire store database.
OK, so at this point, there's one little thing left to do.
And that is to get rid of this toast here.
We won't need it anymore in here and we also don't need to sign out here anymore.
But what we want to do is we want to create a new user.
Right.
So here we just go ahead and say what user is going to be a new user, which is going to be a firebase
user?
Thought you I.D. is what are we going to pass there?
We passed a name and we passed a registered email.
OK, so let's go ahead and import user.
This time it's also our models here.
So we'll create this new user object and now we can pass that user object to our first class function,
which is this registered user.
So we need to pass on an activity which is going to be this, and then we pass in the user, which is
the user that we just created in our sign up activity.
So now we can go ahead and say fires to class, dot register user.
And here we pass on this and we pass in our register or our user that we prepare.
And then, of course, I need the brackets here because I'm not using a first class object.
I'm using the actual class here.
So I need the brackets in order to call its function.
All right.
So at this point, let's test our application and see if it's going to do what we need from it.
And by the way, while it's loading, let's go to authentication and get rid of those two users, because
those two day would cause problems later on.
Because otherwise, well, we will try to access their information as users, but they don't exist,
right, because we changed everything.
So they just didn't exist in the database to exist in the authentication, but they don't exist in the
database.
So if we want to access anything from the database, that would cause problems.
All right, and at that point, we can test it, there's only one little thing that I noticed when I
ran into an issue testing it, and it's not really the code itself.
The code is fine as it is now.
There's just one duplicate that I have here, which is activity finish, which I run here once again
in the Firestone class, even though it's necessary because an user registered success, we already
run finish.
Okay, so it's not really necessary also when testing it.
And by the way, now it works.
So the code is fine and I had to test it on another machine in order to make sure that the code is fine.
But it still didn't work for me.
So registering the user did work for me, but creating the collection for some reason didn't work.
So what I needed to do is I needed to restart my computer and then run it again and then it worked.
So if you have the problem that it doesn't work for you, then just try to do these kind of things,
such as restarting your computer or closing Android studio and opening it up again, or even deleting
the different folders that are inside of this project folder.
So the build cradle an idea and also the build folder in here, you could delete them and then run the
application again.
I'm telling you this, because this issue, which is super funny, it didn't happen on other machines,
but for me it did.
That's why I wanted to talk about it real quick so that, you know, if something like that happens,
that sometimes it's not the code, sometimes it's some unknown force.
That's how I'm going to call it, because I have no idea where it comes from sometimes.
All right.
So let's sign sign up now.
Therefore, I go here, I create a new user, and by the way, I deleted all the other ones, as you
have seen, and now let's add this user here.
And sign up, please wait, and you've successfully registered.
So now let's go back to the authentication.
And just refresh the page just to see if we have new users.
And we can see we have them, of course, I could have pressed reload button that probably would have
been faster and done in the database.
Let's see if we have something in Project Manaj.
We have this collection called Users.
Then we have the user with this unique ID and we have all of this information.
So we have this email system token nothing yet.
ID Yes.
Image nothing.
Amabel zero a name doneness.
All right.
So it worked.
We have passed an object into our database has fields I guess so we have this object.
Is this the object, the user object.
And these are all of the features of the user object.
So all of the variables that the user class has and all of the details that we have with it.
All right.
So now you know how to create a collection, how to add a value in there and store data inside of the
database.
And we will, of course, have to check how to retrieve the data and we will work with all of those
things in the next video.
So see you there.