Expose APK backup feature as a setting, so the user can disable it

The user might not want to have their apps copied to the storage,
because it is very slow or for other reasons.
This commit is contained in:
Torsten Grote 2019-12-30 15:26:03 -03:00
parent 7605762631
commit f562857514
No known key found for this signature in database
GPG key ID: 3E5F77D92CF891FF
4 changed files with 37 additions and 2 deletions

View file

@ -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) })
}

View file

@ -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)
}
}

View file

@ -18,6 +18,12 @@
<string name="settings_info">All backups are encrypted on your phone. To restore from backup you will need your 12-word recovery code.</string>
<string name="settings_auto_restore_title">Automatic restore</string>
<string name="settings_auto_restore_summary">When reinstalling an app, restore backed up settings and data</string>
<string name="settings_backup_apk_title">App backup</string>
<string name="settings_backup_apk_summary">Back up the apps themselves. Otherwise, only app data would get backed up.</string>
<string name="settings_backup_apk_dialog_title">Really disable app backup?</string>
<string name="settings_backup_apk_dialog_message">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.</string>
<string name="settings_backup_apk_dialog_cancel">Cancel</string>
<string name="settings_backup_apk_dialog_disable">Disable app backup</string>
<string name="settings_backup_now">Backup now</string>
<!-- Storage -->

View file

@ -20,6 +20,13 @@
app:summary="@string/settings_auto_restore_summary"
app:title="@string/settings_auto_restore_title" />
<androidx.preference.SwitchPreferenceCompat
app:defaultValue="true"
app:dependency="backup"
app:key="backup_apk"
app:summary="@string/settings_backup_apk_summary"
app:title="@string/settings_backup_apk_title" />
<androidx.preference.Preference
app:allowDividerAbove="true"
app:allowDividerBelow="false"