mirror of
https://github.com/aniyomiorg/aniyomi.git
synced 2024-11-29 09:39:03 +03:00
some more settings backup improvements
This commit is contained in:
parent
e2ad7ac82c
commit
7cc4ec277a
7 changed files with 64 additions and 7 deletions
|
@ -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<PreferencesHelper>()
|
||||
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<BackupCreatorJob>(
|
||||
|
@ -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)
|
||||
|
|
|
@ -87,7 +87,7 @@ class FullBackupManager(context: Context) : AbstractBackupManager(context) {
|
|||
backupExtensionInfo(databaseManga),
|
||||
emptyList(),
|
||||
backupAnimeExtensionInfo(databaseAnime),
|
||||
backupPreferences(prefs, flags)
|
||||
backupPreferences(prefs, flags),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,5 +14,5 @@ data class Backup(
|
|||
@ProtoNumber(101) var backupSources: List<BackupSource> = emptyList(),
|
||||
@ProtoNumber(102) var backupBrokenAnimeSources: List<BrokenBackupAnimeSource> = emptyList(),
|
||||
@ProtoNumber(103) var backupAnimeSources: List<BackupAnimeSource> = emptyList(),
|
||||
@ProtoNumber(104) var backupPreferences: List<BackupPreference> = emptyList()
|
||||
@ProtoNumber(104) var backupPreferences: List<BackupPreference> = emptyList(),
|
||||
)
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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<String>).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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,9 @@
|
|||
<string name="episodes">Episodes</string>
|
||||
<string name="track">Tracking</string>
|
||||
<string name="history">History</string>
|
||||
<string name="settings">Settings</string>
|
||||
|
||||
<string name="backup_settings_warning">Warning: Backing up settings will store your track passwords as well, do not share this backup file!</string>
|
||||
|
||||
<!-- Activities and fragments labels (toolbar title) -->
|
||||
<string name="label_more">More</string>
|
||||
|
@ -516,9 +519,11 @@
|
|||
<string name="pref_create_backup_summ">Can be used to restore current library</string>
|
||||
<string name="pref_restore_backup">Restore backup</string>
|
||||
<string name="pref_restore_backup_summ">Restore library from backup file</string>
|
||||
<string name="pref_backup_flags_summ">What information to include in the backup file</string>
|
||||
<string name="pref_backup_directory">Backup location</string>
|
||||
<string name="pref_backup_service_category">Automatic backups</string>
|
||||
<string name="pref_backup_interval">Backup frequency</string>
|
||||
<string name="pref_backup_flags">Backup options</string>
|
||||
<string name="pref_backup_slots">Maximum backups</string>
|
||||
<string name="source_not_found_name">Source not found: %1$s</string>
|
||||
<string name="tracker_not_logged_in">Not logged in: %1$s</string>
|
||||
|
|
Loading…
Reference in a new issue