Skip to content

Commit c7f2526

Browse files
luca020400SebaUbuntu
authored andcommitted
Twelve: Don't show disk # header if single disk
Change-Id: I0d967c3b49277bc4a31cc9036830265d33c46358
1 parent 431dd45 commit c7f2526

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

app/src/main/java/org/lineageos/twelve/datasources/LocalDataSource.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ class LocalDataSource(context: Context, private val database: TwelveDatabase) :
161161
val (discNumber, discTrack) = track.takeUnless { it == 0 }?.let {
162162
when (track > 1000) {
163163
true -> track / 1000 to track % 1000
164-
false -> 1 to track
164+
false -> null to track
165165
}
166166
} ?: (null to null)
167167

app/src/main/java/org/lineageos/twelve/viewmodels/AlbumViewModel.kt

+11-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import kotlinx.coroutines.Dispatchers
1212
import kotlinx.coroutines.ExperimentalCoroutinesApi
1313
import kotlinx.coroutines.flow.MutableStateFlow
1414
import kotlinx.coroutines.flow.SharingStarted
15-
import kotlinx.coroutines.flow.filter
1615
import kotlinx.coroutines.flow.filterNotNull
1716
import kotlinx.coroutines.flow.flatMapLatest
1817
import kotlinx.coroutines.flow.flowOn
@@ -72,12 +71,20 @@ class AlbumViewModel(application: Application) : TwelveViewModel(application) {
7271

7372
is RequestStatus.Success -> {
7473
val discToTracks = it.data.second.groupBy { audio ->
75-
audio.discNumber ?: 1
74+
audio.discNumber
75+
}
76+
77+
val hideHeaders = with(discToTracks.keys) {
78+
size == 1 && firstOrNull() == 1
7679
}
7780

7881
mutableListOf<AlbumContent>().apply {
79-
discToTracks.keys.sorted().forEach { discNumber ->
80-
add(AlbumContent.DiscHeader(discNumber))
82+
discToTracks.keys.sortedBy { disc ->
83+
disc ?: 0
84+
}.forEach { discNumber ->
85+
discNumber?.takeUnless { hideHeaders }?.let { i ->
86+
add(AlbumContent.DiscHeader(i))
87+
}
8188

8289
discToTracks[discNumber]?.let { tracks ->
8390
addAll(

0 commit comments

Comments
 (0)