Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Favorites screens for albums and artists #361

Merged
merged 1 commit into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ dependencies {
implementation project(":shared:song:random")
implementation project(':feature:album:list')
implementation project(':feature:album:info')
implementation project(':feature:album:favorites')
implementation project(':feature:artist:list')
implementation project(':feature:artist:info')
implementation project(':feature:artist:favorites')
implementation project(':feature:playlist:list')
implementation project(':feature:playlist:info')
implementation project(":feature:main")
Expand All @@ -91,7 +93,7 @@ dependencies {
implementation project(":feature:server:list")
implementation project(":feature:search")
implementation project(":feature:song:info")
implementation project(":feature:favorite:list")
implementation project(":feature:song:favorites")
implementation project(":feature:settings")
implementation project(":feature:about")
implementation project(":feature:personal")
Expand Down
24 changes: 14 additions & 10 deletions app/src/main/java/ru/stersh/youamp/Di.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import org.koin.dsl.module
import ru.stersh.youamp.core.api.provider.ApiProvider
import ru.stersh.youamp.core.room.roomModule
import ru.stersh.youamp.feature.album.albumInfoModule
import ru.stersh.youamp.feature.albums.albumsModule
import ru.stersh.youamp.feature.albums.albumListModule
import ru.stersh.youamp.feature.artist.artistInfoModule
import ru.stersh.youamp.feature.artists.artistsModule
import ru.stersh.youamp.feature.artists.artistListModule
import ru.stersh.youamp.feature.main.mainModule
import ru.stersh.youamp.feature.personal.personalModule
import ru.stersh.youamp.feature.player.mini.playerMiniModule
Expand All @@ -33,9 +33,11 @@ import ru.stersh.youamp.shared.player.playerSharedModule
import ru.stresh.youamp.core.properties.app.AppProperties
import ru.stresh.youamp.core.propertiesModule
import ru.stresh.youamp.feature.about.aboutModule
import ru.stresh.youamp.feature.album.favorites.albumFavoritesModule
import ru.stresh.youamp.feature.artist.favorites.artistFavoritesModule
import ru.stresh.youamp.feature.explore.exploreModule
import ru.stresh.youamp.feature.favorite.list.favoriteListModule
import ru.stresh.youamp.feature.library.libraryModule
import ru.stresh.youamp.feature.song.favorites.songFavoritesModule
import ru.stresh.youamp.feature.song.random.songRandomModule
import ru.stresh.youamp.shared.favorites.favoritesSharedModule
import ru.stresh.youamp.shared.song.random.songRandomSharedModule
Expand Down Expand Up @@ -63,22 +65,24 @@ private val feature = listOf(
playerScreenModule,
playerQueueScreenModule,
albumInfoModule,
albumsModule,
artistsModule,
albumFavoritesModule,
albumListModule,
artistListModule,
artistInfoModule,
artistFavoritesModule,
serverCreateModule,
serverListModule,
playlistListModule,
searchModule,
playlistInfoModule,
favoriteListModule,
searchModule,
songFavoritesModule,
songInfoModule,
songRandomModule,
aboutModule,
personalModule,
exploreModule,
mainModule,
libraryModule,
songInfoModule,
songRandomModule
libraryModule
)

private val impl = module {
Expand Down
42 changes: 39 additions & 3 deletions app/src/main/java/ru/stersh/youamp/main/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ import ru.stersh.youamp.feature.server.create.ui.ServerScreen
import ru.stersh.youamp.feature.server.list.ui.ServerListScreen
import ru.stersh.youamp.feature.song.info.ui.SongInfoScreen
import ru.stresh.youamp.feature.about.ui.AboutScreen
import ru.stresh.youamp.feature.album.favorites.ui.FavoriteAlbumsScreen
import ru.stresh.youamp.feature.artist.favorites.ui.FavoriteArtistsScreen
import ru.stresh.youamp.feature.explore.ui.ExploreScreen
import ru.stresh.youamp.feature.favorite.list.ui.FavoriteSongsScreen
import ru.stresh.youamp.feature.library.ui.LibraryScreen
import ru.stresh.youamp.feature.settings.ui.SettingsScreen
import ru.stresh.youamp.feature.song.favorites.ui.FavoriteSongsScreen
import ru.stresh.youamp.feature.song.random.ui.RandomSongsScreen

class MainActivity : ComponentActivity() {
Expand Down Expand Up @@ -143,8 +145,8 @@ class MainActivity : ComponentActivity() {
onPlaylistClick = { rootNavController.navigate(PlaylistInfo(it)) },
onPlaylistsClick = { rootNavController.navigate(Playlists) },
onFavoriteSongsClick = { rootNavController.navigate(FavoriteSongs) },
onFavoriteAlbumsClick = {},
onFavoriteArtistsClick = {}
onFavoriteAlbumsClick = { rootNavController.navigate(FavoriteAlbums) },
onFavoriteArtistsClick = { rootNavController.navigate(FavoriteArtists) }
)
},
explore = {
Expand Down Expand Up @@ -437,6 +439,40 @@ class MainActivity : ComponentActivity() {
)
}
}
composable<FavoriteAlbums> {
ScreenWithMiniPlayer(
viewModelStoreOwner = viewModelStoreOwner,
onMiniPlayerClick = {
rootNavController.navigate(Player)
}
) {
FavoriteAlbumsScreen(
onBackClick = {
rootNavController.popBackStack()
},
onAlbumClick = {
rootNavController.navigate(AlbumInfo(it))
}
)
}
}
composable<FavoriteArtists> {
ScreenWithMiniPlayer(
viewModelStoreOwner = viewModelStoreOwner,
onMiniPlayerClick = {
rootNavController.navigate(Player)
}
) {
FavoriteArtistsScreen(
onBackClick = {
rootNavController.popBackStack()
},
onArtistClick = {
rootNavController.navigate(ArtistInfo(it))
}
)
}
}
}
songInfoProperties?.let { songProperties ->
ModalBottomSheet(
Expand Down
8 changes: 7 additions & 1 deletion app/src/main/java/ru/stersh/youamp/main/ui/Navigation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,10 @@ object Playlists
object FavoriteSongs

@Serializable
object RandomSongs
object RandomSongs

@Serializable
object FavoriteAlbums

@Serializable
object FavoriteArtists
4 changes: 4 additions & 0 deletions buildscripts/android-feature-module.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ android {
freeCompilerArgs.add('-opt-in=androidx.compose.foundation.layout.ExperimentalLayoutApi')
}
}
composeCompiler {
reportsDestination = layout.buildDirectory.dir("compose_compiler")
metricsDestination = layout.buildDirectory.dir("compose_compiler")
}
buildFeatures {
compose true
}
Expand Down
4 changes: 3 additions & 1 deletion core/api/src/main/java/ru/stersh/youamp/core/api/Album.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ data class Album(
@Json(name = "songCount")
val songCount: Int?,
@Json(name = "year")
val year: Int?
val year: Int?,
@Json(name = "userRating")
val userRating: Int?
)

@JsonClass(generateAdapter = true)
Expand Down
2 changes: 2 additions & 0 deletions core/api/src/main/java/ru/stersh/youamp/core/api/Artist.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,6 @@ data class Artist(
val artistImageUrl: String?,
@Json(name = "album")
val albums: List<Album>?,
@Json(name = "userRating")
val userRating: Int?
)
File renamed without changes.
22 changes: 22 additions & 0 deletions feature/album/favorites/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.kotlin.compose.compiler)
}

apply from: "${project.rootDir}/buildscripts/android-feature-module.gradle"

android {
namespace 'ru.stersh.youamp.feature.album.favorites'
}

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)
implementation(libs.timber)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package ru.stresh.youamp.feature.album.favorites

import org.koin.core.module.dsl.viewModel
import org.koin.dsl.module
import ru.stresh.youamp.feature.album.favorites.data.FavoriteAlbumsRepositoryImpl
import ru.stresh.youamp.feature.album.favorites.domain.FavoriteAlbumsRepository
import ru.stresh.youamp.feature.album.favorites.ui.FavoriteAlbumsViewModel

val albumFavoritesModule = module {
single<FavoriteAlbumsRepository> { FavoriteAlbumsRepositoryImpl(get()) }
viewModel { FavoriteAlbumsViewModel(get(), get()) }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package ru.stresh.youamp.feature.album.favorites.data

import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import ru.stresh.youamp.feature.album.favorites.domain.Album
import ru.stresh.youamp.feature.album.favorites.domain.FavoriteAlbumsRepository
import ru.stresh.youamp.feature.album.favorites.domain.Favorites
import ru.stresh.youamp.shared.favorites.AlbumFavoritesStorage

internal class FavoriteAlbumsRepositoryImpl(
private val albumFavoritesStorage: AlbumFavoritesStorage
) : FavoriteAlbumsRepository {

override fun getFavorites(): Flow<Favorites> {
return albumFavoritesStorage
.flowAlbums()
.map { favoriteAlbums ->
Favorites(
albums = favoriteAlbums.map { it.toDomain() }
)
}
}

private fun ru.stresh.youamp.shared.favorites.Album.toDomain(): Album {
return Album(
id = id,
title = title,
artist = artist,
artworkUrl = artworkUrl,
userRating = userRating
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package ru.stresh.youamp.feature.album.favorites.domain

internal data class Album(
val id: String,
val title: String,
val artist: String?,
val artworkUrl: String?,
val userRating: Int?
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package ru.stresh.youamp.feature.album.favorites.domain

import kotlinx.coroutines.flow.Flow

internal interface FavoriteAlbumsRepository {
fun getFavorites(): Flow<Favorites>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package ru.stresh.youamp.feature.album.favorites.domain

internal data class Favorites(
val albums: List<Album>
)
Loading
Loading