Welcome back in this video, the goal is to display at which exercise we currently are at, and therefore
we are just going to change the background color of the item that Booker and yet so of the exercise
that they're currently at.
So let's go ahead and implement them.
Therefore, we will need to go over to our exercise status adapter.
OK, so here what we're doing is we're binding the view holder, right?
So we are binding the you hold our item, which is currently just a text.
But I also want to update the current item, and I want to make sure that the complete item in the UI
is also changing the color.
And that's pretty much it.
So let's go ahead and set all of that up.
So here I'm going to check when.
The model don't get is select, it is true, then do something, then we have the case where model thought
we get is complete.
It is set to true do something and then we have the block.
OK, where?
Either of them or by both of them are inactive.
OK, so we have this health blog as well, so now we need to think of what do we want to do in each
of the cases.
So the thing that I want to change is I want to change to text you items background property.
OK, so what is this text item again?
It's this binding text you.
So this thing here, this little text and this text you.
I want to set it's background to not be either a circular color grey background, but I want to use
maybe a white background instead, for example.
OK, so how do we do that?
Well.
We can set the background by using context combat.
We have done that before, but it has been a while.
So let me go through it again.
So we use this context combat and we get a draw bill.
We need to pass in the context.
And what can I just say this because this doesn't exist or we're not in the context of a class at this
point, we need to get the context of the class, so we get it from the item view thought context.
The item view is the view of the recycled view view holder.
OK, so it's from the internal class and from there we can get the context.
So we just say, OK, where is this item being displayed?
And then we get its context.
And then we can now use the drug bill.
So our Dodge Draw bill and then I'm going to use item.
And I think we don't have it yet.
So let me just create another one.
And I'm going to call it.
So let me duplicate.
Which one would it be?
I think this great color background, let me duplicate it.
So be.
And paste and we call it circular.
Thin color, accent border, OK.
And now there, I just wanted to be oval and the color should be white.
So here we can just use white as the color.
But then I also want to have a stroke surrounding it, so let me add a stroke with a width of five.
Four zero zero five super thin, 0.5 density pixels and our accent color.
So this green color, so we just want to have a green border surrounding it, maybe 0.5 is too little.
One tip, maybe it's a little more visible.
So basically a super thin stroke around the color.
So I want to use this item, though.
So it was the item then color accent border.
OK, so this is a draw that we just created, and I want to assign this as the background of my text
you item.
So off this number that we see here.
All right.
And.
I'm going to change to the text color of it as well, so all the dots, TV item dot sets, text color,
there's a method for that and not key here, but color.
And here we just can use colored dot parse color and other colors, but color dot parse color from a
string and I'm just going to hard coded here.
You could, of course, just use an internal color as well, but I'm going to be fine like this.
OK, and then I can just copy this code and put it in to get is completed and there I just need to set
it to while I'm going to set it to the color accent background to the green background.
So we know that these are the ones that we have completed.
So we'll have as green for the ones that we completed, white for the ones that we are currently at
and gray for the ones that we haven't finished yet.
OK, so what is the outlook then?
Well, there I'm going to set it to be gray.
OK, so here background will be.
The items, circular color, gray background.
Which is the default that we have already.
And as a text, we can use this same text color here as well.
And by the way, when we're using this green color, I think having this great color is not as nice
as just having a white background.
So here I'm going to use triple or six times F in order to get this white background.
OK, so now we get it based on the model value.
So based on the value of the individual item, but we're never actually triggering this change.
So now we need to find a good spot where to trigger this change and that would be in our exercise activity.
So what do you think?
What would be a good point to change the background color of the ones that we finished and change to
one that we're currently at?
I would say once we're done with an exercise and once we start with the next one, so we have our timer
where we set up the exercise view, for example, and where we set up our rest.
Timers.
So those two.
So let's start with the set rest progress bar.
OK, so here in our arrest timer on finish before we set up our exercise view, what we should do is
we should.
Check for the current item that we're at, so exercise list at the current exercise position, said
selected.
I said is selected, we should set that to true.
So when we are at the progress bar, we set the current exercise to true and at the same time, we need
to make sure that our exercise adapter is being notified about that.
So we need to call notify data set changed because if we don't do that, it will not change the recycler
use appearance or anything because it doesn't know that the data has changed because we have now is
an entirely data driven recycler of you.
We're not changing the appearance of the recycling you manually, but what we're doing is we're saying
we changed the data and recycler view itself should change the appearance based on the data.
So now we're motive while notifying the adapter that the data has changed.
So the adapter will run on by-nd view holder once again.
And also on Create, you're the holder.
So basically, we'll call these methods once again and it will then see, OK, well, I'm just going
to use the latest data or the latest property values for those data.
So I'm going to see is the item selected?
So the current exercise was the exercise completed is the ALS case to case.
So either way, it's going to do the right thing, though.
So that is once we set the progress bar.
But then once we are done and you just copy that once we are done with an exercise, which is in the
moment where we have the time or for our exercise progress bar.
So this one here, then we need to do the same thing, but in the other way around.
OK, so we need to go ahead and on finish here.
So once we are inside of while actually in the unfinished in general, we don't care if we are inside
of a particular exercise item or not.
So here we're going to set is selected to false.
And set is completed to true.
So let me copy this line here and set is complete it.
I'm going to set that to true because now the current exercise that I was at is completed.
And then.
We are setting up the rest of you, which internally will then.
Which then internally is going to hear increment by once, so once the exercise is done, it's going
to prep for the next one.
So let's run it and see if this is actually the case so that we are jumping jacks.
Let's see if it's going to change it once it's finished or unfinished, it should get the next exercise,
which is going to be too.
And you see, it's the current one is set to white and the next one is still gray.
So now after those 30 seconds are over, it will take the number two will make it white and make this
one green because we finished it already.
And if we look at our exercise status adapter, we set it to be green.
So let's see this transition where it goes from white to green.
That we are close to green, but this one doesn't go to white yet because it only goes to white one,
and once it's done with the relaxing phase or the rest phase.
And you see now it goes to the white colour.
Perfect.
So now you see how you can create true recycled view.
Very customized, really like the appearances all custom made.
And you could change it to whatever you like.
But generally speaking, it now has this appearance that we wanted where we now see which exercises
we have already done.
Which one we're currently at.
And then we see how many are still to be done for us.
So now it will turn green once we're done with wall it.
And I hope you that the was--it exercise and now the next one will be to do a 30 seconds of push ups.
So maybe you can do 30 push ups in that time.
Well, depends, of course, on how clean you do them.
OK, so that's it for this video.
See you in the next one.