mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 16:30:31 +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
|
@Entity
|
||||||
data class LocalPlaylist(
|
data class LocalPlaylist(
|
||||||
@PrimaryKey(autoGenerate = true)
|
@PrimaryKey(autoGenerate = true)
|
||||||
val id: Int = 0,
|
var id: Int = 0,
|
||||||
var name: String = "",
|
var name: String = "",
|
||||||
var thumbnailUrl: String = "",
|
var thumbnailUrl: String = "",
|
||||||
var description: String? = ""
|
var description: String? = ""
|
||||||
|
@ -10,7 +10,7 @@ import kotlinx.serialization.Serializable
|
|||||||
@Serializable
|
@Serializable
|
||||||
@Entity
|
@Entity
|
||||||
data class LocalPlaylistItem(
|
data class LocalPlaylistItem(
|
||||||
@PrimaryKey(autoGenerate = true) val id: Int = 0,
|
@PrimaryKey(autoGenerate = true) var id: Int = 0,
|
||||||
@ColumnInfo var playlistId: Int = 0,
|
@ColumnInfo var playlistId: Int = 0,
|
||||||
@ColumnInfo val videoId: String = "",
|
@ColumnInfo val videoId: String = "",
|
||||||
@ColumnInfo val title: String? = null,
|
@ColumnInfo val title: String? = null,
|
||||||
|
@ -55,11 +55,12 @@ object BackupHelper {
|
|||||||
Database.subscriptionGroupsDao().insertAll(backupFile.channelGroups.orEmpty())
|
Database.subscriptionGroupsDao().insertAll(backupFile.channelGroups.orEmpty())
|
||||||
|
|
||||||
backupFile.localPlaylists?.forEach {
|
backupFile.localPlaylists?.forEach {
|
||||||
Database.localPlaylistsDao().createPlaylist(it.playlist)
|
// the playlist will be created with an id of 0, so that Room will auto generate a
|
||||||
val playlistId = Database.localPlaylistsDao().getAll().last().playlist.id
|
// new playlist id to avoid conflicts with existing local playlists
|
||||||
|
val playlistId = Database.localPlaylistsDao().createPlaylist(it.playlist.copy(id = 0))
|
||||||
it.videos.forEach { playlistItem ->
|
it.videos.forEach { playlistItem ->
|
||||||
playlistItem.playlistId = playlistId
|
playlistItem.playlistId = playlistId.toInt()
|
||||||
Database.localPlaylistsDao().addPlaylistVideo(playlistItem)
|
Database.localPlaylistsDao().addPlaylistVideo(playlistItem.copy(id = 0))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user