Welcome back in this video, we're going to set up everything that we need to have in order to retrieve
the dates that we have stored.
So you see we have the history table here with the date that we have stored.
And now let's go ahead and set everything up so that we can then also retrieve the data displayed later
on which we will set up in the next video because we need to prepare our adapter and stuff.
So let's get started.
Therefore, I would start with Nadal always OK, because that's the easiest starting point here.
We need to make sure that we have the right method in order to fetch data.
OK, so I'm going to call this one fun.
Fetch all dates.
OK, and this will be returning a flow of a list of history entities.
So here is the three entities.
So here we need to import flow.
The core routines flow, and it is basically the same approach that we had here when we wanted to retrieve
something.
So here you see with this fetch all employees where we return it flow, which also allows us to reset
our UI without having to do with manually.
So that's pretty cool, I believe.
I think they have done a good job here and by they, I mean Google by setting up the code accordingly.
So you can, of course, hover over it to get more details about this public interface flaw.
So we, of course, also need to have the query for it on top of the method.
OK, so let's go over to our darl and add the query.
So we want to select start from and what was the name of the table that we used?
And but if it was history table, right, so the idea even helps you out here so you can just use history
table here.
Don't even have to write it manually and let me make sure that I have everything set up correctly,
like so and then it's close like this.
OK, so we have the history table now that we get the data from, we select it and we have this function.
And let me also make it the suspend function, suspend function.
So fetch all dates.
OK.
That should be the name, not fit all dates, but fetch all dates.
So let's also use this function somewhere.
What would be a good spot?
Well, I would say a good spot would be in our history activity because that's where we want to display
the history right now, the history entity.
But history activity, it seems like we don't have it open yet.
So let's go over to our history activity.
And let's set up a method that will take care of retrieving data.
So let me set it up.
Private fund, get all complete dates.
Or completed dates, maybe.
Yeah.
Basically a method that will get all of the entries from our database and as we always do, we need
to pass into dole.
OK, so whenever you want to do something with the database, you need to dial because in the Dow,
that's where you define those methods.
Right?
We want to call this method and therefore we need to have the Dow right.
So now this has to, of course, be done in the background so we can use this lifecycle scope here to
launch our call routine like soap.
And I'm just going to use this history Dow that was given to us to fetch all dates.
And then we used this collect method, if you recall to then say what we want to do with it, which
is a list of history entities.
So I'm going to give this a proper name.
I'm going to call this one all completed dates.
Like so.
And it's a list, so this is basically just a way to give this it finger here, a name that you can
use.
So I'm just saying, OK, I'm going to go through this list and for now, for every single entry of
my all completed states, I'm going to display them on the lock.
OK, so I'm going to add this error log entry and this should be with a capital l and import it.
I'm going to just say the dates, colon and then the actual date with a string.
So.
String, empty string plus I.
Okay, so this is for now what this get all complete dates should do later on.
We want to display the data onto our recycled view, which we have to still set up.
OK, and something that I see that I'm missing inside of this function because I'm using bookbinding,
but I'm not clothed or getting rid of the view binding object.
Once the on destroy method is called, so let's add that real quick as well.
So here, let's add binding equals null at this point.
So just to make sure that we are not running into any memory leakages or so.
So now what would be a good spot to call this get all completed dates?
While I would say directly when we get into this history activity.
So let's go, go ahead and call it here.
And now you will notice that we are missing something right because we need to pass a history double.
So how do we create a historical object?
Well, we have used it before in our Finnish activity.
So here you see, we set up this history dull object right here.
So let's do the same thing here and pass that doll in there.
And that will be it.
So now we should get them data, at least should get it onto our locket.
OK, so let's run this real quick.
And see what we get on the lock, even though, of course, it will not display anything else or actually
let me see, I have some error here somewhere.
And it must have to do with me using this suspend function.
So let me check with our room database and we didn't used to suspend keyword because we used to flow.
All right, that wasn't my key problem here.
So inside of our history, we'll make sure not to have to suspend function for your query or for your
fetching methods.
OK, because the flow will take care of the suspense stuff or of the cowritten stuff.
So now this should fix the error.
Let's check it out.
Let's go over to the history.
And of course, we don't see anything but in the lockout, we should see something.
So how we call this thing, we call that and we check in our history activity.
We called the date.
OK, so the search for a date.
All right, and for some reason, I had to.
Well, rerun this entirely.
For some reason, it doesn't show me the date properly.
So you even if I searched for date and by the way, I changed it log entry a little bit because I wanted
to actually debug it and I went to no filters and then it showed me the application.
So maybe it has to do with me having multiple instances of Android Studio open, as well as running
multiple apps on the emulator and stuff.
So once you go to history now, you should see an entry.
So it says here this is the entry that it made 15th of October, while the state entry that we have
in our database, right?
So 10, 23, 36, let's look at the database, to be sure.
So here after it is opened, let's go to the history table and you see 10, 23, 36, so that's exactly
what we've seen the look at, which means now we can get the date.
So you see, you could, of course, also log the eye itself.
So if you run dry, as I did earlier, it will give you the entire entity.
But if you want to specifically have the date, then you can also access to date property of your history
entity.
OK.
So let me jump over to the history and you see that it now gives me the History Entity Object, which
says to date, property of it is 54 October 2021 10:23.
36.
OK, so either way is fine, and now we see that we can retrieve the data.
So now it's just our next task going to be to also display the data.
So let's go ahead and quickly set up a layout for our recycling.
So for the individual items of the recycle view, and I'm just going to paste it in here, it's an item
history row.
It's really simple stuff.
So let me show you what I want to have.
I just want to have the number of the exercise.
So of the entry that we have and then to date.
So if we look at it, we have a linear layout, which is horizontal with a little bit of background.
I have this text view which says position or is the text you position which in tools, says one.
And then we have this text you item, which then should display the actual date.
OK.
So and tools also in our A.D., we're going to say date, but then later on, we're going to replace
that, of course, with the date that we are going to use in the respective you.
OK, so that's what we're going to set up in the next video.
So see you there.