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

Feature: Album duration #666

Merged
merged 4 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package io.github.zyrouge.symphony.services.groove

import androidx.compose.runtime.Immutable
import io.github.zyrouge.symphony.Symphony
import kotlin.time.Duration

@Immutable
data class Album(
val id: String,
val name: String,
val artists: MutableSet<String>,
var numberOfTracks: Int,
var duration: Duration,
) {
fun createArtworkImageRequest(symphony: Symphony) =
symphony.groove.album.createArtworkImageRequest(id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
import java.util.concurrent.ConcurrentHashMap
import kotlin.time.Duration.Companion.milliseconds

class AlbumRepository(private val symphony: Symphony) {
enum class SortBy {
Expand Down Expand Up @@ -51,6 +52,7 @@ class AlbumRepository(private val symphony: Symphony) {
value?.apply {
artists.addAll(song.artists)
numberOfTracks++
duration += song.duration.milliseconds
} ?: run {
_all.update {
it + albumId
Expand All @@ -61,6 +63,7 @@ class AlbumRepository(private val symphony: Symphony) {
name = song.album!!,
artists = song.artists.toMutableSet(),
numberOfTracks = 1,
duration = song.duration.milliseconds,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ fun GenericGrooveBanner(
) {
Box(
modifier = Modifier
.padding(defaultHorizontalPadding, 32.dp, defaultHorizontalPadding, 12.dp)
.padding(defaultHorizontalPadding, 32.dp, 0.dp, 12.dp)
.weight(1f)
) {
ProvideTextStyle(
Expand Down
15 changes: 13 additions & 2 deletions app/src/main/java/io/github/zyrouge/symphony/ui/view/Album.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package io.github.zyrouge.symphony.ui.view

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
Expand Down Expand Up @@ -128,9 +131,17 @@ private fun AlbumHero(context: ViewContext, album: Album) {
content = {
Column {
Text(album.name)
if (album.artists.isNotEmpty()) {
Row(modifier = Modifier.fillMaxWidth()) {
if (album.artists.isNotEmpty()) {
Text(
album.artists.joinToString(),
style = MaterialTheme.typography.bodyMedium
.copy(fontWeight = FontWeight.Bold)
)
}
Spacer(Modifier.weight(1f))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will not provide padding when the artists name is long. Add .padding(left = 4.dp) (change the padding according to the necessity).

Text(
album.artists.joinToString(),
album.duration.toString(),
style = MaterialTheme.typography.bodyMedium
.copy(fontWeight = FontWeight.Bold)
)
Expand Down