Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#879 backup restore #881

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
20 changes: 15 additions & 5 deletions app/src/main/res/xml/fragment_backup_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,24 @@
-->

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >

<PreferenceCategory android:title="@string/title_backup_preference_category">
<Preference android:title="@string/title_select_backup_file"
android:key="@string/key_backup_location"
android:summary="@string/summary_select_backup_file" />

<Preference android:title="@string/title_create_backup_pref"
android:key="@string/key_create_backup"
android:summary="@string/summary_create_backup_pref" />

<Preference android:title="@string/title_restore_backup"
android:key="@string/key_restore_backup"
android:summary="@string/summary_restore_backup_pref" />

<Preference android:title="@string/title_select_backup_file"
android:key="@string/key_backup_location"
android:summary="@string/summary_select_backup_file" />

</PreferenceCategory>

<PreferenceCategory android:title="@string/title_export_preference_category">
<CheckBoxPreference android:title="@string/title_dropbox_sync_preference"
android:summary="@string/summary_dropbox_sync"
android:checked="false"
Expand All @@ -37,20 +45,22 @@
android:checked="false"
android:key="@string/key_owncloud_sync"
android:icon="@drawable/ic_owncloud" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/title_export_preference_category">

<ListPreference android:title="@string/title_default_export_format"
android:entryValues="@array/key_export_format_values"
android:entries="@array/export_formats"
android:key="@string/key_default_export_format"
android:summary="@string/summary_default_export_format"/>

<EditTextPreference android:title="@string/title_default_export_email"
android:key="@string/key_default_export_email"
android:summary="@string/summary_default_export_email"
android:inputType="textEmailAddress"/>

<android.support.v7.preference.SwitchPreferenceCompat android:summary="@string/hint_export_choice" android:key="@string/key_export_all_transactions" android:title="@string/title_export_all_transactions"/>

<android.support.v7.preference.SwitchPreferenceCompat android:summary="@string/hint_delete_after_export" android:key="@string/key_delete_transactions_after_export" android:title="@string/title_always_delete_exported_transactions"/>

<android.support.v7.preference.SwitchPreferenceCompat android:key="@string/key_xml_ofx_header" android:summary="@string/summary_xml_ofx_header" android:title="@string/title_xml_ofx_header"/>
</PreferenceCategory>

Expand Down