Do not return unused fields in DetailedSong

This commit is contained in:
vfsfitvnm
2022-08-03 21:09:08 +02:00
parent 194864bcb4
commit 61c8552ad0
12 changed files with 68 additions and 58 deletions

View File

@@ -1,11 +1,16 @@
package it.vfsfitvnm.vimusic.models
import androidx.room.Embedded
import androidx.room.Junction
import androidx.room.Relation
open class DetailedSong(
@Embedded val song: Song,
val id: String,
val title: String,
val artistsText: String? = null,
val durationText: String,
val thumbnailUrl: String?,
val likedAt: Long? = null,
val totalPlayTimeMs: Long = 0,
@Relation(
entity = SongAlbumMap::class,
entityColumn = "songId",
@@ -24,4 +29,17 @@ open class DetailedSong(
)
)
val artists: List<Artist>?
)
) {
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"
}
}
}