Merge pull request #5585 from Bnyro/master

fix: crash when importing a playlist whose id already exists
This commit is contained in:
Bnyro 2024-02-01 15:30:45 +01:00 committed by GitHub
commit 60ccb24394
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 7 additions and 6 deletions

View File

@ -8,7 +8,7 @@ import kotlinx.serialization.Serializable
@Entity
data class LocalPlaylist(
@PrimaryKey(autoGenerate = true)
val id: Int = 0,
var id: Int = 0,
var name: String = "",
var thumbnailUrl: String = "",
var description: String? = ""

View File

@ -10,7 +10,7 @@ import kotlinx.serialization.Serializable
@Serializable
@Entity
data class LocalPlaylistItem(
@PrimaryKey(autoGenerate = true) val id: Int = 0,
@PrimaryKey(autoGenerate = true) var id: Int = 0,
@ColumnInfo var playlistId: Int = 0,
@ColumnInfo val videoId: String = "",
@ColumnInfo val title: String? = null,

View File

@ -55,11 +55,12 @@ object BackupHelper {
Database.subscriptionGroupsDao().insertAll(backupFile.channelGroups.orEmpty())
backupFile.localPlaylists?.forEach {
Database.localPlaylistsDao().createPlaylist(it.playlist)
val playlistId = Database.localPlaylistsDao().getAll().last().playlist.id
// the playlist will be created with an id of 0, so that Room will auto generate a
// new playlist id to avoid conflicts with existing local playlists
val playlistId = Database.localPlaylistsDao().createPlaylist(it.playlist.copy(id = 0))
it.videos.forEach { playlistItem ->
playlistItem.playlistId = playlistId
Database.localPlaylistsDao().addPlaylistVideo(playlistItem)
playlistItem.playlistId = playlistId.toInt()
Database.localPlaylistsDao().addPlaylistVideo(playlistItem.copy(id = 0))
}
}