diff --git a/core/subsonic-api/src/test/kotlin/org/moire/ultrasonic/api/subsonic/models/AlbumListTypeTest.kt b/core/subsonic-api/src/test/kotlin/org/moire/ultrasonic/api/subsonic/models/AlbumListTypeTest.kt index bde2ead6..932ee62f 100644 --- a/core/subsonic-api/src/test/kotlin/org/moire/ultrasonic/api/subsonic/models/AlbumListTypeTest.kt +++ b/core/subsonic-api/src/test/kotlin/org/moire/ultrasonic/api/subsonic/models/AlbumListTypeTest.kt @@ -1,5 +1,6 @@ package org.moire.ultrasonic.api.subsonic.models +import java.util.Locale import org.amshove.kluent.`should be equal to` import org.amshove.kluent.`should throw` import org.junit.Test @@ -10,7 +11,7 @@ import org.junit.Test class AlbumListTypeTest { @Test fun `Should create type from string ignoring case`() { - val type = AlbumListType.SORTED_BY_NAME.typeName.toLowerCase() + val type = AlbumListType.SORTED_BY_NAME.typeName.lowercase(Locale.ROOT) val albumListType = AlbumListType.fromName(type) diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIIndexesConverter.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIIndexesConverter.kt index fb718204..2567ee67 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIIndexesConverter.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIIndexesConverter.kt @@ -7,15 +7,29 @@ import org.moire.ultrasonic.api.subsonic.models.Index as APIIndex import org.moire.ultrasonic.api.subsonic.models.Indexes as APIIndexes fun APIIndexes.toArtistList(): List { - val list = this.shortcutList.map { it.toDomainEntity() }.toMutableList() - list.addAll(this.indexList.foldIndexToArtistList()) - return list + val shortcuts = this.shortcutList.map { it.toDomainEntity() }.toMutableList() + val indexes = this.indexList.foldIndexToArtistList() + + indexes.forEach { + if (!shortcuts.contains(it)) { + shortcuts.add(it) + } + } + + return shortcuts } fun APIIndexes.toIndexList(musicFolderId: String?): List { - val list = this.shortcutList.map { it.toIndexEntity() }.toMutableList() - list.addAll(this.indexList.foldIndexToIndexList(musicFolderId)) - return list + val shortcuts = this.shortcutList.map { it.toIndexEntity() }.toMutableList() + val indexes = this.indexList.foldIndexToIndexList(musicFolderId) + + indexes.forEach { + if (!shortcuts.contains(it)) { + shortcuts.add(it) + } + } + + return shortcuts } private fun List.foldIndexToArtistList(): List = this.fold( diff --git a/ultrasonic/src/test/kotlin/org/moire/ultrasonic/domain/APIIndexConverterTest.kt b/ultrasonic/src/test/kotlin/org/moire/ultrasonic/domain/APIIndexConverterTest.kt index ca23b15f..06e2cbf9 100644 --- a/ultrasonic/src/test/kotlin/org/moire/ultrasonic/domain/APIIndexConverterTest.kt +++ b/ultrasonic/src/test/kotlin/org/moire/ultrasonic/domain/APIIndexConverterTest.kt @@ -31,7 +31,7 @@ class APIIndexConverterTest { shortcutList = artistsA ) - val convertedEntity = entity.toIndexList(null) + val convertedEntity = entity.toArtistList() val expectedArtists = (artistsA + artistsT).map { it.toDomainEntity() }.toMutableList() with(convertedEntity) {