diff --git a/app/src/main/java/org/oxycblt/auxio/music/info/Disc.kt b/app/src/main/java/org/oxycblt/auxio/music/info/Disc.kt index df1cafea4..759d52b49 100644 --- a/app/src/main/java/org/oxycblt/auxio/music/info/Disc.kt +++ b/app/src/main/java/org/oxycblt/auxio/music/info/Disc.kt @@ -26,6 +26,8 @@ import org.oxycblt.auxio.list.Item * @param number The disc number. * @param name The name of the disc group, if any. Null if not present. */ -data class Disc(val number: Int, val name: String?) : Item, Comparable { +class Disc(val number: Int, val name: String?) : Item, Comparable { + override fun equals(other: Any?) = other is Disc && number == other.number + override fun hashCode() = number.hashCode() override fun compareTo(other: Disc) = number.compareTo(other.number) } diff --git a/app/src/main/java/org/oxycblt/auxio/music/info/Name.kt b/app/src/main/java/org/oxycblt/auxio/music/info/Name.kt index e985a115c..8869e1227 100644 --- a/app/src/main/java/org/oxycblt/auxio/music/info/Name.kt +++ b/app/src/main/java/org/oxycblt/auxio/music/info/Name.kt @@ -111,10 +111,11 @@ sealed interface Name : Comparable { companion object { /** * Create a new instance of [Name.Known] + * * @param raw The raw name obtained from the music item * @param sort The raw sort name obtained from the music item * @param musicSettings [MusicSettings] required to obtain user-preferred sorting - * configurations + * configurations */ fun from(raw: String, sort: String?, musicSettings: MusicSettings): Known = if (musicSettings.intelligentSorting) { @@ -148,6 +149,7 @@ private val PUNCT_REGEX = Regex("[\\p{Punct}+]") /** * Plain [Name.Known] implementation that is internationalization-safe. + * * @author Alexander Capehart (OxygenCobalt) */ private data class SimpleKnownName(override val raw: String, override val sort: String?) : @@ -165,6 +167,7 @@ private data class SimpleKnownName(override val raw: String, override val sort: /** * [Name.Known] implementation that adds advanced sorting behavior at the cost of localization. + * * @author Alexander Capehart (OxygenCobalt) */ private data class IntelligentKnownName(override val raw: String, override val sort: String?) : @@ -192,23 +195,23 @@ private data class IntelligentKnownName(override val raw: String, override val s // individual lexicographic and numeric tokens and then individually compare them // with special logic. return TOKEN_REGEX.findAll(stripped).mapTo(mutableListOf()) { match -> - // Remove excess whitespace where possible - val token = match.value.trim().ifEmpty { match.value } - val collationKey: CollationKey - val type: SortToken.Type - // Separate each token into their numeric and lexicographic counterparts. - if (token.first().isDigit()) { - // The digit string comparison breaks with preceding zero digits, remove those - val digits = token.trimStart('0').ifEmpty { token } - // Other languages have other types of digit strings, still use collation keys - collationKey = COLLATOR.getCollationKey(digits) - type = SortToken.Type.NUMERIC - } else { - collationKey = COLLATOR.getCollationKey(token) - type = SortToken.Type.LEXICOGRAPHIC - } - SortToken(collationKey, type) + // Remove excess whitespace where possible + val token = match.value.trim().ifEmpty { match.value } + val collationKey: CollationKey + val type: SortToken.Type + // Separate each token into their numeric and lexicographic counterparts. + if (token.first().isDigit()) { + // The digit string comparison breaks with preceding zero digits, remove those + val digits = token.trimStart('0').ifEmpty { token } + // Other languages have other types of digit strings, still use collation keys + collationKey = COLLATOR.getCollationKey(digits) + type = SortToken.Type.NUMERIC + } else { + collationKey = COLLATOR.getCollationKey(token) + type = SortToken.Type.LEXICOGRAPHIC } + SortToken(collationKey, type) + } } companion object { diff --git a/app/src/test/java/org/oxycblt/auxio/music/FakeMusic.kt b/app/src/test/java/org/oxycblt/auxio/music/FakeMusic.kt index e835294e4..a3b3b4bac 100644 --- a/app/src/test/java/org/oxycblt/auxio/music/FakeMusic.kt +++ b/app/src/test/java/org/oxycblt/auxio/music/FakeMusic.kt @@ -18,20 +18,16 @@ package org.oxycblt.auxio.music -import android.content.Context import android.net.Uri import org.oxycblt.auxio.music.fs.MimeType import org.oxycblt.auxio.music.fs.Path import org.oxycblt.auxio.music.info.Date import org.oxycblt.auxio.music.info.Disc +import org.oxycblt.auxio.music.info.Name import org.oxycblt.auxio.music.info.ReleaseType open class FakeSong : Song { - override val rawName: String? - get() = throw NotImplementedError() - override val rawSortName: String? - get() = throw NotImplementedError() - override val sortName: SortName? + override val name: Name get() = throw NotImplementedError() override val date: Date? get() = throw NotImplementedError() @@ -59,18 +55,10 @@ open class FakeSong : Song { get() = throw NotImplementedError() override val uid: Music.UID get() = throw NotImplementedError() - - override fun resolveName(context: Context): String { - throw NotImplementedError() - } } open class FakeAlbum : Album { - override val rawName: String? - get() = throw NotImplementedError() - override val rawSortName: String? - get() = throw NotImplementedError() - override val sortName: SortName? + override val name: Name get() = throw NotImplementedError() override val coverUri: Uri get() = throw NotImplementedError() @@ -88,18 +76,10 @@ open class FakeAlbum : Album { get() = throw NotImplementedError() override val uid: Music.UID get() = throw NotImplementedError() - - override fun resolveName(context: Context): String { - throw NotImplementedError() - } } open class FakeArtist : Artist { - override val rawName: String? - get() = throw NotImplementedError() - override val rawSortName: String? - get() = throw NotImplementedError() - override val sortName: SortName? + override val name: Name get() = throw NotImplementedError() override val albums: List get() = throw NotImplementedError() @@ -113,18 +93,10 @@ open class FakeArtist : Artist { get() = throw NotImplementedError() override val uid: Music.UID get() = throw NotImplementedError() - - override fun resolveName(context: Context): String { - throw NotImplementedError() - } } open class FakeGenre : Genre { - override val rawName: String? - get() = throw NotImplementedError() - override val rawSortName: String? - get() = throw NotImplementedError() - override val sortName: SortName? + override val name: Name get() = throw NotImplementedError() override val albums: List get() = throw NotImplementedError() @@ -136,8 +108,4 @@ open class FakeGenre : Genre { get() = throw NotImplementedError() override val uid: Music.UID get() = throw NotImplementedError() - - override fun resolveName(context: Context): String { - throw NotImplementedError() - } }