1
00:00:05,200 --> 00:00:07,400
Welcome back. Did you find the bug?

2
00:00:07,700 --> 00:00:09,700
More importantly, have you fixed it?

3
00:00:10,500 --> 00:00:13,400
I'll start by demonstrating the problem. Run the app,

4
00:00:13,400 --> 00:00:14,900
and switch to landscape mode.

5
00:00:20,800 --> 00:00:22,400
Then edit a task,

6
00:00:24,600 --> 00:00:25,800
then swipe it.

7
00:00:27,910 --> 00:00:30,110
We don't get the confirmation dialog.

8
00:00:30,610 --> 00:00:33,970
That's because we've added code to only proceed with the deletion

9
00:00:34,370 --> 00:00:37,030
if the task isn't also being edited.

10
00:00:37,730 --> 00:00:39,330
We get the Toast message instead.

11
00:00:39,990 --> 00:00:44,350
So nothing gets deleted, and there's no dialog asking for confirmation.

12
00:00:45,010 --> 00:00:47,610
But the task still disappears from the list.

13
00:00:48,410 --> 00:00:51,910
When we're using a button, the OnDeleteClick function

14
00:00:51,910 --> 00:00:54,410
was a good place to test the task ID

15
00:00:54,410 --> 00:00:57,410
to make sure we weren't deleting the task that was being edited.

16
00:00:58,110 --> 00:01:01,110
Now that we're swiping, we've got a bit more work to do.

17
00:01:01,610 --> 00:01:05,910
Swiping removes the tasks from the display, so we need to put it back.

18
00:01:06,910 --> 00:01:09,910
I'll cut that test out of OnDeleteClick.

19
00:01:16,810 --> 00:01:20,170
Use code reformat code to tidy up the formatting.

20
00:01:23,830 --> 00:01:27,930
Next, paste the code into the OnSwiped function

21
00:01:28,290 --> 00:01:31,090
just before the call to OnDeleteClick.

22
00:01:47,090 --> 00:01:48,890
That's put the test in the right place.

23
00:01:49,440 --> 00:01:51,940
We only call OnDeleteClick

24
00:01:51,940 --> 00:01:55,640
if the task to be deleted isn't also being edited.

25
00:01:56,300 --> 00:01:58,900
To restore the task in the RecyclerViewList,

26
00:01:58,900 --> 00:02:02,600
we call NotifyItem Changed on the adapter.

27
00:02:19,400 --> 00:02:23,400
That's the same as we did when the user cancels the deletion from the dialog.

28
00:02:23,760 --> 00:02:26,360
I'd like to call NotifyItemChanged

29
00:02:26,360 --> 00:02:30,760
before showing the toast message but it also works if you put it afterwards.

30
00:02:31,420 --> 00:02:34,220
Okay. I'll run the app and test what happens now.

31
00:02:44,920 --> 00:02:48,580
The animation still runs but then the item reappears

32
00:02:49,180 --> 00:02:50,680
and we get the toast message.

33
00:02:51,560 --> 00:02:53,260
That's the challenge completed,

34
00:02:53,260 --> 00:02:55,960
and now we've implemented delete by swiping.

35
00:02:57,160 --> 00:02:59,960
We're using a long tap to start timing a task.

36
00:03:00,320 --> 00:03:02,760
So if you wanted to remove the edit button

37
00:03:02,760 --> 00:03:07,060
and allow tapping a task to edit it, then that could be a good exercise.

38
00:03:07,610 --> 00:03:11,710
I won't be doing that on video, but you should find it's an easy thing to implement.

39
00:03:12,700 --> 00:03:15,300
Apart from deleting the button from the layout,

40
00:03:15,600 --> 00:03:19,150
the only changes will be in the adapter. In fact,

41
00:03:19,150 --> 00:03:21,510
only one word needs to be changed.

42
00:03:22,110 --> 00:03:26,510
Any other changes are only necessary because the button's been deleted from the layout.

43
00:03:27,310 --> 00:03:30,910
Before I finish this video though, there's one last change to make.

44
00:03:32,070 --> 00:03:35,070
It's a very easy change to forget but it's important.

45
00:03:35,950 --> 00:03:37,950
Remember when we first run the app,

46
00:03:38,200 --> 00:03:40,500
we display some instructions on the screen.

47
00:03:41,160 --> 00:03:43,460
Those instructions are now incorrect,

48
00:03:43,760 --> 00:03:46,660
they mention a delete button and we've removed it.

49
00:03:47,650 --> 00:03:51,310
Go into res values string.xml

50
00:04:02,710 --> 00:04:05,310
and find the instructions tag.

51
00:04:10,210 --> 00:04:14,510
I'll edit that to more accurately reflect how the program now works.

52
00:05:12,810 --> 00:05:16,110
To test the message, you should delete all your tasks

53
00:05:16,110 --> 00:05:18,410
and make sure you get the correct instructions

54
00:05:18,960 --> 00:05:23,360
or you could run the app on a new emulator if you don't want to type all the tasks in again.

55
00:05:24,260 --> 00:05:27,820
In the next video, we'll look at the other change we wanted to make.

56
00:05:28,480 --> 00:05:32,920
We need to deal with deleting a task that's being timed. I'll see you over there.

