Welcome back in this video, we are going to implement the exercises and we're going to add them to
our application, therefore we will actually do two videos.
One was not going to be enough, but we're going to set up at least the model for our exercises.
And then we're going to also look into adding this image to our exercise view, as you see here and
adding all of the different exercises that we have.
So it's going to be a list of a bunch of exercises.
So let's get started.
Therefore, what I'm going to start with are going to be the actual troubles because we are going to
require all of those images for different exercises.
So I'm just going to copy them in here.
You can, of course, go ahead and create your own images or just use your own images from a third party
website that you want to use.
So it should be 12 images in the end.
At least that's going to be the case for me.
So I have this launch, the plank and so forth.
OK, so all of those different exercises, I have created those very basic images for me, and we're
going to use them for our project.
OK, so the next thing that we're going to require is going to be a model because we need to know how
every single exercise is going to look like.
So let's go ahead and create a new class and it will be Kotlin class here, and I'm going to call this
one exercise model.
You could have also just called it exercise, of course, but I'm just going to call it exercise model
because it is a model and this exercise model will need a bunch of data.
So first of all, I want it to have an ID.
So power private VAR ID, which will be an integer, then we need to have the name of the exercise.
So private VAR name, which will be a string.
We need to have the image that we want to display.
So VAR image, which will be an integer, then we want to know whether we completed the exercise.
So private VAR is completed, which would be a Boolean.
And then finally, whether it is the selected exercise, so is so lected, right?
This will also be a Boolean.
OK, so these are all the values that we need for our model.
And now I'm going to add the functions so the getters and setters for all of those properties.
OK, so a getter looks like this fun get idea and it will return the integer.
Which is true here, and what it will return is going to be the actual ID.
OK, return ID.
So that's the getter function.
And then we have the Set ID, which will said the integer value that is passed to be that this ID will
be the ID that is passed.
So this idea is the global ID, which is this one here.
And this ID here is just going to be the value that is passed, the parameter that will then be used
to to assign the ID to the idea of the exercise that we're currently looking at.
And now I just need to add those for all of the other properties as well.
OK, so it's just going to look like this said name, get name, get image set.
Image get is completed, set is completed, get is selected and set is selected.
OK, all with the same structure as I've just explained.
OK, so this will be the model, and now we will be able to access those functions directly to modify
our exercise model.
This is just a cleaner way to do it.
You make your variables private, but you access them with public methods.
OK, so this is giving us control over those variables and how we want to secure them and make them
accessible.
OK, then I'm going to require a constant companion object.
So let's go ahead and create a new Kotlin class file and you can directly create an object here and
call it constants like so this object will then be accessible throughout the entire project.
We have seen that before.
We've used it and.
What I'm going to have here is a function that will give me access to the default exercise list.
OK.
And this will be an array list of type exercise model.
All right.
So this one here.
OK, so what is it that we want to do once we called this method?
Well, we want to return an array list of exercise model.
So let's go ahead and create such a list.
So I'm going to call this one exercise a list, which will be an array list of exercise model, of course,
because otherwise I couldn't return what is required.
So exercise model like so now I have initialize this exercise list and I will need to return that exercise
list accordingly.
So now our function is functional.
But of course, the exercise lists will be empty in the sense that it will be in the red list.
But the array list will not have any content, so it will not be null, but it will not have any values
assigned to it.
So now what we can do is we can create those exercises.
And how does an exercise look like?
Well, you just need to go over to your exercise model and you will know.
So you go to the exercise model and you see you need to pass an idea.
You need your personal name, an image and boolean as well as another Boolean.
So let's just do exactly that.
Let's create the jumping jacks, for example, as the first exercise and you used to exercise model
object and now you pass in the values.
So as we saw, this exercise model needs an idea, a name and image, and boolean, that's another Boolean.
So let's add the ID.
This one will be added one.
Then we add the name.
That's one.
We'll be jumping jacks, OK?
And then the image, which is an integer.
And the cool thing is, if we want to access items from our adorable Florida, we just need to go ahead
and use its integer value by using adorable dot.
And here it's going to be.
I see underscore jumping jacks.
And then we just need to add two more bullets.
And that is whether the exercise is already completed so false here because it's not completed and whether
it's elected, so falls here as well.
So both of them will be false and that is going to be fine for our jumping jacks.
Now we just need to make sure that we aren't this jumping jacks exercise to our exercise list, so we
go ahead and say, add and use our jumping jacks.
So now our exercise list will not be empty, but it will have one exercise.
Of course, we want to add more exercises because one is not going to do it.
So let's go ahead and add all of the other exercises as well.
And I'm just going to copy them in here because I believe that you are capable of adding the exercises
yourself.
You can call them the way you want, but I would recommend to use the same names as we have here in
the images.
So push up would be an exercise push up and rotation side plank and so forth.
So let me add those here and see if I have an arrow that is usually because I'm missing images.
So let me add those images here as well as well.
But as well, I need to add the wall sit and abdominal crunch, so I have forgotten to paste those images
in here as well.
So let's skip this one, let's see, maybe I have some wrong spelling or it wasn't found at first,
but now it seems that I have no more errors.
So just quickly, you see we have the wall sit where it has the idea to, then it has the name of Wall
said it's using the wall said image and is completed and selected.
This always set to false by default.
So we could also in the exercise model predefined that those values will be said to false by default.
So here, for example, is equal false and is equal falls.
Then those would become optional or we could make them optional so we wouldn't have to manually set
them each time in our constants here.
But it's going to be fine either way.
All right.
You don't have to do it this way.
So now imagine you setting them and then you see we have the abdominal crunch with step up onto chair.
Squats.
Tricep dip on chair.
I hate this one, it's super tough, really painful exercise, in my opinion, and Plank also isn't
too much fun, but it's fine.
Yeah.
So basically we have all of those exercises with the draw balls.
And each time that we created an exercise model object, we also added to our exercise list.
So now whenever we call this function, it will return the exercise of this to us.
So now in our exercise activity, we can get the exercises.
All right, so let's set up the exercises first.
So private bar exercise less because we are going to require it right?
And it's an array list of type exercise model like so and I'm going to set that as a Nullarbor and going
to assign null to it.
And then we need to know at which exercise we currently are.
So I'm going to say where current exercise position is going to be at minus one by default.
OK, so we're going to start at minus one.
And then once we increment this value, we're going to be starting at zero and zero is the first index
of an array list, which is going to really make it easier for us.
OK, now that we have that, we can get this exercise list and initialize it in our own create method.
So let's go ahead and do that.
We can do it in here.
So let's just say exercise list.
Is going to be constant start.
Default exercise list, and this method, of course, will now return the default exercise list, which
will be the exercise list with all of the exercises.
So you see there is a pattern here with constants.
It's pretty cool.
You can just create a.
We basically did the same thing with our quiz app, right?
If you recall.
So that really helps us out, too.
So now that we have the exercise list, we can go ahead and use this exercise list to set the image
resource for every single exercise.
And before we do that, where we set up the image view, I would just like to add one thing and that
is here in our own finish, let's use this variable that we just created this current exercise position
and let's increment it.
So once the set progress bar is done, we can say, OK, we are at the next exercise, OK?
And the exercise view currently doesn't have anything to do with image views, so we will need to make
changes to the XML file where we add another image to the XML file and then we or image view.
And then we assign this image for of the exercise to this image view and display the exercise name instead
of saying exercice name, which we hardcoded as of now, I believe so.
It says get ready for where we put it.
It seems that we had said this in our code when our activity code somewhere higher here, there it is.
So instead of displaying exercise names, we of course want to get the exercise name from our exercise
lists, current exercise position, but more on that in the next video.