mirror of
https://github.com/aniyomiorg/aniyomi.git
synced 2024-11-22 12:48:15 +03:00
Fix library is backed up when disabled and make categories backup/restore independent
Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com>
This commit is contained in:
parent
98941fe2d8
commit
83a10d384e
7 changed files with 53 additions and 40 deletions
|
@ -6,7 +6,6 @@ import android.content.Intent
|
|||
import android.net.Uri
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.foundation.layout.ColumnScope
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.Immutable
|
||||
import androidx.compose.runtime.collectAsState
|
||||
|
@ -69,7 +68,7 @@ class CreateBackupScreen : Screen() {
|
|||
LazyColumnWithAction(
|
||||
contentPadding = contentPadding,
|
||||
actionLabel = stringResource(MR.strings.action_create),
|
||||
actionEnabled = state.options.anyEnabled(),
|
||||
actionEnabled = state.options.canCreate(),
|
||||
onClickAction = {
|
||||
if (!BackupCreateJob.isManualJobRunning(context)) {
|
||||
try {
|
||||
|
@ -110,7 +109,7 @@ class CreateBackupScreen : Screen() {
|
|||
}
|
||||
|
||||
@Composable
|
||||
private fun ColumnScope.Options(
|
||||
private fun Options(
|
||||
options: ImmutableList<BackupOptions.Entry>,
|
||||
state: CreateBackupScreenModel.State,
|
||||
model: CreateBackupScreenModel,
|
||||
|
|
|
@ -63,7 +63,7 @@ class RestoreBackupScreen(
|
|||
LazyColumnWithAction(
|
||||
contentPadding = contentPadding,
|
||||
actionLabel = stringResource(MR.strings.action_restore),
|
||||
actionEnabled = state.canRestore && state.options.anyEnabled(),
|
||||
actionEnabled = state.canRestore && state.options.canRestore(),
|
||||
onClickAction = {
|
||||
model.startRestore()
|
||||
navigator.pop()
|
||||
|
|
|
@ -84,15 +84,15 @@ class BackupCreator(
|
|||
throw IllegalStateException(context.stringResource(MR.strings.create_backup_file_error))
|
||||
}
|
||||
|
||||
val databaseAnime = getAnimeFavorites.await()
|
||||
val databaseManga = getMangaFavorites.await()
|
||||
val backupAnime = backupAnimes(getAnimeFavorites.await(), options)
|
||||
val backupManga = backupMangas(getMangaFavorites.await(), options)
|
||||
val backup = Backup(
|
||||
backupManga = backupMangas(databaseManga, options),
|
||||
backupManga = backupManga,
|
||||
backupCategories = backupMangaCategories(options),
|
||||
backupAnime = backupAnimes(databaseAnime, options),
|
||||
backupAnime = backupAnime,
|
||||
backupAnimeCategories = backupAnimeCategories(options),
|
||||
backupSources = backupMangaSources(databaseManga),
|
||||
backupAnimeSources = backupAnimeSources(databaseAnime),
|
||||
backupSources = backupMangaSources(backupManga),
|
||||
backupAnimeSources = backupAnimeSources(backupAnime),
|
||||
backupPreferences = backupAppPreferences(options),
|
||||
backupSourcePreferences = backupSourcePreferences(options),
|
||||
backupExtensions = backupExtensions(options),
|
||||
|
@ -141,17 +141,21 @@ class BackupCreator(
|
|||
}
|
||||
|
||||
private suspend fun backupMangas(mangas: List<Manga>, options: BackupOptions): List<BackupManga> {
|
||||
if (!options.libraryEntries) return emptyList()
|
||||
|
||||
return mangaBackupCreator.backupMangas(mangas, options)
|
||||
}
|
||||
|
||||
private suspend fun backupAnimes(animes: List<Anime>, options: BackupOptions): List<BackupAnime> {
|
||||
if (!options.libraryEntries) return emptyList()
|
||||
|
||||
return animeBackupCreator.backupAnimes(animes, options)
|
||||
}
|
||||
|
||||
private fun backupAnimeSources(animes: List<Anime>): List<BackupAnimeSource> {
|
||||
private fun backupAnimeSources(animes: List<BackupAnime>): List<BackupAnimeSource> {
|
||||
return sourcesBackupCreator.backupAnimeSources(animes)
|
||||
}
|
||||
private fun backupMangaSources(mangas: List<Manga>): List<BackupSource> {
|
||||
private fun backupMangaSources(mangas: List<BackupManga>): List<BackupSource> {
|
||||
return sourcesBackupCreator.backupMangaSources(mangas)
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ data class BackupOptions(
|
|||
extensions,
|
||||
)
|
||||
|
||||
fun anyEnabled() = libraryEntries || appSettings || sourceSettings
|
||||
fun canCreate() = libraryEntries || categories || appSettings || sourceSettings
|
||||
|
||||
companion object {
|
||||
val libraryOptions = persistentListOf(
|
||||
|
@ -37,12 +37,6 @@ data class BackupOptions(
|
|||
getter = BackupOptions::libraryEntries,
|
||||
setter = { options, enabled -> options.copy(libraryEntries = enabled) },
|
||||
),
|
||||
Entry(
|
||||
label = MR.strings.categories,
|
||||
getter = BackupOptions::categories,
|
||||
setter = { options, enabled -> options.copy(categories = enabled) },
|
||||
enabled = { it.libraryEntries },
|
||||
),
|
||||
Entry(
|
||||
label = MR.strings.chapters_episodes,
|
||||
getter = BackupOptions::chapters,
|
||||
|
@ -61,6 +55,11 @@ data class BackupOptions(
|
|||
setter = { options, enabled -> options.copy(history = enabled) },
|
||||
enabled = { it.libraryEntries },
|
||||
),
|
||||
Entry(
|
||||
label = MR.strings.categories,
|
||||
getter = BackupOptions::categories,
|
||||
setter = { options, enabled -> options.copy(categories = enabled) },
|
||||
),
|
||||
)
|
||||
|
||||
val settingsOptions = persistentListOf(
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package eu.kanade.tachiyomi.data.backup.create.creators
|
||||
|
||||
import eu.kanade.tachiyomi.data.backup.models.BackupAnime
|
||||
import eu.kanade.tachiyomi.data.backup.models.BackupManga
|
||||
import eu.kanade.tachiyomi.animesource.AnimeSource
|
||||
import eu.kanade.tachiyomi.data.backup.models.BackupAnimeSource
|
||||
import eu.kanade.tachiyomi.data.backup.models.BackupSource
|
||||
import eu.kanade.tachiyomi.source.MangaSource
|
||||
import tachiyomi.domain.entries.anime.model.Anime
|
||||
import tachiyomi.domain.entries.manga.model.Manga
|
||||
import tachiyomi.domain.source.anime.service.AnimeSourceManager
|
||||
import tachiyomi.domain.source.manga.service.MangaSourceManager
|
||||
import uy.kohesive.injekt.Injekt
|
||||
|
@ -16,20 +16,20 @@ class SourcesBackupCreator(
|
|||
private val mangaSourceManager: MangaSourceManager = Injekt.get(),
|
||||
) {
|
||||
|
||||
fun backupAnimeSources(animes: List<Anime>): List<BackupAnimeSource> {
|
||||
fun backupAnimeSources(animes: List<BackupAnime>): List<BackupAnimeSource> {
|
||||
return animes
|
||||
.asSequence()
|
||||
.map(Anime::source)
|
||||
.map(BackupAnime::source)
|
||||
.distinct()
|
||||
.map(animeSourceManager::getOrStub)
|
||||
.map { it.toBackupSource() }
|
||||
.toList()
|
||||
}
|
||||
|
||||
fun backupMangaSources(mangas: List<Manga>): List<BackupSource> {
|
||||
fun backupMangaSources(mangas: List<BackupManga>): List<BackupSource> {
|
||||
return mangas
|
||||
.asSequence()
|
||||
.map(Manga::source)
|
||||
.map(BackupManga::source)
|
||||
.distinct()
|
||||
.map(mangaSourceManager::getOrStub)
|
||||
.map { it.toBackupSource() }
|
||||
|
|
|
@ -76,8 +76,11 @@ class BackupRestorer(
|
|||
val backupMangaMaps = backup.backupSources + backup.backupBrokenSources.map { it.toBackupSource() }
|
||||
mangaSourceMapping = backupMangaMaps.associate { it.sourceId to it.name }
|
||||
|
||||
if (options.library) {
|
||||
restoreAmount += backup.backupManga.size + backup.backupAnime.size + 2 // +2 for anime and manga categories
|
||||
if (options.libraryEntries) {
|
||||
restoreAmount += backup.backupManga.size + backup.backupAnime.size
|
||||
}
|
||||
if (options.categories) {
|
||||
restoreAmount += 2 // +2 for anime and manga categories
|
||||
}
|
||||
if (options.appSettings) {
|
||||
restoreAmount += 1
|
||||
|
@ -90,7 +93,7 @@ class BackupRestorer(
|
|||
}
|
||||
|
||||
coroutineScope {
|
||||
if (options.library) {
|
||||
if (options.categories) {
|
||||
restoreCategories(
|
||||
backupAnimeCategories = backup.backupAnimeCategories,
|
||||
backupMangaCategories = backup.backupCategories,
|
||||
|
@ -102,9 +105,9 @@ class BackupRestorer(
|
|||
if (options.sourceSettings) {
|
||||
restoreSourcePreferences(backup.backupSourcePreferences)
|
||||
}
|
||||
if (options.library) {
|
||||
restoreAnime(backup.backupAnime, backup.backupAnimeCategories)
|
||||
restoreManga(backup.backupManga, backup.backupCategories)
|
||||
if (options.libraryEntries) {
|
||||
restoreAnime(backup.backupAnime, if (options.categories) backup.backupAnimeCategories else emptyList())
|
||||
restoreManga(backup.backupManga, if (options.categories) backup.backupCategories else emptyList())
|
||||
}
|
||||
if (options.extensions) {
|
||||
restoreExtensions(backup.backupExtensions)
|
||||
|
|
|
@ -5,27 +5,34 @@ import kotlinx.collections.immutable.persistentListOf
|
|||
import tachiyomi.i18n.MR
|
||||
|
||||
data class RestoreOptions(
|
||||
val library: Boolean = true,
|
||||
val libraryEntries: Boolean = true,
|
||||
val categories: Boolean = true,
|
||||
val appSettings: Boolean = true,
|
||||
val sourceSettings: Boolean = true,
|
||||
val extensions: Boolean = false,
|
||||
) {
|
||||
|
||||
fun asBooleanArray() = booleanArrayOf(
|
||||
library,
|
||||
libraryEntries,
|
||||
categories,
|
||||
appSettings,
|
||||
sourceSettings,
|
||||
extensions,
|
||||
)
|
||||
|
||||
fun anyEnabled() = library || appSettings || sourceSettings || extensions
|
||||
fun canRestore() = libraryEntries || categories || appSettings || sourceSettings || extensions
|
||||
|
||||
companion object {
|
||||
val options = persistentListOf(
|
||||
Entry(
|
||||
label = MR.strings.label_library,
|
||||
getter = RestoreOptions::library,
|
||||
setter = { options, enabled -> options.copy(library = enabled) },
|
||||
getter = RestoreOptions::libraryEntries,
|
||||
setter = { options, enabled -> options.copy(libraryEntries = enabled) },
|
||||
),
|
||||
Entry(
|
||||
label = MR.strings.categories,
|
||||
getter = RestoreOptions::categories,
|
||||
setter = { options, enabled -> options.copy(categories = enabled) },
|
||||
),
|
||||
Entry(
|
||||
label = MR.strings.app_settings,
|
||||
|
@ -45,10 +52,11 @@ data class RestoreOptions(
|
|||
)
|
||||
|
||||
fun fromBooleanArray(array: BooleanArray) = RestoreOptions(
|
||||
library = array[0],
|
||||
appSettings = array[1],
|
||||
sourceSettings = array[2],
|
||||
extensions = array[3],
|
||||
libraryEntries = array[0],
|
||||
categories = array[1],
|
||||
appSettings = array[2],
|
||||
sourceSettings = array[3],
|
||||
extensions = array[4],
|
||||
)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue