From 5d0aca1b4969a38cf51f666bd19bc7467fa81d05 Mon Sep 17 00:00:00 2001 From: t-m-w <7275539+t-m-w@users.noreply.github.com> Date: Tue, 3 Jan 2023 11:02:09 -0500 Subject: [PATCH] Warn before turning off backups Let the user know that turning off backups will require a new backup set to be created. Requires: https://github.com/seedvault-app/seedvault/pull/496 Change-Id: I22a1cebd272ac43cab6c68b99ace5919d6a7a9f5 --- .../seedvault/settings/SettingsFragment.kt | 38 +++++++++++++++---- app/src/main/res/values/strings.xml | 3 ++ 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/stevesoltys/seedvault/settings/SettingsFragment.kt b/app/src/main/java/com/stevesoltys/seedvault/settings/SettingsFragment.kt index 227e84d4..eb41bd95 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/settings/SettingsFragment.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/settings/SettingsFragment.kt @@ -63,14 +63,23 @@ class SettingsFragment : PreferenceFragmentCompat() { return@OnPreferenceChangeListener false } // main key is present, so enable or disable normally - try { - backupManager.isBackupEnabled = enabled - if (enabled) viewModel.enableCallLogBackup() - return@OnPreferenceChangeListener true - } catch (e: RemoteException) { - Log.e(TAG, "Error setting backup enabled to $enabled", e) - backup.isChecked = !enabled - return@OnPreferenceChangeListener false + when (enabled) { + true -> return@OnPreferenceChangeListener trySetBackupEnabled(true) + false -> { + AlertDialog.Builder(requireContext()) + .setIcon(R.drawable.ic_warning) + .setTitle(R.string.settings_backup_dialog_title) + .setMessage(R.string.settings_backup_dialog_message) + .setPositiveButton(R.string.settings_backup_dialog_disable) { dialog, _ -> + trySetBackupEnabled(false) + dialog.dismiss() + } + .setNegativeButton(R.string.settings_backup_apk_dialog_cancel) { dialog, + _ -> dialog.dismiss() + } + .show() + return@OnPreferenceChangeListener false + } } } @@ -189,6 +198,19 @@ class SettingsFragment : PreferenceFragmentCompat() { else -> super.onOptionsItemSelected(item) } + private fun trySetBackupEnabled(enabled: Boolean): Boolean { + return try { + backupManager.isBackupEnabled = enabled + if (enabled) viewModel.enableCallLogBackup() + backup.isChecked = enabled + true + } catch (e: RemoteException) { + Log.e(TAG, "Error setting backup enabled to $enabled", e) + backup.isChecked = !enabled + false + } + } + private fun setBackupEnabledState() { try { backup.isChecked = backupManager.isBackupEnabled diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b4976db9..428a2b24 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -14,6 +14,9 @@ None Internal storage Never + Really turn off app backups? + When you turn backups on again, the backup process may take longer than usual, and it will use additional storage space. + Turn off anyway All backups are encrypted on your phone. To restore from backup you will need your 12-word recovery code. Automatic restore When reinstalling an app, restore backed up settings and data.