Add option to auto backup on any edits to entries

This commit is contained in:
RichyHBM 2019-11-02 11:44:42 +00:00
parent 4f76f6a01d
commit 70a194ca5c
7 changed files with 48 additions and 18 deletions

View file

@ -148,7 +148,7 @@ public class SettingsActivity extends BaseActivity
if (fragment.useAutoBackup != null) {
fragment.useAutoBackup.setEnabled(BackupHelper.autoBackupType(this) == Constants.BackupType.ENCRYPTED);
if (!fragment.useAutoBackup.isEnabled())
fragment.useAutoBackup.setChecked(false);
fragment.useAutoBackup.setValue(Constants.AutoBackup.OFF.toString());
}
}
@ -243,7 +243,7 @@ public class SettingsActivity extends BaseActivity
Settings settings;
ListPreference encryption;
CheckBoxPreference useAutoBackup;
ListPreference useAutoBackup;
CheckBoxPreference useAndroidSync;
OpenPgpAppPreference pgpProvider;
@ -352,10 +352,10 @@ public class SettingsActivity extends BaseActivity
}
});
useAutoBackup = (CheckBoxPreference) findPreference(getString(R.string.settings_key_auto_backup_password_enc));
useAutoBackup = (ListPreference)findPreference(getString(R.string.settings_key_auto_backup_password_enc));
useAutoBackup.setEnabled(BackupHelper.autoBackupType(getActivity()) == Constants.BackupType.ENCRYPTED);
if(!useAutoBackup.isEnabled())
useAutoBackup.setChecked(false);
useAutoBackup.setValue(Constants.AutoBackup.OFF.toString());
useAndroidSync = (CheckBoxPreference) findPreference(getString(R.string.settings_key_enable_android_backup_service));
useAndroidSync.setEnabled(settings.getEncryption() == EncryptionType.PASSWORD);

View file

@ -60,6 +60,10 @@ public class Constants {
DEFAULT, FULL
}
public enum AutoBackup {
OFF, NEW_ENTRIES, ALL_EDITS
}
// Intents (Format: A0x with A = parent Activity, x = number of the intent)
public final static int INTENT_MAIN_AUTHENTICATE = 100;
public final static int INTENT_MAIN_SETTINGS = 101;

View file

@ -543,8 +543,17 @@ public class Settings {
return getBoolean(R.string.settings_key_backup_append_date_time, false);
}
private Constants.AutoBackup getAutoBackupEncryptedSetting() {
String stringValue = getString(R.string.settings_key_auto_backup_password_enc, R.string.settings_default_auto_backup_password_enc);
return Constants.AutoBackup.valueOf(stringValue.toUpperCase(Locale.ENGLISH));
}
public boolean getAutoBackupEncryptedPasswordsEnabled() {
return getBoolean(R.string.settings_key_auto_backup_password_enc, false);
return getAutoBackupEncryptedSetting() != Constants.AutoBackup.OFF;
}
public boolean getAutoBackupEncryptedFullEnabled() {
return getAutoBackupEncryptedSetting() == Constants.AutoBackup.ALL_EDITS;
}
public boolean isHighlightTokenOptionEnabled() {

View file

@ -119,7 +119,7 @@ public class EntriesCardAdapter extends RecyclerView.Adapter<EntryViewHolder>
if (! entries.contains(e)) {
entries.add(e);
entriesChanged();
saveEntries(true);
saveEntries(settings.getAutoBackupEncryptedPasswordsEnabled() || settings.getAutoBackupEncryptedFullEnabled());
} else {
Toast.makeText(context, R.string.toast_entry_exists, Toast.LENGTH_LONG).show();
}
@ -138,7 +138,7 @@ public class EntriesCardAdapter extends RecyclerView.Adapter<EntryViewHolder>
public void saveEntries(boolean auto_backup) {
DatabaseHelper.saveDatabase(context, entries, encryptionKey);
if(auto_backup && settings.getAutoBackupEncryptedPasswordsEnabled()) {
if(auto_backup) {
Constants.BackupType backupType = BackupHelper.autoBackupType(context);
if (backupType == Constants.BackupType.ENCRYPTED) {
Uri backupFilename = Tools.buildUri(settings.getBackupDir(), BackupHelper.backupFilename(context, Constants.BackupType.ENCRYPTED));
@ -321,7 +321,7 @@ public class EntriesCardAdapter extends RecyclerView.Adapter<EntryViewHolder>
realEntry.setCounter(counter);
realEntry.updateOTP();
saveEntries(false);
saveEntries(settings.getAutoBackupEncryptedFullEnabled());
}
private void hideEntry(Entry entry) {
@ -374,7 +374,7 @@ public class EntriesCardAdapter extends RecyclerView.Adapter<EntryViewHolder>
Entry e = entries.get(realIndex);
e.setCounter(newCounter);
saveEntries(false);
saveEntries(settings.getAutoBackupEncryptedFullEnabled());
}
})
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@ -392,7 +392,7 @@ public class EntriesCardAdapter extends RecyclerView.Adapter<EntryViewHolder>
displayedEntries.get(position).setLastUsed(timeStamp);
entries.get(realIndex).setLastUsed(timeStamp);
saveEntries(false);
saveEntries(settings.getAutoBackupEncryptedFullEnabled());
if (sortMode == SortMode.LAST_USED) {
displayedEntries = sortEntries(displayedEntries);
@ -411,7 +411,7 @@ public class EntriesCardAdapter extends RecyclerView.Adapter<EntryViewHolder>
displayedEntries = new ArrayList<>(entries);
notifyItemMoved(fromPosition, toPosition);
saveEntries(false);
saveEntries(settings.getAutoBackupEncryptedFullEnabled());
}
return true;
@ -496,7 +496,7 @@ public class EntriesCardAdapter extends RecyclerView.Adapter<EntryViewHolder>
Entry e = entries.get(realIndex);
e.setLabel(newLabel);
saveEntries(false);
saveEntries(settings.getAutoBackupEncryptedFullEnabled());
}
})
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@ -582,7 +582,7 @@ public class EntriesCardAdapter extends RecyclerView.Adapter<EntryViewHolder>
Entry e = entries.get(realIndex);
e.setThumbnail(thumbnail);
saveEntries(false);
saveEntries(settings.getAutoBackupEncryptedFullEnabled());
notifyItemChanged(pos);
alert.cancel();
}
@ -610,7 +610,7 @@ public class EntriesCardAdapter extends RecyclerView.Adapter<EntryViewHolder>
@Override
public Object call() throws Exception {
entries.get(realPos).setTags(tagsAdapter.getActiveTags());
saveEntries(false);
saveEntries(settings.getAutoBackupEncryptedFullEnabled());
List<String> inUseTags = getTags();
@ -655,7 +655,7 @@ public class EntriesCardAdapter extends RecyclerView.Adapter<EntryViewHolder>
notifyItemRemoved(pos);
entries.remove(realIndex);
saveEntries(false);
saveEntries(settings.getAutoBackupEncryptedFullEnabled());
}
})
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {

View file

@ -65,6 +65,7 @@
<string name="settings_default_thumbnail_size" translatable="false">46dp</string>
<string name="settings_default_split_group_size" translatable="false">3</string>
<string name="settings_default_tag_functionality" translatable="false">or</string>
<string name="settings_default_auto_backup_password_enc" translatable="false">off</string>
<string-array name="settings_defaults_search_includes">
<item>label</item>
@ -105,6 +106,14 @@
<item>tags</item>
</string-array>
<string-array name="settings_values_auto_backup_password_enc" translatable="false">
<item>OFF</item>
<item>NEW_ENTRIES</item>
<item>ALL_EDITS</item>
</string-array>
<string-array name="settings_values_locale" translatable="false">
<item>system</item>
<item>ca_ES</item>

View file

@ -68,7 +68,7 @@
backups</string>
<string name="settings_desc_auto_backup_password_enc">Creates a new encrypted backup when new
entries are added if settings conditions are met</string>
entries are added, or edited, if settings conditions are met</string>
<string name="settings_desc_backup_broadcasts">Select which backup types can be triggered by
3rd-party apps using Broadcasts</string>
@ -167,6 +167,12 @@
<item>Tags</item>
</string-array>
<string-array name="settings_entries_auto_backup_password_enc">
<item>Off</item>
<item>New Entries</item>
<item>Any Edits</item>
</string-array>
<string-array name="settings_entries_theme">
<item>Light theme</item>
<item>Dark theme</item>

View file

@ -163,11 +163,13 @@
android:title="@string/settings_title_backup_password"
android:summary="@string/settings_desc_backup_password" />
<CheckBoxPreference
<ListPreference
android:key="@string/settings_key_auto_backup_password_enc"
android:title="@string/settings_title_auto_backup_password_enc"
android:summary="@string/settings_desc_auto_backup_password_enc"
android:defaultValue="false" />
android:entries="@array/settings_entries_auto_backup_password_enc"
android:entryValues="@array/settings_values_auto_backup_password_enc"
android:defaultValue="@string/settings_default_auto_backup_password_enc" />
<MultiSelectListPreference
android:key="@string/settings_key_backup_broadcasts"