1
00:00:04,300 --> 00:00:06,500
Welcome back. Okay.

2
00:00:07,000 --> 00:00:11,000
We should be able to run the app and delete old timing records.

3
00:00:11,660 --> 00:00:15,260
Before you do that, to test that deletion works properly,

4
00:00:15,620 --> 00:00:18,220
I suggest pulling back a copy of the database.

5
00:00:18,820 --> 00:00:21,120
You can then run queries on the copy

6
00:00:21,120 --> 00:00:23,820
to check which record you'd expect to be deleted.

7
00:00:24,420 --> 00:00:27,780
It's important to make sure your code is only deleting

8
00:00:27,780 --> 00:00:29,280
what the user asked for.

9
00:00:29,780 --> 00:00:33,580
I won't do it on the video, it's just more of the things we've already covered

10
00:00:33,940 --> 00:00:35,840
and it would make the video too long.

11
00:00:35,840 --> 00:00:38,640
But make sure you do test your code carefully

12
00:00:39,040 --> 00:00:42,240
and be sure it's really doing what you expect it to do.

13
00:00:42,900 --> 00:00:46,000
Okay. Run the app and go into reports.

14
00:00:48,400 --> 00:00:51,960
When I created the code to generate the random timings data,

15
00:00:52,460 --> 00:00:56,450
I set the years to 2018 and 2019.

16
00:00:57,110 --> 00:01:00,110
That means there should be a load of records in 2018.

17
00:01:01,010 --> 00:01:05,910
Changing the year in the NewDatePicker's a bit less obvious than the old one,

18
00:01:06,270 --> 00:01:08,370
but you can tap the date at the top to change it.

19
00:01:15,270 --> 00:01:16,870
I'll select 2018,

20
00:01:18,170 --> 00:01:21,470
then change the date to the 29th of March,

21
00:01:28,370 --> 00:01:29,670
then tap okay.

22
00:01:30,330 --> 00:01:31,830
When displaying a week,

23
00:01:31,830 --> 00:01:34,830
we should see records from the 25th of March,

24
00:01:35,190 --> 00:01:38,490
which was a Sunday to the 31st of March,

25
00:01:38,490 --> 00:01:39,990
the following Saturday.

26
00:01:40,650 --> 00:01:43,150
If your emulator is set to a different locale,

27
00:01:43,150 --> 00:01:45,450
your week may start on Monday instead.

28
00:01:46,050 --> 00:01:50,550
I'll choose the 29th of March as the date to delete up to.

29
00:01:51,250 --> 00:01:53,450
If you don't have any timings for that date,

30
00:01:53,810 --> 00:01:55,910
choose a date that does have records.

31
00:01:59,910 --> 00:02:03,510
From the overflow menu, the three dots on the right,

32
00:02:03,870 --> 00:02:06,070
choose delete old timings.

33
00:02:10,070 --> 00:02:11,570
That launches the DatePicker.

34
00:02:11,970 --> 00:02:14,640
And notice, the date's automatically set

35
00:02:14,640 --> 00:02:17,240
to the 29th of March 2018.

36
00:02:17,640 --> 00:02:20,940
We made sure to preserve the date that the user last selected

37
00:02:21,300 --> 00:02:23,400
so that things behave as they'd expect.

38
00:02:23,800 --> 00:02:26,900
Tap okay and we get the confirmation dialog.

39
00:02:30,500 --> 00:02:32,490
I'll test cancel first.

40
00:02:35,290 --> 00:02:37,790
Our records are still there so that's good.

41
00:02:38,150 --> 00:02:42,510
Just to be sure, tap the 1 icon to display a single day,

42
00:02:43,720 --> 00:02:46,220
then tap the 7 to get back to a week.

43
00:02:47,020 --> 00:02:49,520
The database is re-queried each time,

44
00:02:49,520 --> 00:02:52,120
so we know the records are still in the database.

45
00:02:52,920 --> 00:02:55,420
Tap delete old timings option again

46
00:02:59,420 --> 00:03:01,020
and tap okay again.

47
00:03:02,820 --> 00:03:05,420
This time, I'll confirm the deletion.

48
00:03:06,820 --> 00:03:10,370
All the records before the 29th of March 2018

49
00:03:10,370 --> 00:03:11,870
should have been deleted.

50
00:03:14,650 --> 00:03:18,250
Records for the 29th of March should still be present.

51
00:03:18,550 --> 00:03:22,750
We've told the user that they're deleting up to the date they choose,

52
00:03:22,750 --> 00:03:23,740
not including it.

53
00:03:24,400 --> 00:03:26,400
The display hasn't updated though,

54
00:03:26,400 --> 00:03:28,760
and we can still see the same records

55
00:03:28,760 --> 00:03:33,260
until I tap the one button then the 7 to re-query the database.

56
00:03:34,760 --> 00:03:37,360
Filter the report to use an earlier date,

57
00:03:37,660 --> 00:03:40,020
and there shouldn't be any records displayed.

58
00:03:47,020 --> 00:03:50,620
Deletion is working but the report isn't getting updated.

59
00:03:50,620 --> 00:03:54,120
Compare the task time of ViewModel class with this one

60
00:03:54,120 --> 00:03:58,420
to work out what we haven't done in this DurationsViewModel class.

61
00:03:59,220 --> 00:04:02,520
We'll fix the problem in the next video. See you there.

