mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
refactor(backup): Manage options from BackupCreator
This commit is contained in:
parent
ca7496bda1
commit
231ece7bfb
4 changed files with 44 additions and 16 deletions
|
@ -5,11 +5,17 @@ import android.net.Uri
|
|||
import co.touchlab.kermit.Logger
|
||||
import com.hippo.unifile.UniFile
|
||||
import eu.kanade.tachiyomi.data.backup.BackupFileValidator
|
||||
import eu.kanade.tachiyomi.data.backup.models.BackupCategory
|
||||
import eu.kanade.tachiyomi.data.backup.models.BackupManga
|
||||
import eu.kanade.tachiyomi.data.backup.models.BackupPreference
|
||||
import eu.kanade.tachiyomi.data.backup.models.BackupSource
|
||||
import eu.kanade.tachiyomi.data.backup.models.BackupSourcePreferences
|
||||
import eu.kanade.tachiyomi.data.backup.create.creators.CategoriesBackupCreator
|
||||
import eu.kanade.tachiyomi.data.backup.create.creators.MangaBackupCreator
|
||||
import eu.kanade.tachiyomi.data.backup.create.creators.PreferenceBackupCreator
|
||||
import eu.kanade.tachiyomi.data.backup.create.creators.SourcesBackupCreator
|
||||
import eu.kanade.tachiyomi.data.backup.models.Backup
|
||||
import eu.kanade.tachiyomi.domain.manga.models.Manga
|
||||
import java.io.FileOutputStream
|
||||
import java.time.Instant
|
||||
import kotlinx.serialization.protobuf.ProtoBuf
|
||||
|
@ -67,13 +73,13 @@ class BackupCreator(
|
|||
}
|
||||
|
||||
val readNotFavorites = if (options.readManga) getManga.awaitReadNotFavorites() else emptyList()
|
||||
val backupManga = mangaBackupCreator(getManga.awaitFavorites() + readNotFavorites, options)
|
||||
val backupManga = backupMangas(getManga.awaitFavorites() + readNotFavorites, options)
|
||||
val backup = Backup(
|
||||
backupManga = backupManga,
|
||||
backupCategories = categoriesBackupCreator(options),
|
||||
backupSources = sourcesBackupCreator(backupManga),
|
||||
backupPreferences = preferenceBackupCreator.backupAppPreferences(options),
|
||||
backupSourcePreferences = preferenceBackupCreator.backupSourcePreferences(options),
|
||||
backupCategories = backupCategories(options),
|
||||
backupSources = backupSources(backupManga),
|
||||
backupPreferences = backupAppPreferences(options),
|
||||
backupSourcePreferences = backupSourcePreferences(options),
|
||||
)
|
||||
|
||||
val byteArray = parser.encodeToByteArray(Backup.serializer(), backup)
|
||||
|
@ -101,4 +107,32 @@ class BackupCreator(
|
|||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun backupCategories(options: BackupOptions): List<BackupCategory> {
|
||||
if (!options.categories) return emptyList()
|
||||
|
||||
return categoriesBackupCreator()
|
||||
}
|
||||
|
||||
private suspend fun backupMangas(mangas: List<Manga>, options: BackupOptions): List<BackupManga> {
|
||||
if (!options.libraryEntries) return emptyList()
|
||||
|
||||
return mangaBackupCreator(mangas, options)
|
||||
}
|
||||
|
||||
private fun backupSources(mangas: List<BackupManga>): List<BackupSource> {
|
||||
return sourcesBackupCreator(mangas)
|
||||
}
|
||||
|
||||
private fun backupAppPreferences(options: BackupOptions): List<BackupPreference> {
|
||||
if (!options.appPrefs) return emptyList()
|
||||
|
||||
return preferenceBackupCreator.createApp(includePrivatePreferences = options.includePrivate)
|
||||
}
|
||||
|
||||
private fun backupSourcePreferences(options: BackupOptions): List<BackupSourcePreferences> {
|
||||
if (!options.sourcePrefs) return emptyList()
|
||||
|
||||
return preferenceBackupCreator.createSource(includePrivatePreferences = options.includePrivate)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,9 +14,7 @@ class CategoriesBackupCreator(
|
|||
*
|
||||
* @return list of [BackupCategory] to be backed up
|
||||
*/
|
||||
suspend operator fun invoke(options: BackupOptions): List<BackupCategory> {
|
||||
if (!options.categories) return emptyList()
|
||||
|
||||
suspend operator fun invoke(): List<BackupCategory> {
|
||||
return getCategories.await()
|
||||
.map { BackupCategory.copyFrom(it) }
|
||||
}
|
||||
|
|
|
@ -20,8 +20,6 @@ class MangaBackupCreator(
|
|||
private val getChapter: GetChapter = Injekt.get(),
|
||||
) {
|
||||
suspend operator fun invoke(mangas: List<Manga>, options: BackupOptions): List<BackupManga> {
|
||||
if (!options.libraryEntries) return emptyList()
|
||||
|
||||
return mangas.map {
|
||||
backupManga(it, options)
|
||||
}
|
||||
|
|
|
@ -23,21 +23,19 @@ class PreferenceBackupCreator(
|
|||
private val sourceManager: SourceManager = Injekt.get(),
|
||||
private val preferenceStore: PreferenceStore = Injekt.get(),
|
||||
) {
|
||||
fun backupAppPreferences(options: BackupOptions): List<BackupPreference> {
|
||||
if (!options.appPrefs) return emptyList()
|
||||
fun createApp(includePrivatePreferences: Boolean): List<BackupPreference> {
|
||||
return preferenceStore.getAll().toBackupPreferences()
|
||||
.withPrivatePreferences(options.includePrivate)
|
||||
.withPrivatePreferences(includePrivatePreferences)
|
||||
}
|
||||
|
||||
fun backupSourcePreferences(options: BackupOptions): List<BackupSourcePreferences> {
|
||||
if (!options.sourcePrefs) return emptyList()
|
||||
fun createSource(includePrivatePreferences: Boolean): List<BackupSourcePreferences> {
|
||||
return sourceManager.getOnlineSources()
|
||||
.filterIsInstance<ConfigurableSource>()
|
||||
.map {
|
||||
BackupSourcePreferences(
|
||||
it.preferenceKey(),
|
||||
it.sourcePreferences().all.toBackupPreferences()
|
||||
.withPrivatePreferences(options.includePrivate),
|
||||
.withPrivatePreferences(includePrivatePreferences),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue