add possibility to backup and restore local playlists

This commit is contained in:
Bnyro 2022-11-23 18:20:43 +01:00
parent 0aaf68ede6
commit 08bbb839aa
5 changed files with 18 additions and 1 deletions

View File

@ -7,7 +7,7 @@ import androidx.room.PrimaryKey
@Entity
data class LocalPlaylistItem(
@PrimaryKey(autoGenerate = true) val id: Int = 0,
@ColumnInfo val playlistId: Int,
@ColumnInfo var playlistId: Int,
@ColumnInfo val videoId: String,
@ColumnInfo val title: String? = null,
@ColumnInfo val uploadDate: String? = null,

View File

@ -1,6 +1,7 @@
package com.github.libretube.obj
import com.github.libretube.db.obj.CustomInstance
import com.github.libretube.db.obj.LocalPlaylistWithVideos
import com.github.libretube.db.obj.LocalSubscription
import com.github.libretube.db.obj.PlaylistBookmark
import com.github.libretube.db.obj.SearchHistoryItem
@ -14,5 +15,6 @@ data class BackupFile(
var localSubscriptions: List<LocalSubscription>? = null,
var customInstances: List<CustomInstance>? = null,
var playlistBookmarks: List<PlaylistBookmark>? = null,
var localPlaylists: List<LocalPlaylistWithVideos>? = null,
var preferences: List<PreferenceItem>? = null
)

View File

@ -40,6 +40,10 @@ class BackupDialog(
it.playlistBookmarks = Database.playlistBookmarkDao().getAll()
})
object LocalPlaylists : BackupOption(R.string.local_playlists, onSelected = {
it.localPlaylists = Database.localPlaylistsDao().getAll()
})
object Preferences : BackupOption(R.string.preferences, onSelected = {
it.preferences = PreferenceHelper.settings.all.map {
PreferenceItem(it.key, it.value)
@ -54,6 +58,7 @@ class BackupDialog(
BackupOption.LocalSubscriptions,
BackupOption.CustomInstances,
BackupOption.PlaylistBookmarks,
BackupOption.LocalPlaylists,
BackupOption.Preferences
)

View File

@ -66,6 +66,15 @@ class BackupHelper(private val context: Context) {
*backupFile.playlistBookmarks.orEmpty().toTypedArray()
)
backupFile.localPlaylists?.forEach {
Database.localPlaylistsDao().createPlaylist(it.playlist)
val playlistId = Database.localPlaylistsDao().getAll().last().playlist.id
it.videos.forEach {
it.playlistId = playlistId
Database.localPlaylistsDao().addPlaylistVideo(it)
}
}
restorePreferences(backupFile.preferences)
}
}

View File

@ -386,6 +386,7 @@
<string name="clear_bookmarks">Clear bookmarks</string>
<string name="bookmarks_empty">No bookmarks yet!</string>
<string name="queue_insert_related_videos">Insert related videos</string>
<string name="local_playlists">Local playlists</string>
<!-- Notification channel strings -->
<string name="download_channel_name">Download Service</string>