Eleven: Fix sorting by track number in albums
* We have to cast the track number column value to an int
* This makes track numbers sort numerically (i.e. 1, 2, ..., 10, ...)
rather than lexically (i.e. 1, 10, ..., 2, ...) in the album view
* This doesn't seem to affect all albums for whatever reason:
albums with m4a tracks seem to be sorted wrong whereas ones
with opus tracks are seemingly fine even without this change
* The root cause here is that the TRACK column seems to be a string,
but not one that is padded to a fixed length to allow lexical sorting.
Note that this appears to be contrary to the documentation at:
https://developer.android.com/reference/android/provider/MediaStore.Audio.AudioColumns#TRACK
which says that the column is stored with FIELD_TYPE_INTEGER
Change-Id: I0bb1ce7a45b42ba58e7aab26d17572f9a71b6ff8
diff --git a/src/org/lineageos/eleven/utils/SortOrder.java b/src/org/lineageos/eleven/utils/SortOrder.java
index 995f305..a57326c 100644
--- a/src/org/lineageos/eleven/utils/SortOrder.java
+++ b/src/org/lineageos/eleven/utils/SortOrder.java
@@ -100,7 +100,7 @@
*/
public interface AlbumSongSortOrder {
/* Album song sort order track list */
- String SONG_TRACK_LIST = MediaStore.Audio.Media.TRACK + ", "
- + MediaStore.Audio.Media.DEFAULT_SORT_ORDER;
+ String SONG_TRACK_LIST = String.format("CAST(%s as int), %s",
+ MediaStore.Audio.Media.TRACK, MediaStore.Audio.Media.DEFAULT_SORT_ORDER);
}
}