1
00:00:05,990 --> 00:00:06,910
What's up guys.

2
00:00:06,920 --> 00:00:14,030
Jacob Bledsoe with Dev slopes dot com and in the last lesson we got everything working for our pace

3
00:00:14,090 --> 00:00:19,760
and now we have distance and now the last thing that we need to do is be able to pause and to resume

4
00:00:19,760 --> 00:00:20,800
our run right.

5
00:00:20,810 --> 00:00:24,680
So this lesson we're going to get our pause and resume function functioning.

6
00:00:24,890 --> 00:00:30,410
So then we can move on and start digging into the awesome realm stuff right.

7
00:00:30,410 --> 00:00:37,040
So before we get started let's pull up our terminal and I am going to just create a new branch for this

8
00:00:37,040 --> 00:00:38,030
lesson.

9
00:00:38,120 --> 00:00:42,190
Check out beshe be less than 10 right.

10
00:00:42,230 --> 00:00:46,270
And now with that going let's go ahead and just start in our current run.

11
00:00:46,280 --> 00:00:47,480
VC right.

12
00:00:47,870 --> 00:00:54,800
And underneath and run we need to just create a pause function that we can call right every time the

13
00:00:54,800 --> 00:00:56,660
pause button is pushed.

14
00:00:56,960 --> 00:01:01,840
So let's just make a funk pause run.

15
00:01:02,480 --> 00:01:03,690
OK.

16
00:01:04,220 --> 00:01:13,240
And what has to what do we have to do in our pause run we need to stop recording and location change.

17
00:01:13,280 --> 00:01:14,650
Right.

18
00:01:14,720 --> 00:01:27,450
We also need to we also need to stop the durations So the timer we need to pause the timer and then

19
00:01:27,450 --> 00:01:32,540
we also need to I think that's it.

20
00:01:32,540 --> 00:01:36,840
Pause the timer and stop recording location right

21
00:01:40,730 --> 00:01:42,720
so pause the timer.

22
00:01:42,770 --> 00:01:46,980
Let's see what would we do if we pull up our timer.

23
00:01:47,360 --> 00:01:55,520
I think so we can do invalidate in if you call Invalidate it just stops.

24
00:01:55,590 --> 00:02:02,220
It basically disables the timer from continuing counting because when we created the timer we just set

25
00:02:02,220 --> 00:02:04,160
it to repeat forever right.

26
00:02:04,170 --> 00:02:06,240
So invalidating it stops it.

27
00:02:06,240 --> 00:02:12,630
So we'll no longer keep track but this won't clear our timer because we have our counter variable that's

28
00:02:12,630 --> 00:02:14,190
holding the duration time.

29
00:02:14,190 --> 00:02:14,970
So that's great.

30
00:02:14,970 --> 00:02:24,520
So this will stop our timer in the pause in the pause function right and then we also need to stop updating

31
00:02:24,550 --> 00:02:25,480
location.

32
00:02:25,520 --> 00:02:29,520
So we call that right here in and run we need to do that again here.

33
00:02:29,600 --> 00:02:33,660
So manager stop updating location.

34
00:02:33,800 --> 00:02:34,860
Great.

35
00:02:34,940 --> 00:02:42,410
And we also need to change our button image right.

36
00:02:42,410 --> 00:02:44,710
We have this cool.

37
00:02:44,780 --> 00:02:47,640
We have a pause button and we have a play button.

38
00:02:47,720 --> 00:02:55,730
So we need to take our play button or pause button and we need to change the image.

39
00:02:55,730 --> 00:03:01,320
So if you call pause button that set image we will now pass in.

40
00:03:01,340 --> 00:03:06,380
I believe the asset is called presumed button.

41
00:03:06,380 --> 00:03:07,280
There we go.

42
00:03:07,370 --> 00:03:12,950
And you don't hit the pass in a string of a name any more just it'll find the asset name and it connects

43
00:03:12,950 --> 00:03:13,940
it for you.

44
00:03:14,000 --> 00:03:17,270
And we want this for state normal.

45
00:03:17,360 --> 00:03:18,580
That is fine.

46
00:03:18,800 --> 00:03:26,110
So this will change the pause button to a resume button which is awesome.

47
00:03:26,900 --> 00:03:28,040
What else do we need to do.

48
00:03:28,040 --> 00:03:39,440
We also need to set our last location to nil this location if we don't set the last location to nil

49
00:03:40,010 --> 00:03:40,480
it.

50
00:03:40,560 --> 00:03:47,000
When you hit resume run it's going to take the very last location wherever you paused your run and add

51
00:03:47,000 --> 00:03:49,120
all the distance in between.

52
00:03:49,220 --> 00:03:51,080
And we don't want that to happen either.

53
00:03:51,080 --> 00:03:53,660
So we want last location to get set.

54
00:03:53,660 --> 00:03:56,360
When you resume again right.

55
00:03:56,510 --> 00:04:03,770
So we actually should probably nilla fi start location and last location.

56
00:04:03,920 --> 00:04:07,680
So both those start over when you hit resume.

57
00:04:07,850 --> 00:04:12,040
And our distance isn't going to reset because we've just been adding to it.

58
00:04:12,080 --> 00:04:14,210
So that is fine as well.

59
00:04:14,210 --> 00:04:16,540
So let's see in paw's run.

60
00:04:17,000 --> 00:04:24,860
Let's go ahead and do start location equals nil and last location equals nil.

61
00:04:24,890 --> 00:04:30,920
And then that will require our location array to start keeping track.

62
00:04:30,950 --> 00:04:38,630
You know it won't add like if you pause Iran and cross the street and play it again it won't add that

63
00:04:38,690 --> 00:04:45,260
extra feet or the extra distance in your total distance.

64
00:04:45,260 --> 00:04:48,010
So that's nullified that's great.

65
00:04:48,020 --> 00:04:54,800
And so now we need to call this function from our action down here right.

66
00:04:55,070 --> 00:05:04,610
So right now if we just said pause run that probably wouldn't work right because our pause button can

67
00:05:04,670 --> 00:05:07,980
either resume or pause right.

68
00:05:08,060 --> 00:05:12,250
So we're just calling pause run and our timer is already invalidated.

69
00:05:12,290 --> 00:05:14,100
We're probably going to get a crash.

70
00:05:14,330 --> 00:05:21,140
So we should check to see if our timers invalidated and we can do that by just an if statement and call

71
00:05:21,140 --> 00:05:24,510
timer that is valid.

72
00:05:24,680 --> 00:05:26,330
And if it's valid it'll be true.

73
00:05:26,330 --> 00:05:27,000
Right.

74
00:05:27,230 --> 00:05:35,480
And so if the timer is true that means the run is in progress and we would want the pause button to

75
00:05:35,480 --> 00:05:37,740
pause our run right.

76
00:05:37,820 --> 00:05:46,640
And then so else if it's not valid that means we would want our run to start again right so we could

77
00:05:47,060 --> 00:05:53,400
call our start run function start run.

78
00:05:53,420 --> 00:05:53,840
OK.

79
00:05:53,870 --> 00:05:54,910
Awesome.

80
00:05:55,310 --> 00:05:58,920
So let's go ahead and run this and see if it works.

81
00:06:01,850 --> 00:06:03,430
All right finds our location.

82
00:06:03,440 --> 00:06:12,740
Let's click on Start Run and the timer is going our pace is calculating and our distance is moving.

83
00:06:12,790 --> 00:06:13,400
Awesome.

84
00:06:13,540 --> 00:06:15,100
So now if we pause this

85
00:06:18,870 --> 00:06:25,300
and it looks like something goofy is happening with our asset we're going to have to figure that out.

86
00:06:25,800 --> 00:06:31,470
But it did change it to the resume button which is cool.

87
00:06:31,650 --> 00:06:37,180
Our duration stopped our pace stopped calculating and our distance is not changing.

88
00:06:37,350 --> 00:06:39,160
So now if we pressed it again

89
00:06:43,540 --> 00:06:48,450
our timer started moving again and it looks like our distance is moving again as well.

90
00:06:48,520 --> 00:06:55,840
But our play button has to change back to the the pause state so we know that clicking it would pause

91
00:06:55,840 --> 00:06:56,180
it.

92
00:06:56,290 --> 00:07:00,700
And we also have to figure out why it looks like our constraints might have broken.

93
00:07:00,720 --> 00:07:03,590
So let's go ahead and check that out.

94
00:07:03,600 --> 00:07:11,740
So in the Start Run we need to do the set image but for the pause button right.

95
00:07:11,900 --> 00:07:13,220
But we don't want that here.

96
00:07:13,220 --> 00:07:16,710
We still want this to be resume.

97
00:07:16,740 --> 00:07:18,160
I don't even see it

98
00:07:21,950 --> 00:07:24,490
maybe we add the asset let me see

99
00:07:28,550 --> 00:07:29,180
our resume.

100
00:07:29,180 --> 00:07:30,490
Yeah we have our resume.

101
00:07:30,500 --> 00:07:31,090
OK.

102
00:07:32,810 --> 00:07:41,450
So down here we want this to be our resume button perfect and up and start run.

103
00:07:41,450 --> 00:07:52,790
We want our pause button set image to be Paul.

104
00:07:53,190 --> 00:07:54,510
I forgot what it was called.

105
00:07:54,510 --> 00:07:59,110
Let's go to our assets pause button.

106
00:07:59,160 --> 00:07:59,710
OK.

107
00:08:02,130 --> 00:08:05,530
So pause button No.

108
00:08:05,640 --> 00:08:07,080
Why is this not pulling up.

109
00:08:09,670 --> 00:08:10,960
Pause button.

110
00:08:10,960 --> 00:08:11,980
There we go.

111
00:08:12,340 --> 00:08:15,890
And then this will be for state normal as well.

112
00:08:16,510 --> 00:08:21,220
OK so now that should switch back and forth so when we pause our run it changes the image.

113
00:08:21,340 --> 00:08:23,860
And when we start our run it changes the image.

114
00:08:23,860 --> 00:08:29,710
Let's check out our story board because something I didn't mean to double click something goofy is going

115
00:08:29,710 --> 00:08:30,780
on with our button.

116
00:08:30,800 --> 00:08:32,960
So.

117
00:08:33,090 --> 00:08:35,090
So let's see.

118
00:08:35,090 --> 00:08:37,720
Pull up and are Inspektor here.

119
00:08:37,780 --> 00:08:38,400
OK.

120
00:08:38,440 --> 00:08:43,390
Something with this constraint doesn't seem right and you might not have had this weird shift it might've

121
00:08:43,430 --> 00:08:44,560
just happened to me.

122
00:08:44,590 --> 00:08:56,080
I'm going to delete this constraint here and I'm going to redo it and just do horizontal spacing.

123
00:08:56,130 --> 00:08:57,540
We'll see if that does anything.

124
00:08:57,540 --> 00:09:01,110
Otherwise we're going to have to dig into this a little more.

125
00:09:01,110 --> 00:09:03,090
So let's run the simulator.

126
00:09:05,150 --> 00:09:07,810
Start our run.

127
00:09:07,840 --> 00:09:11,090
All right durations going distance going pause.

128
00:09:11,450 --> 00:09:11,800
OK.

129
00:09:11,800 --> 00:09:13,460
So it's still moving it.

130
00:09:13,480 --> 00:09:16,560
And then when we play it's coming back.

131
00:09:16,570 --> 00:09:17,200
OK.

132
00:09:17,410 --> 00:09:24,520
So what I think is happening is I actually have a constraint maybe on the image itself

133
00:09:27,530 --> 00:09:29,730
but at least it's changing now.

134
00:09:31,230 --> 00:09:41,860
So it's just very strange because this is the same as a resume.

135
00:09:41,890 --> 00:09:44,300
All right let's figure this out.

136
00:09:48,190 --> 00:09:58,840
All right I'm going to delete this again and I'm going to make sure I have a aspect ratio on this and

137
00:09:58,880 --> 00:10:00,450
just make sure it went in there.

138
00:10:00,470 --> 00:10:02,470
Yeah it's one to one that is good.

139
00:10:02,660 --> 00:10:09,380
And then I'm going to click and drag to the label and do horizontal spacing like that.

140
00:10:09,400 --> 00:10:14,120
All right with the aspect ratio hopefully that will help keep the other items centered.

141
00:10:14,120 --> 00:10:16,730
Let's run this.

142
00:10:16,850 --> 00:10:20,760
And now the constraint to the end labels actually to the edge of our button.

143
00:10:20,810 --> 00:10:23,320
So I think it will work better.

144
00:10:23,840 --> 00:10:31,000
So let's start the Ron and then pause and it's still being silly.

145
00:10:34,590 --> 00:10:36,010
Stop.

146
00:10:36,760 --> 00:10:37,050
OK.

147
00:10:37,050 --> 00:10:39,860
So a quick way to figure out what's going on here.

148
00:10:39,870 --> 00:10:45,400
We can just change this image let's change it to the resume button.

149
00:10:46,810 --> 00:10:48,460
Oh see that's our problem.

150
00:10:48,460 --> 00:10:52,390
So the size of a button is actually changing on us.

151
00:10:52,450 --> 00:10:55,900
It's keeping the 1 to 1 ratio but it's making the buttons smaller.

152
00:10:56,140 --> 00:10:57,490
And I'm glad we did that.

153
00:10:57,490 --> 00:11:05,530
So let's go ahead and change it back to the pause button and we want to set the size up we'll just make

154
00:11:05,530 --> 00:11:09,250
it 75 by 75.

155
00:11:09,360 --> 00:11:13,910
And now if we change the image to resume there we go now we're good.

156
00:11:14,360 --> 00:11:18,900
OK so now let's go ahead and run it and everything should be pretty

157
00:11:22,000 --> 00:11:23,200
star run.

158
00:11:23,280 --> 00:11:24,790
Everything starts moving.

159
00:11:24,810 --> 00:11:25,240
Great.

160
00:11:25,250 --> 00:11:32,580
And then pause there we go our play button or resume button is now in the same spot as the pause and

161
00:11:32,580 --> 00:11:37,150
we can now toggle our runs and then our distance will continue.

162
00:11:38,420 --> 00:11:39,040
Awesome.

163
00:11:39,050 --> 00:11:42,520
And then you can end the run by swiping.

164
00:11:42,560 --> 00:11:44,180
Very cool.

165
00:11:44,180 --> 00:11:44,450
All right.

166
00:11:44,450 --> 00:11:51,320
So let's go back into our current Visi and we pretty much have everything we need right for

167
00:11:53,910 --> 00:11:54,880
running.

168
00:11:54,900 --> 00:11:59,420
I can't think of anything that we're missing at the moment.

169
00:11:59,580 --> 00:12:02,640
We have our duration.

170
00:12:02,640 --> 00:12:10,550
We have our distance and we're a bit we're able to pause and resume our runs.

171
00:12:10,560 --> 00:12:12,870
Let's see in our end run.

172
00:12:13,560 --> 00:12:23,160
So go down here in our end Swype our end run swiped where I commented and run code goes here.

173
00:12:23,220 --> 00:12:29,320
Why don't we call our end run function and and run function.

174
00:12:29,670 --> 00:12:35,010
So now we don't have to be down in this code at all anymore when we swipe and end the run it dismisses

175
00:12:35,010 --> 00:12:37,550
the VC and calls our end run function.

176
00:12:37,590 --> 00:12:46,020
So we came up to our end run function it stops updating location and up here is where we would add our

177
00:12:46,290 --> 00:12:50,220
object to relm.

178
00:12:50,800 --> 00:13:00,810
OK so I'm going to stop the the exercise here this lesson and in the next lesson we're going to start

179
00:13:00,810 --> 00:13:04,590
setting up our our realm data.

180
00:13:04,710 --> 00:13:10,290
So we're going to start setting up our role model for our run.

181
00:13:10,320 --> 00:13:11,430
So that'll be really cool.

182
00:13:11,430 --> 00:13:13,230
I will see you guys in the next lesson.

183
00:13:13,230 --> 00:13:21,240
But before we sign off pull up that terminal and do a get ad period get commit Dasch am and let's see

184
00:13:21,240 --> 00:13:30,550
we got our paws slash resume button function.

185
00:13:31,100 --> 00:13:31,750
OK great.

186
00:13:31,770 --> 00:13:34,480
And I will see you in the next lesson guys.
