Do not return unused fields in DetailedSong
This commit is contained in:
@@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,13 @@ package it.vfsfitvnm.vimusic.models
|
||||
import androidx.room.Relation
|
||||
|
||||
class DetailedSongWithContentLength(
|
||||
song: Song,
|
||||
id: String,
|
||||
title: String,
|
||||
artistsText: String? = null,
|
||||
durationText: String,
|
||||
thumbnailUrl: String?,
|
||||
likedAt: Long? = null,
|
||||
totalPlayTimeMs: Long = 0,
|
||||
albumId: String?,
|
||||
artists: List<Artist>?,
|
||||
@Relation(
|
||||
@@ -13,4 +19,4 @@ class DetailedSongWithContentLength(
|
||||
projection = ["contentLength"]
|
||||
)
|
||||
val contentLength: Long?
|
||||
) : DetailedSong(song, albumId, artists)
|
||||
) : DetailedSong(id, title, artistsText, durationText, thumbnailUrl, likedAt, totalPlayTimeMs, albumId, artists)
|
||||
|
||||
@@ -15,19 +15,6 @@ data class Song(
|
||||
val likedAt: Long? = null,
|
||||
val totalPlayTimeMs: Long = 0
|
||||
) {
|
||||
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"
|
||||
}
|
||||
}
|
||||
|
||||
fun toggleLike(): Song {
|
||||
return copy(
|
||||
likedAt = if (likedAt == null) System.currentTimeMillis() else null
|
||||
|
||||
Reference in New Issue
Block a user