diff --git a/app/src/main/kotlin/it/vfsfitvnm/vimusic/Database.kt b/app/src/main/kotlin/it/vfsfitvnm/vimusic/Database.kt index 967937f..04ceadd 100644 --- a/app/src/main/kotlin/it/vfsfitvnm/vimusic/Database.kt +++ b/app/src/main/kotlin/it/vfsfitvnm/vimusic/Database.kt @@ -26,7 +26,7 @@ interface Database { fun insert(searchQuery: SearchQuery) @Insert(onConflict = OnConflictStrategy.IGNORE) - fun insert(info: Artist) + fun insert(info: Artist): Long @Insert(onConflict = OnConflictStrategy.IGNORE) fun insert(info: Album): Long @@ -40,9 +40,6 @@ interface Database { @Insert(onConflict = OnConflictStrategy.IGNORE) fun insert(songAlbumMap: SongAlbumMap): Long - @Insert(onConflict = OnConflictStrategy.ABORT) - fun insert(info: List): List - @Query("SELECT * FROM Song WHERE id = :id") fun songFlow(id: String): Flow @@ -108,6 +105,12 @@ interface Database { @Update fun update(artist: Artist) + fun upsert(artist: Artist) { + if (insert(artist) == -1L) { + update(artist) + } + } + @Update fun update(album: Album) diff --git a/app/src/main/kotlin/it/vfsfitvnm/vimusic/ui/screens/ArtistScreen.kt b/app/src/main/kotlin/it/vfsfitvnm/vimusic/ui/screens/ArtistScreen.kt index 81eb040..66c5087 100644 --- a/app/src/main/kotlin/it/vfsfitvnm/vimusic/ui/screens/ArtistScreen.kt +++ b/app/src/main/kotlin/it/vfsfitvnm/vimusic/ui/screens/ArtistScreen.kt @@ -95,7 +95,7 @@ fun ArtistScreen( shufflePlaylistId = youtubeArtist.shuffleEndpoint?.playlistId, radioVideoId = youtubeArtist.radioEndpoint?.videoId, radioPlaylistId = youtubeArtist.radioEndpoint?.playlistId, - ).also(Database::update) + ).also(Database::upsert) } }.distinctUntilChanged() }.collectAsState(initial = null, context = Dispatchers.IO)