1
00:00:05,200 --> 00:00:08,900
There's just one final thing I want to mention before we finish the app.

2
00:00:09,890 --> 00:00:13,550
In the emulator, I'll enter a new task with the name

3
00:00:13,550 --> 00:00:17,850
aaa and the description aaaa,

4
00:00:26,350 --> 00:00:27,250
then save.

5
00:00:28,240 --> 00:00:33,230
The task aaa appears below most of the other tasks in the list,

6
00:00:33,630 --> 00:00:35,530
allowing for the sort order column.

7
00:00:35,930 --> 00:00:38,730
So it appears after task 5.

8
00:00:39,130 --> 00:00:41,530
This may not be what users expect.

9
00:00:42,530 --> 00:00:45,330
The reason is that our sort is case-sensitive.

10
00:00:45,880 --> 00:00:50,380
In most collations lowercase letters sort after uppercase.

11
00:00:51,480 --> 00:00:55,780
But that's not true of some character sets such as Cyrillic, for example.

12
00:00:56,440 --> 00:00:59,940
So if you're using Cyrillic, then you'll have to do a lot more research.

13
00:01:00,840 --> 00:01:04,340
I'm assuming you're using a character set that sorts lowercase

14
00:01:04,340 --> 00:01:05,630
after uppercase.

15
00:01:06,510 --> 00:01:09,610
The solution to this problem is to add the SQL

16
00:01:09,610 --> 00:01:11,610
collate no case clause

17
00:01:12,110 --> 00:01:14,910
that we saw in the SQL tutorial part in this section.

18
00:01:15,570 --> 00:01:19,560
I'll call up the documentation for the ContentProvider's Query method

19
00:01:19,810 --> 00:01:23,410
in TaskTimerViewModel's load tasks section.

20
00:01:30,310 --> 00:01:33,910
The description of the sort order parameter is the useful one.

21
00:01:34,460 --> 00:01:38,460
The parameter is formatted as a SQL order by clause,

22
00:01:38,860 --> 00:01:40,060
excluding the order by.

23
00:01:40,940 --> 00:01:45,140
So we can add the no case collation to the sort order string

24
00:01:45,140 --> 00:01:46,640
on line 91.

25
00:02:00,840 --> 00:02:04,040
It's important to put a space before the word collate.

26
00:02:04,040 --> 00:02:06,240
We'll edit the comment above so it matches.

27
00:02:12,940 --> 00:02:16,940
I put the order by in angle brackets because we don't include that

28
00:02:17,340 --> 00:02:19,840
but it's useful to see the complete SQL clause.

29
00:02:20,940 --> 00:02:23,140
I'll stop the app on the emulator

30
00:02:25,140 --> 00:02:28,340
because android studio's InstantRun feature

31
00:02:28,340 --> 00:02:31,640
can sometimes work against us when doing things like this.

32
00:02:32,240 --> 00:02:34,440
It tries to avoid restarting the app,

33
00:02:34,800 --> 00:02:38,700
which here would mean that the view model doesn't re-query the database.

34
00:02:39,480 --> 00:02:42,280
So if you don't get the result you expect when running your app,

35
00:02:42,280 --> 00:02:43,780
make sure to stop it first.

36
00:02:44,380 --> 00:02:45,880
When I run the app now,

37
00:02:49,480 --> 00:02:52,580
the aaa task appears at the start of the list

38
00:02:52,880 --> 00:02:54,280
where a user would expect it.

39
00:02:54,780 --> 00:02:59,380
Google have added two extra collation sequences to SQLite on android,

40
00:02:59,680 --> 00:03:02,080
unicode and localized

41
00:03:02,850 --> 00:03:06,150
If your character set isn't handled correctly by no case,

42
00:03:06,550 --> 00:03:08,750
then you may want to try one of those instead.

43
00:03:09,350 --> 00:03:11,350
There's documentation available here.

44
00:03:13,550 --> 00:03:17,950
If you want to use those collations, remember they're specific to android.

45
00:03:18,390 --> 00:03:23,180
The unicode and localized collations won't work when you use the sqlite3

46
00:03:23,180 --> 00:03:25,180
program on your computer.

47
00:03:25,980 --> 00:03:29,340
You'll need to test your SQL in a shell on your emulator.

48
00:03:29,940 --> 00:03:33,930
All right. That's the app finished, and the end of this section.

49
00:03:34,730 --> 00:03:37,730
In the next section, we'll look at what's involved

50
00:03:37,730 --> 00:03:40,730
when you want to deploy an app to the Google Play Store.

51
00:03:41,230 --> 00:03:42,230
I'll see you there.

