From 7c908f4c58bf887689f168e5d413cd9e399c8d82 Mon Sep 17 00:00:00 2001 From: vfsfitvnm Date: Mon, 29 Aug 2022 20:28:28 +0200 Subject: [PATCH] Revert favorite button behaviour when clicked --- .../it/vfsfitvnm/vimusic/ui/views/player/Controls.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/it/vfsfitvnm/vimusic/ui/views/player/Controls.kt b/app/src/main/kotlin/it/vfsfitvnm/vimusic/ui/views/player/Controls.kt index c83400d..3d76b21 100644 --- a/app/src/main/kotlin/it/vfsfitvnm/vimusic/ui/views/player/Controls.kt +++ b/app/src/main/kotlin/it/vfsfitvnm/vimusic/ui/views/player/Controls.kt @@ -38,6 +38,7 @@ import androidx.media3.common.Player import it.vfsfitvnm.vimusic.Database import it.vfsfitvnm.vimusic.LocalPlayerServiceBinder import it.vfsfitvnm.vimusic.R +import it.vfsfitvnm.vimusic.models.Song import it.vfsfitvnm.vimusic.query import it.vfsfitvnm.vimusic.ui.components.SeekBar import it.vfsfitvnm.vimusic.ui.styling.LocalAppearance @@ -180,7 +181,11 @@ fun Controls( modifier = Modifier .clickable { query { - Database.like(mediaId, if (likedAt == null) System.currentTimeMillis() else null) + if (Database.like(mediaId, if (likedAt == null) System.currentTimeMillis() else null) == 0) { + binder.player.currentMediaItem?.takeIf { it.mediaId == mediaId }?.let { mediaItem -> + Database.insert(mediaItem, Song::toggleLike) + } + } } } .weight(1f)