Welcome back and this video, we are going to actually create the board in the database, and that is
something that you can do yourself already because you have seen how to create a user and also how to
update them.
So now you have to make a connection between the two and.
Use that knowledge in order to create the boat, so it's going to be very similar.
We already have the image of the board.
We have the name of the user.
We have the name of the board.
So name of the board created by is the name of the user.
And then assign to for now will only be the user.
So later on we will of course adjust that.
But for now it's going to be enough if we just have a user who created the board as being assigned to.
The rest will pretty much be the same as signing up a user, but not just signing him up, but actually
updating him.
So I think you can learn more from the update class rather than the creation class.
So the more my profile activity, I think here you can learn a lot more about what we need to do regarding,
for example, uploading a user image.
We're going to do a very similar thing to upload a board image and also.
When updating something, well, I think let's just get started.
You can, of course, try to build all of that yourself.
So let's go over to to create board activity and start by creating a new variable, which will be private
bar
and board image, you, Yoro, which will be a string that will be empty for now.
So we have the selected image URL, but we also need to know the board image URL.
So if there is a your URL for the image already, we need to know that because we of course want to
have a board image, but we just want to use a new board image.
If there is not one selected here in the selected image, file your URL.
All right.
So that's that number then.
We need to go ahead and create a function which actually creates the board.
So private fun, create board.
And here we just go ahead and for now, as I said, I signed the current user to the assigned user array
list.
So assigned users array list is an array list of strings.
So it's what we need in the.
Board here, so this assigned to.
And I'm just going to assign the current user so assigned users a relist thought ad and here get current
user ID.
Now, for this, of course, to work, this has to be an array list, even if it's an empty one.
OK, so that is how we create the board.
Step number one, step number two is we prepared the board information so the board object.
So we create a new board object, which will be of type board.
And here we need to, first of all, get the board name.
And as we are in the create board activity, we will get it from, of course, our activity create board.
So here we have this added text which says board name as the hint, and that's the one we get the data
from.
So from that one, we get the name of the board.
So let's go ahead and use that.
And our create board function, so here it bought name, the text to string will be our port name,
then we need to pass in the image so and board image URL and then the user username.
And then assigned users a realist, OK, so the username is going to be the current user, so when creating
a new board, the user who is creating the board is, of course, the one who is the creator of the
board.
So created by will be the current user.
All right.
So now we can do the actual creation of the board and firestorm, so Firestorm not create board, and
here we need to Brackett's create board here.
We needed to parse the activity.
So it's going to be this and we need to present the board.
So it's going to be the board.
So you can see this create board function, just prepares everything to then pass it to this create
board function inside of our Firestar class, which does the actual firebase stuff, which does the
actual creation of the collection and then storing it in the cloud.
Now, we also, of course, need a function to upload an image because we want to upload the image to
the storage as well.
OK, so let's create a function for it.
Private fund upload, board image.
And here we show the progress dialogue, first of all.
And I'm going to use the resources here.
So the ones that we've prepared, it's going to be resources.
Get string our string.
Please wait.
All right.
So as we've done before, then we need to.
Reference to storage reference, so we can pretty much get that from the update.
Function here, where we update the image.
So upload user image.
So you can see it's pretty much the same code that we need.
So what we can do is actually copy that and make adjustments to it, so create board activity here.
Let's check.
First of all, we need to Staats reference for the instance here, and it's not the user image, but
it's the board underscore image and here bought on this image is how I'm going to call it.
So this is the name of the image.
Right.
And that file extension will be this.
And here.
We have called it a selected image of war, your.
Let's see, it's this one here at the very top of the same name.
So that is good.
We used the same name in both cases.
This makes our copy and pasting a lot easier.
Now, then we have to put the file.
And it's this file that we have in the URAI, which we have selected on the phone.
Right.
The user has selected an image and then we want to put that file onto our storage.
So the firebase storage and then we have an add on success listener.
We take it to task, snapshot from it, and then we know where the image will be stored.
So, Firebase, let's call this one board image.
Your URL will just be there.
And actually that's a long name to longline for tag board material is fine.
Tusk's snapshot will give us to download your URL.
Then we can take that and store it in our M bought image euro, and then instead of updating the user
profile data, we can create the board.
So create what is called and create board.
By the way, this function, which then calls the first class create board.
OK, so uploading a board image, we also create the board, of course.
So then I don't feel your listener will forget an exception.
Well, here we're just going to say make text this exception message and highlight progress dialogue.
So it's pretty much the same code.
There are only some minor changes.
Of course, we need to change the.
Function that we want to call here.
Now, at this point, we can add an unclick event when the user clicks create board, so when the user
press the button and then click create.
OK, so it's inside this create board activity because that's the activity name.
Right.
And then we have the Ivy board image where we select an image that's good.
So this is pretty much the preparation and now we can go ahead and create the actual board.
So button create what's the name of the button and we add an on click listener here in which we first
of all, check if the selected image is null or not.
So if selected image file your eye is not null, then we want to upload the board image and inside of
upload image we also create the board.
Right.
And then else we want to show the progress dialog, social progress, dialogue.
And here we are also going to say, please wait.
And of course we want to create the board here.
So create board.
OK, so inside of the upload board image.
Also create the board.
Right.
We also call create board, but only if uploading the image was successful.
So basically we're saying, OK, let's select an image and then we enter a board name.
And if that was successful, we create then the board and when we click create only then we do the actual
uploading and storing everything right.
So once we select it, it's just there.
Right.
It's just inside of our selected image file.
You are just going to be there.
And of course, it will be displayed inside of our UI element itself, right inside of this image for
you.
But then the upload process happens once we click the create button, and that's pretty much it.
If we don't have selected an image or didn't select an image and we could recreate, it's still going
to create a new board, but it's just going to use the default image that is there.
Or to be more precise, it's just going to use an empty string here.
It's not even going to be the default image.
OK, at this point, we can test it.
All right, so there we are.
Let's go out and create a board.
Let's first create the board without image board.
Without image create.
Please wait, were created successfully.
Now let's go ahead and check it out.
So let's refresh this page here and see if we now have a new collection here so we should have a new
collection.
And we can see there it is, it says Bortz, now let's see, you can see we get a unique, weird, no
such a random value here for our board because we didn't add any name for it specifically.
And then inside of this board, you can see it's assigned to and this number y Cucu HMG.
Let's look at that y Cucu HMG.
So it's the user ID that we have as a scientist to it is created by the user name, which is Holmer,
and then the image is an empty string here, so we don't have an image for it.
So we will just use the default image.
Right.
And we have the name here, Port Without Image.
That's the name of the board itself.
You could of course, argue that created by Homer is a risky one because it just takes the user name
of the current user.
It's not taking the actual user name from the assigned to value.
So we would then have to, of course, read the assigned to value.
So read this number or this value here and then read the name from that one because the name could change
any time.
Right.
But that's going to be fine for now.
But overall, you can see the board is created and that works.
Now let's go out and create an image or create a board with an image.
So let's click the create button and select an image here.
All right, so I'm going to use an image from here, select this photo.
Give it the name bought with image.
So I'm going to call it stupid name, but still good enough.
And now let's see if this new board was created.
We see or created successfully and it's there.
All right.
So there it is.
We also have this image here.
So let's get this whole image and put it in there.
And we can see the images there as well.
OK, so now you can see how you can create boards.
I hope you manage to get some of this done by yourself.
It was a lot of copy and pasting or reusing what we have done before, but it's still good practice
to just try it yourself.
All right.
So thanks a lot and see you in the next video.