We'll come back at this point.
We will need to go on with where we finished in the last video.
So let's get started and we start with setting up the text and the image that we want to set.
Then we can go ahead and.
Set those things.
And the best spot for that would be the set up exercise for you.
So here we want to set everything up, right?
So once the progress bar is set up, we also can set up the time.
So every image, that's a variable that I will create in a second there.
I want to set the image source to be the image.
OK, so an activity exercise.
We need to create this image for you.
So at which point does it make sense?
Well, in the Linera layout, just above that text, so here we have this linear layout, which is our
exercise view, and we have our text you where we need to create the image here.
So we want to have an image view.
Now, what about this image of you?
Well, it should be matching the parent then its height.
Should be zero DP, so I'm going to set it to zero DP for now and it will then just take the size of
whatever we have as the the image size.
All right.
So we will fit it later on.
And how do we fit it?
Well, with scale types.
So there is this variable called scale type and we can set it to fit X and Y.
So just going to fit the image into the screen.
So if you want to know more about the different fit types, you can test all of them and see which does
what.
All right, then I will set the layout weight to be one and I'm going to give this a little description.
So content description is something that you.
Can give here.
And I'm just going to give the string image here.
So what's the idea behind this?
Well.
If a blind person tries to use this app, then this could be red.
So whatever text we have behind string image, so here they'll use.
Strings and we have this image and here is just an image, but we could say something like exercise
image here, and then the person would understand a little more what the idea behind this thing is.
All right.
So now.
Let's go back to our activity exercise, we need to give this imagery an idea, so it's it's best to
have the I.D. at the top.
And I'm going to call this one I've image.
So I've standing for image view and then, of course, image.
Now we can set a source for this directly.
So which is probably not such a bad idea, because just in case that the image is not loaded directly
and it is not displayed, we can set the default image for this image straight from the start.
And I'm just going to use drawable.
And here I see underscore jumping jacks because that's the first exercise, right?
Because if we look at our constants, we can see Volle Jumping Jacks is the first exercise which has
an idea of one.
So it makes sense to display this exercise as the first one.
All right.
And now we can go ahead and use this I.V. image here and we can set its value so we can go ahead and
say set image resource.
And here we have a much bitmap image Straubel But I have a resource here, which is my exercise list.
We saw earlier is another.
All right, so we need to use exclamation marks if you want to use it, and then I'm going to use the
current exercise position that get image.
So why am I doing that?
Well, let's look at our exercise list real quick.
We can see our exercise list isn't a list of type array list, which contains exercise models, and
it's a nullable.
So it's sad to know.
But of course, later on we said it, but it's still going to be.
All type lists and or array list, so if you want to access a part in there, so I index in there,
we need to set a value in here.
So here in the first for the first exercise, it will be zero, then it will be one, two, three and
so forth.
So I'm just going to use this current exercise position to display the right exercise and then I get
the image from that.
What is the cat image?
Well, if we look at our get or exercise model, we can see that we have this variable called image
and then we have this geto function get image which returns the image.
And which image is it going to return?
Well, it's going to return the our drawable I see jumping jacks, so it's just going to return the
image of our jumping jacks and then in the next iteration it's going to return to icy Wall Street and
so forth.
Now, there is something about the idea now you might wonder, well, I'm using it one here and here,
I'm using the current exercise position, which we initialized with minus one, which we then increased
by one once the exercise started.
So we are at position zero instead of ID one, which we had for our jumping jacks.
So why should it still display jumping jacks?
Well, there is a distinction to make.
So exercise model has these IDs, but they are not the the numbers or the indices, the index numbers
of our.
List that we have here, so of our exercise list, because the exercise list has its own index indexes
and it starts at zero.
So the first entry in that list is going to be zero.
Or the index for the first entry, and that is our first exercise that we have in the list and the first
exercise that we have is in the list is the jumping jacks.
All right, so coming back.
And this video is a lot longer than I was anticipating, but we are at the point where we set the image
resource and now we only need to set the exercise name.
So let's set the exercise.
Nice name.
So it's text to exercise list DOT or here.
Actually, it's also the current exercise position.
Dot, good name.
So here, instead of getting the image, we get the name, which means that if we look at our concerns,
we get the variable this year as it says here, name jumping jacks.
All right, so now there's one less thing to set, and that's, of course, to.
Said our exercise correctly.
So I started the code already, but we need to do one more step and that is in our set exercise progress
bar.
Here on finish, so once we finish the exercise, what I want to do is not only to show a text which
says here we will start the next screen, but actually start the next screen.
And that is linked to something where we have to be very careful.
So if the current exercise position is less than 11, then please set up the rest of you, set up rest
of you.
But if it's not so if we are at Exercise 12 already after exercise 12, we don't want to display the
rest of you again, but we want to display the finish for you.
So the ending view where we say congratulations, you finished a seven minute workout app or the seven
minute workout.
Great job.
So what I'm going to do there is I'm just going to post a toast here for now, which is just going to
say congratulations.
You have completed the seven minute workout.
OK, so in order to test that, we could, of course, go ahead and save the position is less than one,
so that would be a good number to test.
And of course, we could also go ahead and make it less.
Let's say let's hardcoded and just look at, um, exercise lists that size minus one, so that's the
thing here about this exercise list.
It is an option or a nullable.
Right.
But we unwrap it until we get that size and then we subtract one because it starts at zero.
Right.
If the size is 12 and it starts at zero.
So we need to reduce one here in order to make sure that it's not going to get to the rest of you after
the last exercise.
All right.
So this would be an alternative to just entering 11 here.
So the way you prefer is what you can go with.
This is the sure or safe way that even if we later on decide to change the amount of exercises here
in the exercise list, that it's still going to work.
All right, and at this point, we can.
Test it, so let's go ahead and test this.
So let's play start.
And now let's see what's going to happen.
Get ready with the jumping jacks pops up and we can also see the image pops up.
And I'm just going to post a video real quick until the timer is almost done.
Just to see if it then goes over to the rest of you after the timer is over.
So there we are.
And as you can see, we didn't get the rest of you, but 10 seconds later, the next exercise popped
up.
So there we have a little issue still in our coat.
So let's fix that.
And this has to do with a set of pressure now for you to try to figure out why it doesn't work.
All right, I'll tell you, I hope you figured it out, it has to do with the visibility so we are not
setting it visible.
So we need to set that visible again.
And the same goes for the exercise of you.
We need to make it invisible.
So view that gone.
All right, because in the set up exercise video, we did set the ones so the rest of you has gone and
exercise you as visible, but we never set it back.
So instead of rescue, we now do the opposite or we do the switch.
So now let's run this again.
And I'm just going to cut to the point where it's actually important.
So at the end of the first exercise, what it's going to switch.
And by the way, for the purpose of testing, it really makes sense to reduce those timers to two or
three seconds, because then you can really quickly test especially this behavior because you don't
want to wait for 30 seconds or even 40 seconds each time just to see if a functionality works as intended.
But here we are.
Jumping jacks goes from one to zero.
And then we get back to our rescue, get ready for.
And there, of course, it should display the name of the next exercise at one point, but now it doesn't.
And there we are.
Next exercise wohlsen so we can see the transition worked.
And that is great.
So I hope you enjoyed this video.
It was a super long one.
I'll probably cut it into two, but that's just how it is.
Some functionality is they need a little time to set up, especially because we set it up in a very
clean way.
We have a model, we have a constant which we can at any time adjust.
And we made it so that our application is easily extendable later on and maintainable.
So that's a thing that you really need to take into consideration when building your apps, because
if you build your apps without these concepts in mind, then it will be really a pain to do that.
All right.
So see you in the next video and thanks for still being with me.