music: add disc number indexing

Change the indexer to parse out the disc number field from
AudioColumns.TRACK.

On newer versions, I hope to further modify the loader to use
the API 30+ CD_TRACK_NUMBER field, as it is more versatile than
TRACK.
This commit is contained in:
OxygenCobalt 2022-05-18 20:03:45 -06:00
parent 6f2a0d66c6
commit 04f254f91b
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
3 changed files with 16 additions and 2 deletions

View file

@ -139,6 +139,7 @@ class DetailViewModel : ViewModel() {
val data = mutableListOf<Item>(album)
data.add(SortHeader(id = -2, R.string.lbl_songs))
data.add(DiscHeader(id = -3, 1))
data.addAll(albumSort.album(album))
_albumData.value = data
}
}

View file

@ -192,8 +192,18 @@ object Indexer {
// and T is the track. This is dumb and insane and forces me to mangle track
// numbers above 1000, but there is nothing we can do that won't break the app
// below API 30.
// TODO: Disk number support?
val track = cursor.getIntOrNull(trackIndex)?.mod(1000)
var track: Int? = null
var disc: Int? = null
val rawTrack = cursor.getIntOrNull(trackIndex)
if (rawTrack != null) {
track = rawTrack % 1000
disc = rawTrack / 1000
if (disc == 0) {
// A disc number of 0 means that there is no disc.
disc = null
}
}
val duration = cursor.getLong(durationIndex)
val year = cursor.getIntOrNull(yearIndex)
@ -225,6 +235,7 @@ object Indexer {
fileName,
duration,
track,
disc,
id,
year,
album,

View file

@ -68,6 +68,8 @@ data class Song(
val duration: Long,
/** The track number of this song, null if there isn't any. */
val track: Int?,
/** The disc number of this song, null if there isn't any. */
val disc: Int?,
/** Internal field. Do not use. */
val _mediaStoreId: Long,
/** Internal field. Do not use. */