Skip to content

Commit

Permalink
codinguser#879 - Reset ability to chose in default automatic backup f…
Browse files Browse the repository at this point in the history
…iles
  • Loading branch information
JeanGarf committed Jun 19, 2020
1 parent 0d2244d commit c33e829
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;


/**
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand All @@ -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);
}
}
6 changes: 3 additions & 3 deletions app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@
<string name="toast_disable_double_entry_to_save_transaction">Créer et spécifier un compte de transfert OU désactiver les doubles entrées dans les paramètres pour enregistrer la transaction</string>
<string name="label_tap_to_create_schedule">Appuyez sur pour créer le calendrier</string>
<string name="title_restore_backup">Restaurer Sauvegarde&#8230;</string>
<string name="header_backup_and_export_settings">Sauvegarde &amp; export</string>
<string name="header_backup_and_export_settings">Sauvegarde &amp; Export</string>
<string name="title_dropbox_sync_preference">Activer DropBox</string>
<string name="title_owncloud_sync_preference">Activer ownCloud </string>
<string name="title_backup_preference_category">Sauvegarde</string>
Expand All @@ -253,7 +253,7 @@
<string name="toast_backup_failed">Échec de la sauvegarde</string>
<string name="export_warning_xml">Exporte tous les comptes et les transactions</string>
<string name="toast_install_file_manager">Installez un gestionnaire de fichiers pour sélectionner les fichiers</string>
<string name="title_select_backup_to_restore">Sélectionnez une sauvegarde à restaurer</string>
<string name="title_select_backup_to_restore">Sélectionnez une sauvegarde à restaurer dans un nouveau Livre de Comptes</string>
<string name="nav_menu_favorites">Favoris</string>
<string name="nav_menu_open">Ouvrir&#8230;</string>
<string name="nav_menu_reports">Rapports</string>
Expand Down Expand Up @@ -435,7 +435,7 @@
<string name="btn_rename">Renommer</string>
<string name="menu_rename">Renommer</string>
<string name="title_select_backup_file">Choisir un fichier de sauvegarde</string>
<string name="summary_select_backup_file">Choisir un fichier pour les sauvegardes automatiques</string>
<string name="summary_select_backup_file">Choisir un fichier spécifique pour les sauvegardes</string>
<string name="title_confirm_restore_backup">Confirmer la restauration depuis la sauvegarde</string>
<string name="msg_confirm_restore_backup_into_new_book">Un nouveau livre sera ouvert avec le contenu de cette sauvegarde. Voulez-vous continuer?</string>
<string name="btn_restore">Restaurer</string>
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@
<string name="toast_disable_double_entry_to_save_transaction">Create and specify a transfer account OR disable double-entry in settings to save the transaction</string>
<string name="label_tap_to_create_schedule">Tap to create schedule</string>
<string name="title_restore_backup">Restore Backup…</string>
<string name="header_backup_and_export_settings">Backup &amp; export</string>
<string name="header_backup_and_export_settings">Backup &amp; Export</string>
<string name="title_dropbox_sync_preference">Enable DropBox</string>
<string name="title_owncloud_sync_preference">Enable ownCloud </string>
<string name="title_backup_preference_category">Backup</string>
Expand All @@ -263,7 +263,7 @@
<string name="toast_backup_failed">Backup failed</string>
<string name="export_warning_xml">Exports all accounts and transactions</string>
<string name="toast_install_file_manager">Install a file manager to select files</string>
<string name="title_select_backup_to_restore">Select backup to restore</string>
<string name="title_select_backup_to_restore">Select Backup to restore in another new Book</string>
<string name="nav_menu_favorites">Favorites</string>
<string name="nav_menu_open">Open…</string>
<string name="nav_menu_reports">Reports</string>
Expand Down Expand Up @@ -451,7 +451,7 @@
<string name="btn_rename">Rename</string>
<string name="menu_rename">Rename</string>
<string name="title_select_backup_file">Select backup file</string>
<string name="summary_select_backup_file">Select a file for automatic backups</string>
<string name="summary_select_backup_file">Select a specific file for backups</string>
<string name="title_confirm_restore_backup">Confirm restore from backup</string>
<string name="msg_confirm_restore_backup_into_new_book">A new book will be opened with the contents of this backup. Do you wish to proceed?</string>
<string name="btn_restore">Restore</string>
Expand Down

0 comments on commit c33e829

Please sign in to comment.