Welcome back.
Now that our authentication functionality seems to work, let's look at database.
So there we have two options, right?
So one, in the database, you can either use fire store or you can use the.
Real time database and I talked about it very briefly before, but what we are just going to use the
cloud firestorm because it's more powerful queries, automatic scaling.
So it's just a better choice for us.
Right.
So let's go ahead and create that.
We are going to use the test mode because we want to be able to test everything.
Right.
Anyone with a database reference will be able to read right to your database for 30 days.
So this is a high risk approach.
Of course, anything good or many things could go wrong.
But in our case, because we want to test it, it's going to make our life a lot easier, especially
at the beginning.
So once you're in production, you should definitely change your rules there.
Then you have to select your cloud forest location so where the data should be located.
So you have, of course, multiple different options here.
I'm just going to use Europe West because I am in Europe and then I'm going to press down.
If you have an application where your user base will be mainly in another country or in one specific
country, then you definitely have to consider that your put your location cloud first location specifically
at that location.
OK.
All right, once that is done, you will find yourself seeing the screen where you have data rules,
indexes and usage and by the way, in rules, that's the thing that has been changed for us to hear.
Read right.
Is activated so that we can.
Ride around and play around with it, you can see, hear, read, write, and then request time, time
stamp date 20, 20, the 22nd of March, then it will change.
OK, so for now, it's a ride are both allowed, but later on we'll change it.
And you can change those rules any time.
If you want to know more about the rules, check out the documents here.
OK, but for now, it's going to be fine for us.
We can just go ahead to the data tab and yea, we can now create our own collections.
For example, we can go ahead and create a collection called User's.
So let's go ahead and create this collection called Users, and now you can go ahead and create and
document ID, for example, you can go ahead and create an auto ID.
You can add all of the different fields that you want to have.
For example, for user, what we have is the name, the email address.
And then we could have something like an image or whatever you can come up with.
Right.
But the thing is, you don't even need to do that here.
So we can, of course, create a collection and create everything just here in this beautiful UI.
But we are going to do that in code.
So you will see how to create collections and those objects, so to speak, in code, because we will
create a class, a user's class, which will then contain all of the information that we want to store
about a user.
All right.
At that point, we can go back to our project and we will need to add a new.
Implementation here or a new dependency to our project, so let's add that it's the first to implementation
here.
Let me add that you can see Firebase.
Firestorm 21 four zero, so it's similar to what we had before when we had firebase off and you can
see the versions, they differ a little bit.
So now we're using Firestone.
Later on, we will use storage and we will need to add another dependancy.
But for now, this is going to do.
So don't forget to think it, of course, and once the singing is done, you can start thinking, all
right, you can start using Storm.
All right, and the next thing is that we are going to create a new class, so the thing is I thought
about different ways to approach this application and doing it in while doing the code that you need
in the classes where you need them to create a lot of duplication.
And I thought it would be a lot nicer to have a very clean structure that you can easily re use and
then also easily adjust and maintain.
So let's say at one point Firebase doesn't work anymore.
So you don't want to go to every single class and make changes to every single part of the application.
But you want to have one class which handles the whole database stuff.
So in case Firebase doesn't work anymore, you need to change to another solution in the future.
For whatever reason, Firebase doesn't exist anymore.
They go bankrupt even though it's highly unlikely that Google will ever go bankrupt.
But I mean, like generally, if you use a solution which could potentially go obsolete at one point,
then it's always good to have the code already be prepared for this.
And that's what we're going to do.
So we are going to create an extra class which will take care of the whole database stuff and horror
of the whole fire store stuff.
And that will make our life a lot easier if we ever have to change anything.
OK, so let's go ahead and create a new directory here.
So a new package and this one will be Firebase and inside of Firebase.
I want to have this new class, which I'm gonna call Firestar class.
Very awesome name.
So file class.
Fire store, or maybe it's just a store class, all right then and here, I want to put all of the different
fire base fire store dependent or irrelevant code.
So, first of all, I will need to have an instance of the fire based fire storm.
All right.
So private fall and fire storm, I'm going to call it, and will be fire base, fire store, dot, get
instance.
So let's get the instance directly.
Fire based firestorm needs to be written correctly.
Then it will also allow me to use it in my case.
So you can see we have this new import here, fire base, fire store, and then we get the instance.
So let me see what still complaining because it added this tour.
OK, so now we have our fire base fire, for instance.
And now we can go ahead and create a new user so we can register a user in our database, so the idea
is that we don't only registered user directly in the authentication module, but also in our database.
So not only here in authentication, where we have the user, we have this identifier that we have when
we was created and the user ID.
But we also want to store a little more information about the user.
So each time user registers, we also want to have them in the database so that we can then add information
about as, let's say, telephone number.
If you want that or if you want to add an image of him or he wants to add an image of him, then we
want to be able to do that, OK?
And that's why we need to have an entry for every user in our database.
So let's create a little function, which will do just that, so fun register user, which will need
an activity and I'm going to pass on the sign up activity and then user info, which will be of type
user.
So we will need to create a class which allows us to do a lot of stuff.
Right.
So let's go ahead.
Do we have the users already?
No, we don't have it.
So we need to create a new model called user.
So let's go ahead and create it real quick, New Scotland class, and this one will be user.
Now, this is going to be a data class, right, data class user, and we want to have a bunch of information
about the user here.
So when we use the data class, we just need those kind of brackets or not the curly ones just around
the ones.
So I want to store the ID of the user.
So let's do that then.
I want to store the name of the user.
Then what else would be interesting?
Well, the email would be nice.
So let's add the email as well.
Email of the user.
Then what else?
Well, image, how about an image, so I'm going to store the image as a string as well because I'm
just going to store the image location on the database.
So it's not really the database, but it's actually the.
Storage functionality of firebase, so you can see we have an extra.
The point here, which is called storage, so you can store images or even videos on the storage.
All right.
So we will have the image then, maybe also the mobile number of the user, so mobile, which will be
a long.
I'm just going to set to zero for now and then to Afkham token.
So we will also need to have a token of the user so that we know that it's the specific user that is
Lockton next.
I would like to make this class pasodoble, and in order to do so, I can of course, write all of the
code manually or I can just go to settings and then have a new plugin.
So here on the plugins, let's search for Paul sellable and you will find this Android Pozible coal
generator.
That's the one that I want.
And for it to work, you need to restart the idea, all right, at that point, it should work.
So let's make it past sellable for so long, though, with a capital P, of course I'll pass lable.
And now implement the members.
And also at the pass the level implementation, so you can see it will create all of this stuff here,
constructor pozole restring.
Right.
Passell described then also this companion object creator.
So this is automatically generated now by the help of the plugin that we just installed.
Now, at this point, it's complaining because Passell.
Our restring is going to return a nullable, so we need to add all of those exclamation marks.
But once we've done that, you can see by my class already so far.
Now, when we want to describe contents, what we're going to do is we're just going to assign zero
to it.
And to write Postle here, we're just going to add a bunch of right strings.
So write string the ID.
And by the way, I'm just going to make Pozole and not Nullable.
And also I need to add this statement here with that.
And now.
Right.
String is going to work.
So we need to do what's right string for all of the different values that we have.
So here it's going to be right long for the number.
For the phone number, right?
So.
That's add mobile here.
This one was the idea, and we had the name, we had the email and we had the image.
Then finally we had the same token.
OK, so.
When we write into a parcel, what we're going to do is we write all of our variables that we have here.
OK, so at this point, this class is going to be ready and we can go on because the video is already
going to be so long because we need to still add quite some stuff in the first class or we need to create
a first class and so forth.
I would say let's make a quick break here and then finish this part of the exercise or part of the code
in the next video where we're going to finally be able to add data to our database in the fire store
database.
So see you there.