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 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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ 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(
Expand All @@ -11,6 +12,7 @@ data class Album(
var startYear: Int?,
var endYear: Int?,
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
import kotlin.math.max
import kotlin.math.min

Expand Down Expand Up @@ -58,6 +59,7 @@ class AlbumRepository(private val symphony: Symphony) {
endYear = endYear?.let { old -> max(old, it) } ?: it
}
numberOfTracks++
duration += song.duration.milliseconds
} ?: run {
_all.update {
it + albumId
Expand All @@ -70,6 +72,7 @@ class AlbumRepository(private val symphony: Symphony) {
startYear = song.year,
endYear = song.year,
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
5 changes: 5 additions & 0 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 @@ -135,6 +135,11 @@ private fun AlbumHero(context: ViewContext, album: Album) {
.copy(fontWeight = FontWeight.Bold)
)
}
Text(
album.duration.toString(),
style = MaterialTheme.typography.bodyMedium
.copy(fontWeight = FontWeight.Bold)
)
}
}
)
Expand Down