Skip to content

Commit

Permalink
Twelve: Don't show disk # header if single disk
Browse files Browse the repository at this point in the history
Change-Id: I0d967c3b49277bc4a31cc9036830265d33c46358
  • Loading branch information
luca020400 authored and SebaUbuntu committed Nov 3, 2024
1 parent 431dd45 commit c7f2526
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<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(
Expand Down

0 comments on commit c7f2526

Please sign in to comment.