Welcome back.
At this time, we can go ahead and prepare everything that we need for the board to work.
So the idea is that we have a data model which allows us to create boards and we can then use that data
model to store the boards in the cloud.
And that's exactly what we want to do.
Right.
So we need to know the details about the board.
So I think let's just get started with it.
You can post a video and think about what would be the things that have to be in such a project board,
so to speak.
OK, so if we look at this here, what we can see, it has an image, it has a board name.
And then what else would we want to display about the board or know about the board in the backend?
All right, so I'm going to tell you what we will start with, it's not everything that we will do for
board later on, but I think it makes sense to start with a name for the board, then with an image
or at least a string for the image or the your eye to link, so to speak.
And then we need to know who created the board.
And then we also would want to know who is assigned to the board.
So this would be the information that we need to know for now.
Later on, we also potentially want to store the information about the different cars that are in the
board and all those kind of things.
So let's get started with a basic model first, though.
All right.
So therefore, I'm going to create a new class in here in the models.
So create New Cutline file class and I'm going to call this one board.
All right, so this board is going to have or it's going to be a data class, so we keep it super simple.
We don't need to have any additional information in there.
Right.
So let's make it the data class, no functions or anything, just the basic data, and we will make
it past a little bit later on.
So what we need is, as I said, the name, which will be a string, then we need the image, which
will also be a string.
And by the way, we need to separate them with a comma, of course, because that's as if it was in
the one line, then I want to know who created it.
So created by which will also be a string.
And this should be the unique user ID or the user name we will see later on.
And then we need to know who is assigned to so assigned to array a list of strings, because now it
could be multiple people.
So it needs to be an array list.
All right.
So I'm going to say that it's an empty array list for now.
All right.
Now, let's make it passable.
So far, so lovable.
And we need the colon here.
And of course, it's with a capital P here, once we have that, we can import parts of the book and
then we need to make adjustments here.
So add harvestable implementation.
So it adds the constructor right to pozole creator and everything.
And here we need to add Passell, not create string radost just like that.
Also, we still need to make some changes here, so I'm just going to say it should directly return
zero.
Well, that's a fine way to do that, actually.
Right to Passell is lacking one thing, so it's still missing our list here.
So right string list.
With our assigned to.
I'm going to say that it should to do with the parcel.
All of those things.
All right, so then the arrow disappears and things seem to work, but here a parcel of red string.
Well, we can also say Passell, that red string list here.
And then here we need to force it here with a bunch of exclamation marks.
OK, so this is going to be our board.
And we need to do that, by the way, because restring is at Nullable, so you can see it returns a
nullable, so a variable that could potentially be null.
And I cannot pass a null to control constructor because it always expect something.
That's why we need to use exclamation marks here.
OK, so that was step number one, our board is prepared now, we will have to adjust accordingly if
we ever want to store more information about the board, but for now, it's going to be fine.
Now, let's go over to the main activity.
And here I want to create a new variable, which will be a light in it variable, and it will store
the user name in here.
And where I'm going to set the username is in our update, navigation user details.
So here.
I'm going to set up a user name is user dot name.
Why is that?
Well, the thing is, at that point, we get the user name.
So as you might have already noticed, we put all of our database relevant code directly into our Floribert
Firebase class or Firestar class here, because if Firestar, for whatever reason, shouldn't work in
the future anymore, we want to just replace the class and do all of the stuff that the class does instead
of having to replace everything.
And that's why we create functions which are not directly related to Firebase in here, where we're
not dependent on Firebase, but we are just depending dependent on a specific variable.
Right.
So here we're just waiting for a user object that is passed to us so that we can then get the name from
the object and stored in our variable username.
Now, at that point, we can pass in the user name to the create board screen, so here when we click
on the five create board on UNCLICK, that is where we start the activity.
Right.
And it would make sense to send some more information with this intent.
So what we're going to do is we are going to create a new intent here, VUL intent, and then we will
add something to the intent.
So intent put extra.
And here I'm just going to say at the position of name, so constants
name and it's this one here I want to pass in the username.
So my user name.
All right, so then start activity.
With the new intent that we prepared, so why can we do that, why can we already pass in the user here?
Because uncreate the thing that is called first, right?
Well, what is also called is Firestar class load user data and load user data is called.
And inside of here, our update navigation user details is called in, which we set the username.
So basically in our uncreate, this line of code is executed before this one, which means that the
load user data function is called inside of our store, which then calls, of course, does update navigation
user details in which the user name is set.
And then we have the user name prepared and ready for our set on Click Listener with our fap button.
So our floating action button.
Now that we sent over the name, let's also retrieve the name, and that is an hour create board activity,
so let's go ahead and catch it here.
First of all, we need a late and it avar, which will be my M username type string.
And then.
We can catch it in our set in our uncreate, actually, so here after the set up action bar, if intent
has extra details for the constant thought name.
Then do something and in this case, just assign to username, so set the username that we prepared
up there, which will be intent, get a string extra at the position constants that name.
So now we sent over the username to the create board activity and we have it here.
This way, we don't have to get the username here again and have another database request, because
what we try to do is to have as few requests as possible.
All right, so now that we use the boards, let's also go to our consultants and add a new name for
the boards here as well.
So we have users.
This is our collection of users.
And now let's create.
The same for our collection of boards, contact wall boards will be a string called boards.
So now if we create a collection.
Here in our database, it will be the sports correction, so here will be called Bortz.
OK, but we don't need to do it here in our firebase interface, but we will do that in the code itself.
So let's move over to our create board activity and let's also create a function here which will let
us know that the board was created successfully, so fun board created successfully, and it will pretty
much be the same.
Information here as our user created successfully so height progress bar and that, well, of course
only work if our.
Create activity is inheriting from our basic activity or base activity.
Yeah, that was the one.
Now we can go ahead and use to highlight progress, dialogue and then we can call finish so we close
this activity.
OK, so this was a little prediction or preparation, so to speak, for the actual creation of the board.
All right.
And now at that point, we can go ahead and create the board.
And where would we do that?
Well, the creation of the board, of course, we would think it's in the create board activity.
But as I said, I try to put everything that has to do with the data by base connections and creating
database entries and updating them in the faster class.
So here we created one where we loaded the user.
So this is how we get the information.
But then we also had one where we created the user.
Right.
So here, document update.
Well, that's updating.
And this is registered user.
This is where we created the user.
So now we're going to create a function which is going to be very similar.
So you can see we need an activity here.
In this case, it was to sign up activity, but we're going to use to create board activity, of course,
then we don't want to have a user but the board then we don't want to use constant users.
But Constance boards, we still want to create a document, but not with the current user I.D. Then
we want to set it and have at Unsuccess listen.
So let's go ahead and just build that code.
So it's going to be very similar.
So create a board which will need an activity which will be of type, create board activity, and then
we need to have a board which will be of type board.
All right.
So then we can now go ahead and use that same approach and focus to a collection.
So let's do that and faster.
And by the way, we need to import board.
So Empire Store Collection, we pass in constants dot boards.
So we are going to give this collection a name and it's going to be Bortz.
All right.
So then.
We can now go ahead and add a document.
Which I'm not going to give any further details here, so it's going to generate a document for me with
random numbers and values or just a random ID, so to speak, and then I want to set it.
So I want to set a board with the set options so you can see data, any any type of data.
In our case, it's going to be a board object that I pass into the database and then we can add the
set options and I want to merge the data.
OK, so there are multiple different options here.
What I'm saying is merge the data if they already exist.
So don't overwrite directly, but merge.
So then I have an add on success.
A listener here in which I of course want to run some code, which is going to be for now a log entry
and a make text.
So here we created successfully is what I want to write there and then.
On top of that, I would also like to run activity that board created successfully, which is going
to be this function here, which is just going to highlight the progress bar at which we'll finish it.
OK, so that is the creation of the board if it worked.
So what shall we do if it failed?
So we had an on failure listener here as well.
So we need the debt here.
Add on failure listener.
Now, here we get an exception.
And what we want to do with the exception, is our decision.
So first of all, I'm going to.
Run, hide, progress, dialogue for that activity, and then I'm going to add an entry for the Lochhead,
so log an error saying error while creating a board and here it's called exception.
So then we know at least what the information is, what the area is about and everything.
OK, so this was just the preparation of creating the board.
The actual testing of that is what we will do in the next video, because we are getting to the point
where the individual versions of finally seeing something new, finally testing something, are getting
bigger and bigger or a code that we need or the steps that we need in order to achieve something visible
in the database are getting longer and longer.
So I need to have multiple videos and to the point where we actually finally see something.
OK, so I'm sorry for that, but otherwise I would have to create 30 to 40 minute video sometimes because
this is advanced stuff.
Right?
So we would need to do all of that in one video.
And I think it just makes sense to have these little breaks in between.
So see you in the next video.