From 186ba9ad9e0387c1b58a600963d7dc296d8a1675 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20Br=C3=BCggemann?= Date: Wed, 24 Jun 2026 16:22:22 +0200 Subject: [PATCH] feat: when sorting albums by artist, sort albums by the same artist by year. --- .../tempo/ui/adapter/AlbumCatalogueAdapter.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/cappielloantonio/tempo/ui/adapter/AlbumCatalogueAdapter.java b/app/src/main/java/com/cappielloantonio/tempo/ui/adapter/AlbumCatalogueAdapter.java index 6b28ba092..01d4b06cb 100644 --- a/app/src/main/java/com/cappielloantonio/tempo/ui/adapter/AlbumCatalogueAdapter.java +++ b/app/src/main/java/com/cappielloantonio/tempo/ui/adapter/AlbumCatalogueAdapter.java @@ -22,6 +22,7 @@ import java.util.Comparator; import java.util.Date; import java.util.List; +import java.util.function.Function; public class AlbumCatalogueAdapter extends RecyclerView.Adapter implements Filterable, StandardViewTypeAdapter { private final ClickCallback click; @@ -164,10 +165,14 @@ public void sort(String order) { )); break; case Constants.ALBUM_ORDER_BY_ARTIST: + // If we call thenComparing() on the Comparator, the Java compiler seems unable + // to figure out that album is supposed to be an AlbumID3, so we explicitly assign + // the lambda to a variable so that we can specify the type. + Function getArtist = album -> album.getArtist() != null ? album.getArtist() : ""; albums.sort(Comparator.comparing( - album -> album.getArtist() != null ? album.getArtist() : "", - String.CASE_INSENSITIVE_ORDER - )); + getArtist, + String.CASE_INSENSITIVE_ORDER + ).thenComparing(AlbumID3::getYear)); break; case Constants.ALBUM_ORDER_BY_YEAR: albums.sort(Comparator.comparing(AlbumID3::getYear));