Twelve: Don't show disk # header if single disk
Change-Id: I0d967c3b49277bc4a31cc9036830265d33c46358
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 1077384..c587804 100644
--- a/app/src/main/java/org/lineageos/twelve/datasources/LocalDataSource.kt
+++ b/app/src/main/java/org/lineageos/twelve/datasources/LocalDataSource.kt
@@ -161,7 +161,7 @@
val (discNumber, discTrack) = track.takeUnless { it == 0 }?.let {
when (track > 1000) {
true -> track / 1000 to track % 1000
- false -> 1 to track
+ false -> null to track
}
} ?: (null to null)
diff --git a/app/src/main/java/org/lineageos/twelve/viewmodels/AlbumViewModel.kt b/app/src/main/java/org/lineageos/twelve/viewmodels/AlbumViewModel.kt
index 1a71036..7e28fbc 100644
--- a/app/src/main/java/org/lineageos/twelve/viewmodels/AlbumViewModel.kt
+++ b/app/src/main/java/org/lineageos/twelve/viewmodels/AlbumViewModel.kt
@@ -12,7 +12,6 @@
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
-import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flowOn
@@ -72,12 +71,20 @@
is RequestStatus.Success -> {
val discToTracks = it.data.second.groupBy { audio ->
- audio.discNumber ?: 1
+ audio.discNumber
+ }
+
+ val hideHeaders = with(discToTracks.keys) {
+ size == 1 && firstOrNull() == 1
}
mutableListOf<AlbumContent>().apply {
- discToTracks.keys.sorted().forEach { discNumber ->
- add(AlbumContent.DiscHeader(discNumber))
+ discToTracks.keys.sortedBy { disc ->
+ disc ?: 0
+ }.forEach { discNumber ->
+ discNumber?.takeUnless { hideHeaders }?.let { i ->
+ add(AlbumContent.DiscHeader(i))
+ }
discToTracks[discNumber]?.let { tracks ->
addAll(