From 0528923f5dcceeaf6f0fe2fd4113f6e66fcf39c1 Mon Sep 17 00:00:00 2001 From: sevonj <100710152+sevonj@users.noreply.github.com> Date: Tue, 19 Nov 2024 13:36:34 +0200 Subject: [PATCH 1/2] Feat: Album year + sorting --- .../java/io/github/zyrouge/symphony/services/groove/Album.kt | 1 + .../symphony/services/groove/repositories/AlbumRepository.kt | 3 +++ .../java/io/github/zyrouge/symphony/ui/components/AlbumGrid.kt | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/github/zyrouge/symphony/services/groove/Album.kt b/app/src/main/java/io/github/zyrouge/symphony/services/groove/Album.kt index 86a4d1ae..5d0c973c 100644 --- a/app/src/main/java/io/github/zyrouge/symphony/services/groove/Album.kt +++ b/app/src/main/java/io/github/zyrouge/symphony/services/groove/Album.kt @@ -8,6 +8,7 @@ data class Album( val id: String, val name: String, val artists: MutableSet, + val year: Int?, var numberOfTracks: Int, ) { fun createArtworkImageRequest(symphony: Symphony) = diff --git a/app/src/main/java/io/github/zyrouge/symphony/services/groove/repositories/AlbumRepository.kt b/app/src/main/java/io/github/zyrouge/symphony/services/groove/repositories/AlbumRepository.kt index 4009325d..7a5a1059 100644 --- a/app/src/main/java/io/github/zyrouge/symphony/services/groove/repositories/AlbumRepository.kt +++ b/app/src/main/java/io/github/zyrouge/symphony/services/groove/repositories/AlbumRepository.kt @@ -21,6 +21,7 @@ class AlbumRepository(private val symphony: Symphony) { ALBUM_NAME, ARTIST_NAME, TRACKS_COUNT, + YEAR, } private val cache = ConcurrentHashMap() @@ -60,6 +61,7 @@ class AlbumRepository(private val symphony: Symphony) { id = albumId, name = song.album!!, artists = song.artists.toMutableSet(), + year = song.year, numberOfTracks = 1, ) } @@ -100,6 +102,7 @@ class AlbumRepository(private val symphony: Symphony) { SortBy.ALBUM_NAME -> albumIds.sortedBy { get(it)?.name } SortBy.ARTIST_NAME -> albumIds.sortedBy { get(it)?.artists?.joinToStringIfNotEmpty() } SortBy.TRACKS_COUNT -> albumIds.sortedBy { get(it)?.numberOfTracks } + SortBy.YEAR -> albumIds.sortedBy { get(it)?.year } } return if (reverse) sorted.reversed() else sorted } diff --git a/app/src/main/java/io/github/zyrouge/symphony/ui/components/AlbumGrid.kt b/app/src/main/java/io/github/zyrouge/symphony/ui/components/AlbumGrid.kt index 6b9f2c3c..ab5d4832 100644 --- a/app/src/main/java/io/github/zyrouge/symphony/ui/components/AlbumGrid.kt +++ b/app/src/main/java/io/github/zyrouge/symphony/ui/components/AlbumGrid.kt @@ -3,7 +3,6 @@ package io.github.zyrouge.symphony.ui.components import androidx.compose.foundation.lazy.grid.itemsIndexed import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Album -import androidx.compose.material3.Button import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Icon import androidx.compose.material3.ModalBottomSheet @@ -111,4 +110,5 @@ private fun AlbumRepository.SortBy.label(context: ViewContext) = when (this) { AlbumRepository.SortBy.ALBUM_NAME -> context.symphony.t.Album AlbumRepository.SortBy.ARTIST_NAME -> context.symphony.t.Artist AlbumRepository.SortBy.TRACKS_COUNT -> context.symphony.t.TrackCount + AlbumRepository.SortBy.YEAR -> context.symphony.t.Year } From ea0270d8695285cdb1d6450a28bd61e808da3eae Mon Sep 17 00:00:00 2001 From: sevonj <100710152+sevonj@users.noreply.github.com> Date: Thu, 21 Nov 2024 15:48:56 +0200 Subject: [PATCH 2/2] Feat: Album year + sorting --- .../github/zyrouge/symphony/services/groove/Album.kt | 3 ++- .../services/groove/repositories/AlbumRepository.kt | 11 +++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/github/zyrouge/symphony/services/groove/Album.kt b/app/src/main/java/io/github/zyrouge/symphony/services/groove/Album.kt index 5d0c973c..2f8fd3fc 100644 --- a/app/src/main/java/io/github/zyrouge/symphony/services/groove/Album.kt +++ b/app/src/main/java/io/github/zyrouge/symphony/services/groove/Album.kt @@ -8,7 +8,8 @@ data class Album( val id: String, val name: String, val artists: MutableSet, - val year: Int?, + var startYear: Int?, + var endYear: Int?, var numberOfTracks: Int, ) { fun createArtworkImageRequest(symphony: Symphony) = diff --git a/app/src/main/java/io/github/zyrouge/symphony/services/groove/repositories/AlbumRepository.kt b/app/src/main/java/io/github/zyrouge/symphony/services/groove/repositories/AlbumRepository.kt index 7a5a1059..18a67a7d 100644 --- a/app/src/main/java/io/github/zyrouge/symphony/services/groove/repositories/AlbumRepository.kt +++ b/app/src/main/java/io/github/zyrouge/symphony/services/groove/repositories/AlbumRepository.kt @@ -14,6 +14,8 @@ import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.update import java.util.concurrent.ConcurrentHashMap +import kotlin.math.max +import kotlin.math.min class AlbumRepository(private val symphony: Symphony) { enum class SortBy { @@ -51,6 +53,10 @@ class AlbumRepository(private val symphony: Symphony) { cache.compute(albumId) { _, value -> value?.apply { artists.addAll(song.artists) + song.year?.let { + startYear = startYear?.let { old -> min(old, it) } ?: it + endYear = endYear?.let { old -> max(old, it) } ?: it + } numberOfTracks++ } ?: run { _all.update { @@ -61,7 +67,8 @@ class AlbumRepository(private val symphony: Symphony) { id = albumId, name = song.album!!, artists = song.artists.toMutableSet(), - year = song.year, + startYear = song.year, + endYear = song.year, numberOfTracks = 1, ) } @@ -102,7 +109,7 @@ class AlbumRepository(private val symphony: Symphony) { SortBy.ALBUM_NAME -> albumIds.sortedBy { get(it)?.name } SortBy.ARTIST_NAME -> albumIds.sortedBy { get(it)?.artists?.joinToStringIfNotEmpty() } SortBy.TRACKS_COUNT -> albumIds.sortedBy { get(it)?.numberOfTracks } - SortBy.YEAR -> albumIds.sortedBy { get(it)?.year } + SortBy.YEAR -> albumIds.sortedBy { get(it)?.startYear } } return if (reverse) sorted.reversed() else sorted }