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 1506682a..0afc43fe 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/settings/SettingsFragment.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/settings/SettingsFragment.kt @@ -18,6 +18,7 @@ import android.util.Log import android.view.Menu import android.view.MenuInflater import android.view.MenuItem +import androidx.appcompat.app.AlertDialog import androidx.lifecycle.Observer import androidx.preference.Preference import androidx.preference.Preference.OnPreferenceChangeListener @@ -40,6 +41,7 @@ class SettingsFragment : PreferenceFragmentCompat() { private lateinit var backup: TwoStatePreference private lateinit var autoRestore: TwoStatePreference + private lateinit var apkBackup: TwoStatePreference private lateinit var backupLocation: Preference private var menuBackupNow: MenuItem? = null @@ -95,6 +97,25 @@ class SettingsFragment : PreferenceFragmentCompat() { } } + apkBackup = findPreference(PREF_KEY_BACKUP_APK)!! + apkBackup.onPreferenceChangeListener = OnPreferenceChangeListener { _, newValue -> + val enable = newValue as Boolean + if (enable) return@OnPreferenceChangeListener true + AlertDialog.Builder(requireContext()) + .setIcon(R.drawable.ic_warning) + .setTitle(R.string.settings_backup_apk_dialog_title) + .setMessage(R.string.settings_backup_apk_dialog_message) + .setPositiveButton(R.string.settings_backup_apk_dialog_cancel) { dialog, _ -> + dialog.dismiss() + } + .setNegativeButton(R.string.settings_backup_apk_dialog_disable) { dialog, _ -> + apkBackup.isChecked = enable + dialog.dismiss() + } + .show() + return@OnPreferenceChangeListener false + } + viewModel.lastBackupTime.observe(this, Observer { time -> setBackupLocationSummary(time) }) } diff --git a/app/src/main/java/com/stevesoltys/seedvault/settings/SettingsManager.kt b/app/src/main/java/com/stevesoltys/seedvault/settings/SettingsManager.kt index fc43c987..52202e23 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/settings/SettingsManager.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/settings/SettingsManager.kt @@ -7,6 +7,8 @@ import androidx.documentfile.provider.DocumentFile import androidx.preference.PreferenceManager import java.util.concurrent.atomic.AtomicBoolean +internal const val PREF_KEY_BACKUP_APK = "backup_apk" + private const val PREF_KEY_STORAGE_URI = "storageUri" private const val PREF_KEY_STORAGE_NAME = "storageName" private const val PREF_KEY_STORAGE_IS_USB = "storageIsUsb" @@ -71,8 +73,7 @@ class SettingsManager(context: Context) { } fun backupApks(): Boolean { - // TODO - return true + return prefs.getBoolean(PREF_KEY_BACKUP_APK, true) } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f546fcd3..427d5f73 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -18,6 +18,12 @@ 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 + App backup + Back up the apps themselves. Otherwise, only app data would get backed up. + Really disable app backup? + Disabled app backup will still back up app data. However, it will not get restored automatically.\n\nYou will need to install all your apps manually while having \"Automatic Restore\" switched on. + Cancel + Disable app backup Backup now diff --git a/app/src/main/res/xml/settings.xml b/app/src/main/res/xml/settings.xml index d19a6063..7a19a7b7 100644 --- a/app/src/main/res/xml/settings.xml +++ b/app/src/main/res/xml/settings.xml @@ -20,6 +20,13 @@ app:summary="@string/settings_auto_restore_summary" app:title="@string/settings_auto_restore_title" /> + +