From 0d2244df4e87f3415cb4f6ec41e268d282f7bb48 Mon Sep 17 00:00:00 2001 From: JeanGarf Date: Fri, 19 Jun 2020 10:16:09 +0200 Subject: [PATCH 1/2] #879 - Move Dropbox into Export Preference Section --- .../res/xml/fragment_backup_preferences.xml | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/app/src/main/res/xml/fragment_backup_preferences.xml b/app/src/main/res/xml/fragment_backup_preferences.xml index 9c2c0ad04..884c232e6 100644 --- a/app/src/main/res/xml/fragment_backup_preferences.xml +++ b/app/src/main/res/xml/fragment_backup_preferences.xml @@ -16,16 +16,24 @@ --> + - + + + + + + + + - - + + + + From c33e82977d34b5e23192574616c2415e829745d4 Mon Sep 17 00:00:00 2001 From: JeanGarf Date: Fri, 19 Jun 2020 10:16:27 +0200 Subject: [PATCH 2/2] #879 - Reset ability to chose in default automatic backup files --- .../ui/settings/BackupPreferenceFragment.java | 80 ++++++++++++++----- app/src/main/res/values-fr/strings.xml | 6 +- app/src/main/res/values/strings.xml | 6 +- 3 files changed, 64 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/org/gnucash/android/ui/settings/BackupPreferenceFragment.java b/app/src/main/java/org/gnucash/android/ui/settings/BackupPreferenceFragment.java index e92f83445..84022a059 100644 --- a/app/src/main/java/org/gnucash/android/ui/settings/BackupPreferenceFragment.java +++ b/app/src/main/java/org/gnucash/android/ui/settings/BackupPreferenceFragment.java @@ -55,10 +55,7 @@ import java.io.File; import java.text.DateFormat; import java.text.SimpleDateFormat; -import java.util.Arrays; -import java.util.Collections; import java.util.Date; -import java.util.List; /** @@ -150,10 +147,10 @@ public void onResume() { pref = findPreference(getString(R.string.key_backup_location)); pref.setOnPreferenceClickListener(this); - String defaultBackupLocation = BackupManager.getBookBackupFileUri(BooksDbAdapter.getInstance().getActiveBookUID()); - if (defaultBackupLocation != null){ - pref.setSummary(Uri.parse(defaultBackupLocation).getAuthority()); - } + String backupFileUri = BackupManager.getBookBackupFileUri(BooksDbAdapter.getInstance() + .getActiveBookUID()); + // Display backupFileUri + pref.setSummary(getBackupLocationSummary(backupFileUri)); pref = findPreference(getString(R.string.key_dropbox_sync)); pref.setOnPreferenceClickListener(this); @@ -438,13 +435,18 @@ public void onClick(DialogInterface dialog, int which) { } @Override - public void onActivityResult(int requestCode, int resultCode, Intent data) { - switch (requestCode){ + public void onActivityResult(int requestCode, + int resultCode, + Intent data) { + + switch (requestCode) { case REQUEST_LINK_TO_DBX: Preference preference = findPreference(getString(R.string.key_dropbox_sync)); if (preference == null) //if we are in a preference header fragment, this may return null + { break; + } toggleDropboxPreference(preference); break; @@ -453,31 +455,65 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { mGoogleApiClient.connect(); Preference pref = findPreference(getString(R.string.key_dropbox_sync)); if (pref == null) //if we are in a preference header fragment, this may return null + { break; + } toggleDropboxPreference(pref); } break; case REQUEST_BACKUP_FILE: - if (resultCode == Activity.RESULT_OK){ - Uri backupFileUri = null; - if (data != null){ - backupFileUri = data.getData(); - } + Uri backupFileUri = null; + + if (resultCode == Activity.RESULT_OK && data != null) { + // User has chosen a file - final int takeFlags = data.getFlags() - & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); - getActivity().getContentResolver().takePersistableUriPermission(backupFileUri, takeFlags); + backupFileUri = data.getData(); + + final int takeFlags = data.getFlags() & (Intent.FLAG_GRANT_READ_URI_PERMISSION + | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); + getActivity().getContentResolver() + .takePersistableUriPermission(backupFileUri, + takeFlags); PreferenceActivity.getActiveBookSharedPreferences() - .edit() - .putString(BackupManager.KEY_BACKUP_FILE, backupFileUri.toString()) - .apply(); + .edit() + .putString(BackupManager.KEY_BACKUP_FILE, + backupFileUri.toString()) + .apply(); + + } else { + // User has clicked on back button - Preference pref = findPreference(getString(R.string.key_backup_location)); - pref.setSummary(backupFileUri.getAuthority()); + // + // Reset ability to chose in default automatic backup files + // + + PreferenceActivity.getActiveBookSharedPreferences() + .edit() + .putString(BackupManager.KEY_BACKUP_FILE, + null) + .apply(); } + + // + // Update Pref Summary (i.e. pref sub-title) + // + + Preference pref = findPreference(getString(R.string.key_backup_location)); + pref.setSummary(getBackupLocationSummary(backupFileUri != null + ? backupFileUri.toString() + : null)); + break; } } + + public String getBackupLocationSummary(final String backupFileUri) { + + return (backupFileUri != null) + ? Uri.parse(backupFileUri) + .getAuthority() + : getString(R.string.summary_select_backup_file); + } } diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 9ab498501..812df71ad 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -239,7 +239,7 @@ Créer et spécifier un compte de transfert OU désactiver les doubles entrées dans les paramètres pour enregistrer la transaction Appuyez sur pour créer le calendrier Restaurer Sauvegarde… - Sauvegarde & export + Sauvegarde & Export Activer DropBox Activer ownCloud Sauvegarde @@ -253,7 +253,7 @@ Échec de la sauvegarde Exporte tous les comptes et les transactions Installez un gestionnaire de fichiers pour sélectionner les fichiers - Sélectionnez une sauvegarde à restaurer + Sélectionnez une sauvegarde à restaurer dans un nouveau Livre de Comptes Favoris Ouvrir… Rapports @@ -435,7 +435,7 @@ Renommer Renommer Choisir un fichier de sauvegarde - Choisir un fichier pour les sauvegardes automatiques + Choisir un fichier spécifique pour les sauvegardes Confirmer la restauration depuis la sauvegarde Un nouveau livre sera ouvert avec le contenu de cette sauvegarde. Voulez-vous continuer? Restaurer diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4ef7ae17e..0e88e430a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -249,7 +249,7 @@ Create and specify a transfer account OR disable double-entry in settings to save the transaction Tap to create schedule Restore Backup… - Backup & export + Backup & Export Enable DropBox Enable ownCloud Backup @@ -263,7 +263,7 @@ Backup failed Exports all accounts and transactions Install a file manager to select files - Select backup to restore + Select Backup to restore in another new Book Favorites Open… Reports @@ -451,7 +451,7 @@ Rename Rename Select backup file - Select a file for automatic backups + Select a specific file for backups Confirm restore from backup A new book will be opened with the contents of this backup. Do you wish to proceed? Restore