2017-09-02 19:40:32 +02:00
|
|
|
// Converts Indexes entity from [org.moire.ultrasonic.api.subsonic.SubsonicAPIClient]
|
|
|
|
// to app domain entities.
|
|
|
|
@file:JvmName("APIIndexesConverter")
|
2018-02-17 20:36:19 +01:00
|
|
|
package org.moire.ultrasonic.domain
|
2017-09-02 19:40:32 +02:00
|
|
|
|
2021-06-20 16:31:08 +02:00
|
|
|
import org.moire.ultrasonic.api.subsonic.models.Index as APIIndex
|
2017-09-02 19:40:32 +02:00
|
|
|
import org.moire.ultrasonic.api.subsonic.models.Indexes as APIIndexes
|
|
|
|
|
2021-06-20 16:31:08 +02:00
|
|
|
fun APIIndexes.toArtistList(): List<Artist> {
|
2021-06-23 17:09:33 +02:00
|
|
|
val shortcuts = this.shortcutList.map { it.toDomainEntity() }.toMutableList()
|
|
|
|
val indexes = this.indexList.foldIndexToArtistList()
|
|
|
|
|
|
|
|
indexes.forEach {
|
|
|
|
if (!shortcuts.contains(it)) {
|
|
|
|
shortcuts.add(it)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return shortcuts
|
2021-06-20 16:31:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fun APIIndexes.toIndexList(musicFolderId: String?): List<Index> {
|
2021-06-23 17:09:33 +02:00
|
|
|
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
|
2021-06-20 16:31:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private fun List<APIIndex>.foldIndexToArtistList(): List<Artist> = this.fold(
|
|
|
|
listOf(),
|
|
|
|
{ acc, index ->
|
|
|
|
acc + index.artists.map {
|
|
|
|
it.toDomainEntity()
|
|
|
|
}
|
|
|
|
}
|
2018-02-22 21:46:53 +01:00
|
|
|
)
|
2017-09-02 19:40:32 +02:00
|
|
|
|
2021-06-20 16:31:08 +02:00
|
|
|
private fun List<APIIndex>.foldIndexToIndexList(musicFolderId: String?): List<Index> = this.fold(
|
|
|
|
listOf(),
|
|
|
|
{ acc, index ->
|
|
|
|
acc + index.artists.map {
|
|
|
|
val ret = it.toIndexEntity()
|
|
|
|
ret.musicFolderId = musicFolderId
|
|
|
|
ret
|
|
|
|
}
|
|
|
|
}
|
2020-06-13 19:04:31 +02:00
|
|
|
)
|