Merge pull request #2012 from Bnyro/backup-restore-local-playlists

add possibility to backup and restore local playlists
This commit is contained in:
Bnyro 2022-11-23 18:21:09 +01:00 committed by GitHub
commit 9ab4b6b2c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 1 deletions

View File

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

View File

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

View File

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

View File

@ -66,6 +66,15 @@ class BackupHelper(private val context: Context) {
*backupFile.playlistBookmarks.orEmpty().toTypedArray() *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) restorePreferences(backupFile.preferences)
} }
} }

View File

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