Skip to content

Commit

Permalink
Backup when import?
Browse files Browse the repository at this point in the history
  • Loading branch information
pnemonic78 committed Feb 2, 2025
1 parent e605785 commit 2fa36db
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 3 deletions.
12 changes: 12 additions & 0 deletions app/src/main/java/org/gnucash/android/app/GnuCashApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,18 @@ public static boolean shouldBackupTransactions(Context context) {
return sharedPrefs.getBoolean(context.getString(R.string.key_delete_transaction_backup), true);
}

/**
* Returns <code>true</code> if setting is enabled to backup the book before importing a book,
* <code>false</code> otherwise.
*
* @param context The context.
* @return <code>true</code> if the book should be backed-up.
*/
public static boolean shouldBackupForImport(Context context) {
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
return sharedPrefs.getBoolean(context.getString(R.string.key_import_book_backup), true);
}

/**
* Get the default transaction type.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,8 @@ public static void startXmlFileChooser(Fragment fragment) {
* @param onFinishTask Task to be executed when import is complete
*/
public static void importXmlFileFromIntent(Activity context, Intent data, TaskDelegate onFinishTask) {
new ImportAsyncTask(context, onFinishTask, true).execute(data.getData());
boolean backup = GnuCashApplication.shouldBackupForImport(context);
new ImportAsyncTask(context, onFinishTask, backup).execute(data.getData());
}

/**
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/donottranslate.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<string name="key_backup_location" translatable="false">backup_location</string>
<string name="key_export_accounts_csv" translatable="false">export_accounts_csv_key</string>
<string name="key_delete_transaction_backup" translatable="false">delete_transaction_backup</string>
<string name="key_import_book_backup" translatable="false">import_book_backup</string>
<!-- This is the filename for default backups. So use only simple characters and no spaces. Do not change the extension -->
<string name="label_backup_filename" translatable="false">gnucash_pocket_backup.gnca</string>
<string-array name="key_account_type_entries" translatable="false">
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,10 @@
<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>
<string name="title_delete_transaction_backup">When delete transaction?</string>
<string name="summary_delete_transaction_backup">Backup active book when delete a transaction?</string>
<string name="title_delete_transaction_backup">When deleting a transaction?</string>
<string name="summary_delete_transaction_backup">Backup the active book before deleting a transaction?</string>
<string name="title_import_book_backup">When importing a book?</string>
<string name="summary_import_book_backup">Backup the active book before importing a book?</string>
<string name="summary_dropbox_sync">Enable exporting to DropBox</string>
<string name="summary_owncloud_sync">Enable exporting to ownCloud</string>
<string name="title_backup_prefs">Backup Preferences</string>
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/xml/fragment_backup_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@
android:key="@string/key_delete_transaction_backup"
android:summary="@string/summary_delete_transaction_backup"
android:title="@string/title_delete_transaction_backup" />

<androidx.preference.SwitchPreference
android:defaultValue="true"
android:key="@string/key_import_book_backup"
android:summary="@string/summary_import_book_backup"
android:title="@string/title_import_book_backup" />
</androidx.preference.PreferenceCategory>
<androidx.preference.PreferenceCategory android:title="@string/title_export_preference_category">

Expand Down

0 comments on commit 2fa36db

Please sign in to comment.