Do not return unused fields in DetailedSong
This commit is contained in:
parent
194864bcb4
commit
61c8552ad0
|
@ -54,26 +54,32 @@ interface Database {
|
|||
|
||||
@Transaction
|
||||
@Query("SELECT * FROM Song WHERE totalPlayTimeMs > 0 ORDER BY ROWID ASC")
|
||||
@RewriteQueriesToDropUnusedColumns
|
||||
fun songsByRowIdAsc(): Flow<List<DetailedSong>>
|
||||
|
||||
@Transaction
|
||||
@Query("SELECT * FROM Song WHERE totalPlayTimeMs > 0 ORDER BY ROWID DESC")
|
||||
@RewriteQueriesToDropUnusedColumns
|
||||
fun songsByRowIdDesc(): Flow<List<DetailedSong>>
|
||||
|
||||
@Transaction
|
||||
@Query("SELECT * FROM Song WHERE totalPlayTimeMs > 0 ORDER BY title ASC")
|
||||
@RewriteQueriesToDropUnusedColumns
|
||||
fun songsByTitleAsc(): Flow<List<DetailedSong>>
|
||||
|
||||
@Transaction
|
||||
@Query("SELECT * FROM Song WHERE totalPlayTimeMs > 0 ORDER BY title DESC")
|
||||
@RewriteQueriesToDropUnusedColumns
|
||||
fun songsByTitleDesc(): Flow<List<DetailedSong>>
|
||||
|
||||
@Transaction
|
||||
@Query("SELECT * FROM Song WHERE totalPlayTimeMs > 0 ORDER BY totalPlayTimeMs ASC")
|
||||
@RewriteQueriesToDropUnusedColumns
|
||||
fun songsByPlayTimeAsc(): Flow<List<DetailedSong>>
|
||||
|
||||
@Transaction
|
||||
@Query("SELECT * FROM Song WHERE totalPlayTimeMs > 0 ORDER BY totalPlayTimeMs DESC")
|
||||
@RewriteQueriesToDropUnusedColumns
|
||||
fun songsByPlayTimeDesc(): Flow<List<DetailedSong>>
|
||||
|
||||
fun songs(sortBy: SongSortBy, sortOrder: SortOrder): Flow<List<DetailedSong>> {
|
||||
|
@ -95,6 +101,7 @@ interface Database {
|
|||
|
||||
@Transaction
|
||||
@Query("SELECT * FROM Song WHERE likedAt IS NOT NULL ORDER BY likedAt DESC")
|
||||
@RewriteQueriesToDropUnusedColumns
|
||||
fun favorites(): Flow<List<DetailedSong>>
|
||||
|
||||
@Query("SELECT * FROM QueuedMediaItem")
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -70,7 +70,7 @@ fun InFavoritesMediaItemMenu(
|
|||
onDismiss = onDismiss,
|
||||
onRemoveFromFavorites = {
|
||||
query {
|
||||
Database.update(song.song.toggleLike())
|
||||
Database.like(song.id, if (song.likedAt == null) System.currentTimeMillis() else null)
|
||||
}
|
||||
},
|
||||
modifier = modifier
|
||||
|
@ -94,15 +94,13 @@ fun InHistoryMediaItemMenu(
|
|||
if (isHiding) {
|
||||
ConfirmationDialog(
|
||||
text = "Do you really hide this song? Its playback time and cache will be wiped.\nThis action is irreversible.",
|
||||
onDismiss = {
|
||||
isHiding = false
|
||||
},
|
||||
onDismiss = { isHiding = false },
|
||||
onConfirm = {
|
||||
(onDismiss ?: menuState::hide).invoke()
|
||||
query {
|
||||
// Not sure we can to this here
|
||||
binder?.cache?.removeResource(song.song.id)
|
||||
Database.update(song.song.copy(totalPlayTimeMs = 0))
|
||||
binder?.cache?.removeResource(song.id)
|
||||
Database.incrementTotalPlayTimeMs(song.id, -song.totalPlayTimeMs)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
@ -111,9 +109,7 @@ fun InHistoryMediaItemMenu(
|
|||
NonQueuedMediaItemMenu(
|
||||
mediaItem = song.asMediaItem,
|
||||
onDismiss = onDismiss,
|
||||
onHideFromDatabase = {
|
||||
isHiding = true
|
||||
},
|
||||
onHideFromDatabase = { isHiding = true },
|
||||
modifier = modifier
|
||||
)
|
||||
}
|
||||
|
@ -134,7 +130,7 @@ fun InPlaylistMediaItemMenu(
|
|||
transaction {
|
||||
Database.delete(
|
||||
SongPlaylistMap(
|
||||
songId = song.song.id,
|
||||
songId = song.id,
|
||||
playlistId = playlistId,
|
||||
position = positionInPlaylist
|
||||
)
|
||||
|
@ -182,9 +178,7 @@ fun NonQueuedMediaItemMenu(
|
|||
onPlayNext = {
|
||||
binder?.player?.addNext(mediaItem)
|
||||
},
|
||||
onEnqueue = {
|
||||
binder?.player?.enqueue(mediaItem)
|
||||
},
|
||||
onEnqueue = { binder?.player?.enqueue(mediaItem) },
|
||||
onRemoveFromPlaylist = onRemoveFromPlaylist,
|
||||
onHideFromDatabase = onHideFromDatabase,
|
||||
onRemoveFromFavorites = onRemoveFromFavorites,
|
||||
|
|
|
@ -251,7 +251,7 @@ fun AlbumScreen(browseId: String) {
|
|||
songs.forEachIndexed { index, song ->
|
||||
Database.insert(
|
||||
SongPlaylistMap(
|
||||
songId = song.song.id,
|
||||
songId = song.id,
|
||||
playlistId = playlistId,
|
||||
position = index
|
||||
)
|
||||
|
@ -320,13 +320,13 @@ fun AlbumScreen(browseId: String) {
|
|||
|
||||
itemsIndexed(
|
||||
items = songs,
|
||||
key = { _, song -> song.song.id },
|
||||
key = { _, song -> song.id },
|
||||
contentType = { _, song -> song }
|
||||
) { index, song ->
|
||||
SongItem(
|
||||
title = song.song.title,
|
||||
authors = song.song.artistsText ?: albumResult?.getOrNull()?.authorsText,
|
||||
durationText = song.song.durationText,
|
||||
title = song.title,
|
||||
authors = song.artistsText ?: albumResult?.getOrNull()?.authorsText,
|
||||
durationText = song.durationText,
|
||||
onClick = {
|
||||
binder?.stopRadio()
|
||||
binder?.player?.forcePlayAtIndex(
|
||||
|
|
|
@ -247,7 +247,7 @@ fun ArtistScreen(browseId: String) {
|
|||
|
||||
itemsIndexed(
|
||||
items = songs,
|
||||
key = { _, song -> song.song.id },
|
||||
key = { _, song -> song.id },
|
||||
contentType = { _, song -> song },
|
||||
) { index, song ->
|
||||
SongItem(
|
||||
|
|
|
@ -74,7 +74,7 @@ fun BuiltInPlaylistScreen(builtInPlaylist: BuiltInPlaylist) {
|
|||
BuiltInPlaylist.Offline -> Database.songsWithContentLength().map { songs ->
|
||||
songs.filter { song ->
|
||||
song.contentLength?.let {
|
||||
binder?.cache?.isCached(song.song.id, 0, song.contentLength)
|
||||
binder?.cache?.isCached(song.id, 0, song.contentLength)
|
||||
} ?: false
|
||||
}
|
||||
}
|
||||
|
@ -180,7 +180,7 @@ fun BuiltInPlaylistScreen(builtInPlaylist: BuiltInPlaylist) {
|
|||
|
||||
itemsIndexed(
|
||||
items = songs,
|
||||
key = { _, song -> song.song.id },
|
||||
key = { _, song -> song.id },
|
||||
contentType = { _, song -> song },
|
||||
) { index, song ->
|
||||
SongItem(
|
||||
|
|
|
@ -625,9 +625,7 @@ fun HomeScreen() {
|
|||
|
||||
itemsIndexed(
|
||||
items = songCollection,
|
||||
key = { _, song ->
|
||||
song.song.id
|
||||
},
|
||||
key = { _, song -> song.id },
|
||||
contentType = { _, song -> song }
|
||||
) { index, song ->
|
||||
SongItem(
|
||||
|
@ -652,7 +650,7 @@ fun HomeScreen() {
|
|||
.align(Alignment.BottomCenter)
|
||||
) {
|
||||
BasicText(
|
||||
text = song.song.formattedTotalPlayTime,
|
||||
text = song.formattedTotalPlayTime,
|
||||
style = typography.xxs.semiBold.center.color(Color.White),
|
||||
maxLines = 2,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
|
|
|
@ -242,7 +242,7 @@ fun LocalPlaylistScreen(playlistId: Long) {
|
|||
|
||||
itemsIndexed(
|
||||
items = playlistWithSongs.songs,
|
||||
key = { _, song -> song.song.id },
|
||||
key = { _, song -> song.id },
|
||||
contentType = { _, song -> song },
|
||||
) { index, song ->
|
||||
SongItem(
|
||||
|
@ -301,7 +301,7 @@ fun LocalPlaylistScreen(playlistId: Long) {
|
|||
|
||||
Database.update(
|
||||
SongPlaylistMap(
|
||||
songId = playlistWithSongs.songs[index].song.id,
|
||||
songId = playlistWithSongs.songs[index].id,
|
||||
playlistId = playlistWithSongs.playlist.id,
|
||||
position = reachedIndex
|
||||
)
|
||||
|
|
|
@ -83,10 +83,10 @@ fun SongItem(
|
|||
trailingContent: (@Composable () -> Unit)? = null
|
||||
) {
|
||||
SongItem(
|
||||
thumbnailModel = song.song.thumbnailUrl?.thumbnail(thumbnailSize),
|
||||
title = song.song.title,
|
||||
authors = song.song.artistsText ?: "",
|
||||
durationText = song.song.durationText,
|
||||
thumbnailModel = song.thumbnailUrl?.thumbnail(thumbnailSize),
|
||||
title = song.title,
|
||||
authors = song.artistsText ?: "",
|
||||
durationText = song.durationText,
|
||||
menuContent = menuContent,
|
||||
onClick = onClick,
|
||||
onThumbnailContent = onThumbnailContent,
|
||||
|
|
|
@ -70,23 +70,23 @@ val DetailedSong.asMediaItem: MediaItem
|
|||
get() = MediaItem.Builder()
|
||||
.setMediaMetadata(
|
||||
MediaMetadata.Builder()
|
||||
.setTitle(song.title)
|
||||
.setArtist(song.artistsText)
|
||||
.setArtworkUri(song.thumbnailUrl?.toUri())
|
||||
.setTitle(title)
|
||||
.setArtist(artistsText)
|
||||
.setArtworkUri(thumbnailUrl?.toUri())
|
||||
.setExtras(
|
||||
bundleOf(
|
||||
"videoId" to song.id,
|
||||
"videoId" to id,
|
||||
"albumId" to albumId,
|
||||
"artistNames" to artists?.map { it.name },
|
||||
"artistIds" to artists?.map { it.id },
|
||||
"durationText" to song.durationText
|
||||
"durationText" to durationText
|
||||
)
|
||||
)
|
||||
.build()
|
||||
)
|
||||
.setMediaId(song.id)
|
||||
.setUri(song.id)
|
||||
.setCustomCacheKey(song.id)
|
||||
.setMediaId(id)
|
||||
.setUri(id)
|
||||
.setCustomCacheKey(id)
|
||||
.build()
|
||||
|
||||
fun YouTube.PlaylistOrAlbum.Item.toMediaItem(
|
||||
|
|
Loading…
Reference in a new issue