Welcome to the final lecture.
In this video, we are going to finalize our application and we're going to finally see the history
of all the different exercises that we finished.
As you can see, the idea is that no data available will be displayed if there is no data available.
All right.
So that's a good practice to do because you don't want the user to not see anything.
If there is no data to see, you should at least tell him that there's no data available.
And maybe you can even add something like finish an exercise in order to see your history.
Or you could even deactivate the history button and inform the user that there is no data available
and he should start an exercise first, or you could even hide the history button.
So there are multiple different options.
You just have to decide for one.
And I personally like the idea that we have here where we say no data available and then once the user
finishes the exercise, then he can see the different exercises that he has finished or the dates when
he finished the exercise.
All right, let's get started.
We will need to have a recycler of you, because here I want to display, of course, all of the data
in the recycle of you.
And we will also, of course, need to have the XML file in which we want to display.
So activity history is going to be the one that I want to display it in.
And I'm just going to post the code in here and go through it.
So I'm just going to use a linear layout here.
At the very top, this linear layout will match its parents and the orientation will be vertical.
And when I insert that, you can see that here, our highest linear layout, so the container everything
is in is complaining.
So I also need to add an orientation in here.
So I'm going to make that vertical as well.
OK, so this is our linear layout in which I have to text you, which just says exercise completed and
has a text size of 18.
Divisibility is gone.
So it's not even so it won't appear at all.
But of course I still want to see it in here.
So you can see I have this little area which says exercise completed and then all of the different items
underneath it.
And then.
I have my respect of you.
Which is going to contain all the different elements, all the different entries that we have, the
visibility is also set to go on.
I have a little margin.
Of course, they all have IDs, right.
So this takes you has an I.D. then our cycle of you has an ID and then the text you on the also has
an ID which says TV, no data available.
And that one is going to be used, of course, to make it visible or invisible.
So we want to make this text at one point invisible, this TextView, because as soon as we have data,
we don't want to say that we don't have any data.
All right.
And that's pretty much the layout that we want to use.
Now, the next thing we need to do is we need to go to our app here and create a new.
Adapter, so I'm just going to create a new file here and you Coppen plus.
And I'm going to call this one history adapter.
Now, the history adapter should inherit from recycler view dot adapter.
OK, and our history adapters should have a constructor where it gets the context.
Which is going to be of type context, and it gets items which will be of type array list.
String.
Now, context is complaining because it doesn't exist in this context, so we need to import context
and then our adapter.
Needs to have a view holder now in order to assign a view holder to it, we need to create a new class
that I want to use as its new holder.
So let's go ahead and create a new class in here.
Class view holder, which will require a view and which will inherit from recycled view that Holder.
All right, so, of course, we need to import view as well.
And what we want to have in here.
Well, first of all, our.
History.
Main item, which will be viewed, not L'il history.
Mean.
And then I want to have the TV item and the TV position.
All right, so what TV item is going to be our view, that TV item and then Voll TV position?
It's going to be our view that TV.
Position.
So basically, it's going to be the ones that we have and this item, History Row, TV item and TV position,
so this XML file, which we prepared in the last video and also this linear layout called a little history
item.
So basically the custom roll that we prepared.
So that's going to be the view holder.
And now I can, of course, go ahead and say that I want to use the fueler here.
And where is this view, Holder?
It's in our history adaptor history adapter, dot view holder.
All right, now our history adapter needs to implement all the members that are still missing.
So uncreate, you, holder get item count and unbind view holder.
So that's important.
All of those.
And let's implement them, so what do we want to do once we create?
The Bueler well, here I want to return the view hold object and what should it have as its layout.
So layout inflator that from context that inflate.
Our dot layout, that item history wrote.
And then we need to pass in the parents and finally the attached to root value, and I'm just going
to present false.
OK, so the parents, that's what we get from here and the touch, the root, we just set it false.
OK, so that's going to be the view holder that we're going to return when we create or when the uncreate
view holder function is called from our history adapter class.
So here I can count.
What do you want to return there, their.
Well, the items such as return items, but size, what is items, well, items is what we get when
an object of the history adapter is created.
So we need it to pass the items.
And then we have to unbind V. Holder.
And this is where we actually.
Point to data, to the list, to you or to the recycler of you.
All right.
So if any of this is too fast for you, then please check out the recycled video once again, because
there I explain everything in more detail.
But basically what I need is the dates that I want to display, which is going to be of type string.
And I get it from items that get position.
So whatever position we currently in, I want to get it from the array list that we get past when we
create an history adapter object.
And then I want to display that and I want to display it correctly, so what I'm going to say is Holder
Dots TV position.
The text should be said to the position plus one.
As a string, so here to string.
So the position starts at zero, and that's the thing, I don't want to have the first entry at zero,
I want the first entry to be at one.
That's why I add one to it.
And then we can go ahead and set also the text of it, so holder that TV.
Item, that text should be the date.
So the date that we got from the item itself, so it's just going to set those two text views here.
So this will be the position and this will be the date.
That's what we do in our history, adeptness, what's what's happening here, basically, and then I
want to.
Move around between a great color and a white color has the background, so here I call this one little
history main item.
Like this, so the holder of his three main items set back on color and basically I'm just setting the
background color off the list element or the list item to either be this almost white color and this
white color.
So every second one will be great and every other second one will be white.
All right.
And now in our history activity, we had this function called get all complete dates.
And now instead of putting it to the log, we want to put it onto our recital of you.
So we wanted this displayed there.
So what we can check here is if we even have any entries.
So here, if.
All completed dates list is.
Greater so its size is greater than zero, then we know that we have at least one entry in their.
And then we can go ahead and say.
TV history should be set to visible, so its visibility should be set to view.
That visible and recycled view, history or history should also be made visible, so visibility view
that visible.
When the TV no data available, so the text with no data available, visibility should be set to count.
Some of you that got.
And now we can finally fill up our R.V. history, which is our recital of you history.
So here.
This one here, this recycle of you, we can fill it up.
And we fill it with some information, first of all, we give it a layout, so I'm going to set the
layout manager to be a linear layout manager.
With this as the context and then I need a history adapter, which will be my history adapter, so I
create an object of my history adapters of this class that I prepared.
And then, of course, I need to pass in the context so this and analyst.
And you guessed it, this all completed states list is an array list.
Of strength, because we get it from get all complete states this and that's unrealistic, right?
So that's exactly what we need in our history activity here when creating a history adaptor.
All right.
So here it says, I want to have an array list of strings.
Now we can go ahead and set the adapter of our arvi history to be the history adapter that we prepared,
so our history adapter object.
And then, of course, if we have no values whatsoever and sort of our all complete dates list, then
we want to make the opposite of what we did here or do the opposite.
So here, this one should be gone.
So our TV history should be gone.
And our Harvey history as well, but our TV, no data available should be set to visible.
All right, and now we can run our application and see if the two dates that we already had in there
are actually going to be.
Appearing.
So that we are history and as you can see.
First entry, second entry, then the two dates that we had last time exercise completed and that we
are, of course, you can make this a lot more beautiful.
So here you can change the title to be exercise completed and get rid of this area here or.
Whatever you think of, so you can make it as beautiful as you want.
Now let's test it.
Let's finish an exercise.
All right, almost done.
And that was a very quick one, so let's finish it, let's go to the history and we can see that the
third exercise is in there as well.
So this list is, of course, a recycled view and we can drag around if we had more entries here.
But, yeah, that's pretty much it already.
Now, you could, of course, go ahead and change the whole list items here instead of just having the
number.
And to date, you could also add an image.
Then you could lead to a different screen in which the user can upload his image that we want the way
he looked after the workout or the way she looks in general, maybe just to see how the progresses in
comparison.
So maybe a person wants to lose weight, then they want to keep the progress.
So each time they finish the exercise, they made an image and they want to store it here.
So that would be an option.
That's something that you can do.
And you will learn how to do that in the next chapter, actually, because we are going to create a
happy places at which you then can use to feed yourself and implement them here.
So you can once you are done with the other exercise, come back here and complete this or extend the
features of this.
And this is not part of the course.
But if you want to do that, please go ahead and try that.
Once you're done with the Happy Places chapter and if you want to share your code, feel free to do
so.
It's definitely interesting for the other students as well.
All right.
So thanks a lot for staying with me for this journey.
And now we're finally done with our seven minute workout app and I'd say see you in the next chapter.