From 2df538ccc5cdc354e4b1c4f4b07eaf04680078b3 Mon Sep 17 00:00:00 2001 From: Adrian Ulrich Date: Wed, 29 Nov 2017 21:37:45 +0100 Subject: [PATCH] change songs compareTo to take the disc number into account --- .../blinkenlights/android/vanilla/Song.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/ch/blinkenlights/android/vanilla/Song.java b/src/ch/blinkenlights/android/vanilla/Song.java index e5f43068..855db080 100644 --- a/src/ch/blinkenlights/android/vanilla/Song.java +++ b/src/ch/blinkenlights/android/vanilla/Song.java @@ -251,15 +251,20 @@ public class Song implements Comparable { } /** - * Compares the album ids of the two songs; if equal, compares track order. + * Compares the virtual order of two song objects. */ @Override - public int compareTo(Song other) - { - if (albumId == other.albumId) + public int compareTo(Song other) { + if (albumId != other.albumId) + return (albumId > other.albumId ? 1 : -1); // albumId is long, avoid overflow fun. + + if (discNumber != other.discNumber) + return discNumber - other.discNumber; + + if (trackNumber != other.trackNumber) return trackNumber - other.trackNumber; - if (albumId > other.albumId) - return 1; - return -1; + + // else: is equal + return 0; } }