All righty, now, let's actually add the members to our list here by entering something and clicking
add.
So let's implement the functionality for them.
Therefore, we are going to mainly work in our members activity because that's where the magic happens.
But of course, as we are doing stuff with our store, we're storing data.
We also will have to look at that class as well.
All right.
So first of all, let's create a new variable, a global variable here at the very top, private late
in it.
VA and assigned members.
List, which will be in the list.
Of.
Members, so, to be precise of users.
Because a member is a user.
OK, we have user already in this class, it's good to see then we need to initialize this variable
and we have a function here, which is to set up members list.
OK, so at this point, we can just use this list here, which is passed to this class to store it in
our variable that we just created.
OK, so now it will be available throughout the whole class and let's see where we call set up member
list.
We call it in here, so we go through the set up, then we show the progress dialogue, then we do the
fire story glass and here we call it a silent members list detail.
But inside of that, we actually.
Called the set up members list, so we passed the list and then we do that.
All right.
OK, so this is what we do here.
We sign it.
The next step is that we want to get the member details.
All right.
So we set up the member list.
Now it's time to get all of the member details.
So let's create a new function fund member details.
So we need to get the user.
And then.
We need to write the code to actually get the member details, OK, and whenever we want to get something
from the database, we use our Firestar class.
All right.
So let's create a new function here, which I'm going to call get member details.
Which needs an activity of type activity.
Member activity and here.
It needs the email of the user, which is going to be this string.
All right, so this is the member activity and then the next step is to get that data from the database
where the email is existing in the contacts.
So we look at our fire story collection called Constance Users.
But users and here we check where equal to.
Constance thought email.
So here it's email.
Email.
OK, so we need to create this new constant look at our constant.
Because we are using something from the database again, right, so let's do it consed while.
Email, which will be a string.
Which I'm going to call email.
So if we look at our users board here or the collection users, then every user is a document, right?
And inside of that user, we have the email address.
So this field email, and that is what we want to get now.
So we want to check through all of the users if the email address that we just entered here.
If that exists in the users.
So check this field here.
And once it has done that.
We can get all of the data, and if that was successful, we will call the on success listener and here
we get the document with all the results.
So here document will contain all of the results here.
And what we want to do with that is we want to check if the document has a size of more than one so
or more than zero, actually, if at least one.
Right.
So documents.
Size is greater than zero.
Because only if there are any entries in there, we want to do anything right.
So, first of all, what we are going to do is we're going to create a user out of that.
We're going to say document.
The documents.
And position zero.
To.
Object.
With user, colon, colon class, the Java.
All right, so this is our user that we are creating inside of this document or from that document and
then.
We called the activity, thought no details where we then can pass in the user.
Now, if we look at this activity, member details.
Here, it requires a user, but so far doesn't do anything right.
So we will still need to implement that.
By the way, we need to add exclamation marks here so that the error disappears or the warning here.
OK, and then here.
What if there are no members found for the email address that the user entered?
Well, first of all, we want to highlight the progress dialogue and then we want to do activity that
show our snack bar.
And here, just a text and you could use a warning.
I think we don't have any strings prepared for that, so you could prepare a string for that most such
member found.
It's going to be the snake that I want to display, so Chautara snack bar is the function that we created
ourselves in the base activity.
Maybe you remember just 20 years ago or so, but we created the snack bar.
A function which displays an error or snack bar, which has a red color and then displays the text that
we pass in as the message.
All right, so now you might wonder why we only add the positions zero here?
Well, because the email address is going to be unique, so no one will have to work.
One e-mail address cannot have two accounts.
OK, at least by design, it shouldn't happen.
Of course, we can trick the system, but users will not create or not be able to create an account
with a user name or actually an email address that already exists.
OK, so that's what we don't have to take care of here because we can just take the first entry that
is found and that will be the only entry that there is.
That's why it's fine to use the approach that we do here.
OK, so that is what should happen if we were successful now, if we weren't successful, let's just
add an unfair your in here, which is just going to say.
Well, first of all, it's going to hide the progress dialogue, and that is going to say Erra while
getting user details, OK, we're just going to have a little log entry.
Of course, you could also display that to the user by showing an arrow snack bar or something like
that.
But I think for now, this is going to be fine.
OK, now, in our member activity or no activity here, we, of course, still need to implement that
functionality.
But at the same time, we have this add button that we click or can click on.
You can see here to do implement adding member logic.
So that is exactly what we just implemented.
Right.
So let's add that line here.
So first of all, I will show the progress dialogue here, which is just going to say, please wait.
So here this is our strength that we prepared and then I want to use fire store class dots, get member
details.
And here we need to pass in the activity so this and the email.
Well, guess what?
We prepared the email already, and that is the email that the user prepared or entered into the edited
text, email search member.
So into that had a text field here.
OK, now if we look at our get no details now it is called right and we also call member details, but
no details is an empty function.
So at this point, we get the user that will be added to the.
Members, and we can now go ahead and add that to our more details.
Assigned to add and user.
Thought ID, so now we add the user ID to the assigned to, which is this array list of strings, so
the board is assigned to multiple users now or at least one more user.
OK, now, going back to our activity here, our members activity created this variable, right, this,
um, assigned members list, but we didn't add anything to it.
So so far, we just set up the members list with the existing list.
But now we also at one point need to add a new member to this list when we have actually finished this
approach or for this finished this step.
So let's go ahead and create a new function which will take care of the member assign.
Success call.
So here we get a user object and then first of all, we want to highlight the progress dialogue because
just before we call this function, we will display the progress dialogue and then we want to make sure
that the user that is part of this function is added to the assigned members list.
And then we can call our set up member.
List with the.
Latest members list, okay, so this should be called once we assigned a new member.
So once we have added a new member, we click on ADD.
But if we do that, our UI doesn't set up once again.
So it's not going to be updated, but we want that to happen.
Right.
So we want to see that we have a new member in there.
And that is exactly what this set up members list does.
Right.
So if we look at it, it sets up the whole.
Of you and the adapter and everything, so this is the function that takes care of displaying things,
pretty much the case to populate all of our elements, our UI elements with the data.
That's why we need to call it.
But in order to call it, we need to give it a list.
And in order to give it the list that is updated, we, of course, need to update the list.
And that is what we have done at the point when we call this member assigned success, because it will
only be called once the assigning of a member was successful.
Now, if we look at our fire story here, here we are just getting the numbers so we get all of the
membered births that we have.
So we have this add on success listener where we check whether the email exists and so forth.
OK, but at this point we don't add any new members, so we don't have any new members that are assigned
to the board.
So that is what we will need to create here.
So assign member to board.
OK, so here we need to pass in the negativity, which will be our members activity, because guess
what, when we assign a member and that was successful, we, of course, want to call this function
that we just prepared this member assigned success function so we can see we're constantly moving back
and forth between the master class and the different activities so that the activities are not dependent
on fire or stored or fire based to work.
But they're just dependent on the data, because if you look at it, our members activity doesn't care
where the user comes from, whether it comes from Firebase, whether it comes from a local database,
whether it comes from an external file, whatever, just needs to get a user with the right format.
And that is how our whole app is designed.
All right.
So now if we assign a member to board what we will need as the member and we need the board, OK, we
have the activity already in which we want to run the call of the function, but we also need to have
the board and we also need to have the member, which is a user.
OK, so the user is of type user.
And then in here, we can now finally do the magic that actually adds something to the firestorm.
Now, you remember maybe that if you want to make updates, that we needed to make a hash map out of
the board, OK?
So here, for example, when we updated the user profile data, we needed the user hash map.
OK, so this is what we passed into the update function and then add updates to this.
He also, as you can see, we used a hash map of strings and any and then we could updated with the
hash map.
And that is going to be very similar to what we are going to do in our assigned member to board, because
here we, first of all, need to have the hash map of the board pretty much OK.
Of the assigned to.
OK, so Vul assigned to Hashmat, so I'm going to call that one and it will be a Hashmat of string and
any.
And then we can go ahead and say at the position of constant thought assigned to I want to assign the
board that.
Assigned to.
So the board first, we always download the board, right, so we download the board from the database,
then we add stuff to the board.
For example, we add new cards or lists or we add lists with cards, and then we also add new members,
which means new users.
And then at one point we need to update the board and that's what we do here.
So after we assigned a member to a board, we also want to update it in the database.
So what we do is we, first of all, create this assigned to Hashmat.
Which is basically inside of our board, if you look at it, this is assigned to variable.
And you can see here, it's just assigned to one person, so we have an entry and then we have the value
for it.
So key and value.
So now we can do the whole Firestone stuff, which means we can call fire store collection and then
we want to update the constants that Borz.
Documents.
That has the board ID, so board document ID, because we, of course, only want to update the board
that we currently are working on or that the what the user has entered a new entry for the members game.
And then we want to update that.
And if you want to update it, we need to give it a hash map.
Could see it requires a map here.
So one that has a string, any format.
OK, so I'm going to assign it.
We're going to posta assigned to Hashmat and then.
If things went right, then we will see the Allen success listener and here I'm just in a call activity
that member assign success and here we need to pass in the user and that is the user that we get when
we call this function.
And then if things went wrong, we're just going to add a little log entry.
OK, so here the hard progress up will be called.
So we don't dispute the progress dialogue and then we'll just display error while creating a board.
OK, now dysfunction is prepared, but as you can see, it's great out yet, so it doesn't have the
color that we need, which is this beautiful orange yellow color which indicates that this function
is called.
Now, where would it make sense to call this function?
Well, in our members activity, we by the way, we can see that number of signs is now called.
But here.
We should do that when we called the member details function so here after we assigned.
The user or added the new user to the assigned board.
We can now call this assigned member to board function, which means that we, of course, need to use
Firestar class.
Not a sign member to board and here we need to assign the activity so we pass on the activity, then
we need to pass in the board and that will be our end board details and we need to pass on the user,
which will be our user that is passed to the member details.
So we are constantly passing values from one function to another, as you can see.
But overall, this allows us to be independent of using the surplus.
So if we ever should replace that, it will still work.
We, of course, need to make sure that we have the same function names in whatever other class we're
using and that it requires the same type of data.
At that point, we should be able to test it and it should run flawlessly on our application.
Or better said on the emulator.
OK, so that we are caught with image.
Now let's go to our members.
Now, let's add a member, but the thing is, in order to add a member, we first of all need to create
a new member.
OK, so let's do it this way.
Let's sign out.
Let's sign up with the new user and I'm going to call this one Bart, and he will be called or his email
will be barred at Gmail dot com and he will have a secure password.
So now let's sign up.
OK, now could, of course, signing the user directly, so that is something that you can to yourself,
it's very easy actually to just directly log in the user instead of sending him back here.
So Bart at Gmail dot com password is secure.
Let's sign them.
Now.
Let's create a new board.
I'm going to call this deadeye.
Or that his tasks.
And here we can select Haoma.
OK, so let's create this board.
OK, created by Bart, very good.
Now let's check this board out.
Let's create a list here.
So.
Today, they said that should finish today.
And then eat a donut.
All right.
The least healthy thing that you can eat, but now we can see that it's there.
Now, let's add a member we can see in members only Bartis there.
Now, let's add Dennis at Gmail dot com, because that's the email address that I had for Holmer.
And you can see now Holmer is here.
So that works perfectly.
Now let's go.
I do the final test, let's log in.
As Homer So let's sign out first and signing as Homer.
And we can see that his tasks are there so that we are we can now create tasks which are or boards pretty
much, which are linked to multiple users so multiple users can use sports and they can inform each
other about sports or they can just add other people to the boards.
Of course, he can only add people of which they know the email address.
So this is something that you definitely have to take into consideration.
All right.
So that is it for this video.
It was a longer one, but we had to add a lot of functionality and a lot of stuff that has to be done
when working with Firestorm, as you know.
And yeah, now we have a pretty cool feature added to the app.
Of course, there are still other features to come.
So see you in the next video.