Welcome back and this and the next video, we are going to prepare Cartes, so as you know, we now
can create Bortz, we can create lists in those boards and we can edit those.
We can delete those.
Now it's time to add Cartes as well.
So a list can have multiple cards.
And that's the idea here.
So this could be individual exercises or individual tasks or in this case, individual episodes that
we want to add.
So here I can create a new card, for example, episode one.
And as you can see, the UI changes.
But then of course, when I click the button, stuff happens, but it's not loaded yet.
So that's something that we will have to do later on.
But for now, we can add that functionality here and you can try to do that yourself because you have
seen how to do that with lists and now it's time to do the same thing with cards.
So it's very similar.
And you can try to do that.
Of course, you will have to create a new model, so a card model, and then you will need to adjust
the task model a little bit and pretty much the rest will happen in the task list items adapter.
So if you want, you can try that, of course, task.
This activity also needs to do something, but you can also just follow along.
All right.
So if you really feel good today and you feel like challenging yourself, then try yourself.
OK, so let's get started.
So I think the first thing that we should do is we should create a new model.
So I'm just going to go over to Java and here into models.
I'm going to create a new class.
So here Cutline file class, this one will be Kaat.
So a individual card should be created.
And of course I want to have a data class here, so let's make it the data class.
Because I don't want to have any functions or other members, I just want to have the different variables
and that should be Parslow, of course.
So what could we need about a cart?
Well, we need the name of the cart
then.
What else?
What makes sense?
Well, who created it so created by and then also the volle assigned to.
And that one will be and the relist, because it could be assigned to multiple people, right?
So an array of strings, which will be a great list, by the way, in my case, I keep the card as well
as the tasks super simple.
So I don't have anything about the date, about the order, those kind of things.
I don't have them in here.
So the way we do it now is we do it based on when things were created.
That's something that you might already have noticed here.
So you can see the last thing that you create goes to the beginning of the screen.
So we have an order where the latest created element is the first one in our list here on the left hand
side.
You can, of course, adjust that.
So if you want to have a different set of order, where you then maybe later on drag and drop stuff
around, then you have to adjust your task as well as your card and have some additional information
about, for example, the position in here as well.
But as I said, I'm going to keep it simple.
I'm going to create cards based on when they were created and they will be added to the list accordingly.
OK, so that's the idea here.
We have the card now and of course, we want to make it passable.
And I'm going to use Parcell Bowl so that we can store it right.
So if you want to make something passable, you need to store it.
Now, of course, we need to add the BASTABLE implementation now, depending on the.
Add on that you used to and by the way, I'm using a plugin, as you know, probably, but here some
things are missing.
So let me just paste everything in here and go over real quick or run over it so you can see it.
But we have done this multiple times.
So I think it doesn't make sense for me to go over it in depth or in detail.
So the code is a little different here.
You can see I'm using source restring.
It could also be Passell.
Doesn't matter.
The name here doesn't really matter.
Then we have the restring with double exclamation mark.
Same for the string here as well.
So the created by.
And then we have the assigned two which is an array list.
So create string array list here.
Describe contents returns zero right to Passell here.
We need to write the string, write the string and then write the string list where we then each time
pass in the variables that we created for the card.
And here I'm using equals with that.
So this one here and then the companion object is the creator which creates the card you can see object,
create a card, create from Passell a new array, order to override functions or override one overridden
function, so to speak.
And that's what's happening here.
OK, so depending on the tool that you use, this should be auto generated.
But in my case it doesn't auto generated this way.
So I would still need to make manual changes.
But I will just what I've just shown you how it would look like, what it should look like.
OK, so this is a card now.
We need to adjust our task because our task can now have multiple cards.
OK, so let's go over here and add a new entry here.
Of course, we need to add a comma here at the top and then we say what cards should be an array list
of card elements?
And I'm going to initialize it directly with an empty.
I realized, according to we, of course, need to make changes as well here.
So here I'm going to add Passell thought created type or create type array list.
And here I need to pass and card dot create tert and here of course it's the list and here we need to
come up.
OK, so create type array list with the card and double exclamation mark here at the end as well as
here.
We need to add this line here saying write piped list and what is it.
It's the Cartes list that we created here.
All right, and the rest should stay the same.
Now we can go over to our task list items adductor, because what we want to do here is we want to activate
this part here.
So we want to make this visible this year.
The left more this button here than this element and that one.
So we want to make all of that visible once we click on Add to Cart.
All right.
So let's add the functionality in our function here.
And we need to do that in our unbind view.
Holder So there where we do all of the holder items stuff.
So a bunch of code you can see to the longest function that we've created so far, I think, because
here we have all of the different cases, all of the different items that we use.
So Holder item view, dot, TV and card.
And I want to add and set on Click Listener here said on Click Listener.
So TV ad cart is this button here.
OK, this TextView.
It's not an edited text or anything else, not a button, it's just a text you write we had that before.
And once we click on that, then we want to make this thing here visible, which is a card by itself.
OK, so let's do that.
Let's go ahead and say holder dot item view, dot TV ad card.
Thought visibility should be gone, so the TextView should be gone, Budos gone and the Cevat card,
so holder dot card for or items view thought card view SCV at card visibility should be visible.
So you thought visible.
So basically, we're hiding this at card and would explain this part here, so that's what happens once
you click on that button.
Now we have this button here which cancels the whole process and does the opposite.
So it just displays the at card again, but doesn't display this card view anymore.
So.
We need to implement that as well, of course, here, holder, that item you thought I be close and
hear card name said on Click Listener and here I want to pretty much do the opposite of what we've done
here.
So now this one will be visible.
And the other one will be gone.
All right, and now the magic happens in the next step.
So here this is where the actual creation of the card happens.
So when we click on this button here, then a very similar thing to what we have done here when we're
done editing the list or actually even here when we're done creating the list should happen.
So let's go ahead and copy that.
And put that in here, so this time it's I've done the list name but can't name set on Click Listener.
So here now we get the card name.
And where do we get it from?
Well, from our added text card name.
So here is the card name at Urtext.
From that, we get the string and then we check is the card name not empty?
If it's not empty, then we want to call a function here.
To do add a cart.
OK, so this is what we need to implement, stop, and otherwise we will make a text, please enter
a card name.
All right, so now let's implement this function, we need to build it, where would we build it?
Well, let's see where we build this other function.
This update, Paschalis, for example.
It's in the context.
What is the context?
Well, the context is the task list activity.
So let's go over to the task list activity and actually create a function there.
All right.
So let's go ahead and create a new function at the very bottom.
I'm just going to call this one fun add cart to task list.
And here we need to pass on the position then the card name, which will be a string.
And that's it.
OK, so we don't need much more here and what do we want to do?
Well, we want to remove the last item.
So it's pretty much the same thing that we have done here with this board list.
So let's do that remove add board task list.
As you know, we get rid of stuff here with that and then.
We can create a new card assigned users list, which will be an array list of string, and I'm going
to assign an array list here.
For now, a. list, and then we can add something to it, so Kaat assigned users list that ad.
And here we get it from the master class, get current.
User, so here, fast or clustered, get current user ID.
So this will give us the assigned users, if you recall, if we look at a card, we can see we need
to get an array list of strings which is assigned to so all of the people that this card is assigned
to.
All right.
So that's what we do with this here.
So we get the current user and we add that to the users who this card is assigned to because it can
be assigned to multiple users.
Right.
And then we can create the card Volkert, which will be based on the card name.
Where do we get the card name from?
Well, we get that from the here from the top.
And by the way, let's import card here so that we can use it.
So we need a card name and we need to get the current user.
Because that's the one who created it, so we can just go ahead and say fire store class.
And at that point, maybe it makes sense to store that in a variable so that it's constantly available,
right?
That would be an option.
And then we also need to pass in the card assigned user list.
OK, so all the three values, if you look at it, the name created by and assigned to.
OK, so that's what we pass here.
The name of the card, the person who created the card, which is the person who is currently logged
in, and then the card assigned users list, which currently just has the creator in it.
OK, because that's the only information we have so far.
Later on we can of course, adjusted, but for now that's going to be it.
OK, and now we can go ahead and create a card list, which will be.
The M board's details thart task list head to position that we're currently at.
So, as you know, we have multiple positions now.
So this one is the position of the list.
So it is at least one list to list three and so forth.
And then we have another position, which is the position within the list of cards.
OK, so this is the task list position that we currently are at.
And there we need the Cartes.
OK, so if we look at the list you can see here at list consists of tasks, a task consists of cards
and that's basically what we have here.
We get the cards from the task list, which is inside of wards, and then we can use that card list
and add something to it.
And what will we add?
Well, we add the card that we just created, so add the card.
So if there was nothing in there, then this will be the first card.
But then if there were cards in there, this won't be the next card that will be added to our cards
list.
All right.
And at that point, we can create a task so we can go ahead and say a task should be task.
With M. board details that task list at the position.
Title, so this way we get the title of the task list and then.
What else do we need when we create a task?
Well, we need to know who created it so we can just go ahead and say.
Created by so was the creator DOT, created by and then we can pass and the cast list that we just prepared.
So we created it.
We got the old cast that we had.
We added the new car that we just created before hand.
And then we created the task based on that.
And now we can assign that task that we just created as the task for the current position.
So we basically just replace the old task with the new task.
But the update, the task.
So this is just to update the task, which also contains the latest cast list.
All right.
So here we are just going to say, OK, let's go ahead and use the task list at the position.
Equals TASC.
So I see that this could potentially be the most complex part if you try to build it yourself, this
will be probably the most complex part to make this connection between the three elements right.
Between the board to task and the actual card.
All right, so then we can now.
Go ahead and show the progress and update the task list.
So basically what we've done here as well, because now we have the latest version of the boards and
that's a cool thing about the board, because the board contains everything, right?
The board is the parent.
The board is the parent of the tasks and the task is the parent of the card.
So if we have the board, we have the task and we have the cards.
So we don't need to update them individually, but we can just put everything into the board, which
we do here, and then we can just say, OK, let's update the board.
OK, now we can test that on our device, but see if it's actually creating the task, even though,
of course, we have no way of displaying tasks yet, so are actually the cards yet.
So we still need to add that functionality, but step by step.
Right.
So, first of all, created in the database, we check the database out if it's there, and then later
on we can get that from the database.
OK, so there we are.
Let's go to the board with image, let's add a new card, OK?
The button seems to work.
Let's cancel it.
OK, that worked.
Now, let's call this one card, one stupid name, but good enough.
Let's press this button.
And currently, nothing happens, and that is, of course, because we're not calling this function,
so you can see this function is great.
If it's great, it's never called that's it's always a good indicator that you miss some code.
And that's the way to do that.
We prepared right in our task list adaptor where we said, OK, here, if it's not empty here at the
bottom, add a card.
So let's call this function and we get that from the context.
Right context dot at card to task list.
Like that, and, of course, it needs some information.
So what kind of information does it need?
It needs to position and the car to name, so let's give it the position and card name.
So.
It's basically the position and card name, because the position, it's the same name, right?
It's the position of the here at the very top of the unbind view holder.
And it's the card name which we just prepared a second ago, which we get from the added text.
OK, now let's run it again.
OK, so let's load the board again.
Let's create a card.
I'm going to call this one card one, let's press the button this time.
Please wait.
All right, it's gone.
Now, let's look in the database.
And we can see we have a task list.
And it's out of this task that we have a cart.
Which is called card one, which was created by that person and which is assigned to that person, which
is the creator, which is the only user that we have, which is Homer or Dennis, a Gmail account.
OK, so that seems to work.
Now we just need to retrieve the cards to also display them, because just storing them is not going
to be enough.
Right.
But you can already see how the whole structure comes together.
Right.
So we have decided to.
So a board is assigned to someone that's created by someone.
There's an image for the board.
It has a name.
Then it has a task list.
In our case, we only have one entry here in the task list and then it has a bunch of cards.
Well, the task this is created see title list one that created by the person and then it has a bunch
of cards in there.
OK, so that is it for now.
And I see you in the next video.