diff --git a/app/src/main/java/org/shadowice/flocke/andotp/Activities/MainActivity.java b/app/src/main/java/org/shadowice/flocke/andotp/Activities/MainActivity.java index b7de7cd9..a91a943b 100644 --- a/app/src/main/java/org/shadowice/flocke/andotp/Activities/MainActivity.java +++ b/app/src/main/java/org/shadowice/flocke/andotp/Activities/MainActivity.java @@ -379,7 +379,6 @@ public class MainActivity extends BaseActivity e.updateOTP(); e.setLastUsed(System.currentTimeMillis()); adapter.addEntry(e); - adapter.saveEntries(); refreshTags(); } catch (Exception e) { Toast.makeText(this, R.string.toast_invalid_qr_code, Toast.LENGTH_LONG).show(); diff --git a/app/src/main/java/org/shadowice/flocke/andotp/View/EntriesCardAdapter.java b/app/src/main/java/org/shadowice/flocke/andotp/View/EntriesCardAdapter.java index 762fb5d8..b735c655 100644 --- a/app/src/main/java/org/shadowice/flocke/andotp/View/EntriesCardAdapter.java +++ b/app/src/main/java/org/shadowice/flocke/andotp/View/EntriesCardAdapter.java @@ -119,6 +119,7 @@ public class EntriesCardAdapter extends RecyclerView.Adapter if (! entries.contains(e)) { entries.add(e); entriesChanged(); + saveEntries(true); } else { Toast.makeText(context, R.string.toast_entry_exists, Toast.LENGTH_LONG).show(); } @@ -134,10 +135,10 @@ public class EntriesCardAdapter extends RecyclerView.Adapter notifyDataSetChanged(); } - public void saveEntries() { + public void saveEntries(boolean auto_backup) { DatabaseHelper.saveDatabase(context, entries, encryptionKey); - if(settings.getAutoBackupEncryptedPasswordsEnabled()) { + if(auto_backup && settings.getAutoBackupEncryptedPasswordsEnabled()) { Constants.BackupType backupType = BackupHelper.autoBackupType(context); if (backupType == Constants.BackupType.ENCRYPTED) { Uri backupFilename = Tools.buildUri(settings.getBackupDir(), BackupHelper.backupFilename(context, Constants.BackupType.ENCRYPTED)); @@ -286,7 +287,7 @@ public class EntriesCardAdapter extends RecyclerView.Adapter realEntry.setCounter(counter); realEntry.updateOTP(); - DatabaseHelper.saveDatabase(context, entries, encryptionKey); + saveEntries(false); } @Override @@ -348,7 +349,7 @@ public class EntriesCardAdapter extends RecyclerView.Adapter Entry e = entries.get(realIndex); e.setCounter(newCounter); - DatabaseHelper.saveDatabase(context, entries, encryptionKey); + saveEntries(false); } }) .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @@ -366,7 +367,7 @@ public class EntriesCardAdapter extends RecyclerView.Adapter displayedEntries.get(position).setLastUsed(timeStamp); entries.get(realIndex).setLastUsed(timeStamp); - DatabaseHelper.saveDatabase(context, entries, encryptionKey); + saveEntries(false); if (sortMode == SortMode.LAST_USED) { displayedEntries = sortEntries(displayedEntries); @@ -385,7 +386,7 @@ public class EntriesCardAdapter extends RecyclerView.Adapter displayedEntries = new ArrayList<>(entries); notifyItemMoved(fromPosition, toPosition); - DatabaseHelper.saveDatabase(context, entries, encryptionKey); + saveEntries(false); } return true; @@ -425,7 +426,7 @@ public class EntriesCardAdapter extends RecyclerView.Adapter Entry e = entries.get(realIndex); e.setLabel(newLabel); - DatabaseHelper.saveDatabase(context, entries, encryptionKey); + saveEntries(false); } }) .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @@ -511,7 +512,7 @@ public class EntriesCardAdapter extends RecyclerView.Adapter Entry e = entries.get(realIndex); e.setThumbnail(thumbnail); - DatabaseHelper.saveDatabase(context, entries, encryptionKey); + saveEntries(false); notifyItemChanged(pos); alert.cancel(); } @@ -539,7 +540,7 @@ public class EntriesCardAdapter extends RecyclerView.Adapter @Override public Object call() throws Exception { entries.get(realPos).setTags(tagsAdapter.getActiveTags()); - DatabaseHelper.saveDatabase(context, entries, encryptionKey); + saveEntries(false); List inUseTags = getTags(); @@ -584,7 +585,7 @@ public class EntriesCardAdapter extends RecyclerView.Adapter notifyItemRemoved(pos); entries.remove(realIndex); - DatabaseHelper.saveDatabase(context, entries, encryptionKey); + saveEntries(false); } }) .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { diff --git a/app/src/main/java/org/shadowice/flocke/andotp/View/ManualEntryDialog.java b/app/src/main/java/org/shadowice/flocke/andotp/View/ManualEntryDialog.java index 52fae359..74a49e16 100644 --- a/app/src/main/java/org/shadowice/flocke/andotp/View/ManualEntryDialog.java +++ b/app/src/main/java/org/shadowice/flocke/andotp/View/ManualEntryDialog.java @@ -203,7 +203,6 @@ public class ManualEntryDialog { e.updateOTP(); e.setLastUsed(System.currentTimeMillis()); adapter.addEntry(e); - adapter.saveEntries(); callingActivity.refreshTags(); } else if (type == Entry.OTPType.HOTP) { @@ -213,7 +212,6 @@ public class ManualEntryDialog { e.updateOTP(); e.setLastUsed(System.currentTimeMillis()); adapter.addEntry(e); - adapter.saveEntries(); } } })