1 00:00:00,460 --> 00:00:04,760 So we know that when that clock hits zero, we want some stuff to happen. 2 00:00:04,760 --> 00:00:08,320 Let's go look at how to know the attempt is completed, and 3 00:00:08,320 --> 00:00:11,070 then figure out how to, and what stuff we should do. 4 00:00:12,220 --> 00:00:13,820 First, let's clean up that to do. 5 00:00:13,820 --> 00:00:17,810 We definitely wanna stop the existing timelines from running, so 6 00:00:17,810 --> 00:00:19,610 that seems like we wanna do that. 7 00:00:19,610 --> 00:00:21,290 Every time we create or 8 00:00:21,290 --> 00:00:25,250 prepare a new attempt, we wanna wipe out that existing timeline permanently. 9 00:00:26,450 --> 00:00:28,500 So, let's take a look. 10 00:00:28,500 --> 00:00:29,710 Let's think this through a little bit. 11 00:00:29,710 --> 00:00:31,540 Let's come up here. 12 00:00:31,540 --> 00:00:34,560 It seems like right about here, right? 13 00:00:34,560 --> 00:00:38,930 So, there's gonna be a chance that mTimeLine's not set. 14 00:00:38,930 --> 00:00:42,050 So, we're gonna have to say, like, it hasn't started yet. 15 00:00:42,050 --> 00:00:44,950 So if it's not equal to null, 16 00:00:44,950 --> 00:00:48,230 that's always a good thing to do to check otherwise. 17 00:00:48,230 --> 00:00:52,080 When you go to access a property, like, we wanna see if it's running, right? 18 00:00:52,080 --> 00:00:53,690 We wanna see if the thing's running. 19 00:00:53,690 --> 00:00:55,390 So we're gonna say, get status. 20 00:00:55,390 --> 00:00:58,140 And if I didn't check for that null, what would happen when I called this, 21 00:00:58,140 --> 00:01:00,550 we would get a null pointer exception. 22 00:01:00,550 --> 00:01:01,380 And those are no fun. 23 00:01:01,380 --> 00:01:03,860 So you'll always want to check the state of things. 24 00:01:03,860 --> 00:01:07,806 So then we're gonna say if the status, and 25 00:01:07,806 --> 00:01:14,391 this status returns an enumeration of animation.status.running. 26 00:01:17,761 --> 00:01:19,561 That is a long looking line, isn't it. 27 00:01:22,511 --> 00:01:27,440 So if it's not null and it is running, we should just stop it. 28 00:01:27,440 --> 00:01:30,439 So we'll say mTimeLine.stop[};, okay? 29 00:01:30,439 --> 00:01:33,240 So that will stop it from playing into the future. 30 00:01:33,240 --> 00:01:35,470 Cool, we got that taken care of, but you know what? 31 00:01:35,470 --> 00:01:39,290 Those first couple of lines there, they kind of look like they belong together in 32 00:01:39,290 --> 00:01:41,050 some sort of method, don't they? 33 00:01:41,050 --> 00:01:42,150 When stuff starts feeling like that, 34 00:01:42,150 --> 00:01:44,610 like that doesn't really feel like it's very succinct. 35 00:01:44,610 --> 00:01:46,460 Like if I just look at this like what is going on there? 36 00:01:47,770 --> 00:01:50,980 Why don't we refactor this into a single method and that way it will be cleaner as 37 00:01:50,980 --> 00:01:54,110 to what's happening, as well as the method could be called elsewhere. 38 00:01:54,110 --> 00:01:58,130 So, when you get this feeling, a nice thing to do is you come in here like this, 39 00:01:58,130 --> 00:02:02,550 and you right click it and choose Refactor, Refactor, 40 00:02:02,550 --> 00:02:07,470 and we're gonna choose extract, and let's extract that one more time. 41 00:02:08,800 --> 00:02:16,660 Extract, and we're gonna extract a method okay? 42 00:02:16,660 --> 00:02:21,150 Private is fine, let's call that something that makes sense for both of those. 43 00:02:21,150 --> 00:02:22,950 We kinda want to reset things, right? 44 00:02:22,950 --> 00:02:28,740 So let's call that reset doesn't take any types, and click OK. 45 00:02:28,740 --> 00:02:31,300 Okay, awesome. 46 00:02:31,300 --> 00:02:34,850 So what it did is it took those and put them into this new method down here, cool. 47 00:02:34,850 --> 00:02:36,410 That's much cleaner now, I think. 48 00:02:36,410 --> 00:02:38,410 We come in, we prepare the new attempt, we reset the board. 49 00:02:38,410 --> 00:02:41,870 So anything that we need to do that resets the way that that screen looks, 50 00:02:41,870 --> 00:02:43,060 we just put that function now. 51 00:02:43,060 --> 00:02:46,680 And if we need to call that elsewhere, we can also call it elsewhere. 52 00:02:46,680 --> 00:02:51,530 Or if it makes sense at a higher level, we could put that above that, make sense? 53 00:02:51,530 --> 00:02:53,800 Great, now what we were doing? 54 00:02:53,800 --> 00:02:54,450 Oh yeah. 55 00:02:54,450 --> 00:02:56,820 Let's take a peek back over here at the board. 56 00:02:56,820 --> 00:02:58,760 So we still can't complete this one yet, right? 57 00:02:58,760 --> 00:03:01,060 Because as a user, I should know what state I'm in. 58 00:03:01,060 --> 00:03:03,260 If it's focus/break, we have that going on. 59 00:03:03,260 --> 00:03:07,130 We don't have paused yet, so we're kinda blocked on that. 60 00:03:07,130 --> 00:03:08,850 I guess we should start this one. 61 00:03:08,850 --> 00:03:12,750 As a user in a Pomodoro attempt, I should be notified when the attempt completes, so 62 00:03:12,750 --> 00:03:16,600 that I'm aware of what my next step should be, break or focus, okay. 63 00:03:16,600 --> 00:03:18,030 That's cool, we can do that. 64 00:03:18,030 --> 00:03:21,970 And while we're in here, why don't we take a look at this one. 65 00:03:21,970 --> 00:03:24,840 As a user, I should be able to detail what my Pomodoro was about so 66 00:03:24,840 --> 00:03:27,440 I can keep track of what's happened for future planning. 67 00:03:27,440 --> 00:03:29,220 So let's drag that over. 68 00:03:29,220 --> 00:03:30,890 Okay, so we've got three of them. 69 00:03:30,890 --> 00:03:33,120 We better get cranking on some of these. 70 00:03:33,120 --> 00:03:37,620 We aren't actually going to save anything, but let's mock it out. 71 00:03:38,660 --> 00:03:39,310 So, let's flip back. 72 00:03:41,620 --> 00:03:46,000 Okay, so, we want something to happen when the timeline finishes. 73 00:03:46,000 --> 00:03:48,570 You know, when all the pages have gone through. 74 00:03:48,570 --> 00:03:52,400 Well the good news is that an event is fired when the timeline completes. 75 00:03:52,400 --> 00:03:55,930 And it exposes a way for you to register an event handler when it completes. 76 00:03:55,930 --> 00:03:57,180 So let's do that. 77 00:04:01,800 --> 00:04:04,970 And it's called setOnFinished. 78 00:04:04,970 --> 00:04:09,625 And it expects an event handler which means we can pass in a lambda like we have 79 00:04:09,625 --> 00:04:13,460 been, which takes an event and let's make it a multi-line. 80 00:04:13,460 --> 00:04:15,240 I'm gonna do a couple things in here. 81 00:04:15,240 --> 00:04:19,900 So, here is one of those weird cases where a ternary might actually make sense. 82 00:04:19,900 --> 00:04:21,930 Do you remember what ternaries are? 83 00:04:21,930 --> 00:04:25,010 So, it's when you have the option to go between two different things. 84 00:04:25,010 --> 00:04:29,970 So, we want to prepare an attempt, and we want to prepare the next attempt, right? 85 00:04:29,970 --> 00:04:31,580 But how do we know what that is? 86 00:04:31,580 --> 00:04:35,560 So, if we say that we get the current attempt, 87 00:04:35,560 --> 00:04:39,410 we get the kind of attempt that it is. 88 00:04:39,410 --> 00:04:45,970 That's equal to focus, well then the next one we know is break. 89 00:04:49,170 --> 00:04:53,530 [INAUDIBLE] is right over, my typing's bad there. 90 00:04:53,530 --> 00:04:54,205 It's hard to see. 91 00:04:54,205 --> 00:05:00,548 AttemptKind.BREAK, otherwise it's a FOCUS. 92 00:05:04,378 --> 00:05:05,428 Does that make sense? 93 00:05:10,928 --> 00:05:18,280 So it's saying, if the current Kind is FOCUS, then switch it to break. 94 00:05:18,280 --> 00:05:20,660 Otherwise, switch it to focus. 95 00:05:20,660 --> 00:05:21,910 Make sense? 96 00:05:21,910 --> 00:05:24,000 So that should take care of that first ticket that we looked at. 97 00:05:24,000 --> 00:05:24,820 Now the second one. 98 00:05:25,860 --> 00:05:29,320 So we want to save the current attempt. 99 00:05:29,320 --> 00:05:32,110 So we should probably do that before we prepare the attempt right. 100 00:05:32,110 --> 00:05:35,220 So let's come in here and let's make a method. 101 00:05:35,220 --> 00:05:37,610 I feel like we might be calling this a couple more times. 102 00:05:37,610 --> 00:05:41,430 So we're going to say save CurrentAttempt, 103 00:05:41,430 --> 00:05:43,490 it's a method we that haven't declared yet. 104 00:05:43,490 --> 00:05:48,620 So, let's just go ahead and have it build one for us, awesome. 105 00:05:48,620 --> 00:05:53,510 You don't really have anything set up on our actual model to save. 106 00:05:53,510 --> 00:05:56,060 So, let's just make a mock method. 107 00:05:56,060 --> 00:05:57,290 So let's do that. 108 00:05:57,290 --> 00:05:59,440 We'll just have it print out what we're going to save or 109 00:05:59,440 --> 00:06:00,580 what it is that it's saving. 110 00:06:00,580 --> 00:06:04,080 So let's so that. So let's say mCurrentAttempt.save. 111 00:06:04,080 --> 00:06:07,080 And of course, that method doesn't exist. 112 00:06:07,080 --> 00:06:10,000 Let's go create it, okay. 113 00:06:10,000 --> 00:06:16,240 So here let's print out Saving, cuz we don't have a database set up and 114 00:06:16,240 --> 00:06:19,320 it's kinda out of the scope of where we're at here. 115 00:06:19,320 --> 00:06:22,210 But it would save if this method existed. 116 00:06:22,210 --> 00:06:26,340 And this is typically what it is called on a model as you save it up to the database. 117 00:06:26,340 --> 00:06:29,160 So we wanna print out the current object. 118 00:06:29,160 --> 00:06:32,080 And the way that you do that is with the keyword this, right? 119 00:06:32,080 --> 00:06:37,600 That's referring to this instance, make sense? 120 00:06:37,600 --> 00:06:38,170 Oh yeah, you know what? 121 00:06:38,170 --> 00:06:40,690 That reminds me we should generate one of those toStrings methods and 122 00:06:41,980 --> 00:06:46,830 this IDE will do it for us so we're gonna generate to string, and 123 00:06:46,830 --> 00:06:48,300 yeah all that stuff, let's generate it all. 124 00:06:50,110 --> 00:06:54,760 Cool, okay, now one thing that we need to remember 125 00:06:54,760 --> 00:06:57,800 is that we need to get the value out of that message field. 126 00:06:57,800 --> 00:07:00,320 Do you remember that we had the message field at the bottom? 127 00:07:00,320 --> 00:07:01,710 We could bind to that right. 128 00:07:01,710 --> 00:07:02,660 So we could bind to it and 129 00:07:02,660 --> 00:07:06,290 say every time that that field changes, update the message. 130 00:07:06,290 --> 00:07:07,940 But that seems like a little overkill. 131 00:07:07,940 --> 00:07:11,890 Think if we just have this save current attempt method and write right before we 132 00:07:11,890 --> 00:07:18,680 save it, we go and get that value if we say mCurrentAttempt.setMessage. 133 00:07:18,680 --> 00:07:22,290 You know what, why don't you go ahead and pause me? 134 00:07:22,290 --> 00:07:25,860 I want you to pull the value out of the message field. 135 00:07:25,860 --> 00:07:28,370 Now, the message field isn't over here yet in the controller. 136 00:07:28,370 --> 00:07:30,720 How do we get that over here, can you figure that out? 137 00:07:30,720 --> 00:07:31,600 Pause me and come back. 138 00:07:33,440 --> 00:07:35,170 Okay, did you get it? 139 00:07:35,170 --> 00:07:42,490 Cool, so over at home.xml if we look down here, this text area has an ID of message. 140 00:07:42,490 --> 00:07:43,600 So let's flip back over here. 141 00:07:46,140 --> 00:07:53,140 We will say @fxml that is a private text area. 142 00:07:53,140 --> 00:07:57,750 Be very careful not to get the java awt It's a common, common error, so 143 00:07:57,750 --> 00:08:02,620 this TextArea here is the one that we want, and it is called message;. 144 00:08:02,620 --> 00:08:05,100 Cool, so then if we come back to where we were, sorry, 145 00:08:05,100 --> 00:08:10,230 I am scrolling all over the place, save message, 146 00:08:10,230 --> 00:08:16,970 we wanna get message.getText cool, right? 147 00:08:16,970 --> 00:08:18,390 Let's see how we did. 148 00:08:18,390 --> 00:08:20,320 Two tickets, let's see if we did two at once. 149 00:08:20,320 --> 00:08:22,340 So, oh you know what though? 150 00:08:22,340 --> 00:08:24,100 We don't have the play and the pause button that's wound up. 151 00:08:25,390 --> 00:08:27,200 I know, what if we change the temp, 152 00:08:27,200 --> 00:08:31,340 temporarily we change the time that was required on the first focus. 153 00:08:31,340 --> 00:08:34,040 Then it would just switch over to break and we'd make sure that we did it right. 154 00:08:34,040 --> 00:08:37,380 So, let's go into our AttemptKind here. 155 00:08:37,380 --> 00:08:39,480 And we'll go into our definition of AttemptKind. 156 00:08:40,500 --> 00:08:43,620 And let's change the Focus time just temporarily. 157 00:08:44,680 --> 00:08:48,410 Change that to three so we'll just count down from three, all right. 158 00:08:48,410 --> 00:08:50,550 Let's run it and see what happens. 159 00:08:51,590 --> 00:08:53,310 So, we bound this button. 160 00:08:53,310 --> 00:08:54,070 This restart button. 161 00:08:54,070 --> 00:08:54,928 So it will go to three. 162 00:08:54,928 --> 00:08:58,370 Two, one, boom. 163 00:08:58,370 --> 00:08:59,730 Oh cool, and look. 164 00:08:59,730 --> 00:09:02,936 Not only did it switch to break, but it also saved and, 165 00:09:02,936 --> 00:09:06,508 it doesn't have the message but let's see if we can make it, 166 00:09:09,548 --> 00:09:13,630 Have the message, because we didn't have one there awesome. 167 00:09:13,630 --> 00:09:17,720 It pulled the message and the remaining seconds is zero. 168 00:09:17,720 --> 00:09:21,650 So we can actually probably use that save in a different way, right? 169 00:09:21,650 --> 00:09:24,090 Whenever that restart was called, we could do it. 170 00:09:25,090 --> 00:09:25,760 Let's think about that. 171 00:09:26,900 --> 00:09:27,700 Awesome job. 172 00:09:27,700 --> 00:09:30,740 I hope you enjoyed the concept of event listeners. 173 00:09:30,740 --> 00:09:33,150 They are very prominent in most UI code 174 00:09:33,150 --> 00:09:36,560 as it lets you hook into different life cycles of objects. 175 00:09:36,560 --> 00:09:40,160 So we pretty much got the visual stuff in place to let the user know that 176 00:09:40,160 --> 00:09:41,710 things are changing. 177 00:09:41,710 --> 00:09:46,600 But if focus time is working correctly, we should make sure that they really know. 178 00:09:46,600 --> 00:09:48,610 We wanna snap them out of it. 179 00:09:48,610 --> 00:09:51,540 Now JavaFX is super media friendly so 180 00:09:51,540 --> 00:09:54,130 why don't play an appropriate sound to get their attention?