Welcome back.
And this video, we are going to put everything together, so we have set up all of this room stuff,
we've set up the adapter and the adapter stuff is really just necessary because we have this more complex
demo where we are also having multiple entries, but not just storing one piece of information.
And that's why we needed the respect of you and we needed to have the items adapter where we all not
only want to have them in there those entries, but we also want to be able to delete them directly
from the user interface, which is, I believe, the best way to do it.
So let's go ahead and implement that using our code.
So now we can go to our main activity and finally use this item adapter that we have set up, which
will also require, of course, the employee and well, employees as well while we're at it because
we added the record using them.
We're going to use it as well to delete and stuff.
OK, so so first of all, let's create a function which will take care of displaying our employee list
that we have in the database already.
So I'm going to create this private fund, set up a list of data into recycler view.
OK, and it needs to have the employee list that we want to display.
So employees list, which is going to be in the red list.
Of employee entity, and then we need to get the employee down as well.
So here am employee Dow with our employee Dow Object and Baloyi dull.
OK, so now this function, what shall I do?
Well, it should set up our recyclables, so it should set up the data.
So first, we are going to check if the employee list is empty.
So is this list empty?
And I'm going to say is not empty, so if it's not empty, I want to display the data into our recycling
view.
So here I will need to create an item adapter object, which is going to be our item adapter class that
we just had created, right?
So here we need to pass in the employees list as well as the upbeat listener.
And to the listener.
So how does this update listen, the work we need to get an I.D. and we need to return a unit.
So how does it work?
Let's look at it.
So here I will need to call the method that I want to call once I want to update something.
So we need to prepare this method.
Therefore, let me comment this line out and prepared a method that will take care of it.
Actually, after having recorded the entire thing and showing you how to delete and edit and all of
those things, I realized that it would have been way too much code before we actually see something.
So I have decided to make a cut here and actually simplify our item adapter because we are using this
unit thing here.
And you might have wondered what is this unit?
Well, it's basically just saying that we need a method here which will return nothing.
So unit is just a void keyboard from Java, and we will get the idea of the thing that we need to update.
So what I'm going to do here is I'm going to comment those two things out here because the only thing
that I will for now need for the item adapter to work will be the array list of employees.
Accordingly, I will need to uncomment or comment this to out here.
So once I click on the added button, nothing will happen.
And once I click on the delete button, nothing will happen either.
Because we're here invoking our delete listener.
We're just basically calling the method.
We're passing the I.D. We're calling the method that we will create, which will be like and it will
be a lambda method.
Or you could say a.
Nameless function that we use in our main activity, but we're not going to do that for now.
OK, we're going to skip all of that for now.
We're going to focus on just displaying the data that we have in our database.
So let's set up the item adapter, which we do have now and now.
We need to make sure that we are displaying the information accordingly, which means we need to display
our recycler view.
We need to assign the adapter, this item adapter we just created and so forth.
So let's, first of all, set up the Recycler View Layout Manager.
So I'm going to say I'm using a linear lay up manager, which you can see here.
So items are going to be on top of each other when not using a grid layout or anything like that, then
I'm assigning these item adapter to do just created as the adapter for my recycler view, which is this
recycler view here, as you see inside of our application's activity.
Next email and then I'm going to make sure that the recycler view will be made visible and the text
view that says no records are available will not be visible, so it will be gone.
OK, so here TV, no records available, which is this text you.
And by the way, in the code, I made sure that this text view is by default set to visible at this
recycler.
View by default is set to go on.
OK, I made a little change here in the XML file and now.
In the case that the employee list is not empty, this code will be executed, right, but if it is
empty, then what I want to do is I want to make sure that the opposite happens so that I do display
the text view that says that there is nothing happening.
So there's no records available and the respect of you should be gone.
So should not take any space in my user interface.
So at this point, we can call this set up a list of data into recycled u method inside of our own create
method.
Which I will do in here.
Okay, so here on create.
Let's go ahead and set that up.
So this will have to run in the background because we're loading data, right?
So let's launch a call routine here, which will use our employee Dow to fetch all employees, and it
will collect the entry.
So it will basically with this collect method, we now get the list of employee entity items that are
inside of our database.
Because this fetch all employee is this Dow method that we created, which selects all star from our
employee table.
So it's going to give us all the entries that we have in our employee table.
It's going to fetch them and it's going to return a flow.
Which is a part of the coalition class, just like to suspend key word, it runs the operation on a
different threat, but with an additional feature of omitting updates automatically when they occur.
So this is important.
What this allows us to do is we don't have to tell the risk of you to update itself.
It will do that automatically because we're using flow here.
OK, so now we are fetching all employees.
We're collecting them, we get them in form of a list so you can see your list employee entity.
So what's the problem here?
If we're working with the list and we want to pass this to this method here, set up a list of data
into recycling of you.
Well, we don't need a list.
Well, even though we call it ambiguous list, we need an array list.
So we need an array list of employee entity items and we get a list of employee entity items.
So how do we fix that?
Well, we can quickly make an ArrayList out of this list.
So let's go ahead and do that.
Therefore, what we need to do is we just need to say Vul list, which will be an array list of it and
we just pass it to it.
So we create an array list out of this list of employee entity.
So it's just it keyword.
OK, and now.
We can use that in order to.
Display or pastas to the set up list data into respect of you.
OK, so we just passed the list to this method that we just had set up and we need to pass the employees
down as well.
So here, employee Dow, like so and at this point, if we run the application, we should get all the
entries that we have in our recyclables.
So we see we get them.
Now let me test this with another entry.
So here then is and you see it's different data than we had before because as I said, I had to cut
the video and stuff.
But you see, I added the data and automatically updated the UI.
So let me add another one CC.
And here it's um, she has a unique email ID, which is not even an email I.D. But you see all of the
data is now appearing, so we just add the data and automatically updates our recycler view.
And it's almost like magic.
But unfortunately, the magic requires a bunch of set up, which we did do over the last couple of videos.
So I'd say, let's make a break here because the video is going to be while the next video is going
to be long enough because we need to take care of those two methods.
Let me show you the update record dialog and to delete record dialog.
And they are extensive because we are creating dialogues and we are also using an alert dialog here
and so forth.
So let's make a break here and see you back in the next video.