Move app backup to expert settings

This commit is contained in:
Torsten Grote 2024-09-17 17:33:41 -03:00
parent 9de1d2472b
commit 62991ed38b
No known key found for this signature in database
GPG key ID: 3E5F77D92CF891FF
5 changed files with 39 additions and 30 deletions

View file

@ -5,11 +5,15 @@
package com.stevesoltys.seedvault.settings
import android.app.backup.IBackupManager
import android.os.Bundle
import androidx.activity.result.contract.ActivityResultContracts.CreateDocument
import androidx.preference.Preference
import androidx.preference.Preference.OnPreferenceChangeListener
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.SwitchPreferenceCompat
import androidx.preference.TwoStatePreference
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.mms.ContentType.TEXT_PLAIN
import com.stevesoltys.seedvault.R
import com.stevesoltys.seedvault.permitDiskReads
@ -21,6 +25,9 @@ class ExpertSettingsFragment : PreferenceFragmentCompat() {
private val viewModel: SettingsViewModel by sharedViewModel()
private val packageService: PackageService by inject()
private val backupManager: IBackupManager by inject()
private lateinit var apkBackup: TwoStatePreference
private val createFileLauncher =
registerForActivityResult(CreateDocument(TEXT_PLAIN)) { uri ->
@ -32,6 +39,25 @@ class ExpertSettingsFragment : PreferenceFragmentCompat() {
setPreferencesFromResource(R.xml.settings_expert, rootKey)
}
apkBackup = findPreference(PREF_KEY_BACKUP_APK)!!
apkBackup.onPreferenceChangeListener = OnPreferenceChangeListener { _, newValue ->
val enable = newValue as Boolean
if (enable) return@OnPreferenceChangeListener true
MaterialAlertDialogBuilder(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 = false
dialog.dismiss()
}
.show()
return@OnPreferenceChangeListener false
}
findPreference<Preference>("logcat")?.setOnPreferenceClickListener {
val versionName = packageService.getVersionName(requireContext().packageName) ?: "ver"
val timestamp = System.currentTimeMillis()
@ -51,5 +77,6 @@ class ExpertSettingsFragment : PreferenceFragmentCompat() {
override fun onStart() {
super.onStart()
activity?.setTitle(R.string.settings_expert_title)
apkBackup.isEnabled = backupManager.isBackupEnabled
}
}

View file

@ -47,7 +47,6 @@ class SettingsFragment : PreferenceFragmentCompat() {
private lateinit var backup: TwoStatePreference
private lateinit var autoRestore: TwoStatePreference
private lateinit var apkBackup: TwoStatePreference
private lateinit var backupLocation: Preference
private lateinit var backupStatus: Preference
private lateinit var backupScheduling: Preference
@ -121,24 +120,6 @@ class SettingsFragment : PreferenceFragmentCompat() {
}
}
apkBackup = findPreference(PREF_KEY_BACKUP_APK)!!
apkBackup.onPreferenceChangeListener = OnPreferenceChangeListener { _, newValue ->
val enable = newValue as Boolean
if (enable) return@OnPreferenceChangeListener true
MaterialAlertDialogBuilder(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 = false
dialog.dismiss()
}
.show()
return@OnPreferenceChangeListener false
}
backupStatus = findPreference("backup_status")!!
backupScheduling = findPreference("backup_scheduling")!!

View file

@ -7,8 +7,9 @@ package com.stevesoltys.seedvault.ui
import android.app.Application
import androidx.lifecycle.AndroidViewModel
import com.stevesoltys.seedvault.crypto.KeyManager
import com.stevesoltys.seedvault.backend.BackendManager
import com.stevesoltys.seedvault.crypto.KeyManager
import com.stevesoltys.seedvault.permitDiskReads
import com.stevesoltys.seedvault.settings.SettingsManager
abstract class RequireProvisioningViewModel(
@ -26,7 +27,7 @@ abstract class RequireProvisioningViewModel(
internal fun validLocationIsSet() = backendManager.isValidAppPluginSet()
internal fun recoveryCodeIsSet() = keyManager.hasBackupKey()
internal fun recoveryCodeIsSet() = permitDiskReads { keyManager.hasBackupKey() }
open fun onStorageLocationChanged() {
// noop can be overwritten by sub-classes

View file

@ -43,13 +43,6 @@
app:title="@string/settings_auto_restore_title"
tools:defaultValue="true" />
<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:fragment="com.stevesoltys.seedvault.settings.SchedulingFragment"
app:icon="@drawable/ic_access_time"

View file

@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
<?xml version="1.0" encoding="utf-8"?><!--
SPDX-FileCopyrightText: 2020 The Calyx Institute
SPDX-License-Identifier: Apache-2.0
-->
@ -9,6 +8,14 @@
android:key="unlimited_quota"
android:summary="@string/settings_expert_quota_summary"
android:title="@string/settings_expert_quota_title" />
<SwitchPreferenceCompat
android:defaultValue="true"
android:icon="@drawable/ic_apps"
android:key="backup_apk"
android:summary="@string/settings_backup_apk_summary"
android:title="@string/settings_backup_apk_title" />
<Preference
android:icon="@drawable/ic_bug_report"
android:key="logcat"