Welcome back.
In this video, we are going to implement the functionality to edit the name of a cart so added to cart
name here and also to delete the card itself as well.
So we are going to add those two features.
And because we are doing stuff with the database, it makes sense to look at our Firestar class and
make some changes here.
What I want to do here is to make some changes to the ADD update task list.
So here we want to make sure that we don't only accept a task list, but we accept any activity.
So not just task list activity, but also the activity of type.
For example, our card details activity.
OK, because I want to call this add updates task, this success in both cases.
So this, of course, only works if we double check here.
So if we add an if statement here where we say if the activity is a task list activity, then we want
to call this year this code and else if it is.
And activity of type, car details, activity.
So is card details activity, then we want to pretty much called the same function, right?
So the thing is, I need to implement this function in my card.
Details activity.
OK, so let's add a new function here.
Fun add update task list success.
And here I want to do some basic things, for example, to highlight the progress dialogue.
And this, of course, only works if this activity is inheriting from our base activity, because this
function is inside of our base activity, if you recall.
All right.
So this was our function will show the progress dialogue where we or the class where we show and hide
the progress, dialogue and so forth.
OK, so then this error disappears.
Of course we can while we're at it.
Add a little more coat to this, because basically what we want to do is we also want to set the result
to be OK.
So activity.
That result is OK.
And also want to close this activity so we finish it.
OK, now we still get an error here in our Firestar class, and that is because we need to make the
same.
If statements or at the same if statements here as well for the activity, height, progress, dialogue.
So let's add this and both cases.
All right.
And then inside of our car details activity, we will need a function to update card details and in
its function, we will for now just update the text.
So private fund update card details.
So I'm going to call it and hear the first of all, create a card object.
So user say card.
And when you look at card, we first of all need to import it.
You can see that we need a name, we need to created by and designed to so whenever we create such an
object.
OK, so let's go ahead and pass in the name where we get that from.
Well, it name card details, dot text to string.
So it's this added text here.
This one here with the card name, so to speak.
So this one here we get that name, whatever that name is.
Then.
As next parameter, we need to pass in the task list created by Soheir who created it.
It's a string so here and board details that task list.
At the position and past this position.
Thought cart.
Or cards at the position.
And card position.
That created by.
And then we need to get the.
More details, the task list at the position and task list position, but Cartes.
At the position and card position.
And then DOT assigned to.
OK, so when we pass all of this information, then we can create a new card object.
So now we have the updated cart because we don't only get the name from the import details, we don't
get it from there, but we get it actually from the edit text.
Right.
And now we can overwrite our import details.
So we can now just say that more details at the cart's position.
So here, Cartes.
Is the.
Can't we prepare?
OK, so what we did is we created a card based on all of the information except for or that are in the
database except for the name itself.
So the name that's what we get from the latest edition.
So the latest changes, so to speak, here in Cartney.
And then we put it back into the import details at the position of that card.
All right, so now what we can do is we can show the progress, dialogue and reload.
I think we don't have the code here.
So it's basically the same code that we have.
Done multiple times whenever we wanted to breathe fresh.
Data from the database, so first of all, we call it show progress, dialogue with please wait and
then we use our Firestar class.
To add called the add update task list function, which is this one here in which we call our updated
task, this success.
And that's pretty much it, right?
Now, of course, we only want to make these changes, wants to update partners clicked, so let's implement
the update button functionality and we can do that in the uncreate.
Method, so we can just say here, button update.
So it was actually buttoned up, that card details said on listener.
And here we want to check first if the edited text has an entry or not.
So ETN name card details, text to string.
Is not empty, so only if it's not empty, I want to call the update card details function, which is
this function here, which then updates the card itself.
OK, and else, if it is a. let's just inform the user about it, so let's try the little toast saying
please enter.
Eckardt name.
All right, at that point, we will be able to update the name, but we also want to be able to delete
an entry, right?
So we want to be able to delete a card.
So let's go ahead and create a function for that private fund, the lead card.
I know, first of all, we get the cards lists.
Which is going to be the array list of card.
That comes from more details, not.
Personalist.
At the position of.
The task is position dot cartes, so we get all of the current cards with this line of code.
The card with all of the cards, so at least for this specific task list and then what we can do is
we can remove the cards list at the current position.
So cards list, remove that.
The card ATM card position.
That one here.
And then we can update the task lists of one task list.
Which is going to be an array list of task.
Can now be, first of all, important.
So it's this task you in my case, my project.
The task class, and then we can get the amber details that.
Hospice, so the current list as we have it.
And we can remove the task list, remove that.
Task list.
Sighs Minus one.
And now you might wonder why would delete something from the task list?
Well, the thing is, our task list is consisting of also the ad part, which is here.
And we look at the board, we can see this little list here.
And it not only consists of card one, card two or card one and random name, but it also consists of
card.
So this card, this text that we can see here, this is the last entry inside of a task list, so to
speak.
So the task list in this case consists of three elements, card one random name and add card.
And if we want to make updates to our boards list in the database, we don't want to have that card
in there.
That's why we need to get rid of it.
That's what we do with this line of code here.
All right.
So then the next thing is that we can now go ahead and update the task list.
And task list position, so at that position that cards with the cards list that we prepared earlier
on.
So this one here that we get from there and more details, cards.
Now, in order to make this change, we, of course, need to make the change to Vasso cards now will
be a VA instead of a wall so that we can make changes to it.
All right.
So then going back.
They are card details activity because we're not done yet.
So this is our task list with the updated task list with the new card, so to speak.
So with the new cards list, because the new cards list does not consist of the same amount of cards
anymore, it has one card less as we have removed one, and then we want to update our database.
So we do the same thing as we done their show.
Progress Dialogue.
Please wait and then add updated task us with the latest and more details.
Now, you might also wonder, why do we even have to enter into the task list to make changes to our
cards?
Because why can't we just make changes to the cards directly?
Well, as far as I know, you cannot make changes directly to elements within a field without adjusting
the whole field, which means that, for example, we have these fields, right.
So assigned to created by image name and then we have a task list.
So you can't specifically talk to cards or any element inside of a task list.
So you cannot specifically edit to created by.
But you have to edit the whole task list to specifically then make changes to created by.
There might be other ways if there are.
And please let me know.
Shared in the comments, but this is as far as I could find it.
This is the way to do it.
All right.
So we need to make some changes to the whole task list.
That's why it doesn't make sense to make super complex structures here, but try to have separate fields
which contain different informations if possible.
All right, at this point, I also want to display a message that lets the user know that he's about
to delete something and he should only be able to delete something after he has accepted that.
So I'm just going to use this alert dialog that we have done in the past.
Which is going to be the following, so alert dialogue for the lead card is the name of the function
we need to pass and the card name.
Then we create a boulder, which is the alert dialogue builder.
We set the title of it, which will be alert.
So we need to create a new string for that.
Then we have the message that we want to display to the user.
So confirm message to the lead card is going to be the message.
We also need to create that string for it.
Then the icon is going to be the icon that you can see here, said positive button.
If that is clicked, we want to dismiss the dialogue interface, which means we want to dismiss this
alert dialogue and we want to call the lead card, which is the function that we just prepare.
OK, so we don't want to directly delete the card if the user presses the delete button.
But we first of all want to display this alert dialog to the user so that he knows, OK.
I'm really deleting something now.
All right, then, if you press the negative button, then the dialogue will be dismissed and then we
also set that to cancelable false.
So you cannot cancel it.
You cannot click next to it.
You can only either press yes or no.
And then we want to display this alert dialog.
So first we create the boulder, which is the alert dialogue builder, as usual, and then we use the
alert dialog class to then use that boulder that we prepared to create the dialogue.
All right, so you see, we need a string for no string for yes, a string for confirmation message
to the lead card and the string four alert.
So let's add those strings to our strings, that XML file, and I'm using the ones here.
So alert should just be the alert text.
Yes.
Should be.
Yes, yes.
No.
Then we have the confirmation message to the lead card.
Are you sure you want to delete card?
And then this part here will then allow us to display the card name which we use inside of our card
details activity.
Where we say our string, the D card with the card name so you can use this approach, get string,
there are multiple overloads for string.
This one, we just get the resource.
But there's also one where you can override something.
So object format arcs or arcs.
So this is exactly what we do here.
We pass in some formatting arguments in here in this case is the card name so that the user can also
see which card he's about to delete.
All right, at that point, we just need to call this function here and when do we want to call it?
Well, once we delete it or once we click on the delete icon and in order to implement that delete icon
click event, if you look at it, it's this icon here and it's a menu item.
So if you have multiple options in menus or even just one, you need to implement them by using on options
item selected.
So this function here and what I want to do is I want to check when.
Item thought, item ID is equal to our dot it dot action, the lead card, then I want to run the code,
which is to call this alert dialog for delete card function with M board details dot.
Task list and so forth.
So let me get that from here and board details, task list, Cartes.
This part here all the way here.
Top name, so here.
Name.
OK, so basically I pass in the name into this alert dialogue for the lead card function, so the card
name and then it will display this alert dialogue.
All right.
So then we only need to return something here, so I'm just going to return, true.
In this case.
OK, so now we can go ahead and test our application.
So let's go to our board with image, let's go into random name, let's click on Delete.
We can see this is the alert Dialogued comes up.
Are you sure you want to lead Kaat random name.
That's exactly the text that we prepared.
Let me press.
Yes.
Please wait, and we're sent back to this activity, as you can see, the cart is not here anymore and
we can even check that.
So let's go back to the.
Bacons.
And here we can see bought with image.
Let's look at the cards and we can see there is only card one, so there's no card random name anymore
or random card anymore.
Now, let's for a double check, let's do that real quick with Kartu, so let's get rid of Kartu inside
of the other list, which is our.
List with the name Missy.
Well.
Part one here, this one, so let's get rid of this one as well, so here carto, let's click on it
deleted and let's see in the back end and we can see Kartu has been deleted.
So now there's only card one and called three.
All right, so now you know how to delete cards, how to make changes to your task list and so forth.
Now, of course, we still have quite some features here and labor color members, due date and so forth.
So see you in the next video.