Skip to content

Commit

Permalink
Fix favorite songs screen (#358)
Browse files Browse the repository at this point in the history
  • Loading branch information
siper authored Feb 6, 2025
1 parent 43fe322 commit 3b159a7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
1 change: 1 addition & 0 deletions feature/favorite/list/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ dependencies {
implementation project(":core:ui")
implementation project(":core:api")
implementation project(":shared:player")
implementation project(":shared:favorites")
implementation(libs.bundles.lifecycle)
implementation(libs.coil.compose)
implementation(libs.bundles.koin)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,31 @@ package ru.stresh.youamp.feature.favorite.list.data

import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import ru.stersh.youamp.core.api.SubsonicApi
import ru.stersh.youamp.core.api.provider.ApiProvider
import ru.stresh.youamp.feature.favorite.list.domain.FavoriteSongsRepository
import ru.stresh.youamp.feature.favorite.list.domain.Favorites
import ru.stresh.youamp.feature.favorite.list.domain.Song
import ru.stresh.youamp.shared.favorites.SongFavoritesStorage

internal class FavoriteSongsRepositoryImpl(private val apiProvider: ApiProvider) : FavoriteSongsRepository {
internal class FavoriteSongsRepositoryImpl(
private val songFavoritesStorage: SongFavoritesStorage
) : FavoriteSongsRepository {

override fun getFavorites(): Flow<Favorites> {
return apiProvider
.flowApi()
.map { api ->
val starred = api.getStarred2().starred2Result
return songFavoritesStorage
.flowSongs()
.map { favoriteSongs ->
Favorites(
songs = starred
.song
.orEmpty()
.map { it.toDomain(api) }
songs = favoriteSongs.map { it.toDomain() }
)
}
}

private fun ru.stersh.youamp.core.api.Song.toDomain(api: SubsonicApi): Song {
private fun ru.stresh.youamp.shared.favorites.Song.toDomain(): Song {
return Song(
id = id,
title = title,
artist = artist,
artworkUrl = api.getCoverArtUrl(coverArt),
artworkUrl = artworkUrl,
userRating = userRating
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ internal class FavoritesStorageImpl(
albumId = it.albumId,
artist = it.artist,
artistId = it.artistId,
artworkUrl = api.getCoverArtUrl(it.coverArt)
artworkUrl = api.getCoverArtUrl(it.coverArt),
userRating = it.userRating
)
}.orEmpty(),
albums = newFavorites.starred2Result.album?.map {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ data class Song(
val artist: String?,
val artistId: String?,
val artworkUrl: String?,
val userRating: Int?
)

0 comments on commit 3b159a7

Please sign in to comment.