From bf9222ab0d4625bd3939b9ef24afb64310d88404 Mon Sep 17 00:00:00 2001 From: avi Date: Sat, 3 Oct 2026 19:43:44 -0500 Subject: [PATCH] fix(playlists): re-adding a song to a playlist crashed with SQLiteConstraintException (playlistId, songId) is the playlist_songs PK, so a second @Insert of the same pair threw UNIQUE constraint failed and killed the app (reproduced twice in the crash buffer on 10-03). Switch to OnConflictStrategy.IGNORE: duplicate add is now a silent no-op. Verified on-device on 0.1.5 (7): re-adding 'The Humbling River' to FAVORITES keeps the song list intact, 0 FATALs, no new crash-buffer entries. --- app/build.gradle.kts | 4 ++-- app/src/main/java/com/rada/data/local/dao/PlaylistDao.kt | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 0ed92bc..c7e0393 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -15,8 +15,8 @@ android { applicationId = "com.rada" minSdk = 26 targetSdk = 35 - versionCode = 6 - versionName = "0.1.4" + versionCode = 7 + versionName = "0.1.5" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" } diff --git a/app/src/main/java/com/rada/data/local/dao/PlaylistDao.kt b/app/src/main/java/com/rada/data/local/dao/PlaylistDao.kt index 5d3ed84..4fbc280 100644 --- a/app/src/main/java/com/rada/data/local/dao/PlaylistDao.kt +++ b/app/src/main/java/com/rada/data/local/dao/PlaylistDao.kt @@ -3,6 +3,7 @@ package com.rada.data.local.dao import androidx.room.Dao import androidx.room.Delete import androidx.room.Insert +import androidx.room.OnConflictStrategy import androidx.room.Query import com.rada.data.local.entity.PlaylistEntity import com.rada.data.local.entity.PlaylistSongEntity @@ -30,7 +31,9 @@ interface PlaylistDao { @Query("DELETE FROM playlists WHERE id = :playlistId") suspend fun deletePlaylistById(playlistId: Long) - @Insert + // IGNORE: (playlistId, songId) is the PK — re-adding a song that is + // already in the playlist must be a no-op, not a crash. + @Insert(onConflict = OnConflictStrategy.IGNORE) suspend fun addSongToPlaylist(playlistSong: PlaylistSongEntity) @Query("DELETE FROM playlist_songs WHERE playlistId = :playlistId AND songId = :songId")