From 368c8cf00fbf3d033cc97f11ae0353ffda2eaa4c Mon Sep 17 00:00:00 2001 From: Alexander Capehart Date: Sat, 22 Jun 2024 13:43:40 -0600 Subject: [PATCH] music: sort songs by individual date first While still falling back to the album date for libraries that have the same date for all songs (like mine) Resolves #797. --- CHANGELOG.md | 3 +++ app/src/main/java/org/oxycblt/auxio/list/sort/Sort.kt | 9 +++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 52403829e..27f6edc84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ - New app branding and icon - Refreshed playback design +#### What's Improved +- Sorting songs by date now uses songs date first, before the earliest album date + #### What's Fixed - Music loader no longer spawns thousands of threads when scanning - Excessive CPU no longer spent showing music loading process diff --git a/app/src/main/java/org/oxycblt/auxio/list/sort/Sort.kt b/app/src/main/java/org/oxycblt/auxio/list/sort/Sort.kt index d4088358a..0f9fd3cb0 100644 --- a/app/src/main/java/org/oxycblt/auxio/list/sort/Sort.kt +++ b/app/src/main/java/org/oxycblt/auxio/list/sort/Sort.kt @@ -18,9 +18,10 @@ package org.oxycblt.auxio.list.sort -import kotlin.math.max import org.oxycblt.auxio.IntegerTable import org.oxycblt.auxio.R +import org.oxycblt.auxio.list.sort.Sort.Direction +import org.oxycblt.auxio.list.sort.Sort.Mode import org.oxycblt.auxio.music.Album import org.oxycblt.auxio.music.Artist import org.oxycblt.auxio.music.Genre @@ -29,6 +30,7 @@ import org.oxycblt.auxio.music.Playlist import org.oxycblt.auxio.music.Song import org.oxycblt.auxio.music.info.Date import org.oxycblt.auxio.music.info.Disc +import kotlin.math.max /** * A sorting method. @@ -284,7 +286,7 @@ data class Sort(val mode: Mode, val direction: Direction) { override fun getSongComparator(direction: Direction): Comparator = MultiComparator( - compareByDynamic(direction, NullableComparator.DATE_RANGE) { it.album.dates }, + compareByDynamic(direction, NullableComparator.DATE) { it.date }, compareByDescending(BasicComparator.ALBUM) { it.album }, compareBy(NullableComparator.DISC) { it.disc }, compareBy(NullableComparator.INT) { it.track }, @@ -624,5 +626,8 @@ private class NullableComparator> private constructor() : Comp val DISC = NullableComparator() /** A re-usable instance configured for [Date.Range]s. */ val DATE_RANGE = NullableComparator() + + /** A re-usable instance configured for [Date]s. */ + val DATE = NullableComparator() } }