From c7f2526fc9d64deecfe02f573b695c14e1e4d642 Mon Sep 17 00:00:00 2001 From: Luca Stefani Date: Fri, 1 Nov 2024 18:47:22 +0100 Subject: [PATCH] Twelve: Don't show disk # header if single disk Change-Id: I0d967c3b49277bc4a31cc9036830265d33c46358 --- .../twelve/datasources/LocalDataSource.kt | 2 +- .../lineageos/twelve/viewmodels/AlbumViewModel.kt | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) 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 10773842..c5878042 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 @@ class LocalDataSource(context: Context, private val database: TwelveDatabase) : 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 1a710369..7e28fbc1 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.Dispatchers 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 @@ class AlbumViewModel(application: Application) : TwelveViewModel(application) { 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().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(