-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
403 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package ru.stersh.youamp.core.ui | ||
|
||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material3.Button | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Scaffold | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.text.style.TextAlign | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
|
||
|
||
@Composable | ||
fun ErrorLayout( | ||
onRetry: () -> Unit, | ||
modifier: Modifier = Modifier | ||
) { | ||
Box(modifier = modifier.fillMaxSize()) { | ||
Error( | ||
onRetry = onRetry, | ||
modifier = Modifier.align(Alignment.Center) | ||
) | ||
} | ||
} | ||
|
||
@Composable | ||
fun Error( | ||
onRetry: () -> Unit, | ||
modifier: Modifier = Modifier | ||
) { | ||
Column( | ||
modifier = modifier.padding(horizontal = 48.dp), | ||
verticalArrangement = Arrangement.spacedBy(16.dp), | ||
horizontalAlignment = Alignment.CenterHorizontally | ||
) { | ||
Text( | ||
textAlign = TextAlign.Center, | ||
style = MaterialTheme.typography.titleLarge, | ||
text = stringResource(R.string.error_title) | ||
) | ||
|
||
Text( | ||
textAlign = TextAlign.Center, | ||
style = MaterialTheme.typography.bodyLarge, | ||
color = MaterialTheme.colorScheme.outline, | ||
text = stringResource(R.string.error_message) | ||
) | ||
|
||
Button(onClick = onRetry) { | ||
Text(text = stringResource(R.string.error_button_title)) | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
@Preview | ||
private fun ErrorLayoutPreview() { | ||
YouAmpPlayerTheme { | ||
Scaffold { | ||
ErrorLayout( | ||
onRetry = {}, | ||
modifier = Modifier.padding(it) | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...t/info/src/main/java/ru/stersh/youamp/feature/playlist/data/PlaylistInfoRepositoryImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package ru.stersh.youamp.feature.playlist.data | ||
|
||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.combine | ||
import kotlinx.coroutines.flow.flatMapLatest | ||
import kotlinx.coroutines.flow.flow | ||
import ru.stersh.youamp.core.api.Playlist | ||
import ru.stersh.youamp.core.api.provider.ApiProvider | ||
import ru.stersh.youamp.feature.playlist.domain.PlaylistInfo | ||
import ru.stersh.youamp.feature.playlist.domain.PlaylistInfoRepository | ||
import ru.stersh.youamp.feature.playlist.domain.PlaylistSong | ||
import ru.stersh.youamp.shared.player.metadata.CurrentSongInfoStore | ||
import ru.stersh.youamp.shared.player.state.PlayStateStore | ||
|
||
internal class PlaylistInfoRepositoryImpl( | ||
private val playerStateStore: PlayStateStore, | ||
private val apiProvider: ApiProvider, | ||
private val currentSongInfoStore: CurrentSongInfoStore, | ||
) : PlaylistInfoRepository { | ||
|
||
override fun getPlaylistInfo(playlistId: String): Flow<PlaylistInfo> { | ||
return flowPlaylist(playlistId).flatMapLatest { playlist -> | ||
combine( | ||
currentSongInfoStore.getCurrentSongInfo(), | ||
playerStateStore.isPlaying() | ||
) { currentSongInfo, isPlaying -> | ||
val api = apiProvider.getApi() | ||
return@combine PlaylistInfo( | ||
title = playlist.name, | ||
artworkUrl = api.getCoverArtUrl(playlist.coverArt), | ||
songs = playlist | ||
.entry | ||
.orEmpty() | ||
.map { entry -> | ||
val isCurrent = currentSongInfo?.id == entry.id | ||
PlaylistSong( | ||
id = entry.id, | ||
title = entry.title, | ||
artist = entry.artist, | ||
artworkUrl = entry.coverArt?.let { api.getCoverArtUrl(it) }, | ||
isCurrent = isCurrent, | ||
isPlaying = isCurrent && isPlaying | ||
) | ||
} | ||
) | ||
} | ||
} | ||
} | ||
|
||
private fun flowPlaylist(playlistId: String): Flow<Playlist> { | ||
return flow { | ||
val api = apiProvider.getApi() | ||
emit(api.getPlaylist(playlistId)) | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
feature/playlist/info/src/main/java/ru/stersh/youamp/feature/playlist/domain/PlaylistInfo.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package ru.stersh.youamp.feature.playlist.domain | ||
|
||
internal data class PlaylistInfo( | ||
val artworkUrl: String?, | ||
val title: String, | ||
val songs: List<PlaylistSong> | ||
) |
7 changes: 7 additions & 0 deletions
7
...ist/info/src/main/java/ru/stersh/youamp/feature/playlist/domain/PlaylistInfoRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package ru.stersh.youamp.feature.playlist.domain | ||
|
||
import kotlinx.coroutines.flow.Flow | ||
|
||
internal interface PlaylistInfoRepository { | ||
fun getPlaylistInfo(playlistId: String): Flow<PlaylistInfo> | ||
} |
10 changes: 10 additions & 0 deletions
10
feature/playlist/info/src/main/java/ru/stersh/youamp/feature/playlist/domain/PlaylistSong.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package ru.stersh.youamp.feature.playlist.domain | ||
|
||
internal data class PlaylistSong( | ||
val id: String, | ||
val title: String, | ||
val artist: String?, | ||
val artworkUrl: String?, | ||
val isCurrent: Boolean, | ||
val isPlaying: Boolean | ||
) |
25 changes: 25 additions & 0 deletions
25
feature/playlist/info/src/main/java/ru/stersh/youamp/feature/playlist/ui/Mapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package ru.stersh.youamp.feature.playlist.ui | ||
|
||
import ru.stersh.youamp.feature.playlist.domain.PlaylistInfo | ||
import ru.stersh.youamp.feature.playlist.domain.PlaylistSong | ||
|
||
internal fun PlaylistInfo.toUi(): PlaylistInfoUi { | ||
return PlaylistInfoUi( | ||
artworkUrl = artworkUrl, | ||
title = title, | ||
songs = songs.toUi() | ||
) | ||
} | ||
|
||
internal fun List<PlaylistSong>.toUi(): List<PlaylistSongUi> = map { it.toUi() } | ||
|
||
internal fun PlaylistSong.toUi(): PlaylistSongUi { | ||
return PlaylistSongUi( | ||
id = id, | ||
title = title, | ||
artist = artist, | ||
artworkUrl = artworkUrl, | ||
isCurrent = isCurrent, | ||
isPlaying = isPlaying | ||
) | ||
} |
Oops, something went wrong.