diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/data/CreateBackupScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/data/CreateBackupScreen.kt index a45fd374e5..fdadafb437 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/data/CreateBackupScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/data/CreateBackupScreen.kt @@ -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 @@ -68,7 +67,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 { @@ -103,7 +102,7 @@ class CreateBackupScreen : Screen() { } @Composable - private fun ColumnScope.Options( + private fun Options( options: ImmutableList, state: CreateBackupScreenModel.State, model: CreateBackupScreenModel, diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/data/RestoreBackupScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/data/RestoreBackupScreen.kt index 1e5e36169e..489ff96b4c 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/data/RestoreBackupScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/data/RestoreBackupScreen.kt @@ -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() diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/create/BackupCreator.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/create/BackupCreator.kt index 42c97ca9c5..406e3bac04 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/create/BackupCreator.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/create/BackupCreator.kt @@ -74,11 +74,11 @@ class BackupCreator( throw IllegalStateException(context.stringResource(MR.strings.create_backup_file_error)) } - val databaseManga = getFavorites.await() + val backupManga = backupMangas(getFavorites.await(), options) val backup = Backup( - backupManga = backupMangas(databaseManga, options), + backupManga = backupManga, backupCategories = backupCategories(options), - backupSources = backupSources(databaseManga), + backupSources = backupSources(backupManga), backupPreferences = backupAppPreferences(options), backupSourcePreferences = backupSourcePreferences(options), ) @@ -120,10 +120,12 @@ class BackupCreator( } private suspend fun backupMangas(mangas: List, options: BackupOptions): List { + if (!options.libraryEntries) return emptyList() + return mangaBackupCreator.backupMangas(mangas, options) } - private fun backupSources(mangas: List): List { + private fun backupSources(mangas: List): List { return sourcesBackupCreator.backupSources(mangas) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/create/BackupOptions.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/create/BackupOptions.kt index 868458b8a8..7130c25cfb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/create/BackupOptions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/create/BackupOptions.kt @@ -26,7 +26,7 @@ data class BackupOptions( privateSettings, ) - fun anyEnabled() = libraryEntries || appSettings || sourceSettings + fun canCreate() = libraryEntries || categories || appSettings || sourceSettings companion object { val libraryOptions = persistentListOf( @@ -35,12 +35,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, getter = BackupOptions::chapters, @@ -59,6 +53,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( diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/create/creators/SourcesBackupCreator.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/create/creators/SourcesBackupCreator.kt index 075e449a72..0052c2c938 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/create/creators/SourcesBackupCreator.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/create/creators/SourcesBackupCreator.kt @@ -1,8 +1,8 @@ package eu.kanade.tachiyomi.data.backup.create.creators +import eu.kanade.tachiyomi.data.backup.models.BackupManga import eu.kanade.tachiyomi.data.backup.models.BackupSource import eu.kanade.tachiyomi.source.Source -import tachiyomi.domain.manga.model.Manga import tachiyomi.domain.source.service.SourceManager import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get @@ -11,10 +11,10 @@ class SourcesBackupCreator( private val sourceManager: SourceManager = Injekt.get(), ) { - fun backupSources(mangas: List): List { + fun backupSources(mangas: List): List { return mangas .asSequence() - .map(Manga::source) + .map(BackupManga::source) .distinct() .map(sourceManager::getOrStub) .map { it.toBackupSource() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/restore/BackupRestorer.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/restore/BackupRestorer.kt index a17d33f43f..1c5a3a2d23 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/restore/BackupRestorer.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/restore/BackupRestorer.kt @@ -67,8 +67,11 @@ class BackupRestorer( val backupMaps = backup.backupSources + backup.backupBrokenSources.map { it.toBackupSource() } sourceMapping = backupMaps.associate { it.sourceId to it.name } - if (options.library) { - restoreAmount += backup.backupManga.size + 1 // +1 for categories + if (options.libraryEntries) { + restoreAmount += backup.backupManga.size + } + if (options.categories) { + restoreAmount += 1 } if (options.appSettings) { restoreAmount += 1 @@ -78,7 +81,7 @@ class BackupRestorer( } coroutineScope { - if (options.library) { + if (options.categories) { restoreCategories(backup.backupCategories) } if (options.appSettings) { @@ -87,8 +90,8 @@ class BackupRestorer( if (options.sourceSettings) { restoreSourcePreferences(backup.backupSourcePreferences) } - if (options.library) { - restoreManga(backup.backupManga, backup.backupCategories) + if (options.libraryEntries) { + restoreManga(backup.backupManga, if (options.categories) backup.backupCategories else emptyList()) } // TODO: optionally trigger online library + tracker update diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/restore/RestoreOptions.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/restore/RestoreOptions.kt index c824cb3d4f..30c34200d0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/restore/RestoreOptions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/restore/RestoreOptions.kt @@ -5,25 +5,32 @@ 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, ) { fun asBooleanArray() = booleanArrayOf( - library, + libraryEntries, + categories, appSettings, sourceSettings, ) - fun anyEnabled() = library || appSettings || sourceSettings + fun canRestore() = libraryEntries || categories || appSettings || sourceSettings 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, @@ -38,9 +45,10 @@ data class RestoreOptions( ) fun fromBooleanArray(array: BooleanArray) = RestoreOptions( - library = array[0], - appSettings = array[1], - sourceSettings = array[2], + libraryEntries = array[0], + categories = array[1], + appSettings = array[2], + sourceSettings = array[3], ) }