Welcome back in this video, I have a little challenge for you, and that would be to create this behavior
where the timer runs to zero and then the exercise starts and you don't have to create an extra activity.
You see here the exercise starts and goes from 30 seconds all the way down to zero.
And well, that's basically what we want to achieve.
And you can achieve it in multiple different ways.
You could go ahead and just replace the existing timer that you have there, and you could just go ahead
and replace just the values of the existing user interfaces items.
Or you could go ahead and replace the entire frame layout and duplicate it.
So I'm just going to quickly show you what I mean.
You can go ahead and use this entire frame layout.
Duplicate it.
Give it an I.D. as well a different one.
Make a couple of changes for the progress bar, for example.
My recommendation is to change the MAX here because it's not going to be 10 seconds, but 30 and the
progress.
It's not going to be 100 but 300.
And then you need to make a couple more changes, like smaller changes.
And then of course, calling the inside of the exercise activity.
You can set up the changes that you need to make and that is to have.
And while he instead of on finish here, added now the exercise will start here, you need to make sure
that you make the exercise start.
And this means you need to reset a timer.
Well, you need to start a new timer.
And that new timer will not run for 10 seconds, but the 30 seconds and what you can then do, you can
make the current.
Frame lay out invisible.
So this one and make the other one visible.
But what's important is so here you can use another to set up review rest of you, but here and by and
so binding dot and it was the AFL Progress bar, so the frame layout thought visible the then set that
value to view Dot gone.
Okay, so that will make it invisible and at the same time entirely gone from DUI.
Wherever or however invisible will just make it invisible, but it will still be taking its space inside
the user interface.
So try both things, check out how they differ, and it's not going to be specifically at this point.
You should do it in the set up exercised view point.
But yeah, definitely try it out.
I wish you all the best, and once it done, you can, of course, check out my solution.
OK, so let's get started with the layout, and as I said, I'm just going to copy this frame layout
and paste it in here.
Now, according to I need to, of course, make a change here.
You can call it felt progress bar exercise or maybe something like an exercise view or something like
that.
OK, so I'm going to call it like this, which will make it unique.
The size and all of that can stay the same.
Then.
I'm going to set it in the visibility inside of the tools, so tools that visibility, I'm going to
set that to visible so that in the tools we see it.
But in the actual application, this will be invisible.
So visibility will be set to gone.
Okay, because now you will see that in the tools.
Well, it's it's not very well visible here because it's existing twice, but this is going to be our
frame layout here and then we have the progress bar.
We need to give it a unique name as well.
I'm going to call this one progress bar exercise.
So that's going to be unique.
We need to make a couple of changes the MAX to 30 and progress to 300 because we want to have 30 seconds
now.
OK, so I'm going to set it up like so and then the rest should pretty much stay the same.
No, the text of a timer, of course, needs to have a different name.
I'm going to call this exercise and the tools text will not be 10 but 30.
And now in the designer, we should see the second one because it's underneath in terms of the code
position.
OK, so that will be that let's go over to the exercise activity.
So here we need to make sure that we have an exercise timer and an exercise progress.
OK, so we basically do the same thing as we did here, only that we now call it exercise timer.
And here, exercise progress.
All right.
And accordingly, we will need to set those as well.
But what would be a good spot for that?
Well, the thing is, I would say, let's set up an entirely new.
Method where we set the exercise progress bar, which will be very similar to what we have here.
OK, so let me just copy this code here and now this one said Exercise Progress Bar.
And this one will be the progress bar exercise that we need to set the progress to the exercise progress.
The rest timer will be the exercise timer to countdown seconds will be 30.
The interval will still be one seconds and on click we need to increase or increment exercise timer.
And exercise progress to be precise, so exercise progress.
He had a progress bar will be our progress bar exercise, of course.
So here progress bar exercise.
And we said that the 30 minutes to exercise progress as well as here.
This will also not be the TV timer, but TV timer exercise.
And is exercise progress?
We just need to make the changes, basically replacing the names.
And that should do the trick.
And then on finish.
So here we can just say, um.
Thirty seconds are over.
Let's go to the rest for you.
OK, so the idea is that we go to the rescue again, so we basically restart the rest and.
Your timer progress bar, OK, so now.
We also maybe should make sure that we have gotten rid of the other timer as well.
So if.
The exercise timer is not null, then let's make sure that the exercise timer will be cancelled.
As well as the exercise, progress will be reset to zero.
OK.
So where would we call this method?
Well, the thing is, we will need to set up the exercise for you as well.
So here we have the rest of you and we will need to also set up the exercise for you in a similar fashion.
OK, so let's do that.
Private fund set up.
Exercise for you, so.
And now what do we need to do here?
Well, I talked about visibility and stuff, right?
So we should make sure that we use binding here, which is pretty cool.
So now we can access our progress bar and make it invisible.
And you see the name is not really well here we should.
Um.
Well, we could recall it fell.
Rest view or so, but it's going to be fine for now.
And then view, you can set it to invisible.
This will just make it invisible.
It will still stay inside of the view.
You can also make it gone than it will be outside of the view for that moment.
And then you can set the title of the text.
So text view title.
That.
Text to be and then for now, it's going to be exercise name.
OK.
Later on, we're going to replace it later on.
It's going to get an actual exercise name based from a list that we have.
But for now, this will be fine.
And then we need to make sure that the exercise view which currently if we look at it, this.
Frame layout exercise for you, this one is currently set to go on, so it's not visible, and we need
to make it visible so we can use binding once again.
Dot.
And here I'll exercise for you.
So this allows us to get access to this frame, layout, exercise view and directly work with its properties.
We don't need to use find view by the anymore.
As you see, we're using view few binding here, and we set the visibility property of that frame layout
to be viewed, not visible.
So now we're making it visible.
And then we also need to make sure that we reset the exercise timer each time that we want to make it
visible and set it up.
So first we reset it with the same approach that we had here, which means we can just reset the timer
and then we can set the exercise progress bar.
So this is the method that we just had created, which sets the progress to be the exercise progress
and so forth.
OK, and also starts the timer accordingly, of course.
So now if I didn't make a mistake when copying and stuff, I just need to set up the exercise view at
the right moment.
So what would be a good spot to call the exercise view?
Well, I hope you came up with it.
It's, of course, when the.
Riskview is finished.
So here we should call that set up exercise view method.
So now let's see if this is actually going to work or if I still need to make a change.
So let's start it.
Let's see once the timer is over, whether it's going to jump over as intended.
And there we are.
It jumps over, even though it's not perfect, because exercise name is just not positioned correctly.
So let's check out what the problem is.
And actually, I think I have a very clear or easy solution.
That is because I am making the AFL Progress bar view that gone, so I'm making it go entirely away.
And if I just make it invisible at this, this will show you the difference.
Very well.
I think that's amazing.
I like that it comes up like this.
So not once a timer will be gone.
You will see that the text will stay where it is because the text, so the TV title is currently linked.
There we are.
It's currently linked to our AFL Progress bar.
So the bottom of it is to the top of the AFL Progress bar, which is when it's gone.
So if this frame layout is gone, which means it's it's basically as if we were to delete this entire
frame layout out of the XML file.
That's what's gone with you.
OK.
But invisible.
The only thing that it does is it just makes it not visible, but it's still there.
Like it still takes the space that it requires on our user interface.
And because we are not saying that, we are also because otherwise we would have to do.
We would also have to go and set the constraint here.
And I'm not even sure how to do it because I've never done it in code, but we would have to go ahead
and do something like a TV title that constraints.
Now, I wouldn't even know how to get there, but we would have to play around with the constrained
properties.
So what I would do is in order to find that out, I would go to the documentation.
I would check out how does or how do I access the constraint property?
The one bottom to top off.
So layout constraint bottom to top of it could actually try that.
So binding layout constraint?
Oh, it's actually a TV title that was the first of all.
You have to get the item itself.
And here to lay out constraint doesn't exist.
Let's see if we enter layout.
And layout change, listener remove well, doesn't seem like it.
OK, so in this case, you would really have to check out the documentation.
And I would recommend you try this as well.
This is just a different approach.
You see, there are many different ways of fixing this, and I hope you came up with this and made it
possible so that the exercise does actually work as intended.
And yeah, see you in the next video.