mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 08:20:32 +05:30
Merge pull request #5585 from Bnyro/master
fix: crash when importing a playlist whose id already exists
This commit is contained in:
commit
60ccb24394
@ -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? = ""
|
||||
|
@ -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,
|
||||
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user