diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupCreatorJob.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupCreatorJob.kt index cff2ebde7..04a1e8fae 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupCreatorJob.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupCreatorJob.kt @@ -54,9 +54,12 @@ class BackupCreatorJob(private val context: Context, workerParams: WorkerParamet return list.find { it.state == WorkInfo.State.RUNNING } != null } - fun setupTask(context: Context, prefInterval: Int? = null) { + fun setupTask(context: Context, prefInterval: Int? = null, prefFlags: Int? = null) { val preferences = Injekt.get() val interval = prefInterval ?: preferences.backupInterval().get() + val flags = prefFlags ?: preferences.backupFlags().get().sumOf { s -> + s.toInt(16) + } val workManager = WorkManager.getInstance(context) if (interval > 0) { val request = PeriodicWorkRequestBuilder( @@ -66,7 +69,12 @@ class BackupCreatorJob(private val context: Context, workerParams: WorkerParamet TimeUnit.MINUTES, ) .addTag(TAG_AUTO) - .setInputData(workDataOf(IS_AUTO_BACKUP_KEY to true)) + .setInputData( + workDataOf( + IS_AUTO_BACKUP_KEY to true, + BACKUP_FLAGS_KEY to flags, + ) + ) .build() workManager.enqueueUniquePeriodicWork(TAG_AUTO, ExistingPeriodicWorkPolicy.REPLACE, request) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/FullBackupManager.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/FullBackupManager.kt index dcfb6ed21..8b8128034 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/FullBackupManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/FullBackupManager.kt @@ -87,7 +87,7 @@ class FullBackupManager(context: Context) : AbstractBackupManager(context) { backupExtensionInfo(databaseManga), emptyList(), backupAnimeExtensionInfo(databaseAnime), - backupPreferences(prefs, flags) + backupPreferences(prefs, flags), ) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/models/Backup.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/models/Backup.kt index 3794032b2..e281c4fd0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/models/Backup.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/models/Backup.kt @@ -14,5 +14,5 @@ data class Backup( @ProtoNumber(101) var backupSources: List = emptyList(), @ProtoNumber(102) var backupBrokenAnimeSources: List = emptyList(), @ProtoNumber(103) var backupAnimeSources: List = emptyList(), - @ProtoNumber(104) var backupPreferences: List = emptyList() + @ProtoNumber(104) var backupPreferences: List = emptyList(), ) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceValues.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceValues.kt index 28cadea0c..2fa35464b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceValues.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceValues.kt @@ -10,6 +10,12 @@ const val MANGA_NON_COMPLETED = "manga_ongoing" const val MANGA_HAS_UNREAD = "manga_fully_read" const val MANGA_NON_READ = "manga_started" +const val FLAG_CATEGORIES = "1" +const val FLAG_CHAPTERS = "2" +const val FLAG_HISTORY = "4" +const val FLAG_TRACK = "8" +const val FLAG_SETTINGS = "10" + /** * This class stores the values for the preferences in the application. */ diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index 9208dcd9b..93b524027 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -248,6 +248,7 @@ class PreferencesHelper(val context: Context) { fun numberOfBackups() = flowPrefs.getInt("backup_slots", 2) fun backupInterval() = flowPrefs.getInt("backup_interval", 0) + fun backupFlags() = flowPrefs.getStringSet("backup_flags", setOf(FLAG_CATEGORIES, FLAG_CHAPTERS, FLAG_HISTORY, FLAG_TRACK)) fun removeAfterReadSlots() = prefs.getInt(Keys.removeAfterReadSlots, -1) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt index 598bf533a..ff1cdfe5d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt @@ -26,12 +26,18 @@ import eu.kanade.tachiyomi.data.backup.ValidatorParseException import eu.kanade.tachiyomi.data.backup.full.FullBackupRestoreValidator import eu.kanade.tachiyomi.data.backup.full.models.BackupFull import eu.kanade.tachiyomi.data.backup.legacy.LegacyBackupRestoreValidator +import eu.kanade.tachiyomi.data.preference.FLAG_CATEGORIES +import eu.kanade.tachiyomi.data.preference.FLAG_CHAPTERS +import eu.kanade.tachiyomi.data.preference.FLAG_HISTORY +import eu.kanade.tachiyomi.data.preference.FLAG_SETTINGS +import eu.kanade.tachiyomi.data.preference.FLAG_TRACK import eu.kanade.tachiyomi.ui.base.controller.DialogController import eu.kanade.tachiyomi.ui.base.controller.requestPermissionsSafe import eu.kanade.tachiyomi.util.preference.bindTo import eu.kanade.tachiyomi.util.preference.entriesRes import eu.kanade.tachiyomi.util.preference.infoPreference import eu.kanade.tachiyomi.util.preference.intListPreference +import eu.kanade.tachiyomi.util.preference.multiSelectListPreference import eu.kanade.tachiyomi.util.preference.onChange import eu.kanade.tachiyomi.util.preference.onClick import eu.kanade.tachiyomi.util.preference.preference @@ -125,6 +131,34 @@ class SettingsBackupController : SettingsController() { true } } + multiSelectListPreference { + bindTo(preferences.backupFlags()) + titleRes = R.string.pref_backup_flags + summaryRes = R.string.pref_backup_flags_summ + entriesRes = arrayOf( + R.string.general_categories, + R.string.chapters_episodes, + R.string.track, + R.string.history, + R.string.settings, + ) + entryValues = arrayOf( + FLAG_CATEGORIES, + FLAG_CHAPTERS, + FLAG_TRACK, + FLAG_HISTORY, + FLAG_SETTINGS, + ) + + onChange { + val flags = (it as Set).sumOf { s -> + s.toInt(16) + } + if (flags and BackupConst.BACKUP_PREFS_MASK == BackupConst.BACKUP_PREFS) context.toast(R.string.backup_settings_warning) + BackupCreatorJob.setupTask(context, prefFlags = flags) + true + } + } preference { bindTo(preferences.backupsDirectory()) titleRes = R.string.pref_backup_directory @@ -229,10 +263,10 @@ class SettingsBackupController : SettingsController() { R.string.chapters_episodes, R.string.track, R.string.history, - R.string.label_settings, + R.string.settings, ) .map { activity.getString(it) } - val selected = options.map { true }.toBooleanArray() + val selected = options.mapIndexed { i, _ -> i <= 4 }.toBooleanArray() // Settings are disabled by default return MaterialAlertDialogBuilder(activity) .setTitle(R.string.backup_choice) @@ -252,7 +286,10 @@ class SettingsBackupController : SettingsController() { 2 -> flags = flags or BackupConst.BACKUP_CHAPTER 3 -> flags = flags or BackupConst.BACKUP_TRACK 4 -> flags = flags or BackupConst.BACKUP_HISTORY - 5 -> flags = flags or BackupConst.BACKUP_PREFS + 5 -> { + activity.toast(R.string.backup_settings_warning) + flags = flags or BackupConst.BACKUP_PREFS + } } } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 944acfb1a..afecccb16 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -14,6 +14,9 @@ Episodes Tracking History + Settings + + Warning: Backing up settings will store your track passwords as well, do not share this backup file! More @@ -516,9 +519,11 @@ Can be used to restore current library Restore backup Restore library from backup file + What information to include in the backup file Backup location Automatic backups Backup frequency + Backup options Maximum backups Source not found: %1$s Not logged in: %1$s