1 00:00:03,820 --> 00:00:11,360 G'day everyone. The app's now saving timing data, but it's not very user friendly. 2 00:00:11,360 --> 00:00:16,440 We need to update the display, when the user starts timing a task. 3 00:00:16,440 --> 00:00:21,259 The Timing data is being saved in our TaskTimerViewModel, and we want to display 4 00:00:21,259 --> 00:00:27,110 some information in MainActivity. That sounds like the job of another LiveData 5 00:00:27,110 --> 00:00:33,130 object, that MainActivity can observe. I'll create the LiveData objects in 6 00:00:33,130 --> 00:00:41,540 TaskTimerViewModel, after the database cursor, LiveData. 7 00:00:46,060 --> 00:00:54,240 We expose a LiveData object called Timing, and update it via the mutable LiveData object called taskTiming. 8 00:00:54,240 --> 00:00:59,040 Refer back to the videos in section 11, if you're not sure how this works. 9 00:00:59,040 --> 00:01:06,120 The code to update timing goes at the end of our timeTask function. 10 00:01:13,300 --> 00:01:17,820 We have to check that something is being timed, because this function gets called 11 00:01:17,820 --> 00:01:23,450 to stop timing, as well as to start it. Okay, MainActivity has to observe this 12 00:01:23,450 --> 00:01:28,490 LiveData object, and update the display when it changes. We start by declaring 13 00:01:28,490 --> 00:01:31,600 the view model, 14 00:01:52,439 --> 00:01:59,960 then we can observe it to update the display. I'll set that up in onCreate. 15 00:02:14,780 --> 00:02:19,900 You want android x dot lifecycle dot observer, when prompted for the input. 16 00:02:19,900 --> 00:02:25,660 Run the app, and the task being timed is now shown at the top of the display. 17 00:02:25,660 --> 00:02:31,780 When I stop typing a task, the message disappears. We can do better 18 00:02:31,790 --> 00:02:36,610 by displaying a message, instead of just a task name. 19 00:02:39,340 --> 00:02:45,040 Split the function here, and add the following code. 20 00:02:55,459 --> 00:03:00,500 I haven't added the task name to the string, Currently timing, because it's 21 00:03:00,500 --> 00:03:04,969 easier to extract the string resources without it. Remember, the option doesn't 22 00:03:04,969 --> 00:03:20,800 appear if you include the variable. I'll call the string resource timing underscore message. 23 00:03:22,240 --> 00:03:26,380 We then need to add a value to the string. We can add that in 24 00:03:26,389 --> 00:03:36,400 this dialog, so that the text becomes Currently timing space % $1 s. We haven't 25 00:03:36,400 --> 00:03:42,900 done that before, but it can be easier than going into the strings dot XML file. 26 00:03:42,900 --> 00:03:49,240 I'll open that anyway, just so that we can check. 27 00:03:49,240 --> 00:03:56,860 While I'm here, the message No tasks selected may be better as No task being timed. 28 00:03:56,870 --> 00:04:00,310 I'll change that on line 9. 29 00:04:06,210 --> 00:04:11,300 Now we can provide the task name in MainActivity. 30 00:04:17,459 --> 00:04:21,440 Alright, let's see what that looks like. 31 00:04:24,830 --> 00:04:30,330 When I long-tap a task, we get an informative message. As I long-tap 32 00:04:30,330 --> 00:04:38,580 different tasks, the message changes. When I long-tap the same task again, we have 33 00:04:38,580 --> 00:04:44,039 the No task being timed message. That wasn't a lot of extra work, and it makes 34 00:04:44,039 --> 00:04:49,050 the app much more user friendly. In the next video, we'll look at what happens if 35 00:04:49,050 --> 00:04:55,220 the app is closed down, while we're timing a task. See you in the next one.