Twelve: Add disc number to audio model

Change-Id: I9b4934ced86a4e0043b3609b3840bb35aa7b49b6
diff --git a/app/src/main/java/org/lineageos/twelve/datasources/LocalDataSource.kt b/app/src/main/java/org/lineageos/twelve/datasources/LocalDataSource.kt
index 47369ff..1077384 100644
--- a/app/src/main/java/org/lineageos/twelve/datasources/LocalDataSource.kt
+++ b/app/src/main/java/org/lineageos/twelve/datasources/LocalDataSource.kt
@@ -158,6 +158,13 @@
             else -> Audio.Type.MUSIC
         }
 
+        val (discNumber, discTrack) = track.takeUnless { it == 0 }?.let {
+            when (track > 1000) {
+                true -> track / 1000 to track % 1000
+                false -> 1 to track
+            }
+        } ?: (null to null)
+
         Audio(
             uri,
             uri,
@@ -169,7 +176,8 @@
             artist,
             albumUri,
             album,
-            track,
+            discNumber,
+            discTrack,
             genreUri,
             genre,
             year.takeIf { it != 0 },
diff --git a/app/src/main/java/org/lineageos/twelve/datasources/SubsonicDataSource.kt b/app/src/main/java/org/lineageos/twelve/datasources/SubsonicDataSource.kt
index b406700..d2d38ee 100644
--- a/app/src/main/java/org/lineageos/twelve/datasources/SubsonicDataSource.kt
+++ b/app/src/main/java/org/lineageos/twelve/datasources/SubsonicDataSource.kt
@@ -241,7 +241,8 @@
         artistName = artist ?: "",
         albumUri = albumId?.let { getAlbumUri(it) } ?: Uri.EMPTY,
         albumTitle = album ?: "",
-        albumTrack = track ?: 0,
+        discNumber = discNumber,
+        trackNumber = track,
         genreUri = genre?.let { getGenreUri(it) },
         genreName = genre,
         year = year,
diff --git a/app/src/main/java/org/lineageos/twelve/ext/MediaItem.kt b/app/src/main/java/org/lineageos/twelve/ext/MediaItem.kt
index ce8276a..052ee57 100644
--- a/app/src/main/java/org/lineageos/twelve/ext/MediaItem.kt
+++ b/app/src/main/java/org/lineageos/twelve/ext/MediaItem.kt
@@ -23,6 +23,8 @@
     artworkData: ByteArray? = null,
     artworkType: @MediaMetadata.PictureType Int? = null,
     artworkUri: Uri? = null,
+    discNumber: Int? = null,
+    trackNumber: Int? = null,
 ): MediaItem {
     val metadata =
         MediaMetadata.Builder()
@@ -35,6 +37,8 @@
             .setArtworkData(artworkData, artworkType)
             .setArtworkUri(artworkUri)
             .setMediaType(mediaType)
+            .setDiscNumber(discNumber)
+            .setTrackNumber(trackNumber)
             .build()
 
     return MediaItem.Builder()
diff --git a/app/src/main/java/org/lineageos/twelve/models/Audio.kt b/app/src/main/java/org/lineageos/twelve/models/Audio.kt
index 092c129..f52f9c6 100644
--- a/app/src/main/java/org/lineageos/twelve/models/Audio.kt
+++ b/app/src/main/java/org/lineageos/twelve/models/Audio.kt
@@ -24,7 +24,8 @@
  * @param artistName The name of the artist of the audio
  * @param albumUri The URI of the album of the audio
  * @param albumTitle The title of the album of the audio
- * @param albumTrack The track number of the audio in the album
+ * @param discNumber The number of the disc where the album is present, starts from 1
+ * @param trackNumber The track number of the audio within the disc, starts from 1
  * @param genreUri The URI of the genre of the audio
  * @param genreName The name of the genre of the audio
  * @param year The year of release of the audio
@@ -40,7 +41,8 @@
     val artistName: String,
     val albumUri: Uri,
     val albumTitle: String,
-    val albumTrack: Int,
+    val discNumber: Int?,
+    val trackNumber: Int?,
     val genreUri: Uri?,
     val genreName: String?,
     val year: Int?,
@@ -79,7 +81,8 @@
         Audio::artistName,
         Audio::albumUri,
         Audio::albumTitle,
-        Audio::albumTrack,
+        Audio::discNumber,
+        Audio::trackNumber,
         Audio::genreUri,
         Audio::genreName,
         Audio::year,
@@ -96,6 +99,8 @@
         genre = genreName,
         sourceUri = playbackUri,
         mimeType = mimeType,
+        discNumber = discNumber,
+        trackNumber = trackNumber,
     )
 
     companion object {