Merge pull request #366 from moritzgloeckl/gen_new_hotp_hidden

Instantly generate new code when showing hidden code for HOTP token
This commit is contained in:
Jakob Nixdorf 2019-10-20 12:48:50 +02:00 committed by GitHub
commit 266f0e4206
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 12 deletions

View file

@ -252,6 +252,8 @@ public class Entry {
return type == OTPType.TOTP || type == OTPType.STEAM;
}
public boolean isCounterBased() { return type == OTPType.HOTP; }
public OTPType getType() {
return type;
}

View file

@ -247,6 +247,9 @@ public class EntriesCardAdapter extends RecyclerView.Adapter<EntryViewHolder>
});
taskHandler.postDelayed(entries.get(realIndex).getHideTask(), settings.getTapToRevealTimeout() * 1000);
if (entry.isCounterBased()) {
updateEntry(entry, entries.get(realIndex), position);
}
entry.setVisible(true);
notifyItemChanged(position);
}
@ -255,18 +258,7 @@ public class EntriesCardAdapter extends RecyclerView.Adapter<EntryViewHolder>
@Override
public void onCounterClicked(int position) {
Entry entry = displayedEntries.get(position);
Entry realEntry = entries.get(getRealIndex(position));
long counter = entry.getCounter() + 1;
entry.setCounter(counter);
entry.updateOTP();
notifyItemChanged(position);
realEntry.setCounter(counter);
realEntry.updateOTP();
DatabaseHelper.saveDatabase(context, entries, encryptionKey);
updateEntry(displayedEntries.get(position), entries.get(getRealIndex(position)), position);
}
@Override
@ -278,6 +270,18 @@ public class EntriesCardAdapter extends RecyclerView.Adapter<EntryViewHolder>
return viewHolder;
}
private void updateEntry(Entry entry, Entry realEntry, final int position) {
long counter = entry.getCounter() + 1;
entry.setCounter(counter);
entry.updateOTP();
notifyItemChanged(position);
realEntry.setCounter(counter);
realEntry.updateOTP();
DatabaseHelper.saveDatabase(context, entries, encryptionKey);
}
private void hideEntry(Entry entry) {
int pos = displayedEntries.indexOf(entry);
int realIndex = entries.indexOf(entry);