Files
muza/app/src/main/kotlin/it/vfsfitvnm/vimusic/models/DetailedSong.kt
2022-09-29 19:36:29 +02:00

48 lines
1.2 KiB
Kotlin

package it.vfsfitvnm.vimusic.models
import androidx.compose.runtime.Immutable
import androidx.room.Junction
import androidx.room.Relation
@Immutable
open class DetailedSong(
val id: String,
val title: String,
val artistsText: String? = null,
val durationText: String?,
val thumbnailUrl: String?,
val totalPlayTimeMs: Long = 0,
@Relation(
entity = SongAlbumMap::class,
entityColumn = "songId",
parentColumn = "id",
projection = ["albumId"]
)
val albumId: String?,
@Relation(
entity = Artist::class,
entityColumn = "id",
parentColumn = "id",
associateBy = Junction(
value = SongArtistMap::class,
parentColumn = "songId",
entityColumn = "artistId"
),
projection = ["id", "name"]
)
val artists: List<Info>?
) {
val formattedTotalPlayTime: String
get() {
val seconds = totalPlayTimeMs / 1000
val hours = seconds / 3600
return when {
hours == 0L -> "${seconds / 60}m"
hours < 24L -> "${hours}h"
else -> "${hours / 24}d"
}
}
}