Welcome back.
In this video and probably the next one, we are going to add the exercises and we so far only have
the exercise screen, which was just a timer.
But of course, we want an image to be displayed, as you can see here.
So we have this little image that will change after each exercise or will be different for each exercise.
So we have jumping jacks.
And as you can see, this is the jumping jacks that we have here and the timer goes down and which is
great.
So the next thing we need to do is, of course, to create a model.
With all of that, we need to have all of the images and we also need to take care of having the right
constants, so to say so having the right names assigned to the right images and so forth.
All right.
So I'd say, let's get started with this.
Let's, first of all, import all of the images to our drawable folder.
So I'm just going to drag them in here.
So just go ahead and.
Mark all of them and then copy them into your project so you can just drag it into your drawable folder
directly, it's 12 images.
So I'm just going to say, OK, here.
And of course, you could optimize those images to be smaller or for smaller devices and so forth.
So you could have the drawable folder with all of the different sizes.
Right.
And that's something that I'm going to keep simple for now.
But if you want to put it to production, then that's something that you would have to take into consideration
in order to optimize it for different screen sizes.
All right.
So that's the first step.
And the next one will be to make a model class, which we can adjust later on if we need to.
So I'm just going to create a new class here.
And it's not going to be an activity this time, it's really just going to be a new class, so new kotlin
file class and I'm going to create this class as being the exercise model.
So the idea behind this is that we generally have the structure of an exercise, and that's something
that we have to think about.
So what is the structure of a of an exercise?
What do we need to know about each exercise?
Well, the obvious one will be the name, right?
The obvious one should be the image.
But then there are some ones that or some that are not obvious for now, which is, for example, the
ID.
So we need to know which exercise is going to be the first one, which is going to be the second one
and so forth.
Then we should know whether the exercise is currently selected or not, because we later on will have
this little adapter view or a little recycler view which will display which exercises we already have
finished and which exercise we currently are.
And so we also need to know whether an exercise is finished or completed.
And the thing about those variables is that they need to be passed every single time that we create
an exercise model.
So let's go ahead and add those variables in here.
So in brackets, just after the name exercise model, as you can see, we have all of those variables.
So each time you create an object of exercise model, you need to pass the ID to name the image is completed
studies and is selected status.
So ID is the number.
So I one would be first exercise idea to second exercise to name is the name of the exercise.
Image is the image that should be displayed is completed whether we have finished the exercise or whether
we have not, and then is selected to check which exercise is the currently selected exercise.
So that's our exercise model.
And now I need to have getters and setters for all of them because I want to be able to access them
at any time.
And instead of now typing it in for you one by one, I'm just going to place them in here, because
as you can see here, we have a getter for getting the ID.
We have a center for setting the ID and the same for the name, the image that is completed status and
the selected status.
And the cool thing about this model is that we can easily adjust it later on if we need to.
So if we decide that we want to have even more information about each exercise, then we can change
it in here.
On top of that, if you have any questions regarding getters and setters, then you should check out
the fundamentals video about that.
All right, so that's our exercise model.
Then the next step is to make a default list of exercises.
And I'm going to create a constant file, so to speak, a constant class in order to have that.
So let's go ahead and create a new kotlin file.
And it's going to be a new class and I'm going to call this one Constance, you could call these exercises
that would be fine as well.
I'm just going to go with Constance here.
Now, the thing is, in order to make them available throughout the whole files of all sold throughout
the whole project without having to create an object of our Constance class, I can use a keyword called
companion.
So I'm going to create a companion object, which pretty much means that it's the same thing as static
in other classes.
All right.
So if you have ever seen the keyword static in Java or C Sharp or other programming languages, so that's
basically the same concept that we're using here.
But we create a static variable or in this case, multiple static variables and static functions that
can be used throughout the whole project without having to create an object of a specific class, in
this case of the Constants class.
All right.
So in here, we will need to have a function which will take care of the default exercise list.
So I'm just going to create this fun default exercise list.
The idea behind this is that we can always go back to the default exercise, this which contains all
of our exercise.
So the 12 different exercises and what it's going to be is an array list of exercise model.
So now we can see where exercise model comes into play because our exercise model contains information
about how each exercise will look like it will have an idea, it will have a name and so forth.
So what we need to do is we need to set those values in here.
First of all, I'm going to create a variable here which is going to store the exercise list.
So exercise list is going to be an array list of exercise model here.
So, by the way, what you can see here, it is a return type.
So it's going to return an array list of exercise models.
So each time that we call this function, it will return that to us.
So to the caller.
So that's why it's expecting a return statement here, return exercise lists.
So that's what we want to return and here to array a list.
Now, this, of course, is not a function, so I don't need the curly brackets here.
Then we have the first variable, which will be jumping jacks and it will be an exercise.
So we need to have an exercise model, so what's the idea of the jumping jacks?
Well, it is one then.
The second variable is the strength of the name of the variable or of the exercise jump being jacks
and.
Let me close this and we can see here jumping jacks, then the next variable is the image that we want
to use.
So our daughter Wrobel thought and here we have I see jumping jacks.
So that's the one that I want to use.
Then I will put them in multiple different lines so it's a little more readable.
So the next one is our is completed status and I'm going to set that to false.
And finally, our.
Is current or is selected?
I'm going to set it to false as well.
All right.
So this is our exercise jumping jacks.
And now what I need to do is I need to assign that exercise jumping jacks to our exercise list.
So exercise list.
And here, of course, I don't need to create a new variable, just going to add my jumping jacks in
there and now we need to do that for all of the exercises.
So this is just one exercise, jumping jacks, exercise model drawable and so forth.
But now.
The next exercise will be our wasit, so instead of.
Typing everything now I'm just going to.
Copy and paste them, so you're not getting bored too much, you can, of course, type them in or you
can have the other project open and parallel and paste all of the stuff in here, because this is really
the same thing over and over.
So I'm going to go through it real quick.
We have the wall set here, which is the ID to it has the name Wall said it's going to use the drawable
Wall said it's going to have is completed to set false and is selected is also set as false.
Then we have to add it to our exercise list now, the same thing with the push up we pass and all of
the names, and then we add that to our exercise list, abdominal crunch.
Then set or step up on chair.
Squats tricep on chair and maybe a triceps dip on chair would be the correct name, but now.
It's fine like that.
Then we have the exercise model again.
We added to our list the plank, the Chinese running in place, the longest push up and rotation.
And finally, the site blank, so you can see we have 12 ideas, so we have 12 exercises in total and
you can, of course, now go ahead and type all of that.
But I don't want to do that in this video because I don't want to bore you too much.
So let's go to the next step.
So now let's go back to our exercise activity, because that's where we will, in the end, want to
display all of that stuff.
So here we need to have a new variable and this will be the exercise list.
So private for exercise list, which will be of type array list, and it will contain an exercise model.
Now, this one will be a nullable because I don't want to set it here directly.
I will set it in initializing more in an illusion, losing function.
So we have this private water exercise list.
And the question mark should be after their release, so they are released, is an optional not exercise
model or an nullable, then we have the private of our current exercise position because we need to
know at which position we are.
So the thing is, I'm going to set that to minus one because the position of an exercise starts at zero.
So what I will do is I will increase or increment by one before I actually use the current exercise
position.
So minus one is a good choice here.
You will see later on that it makes sense once we get to where we actually use it.
Then in our uncreate, I can set that exercise list because as I said, we need to at one point initialize
it and that's what I'm going to do in here.
So exercise a list is going to be.
From my Constance.
Default exercise list.
So what I'm doing is I'm just.
Saying or calling this function here to follow the exercise list, which is going to return an exercise
list of exercise model, which is our exercise list, which contains all of the exercises.
Right.
So our jumping jack on Wall Street and so forth.
So that's where all of the stuff is.
That's what we set up.
And now we can use this default exercise list as being the exercise list that should be displayed in
our application.
Now, you could, of course, go ahead and create your very own set of exercises.
So let's say you extend the application later on and the user can create his very own structure on the
exercises that he wants to to do.
Then you could go ahead and say, OK, so instead of using our default exercise list, use the list
that the user created.
But of course, we're not going to do that because that would really be way too big of a project for
now.
All right.
So exercise list concerns default exercise this now that is set.
The next step is to increase the current exercise position.
So.
Where would we do that?
Well, that would make sense each time that the new exercise started, and that is after the progress
bar.
So once we finish.
Our.
Rest progress, so this rests Taimur, we want to increase the current.
Exercised position by one.
So we want to incremented and then.
We also need, of course, to change the image that is displayed and we need to change the name that
is displayed in our.
You so in our exercise view, so in our here activity exercise, we have this linear layout which only
takes care of our exercise.
You add in here we have this TextView, which is called TV exercise name, and we will still need to
set up the image for you.
But before we do that, I'd say we take a little break because we still need to do quite some stuff
in the next video.
So see you there.