mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-05-14 14:02:49 +00:00
Fix the last couple of issues with tap-to-reveal
This commit is contained in:
parent
c9b312a398
commit
14b8ba89c8
2 changed files with 27 additions and 30 deletions
|
@ -208,7 +208,7 @@ public class EntryAdapter extends RecyclerView.Adapter<EntryHolder> implements I
|
|||
@Override
|
||||
public void onClick(View v) {
|
||||
int position = holder.getAdapterPosition();
|
||||
if (_tapToReveal && !holder.codeIsRevealed()) {
|
||||
if (_tapToReveal && holder.isCodeHidden()) {
|
||||
holder.revealCode();
|
||||
} else {
|
||||
_listener.onEntryClick(_shownEntries.get(position));
|
||||
|
@ -227,7 +227,7 @@ public class EntryAdapter extends RecyclerView.Adapter<EntryHolder> implements I
|
|||
public void onClick(View v) {
|
||||
// this will only be called if the entry is of type HotpInfo
|
||||
try {
|
||||
((HotpInfo)entry.getInfo()).incrementCounter();
|
||||
((HotpInfo) entry.getInfo()).incrementCounter();
|
||||
} catch (OtpInfoException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
@ -267,12 +267,6 @@ public class EntryAdapter extends RecyclerView.Adapter<EntryHolder> implements I
|
|||
return period;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewDetachedFromWindow(final EntryHolder holder) {
|
||||
holder.hideCode();
|
||||
super.onViewDetachedFromWindow(holder);
|
||||
}
|
||||
|
||||
public boolean isPeriodUniform() {
|
||||
return getUniformPeriod() != -1;
|
||||
}
|
||||
|
|
|
@ -29,8 +29,7 @@ public class EntryHolder extends RecyclerView.ViewHolder {
|
|||
|
||||
private View _currentView;
|
||||
|
||||
private boolean _codeIsRevealed;
|
||||
private boolean _tapToReveal;
|
||||
private boolean _hidden;
|
||||
private int _tapToRevealTime;
|
||||
|
||||
private PeriodProgressBar _progressBar;
|
||||
|
@ -55,7 +54,7 @@ public class EntryHolder extends RecyclerView.ViewHolder {
|
|||
_refresher = new UiRefresher(new UiRefresher.Listener() {
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
if (!_tapToReveal) {
|
||||
if (!isCodeHidden()) {
|
||||
refreshCode();
|
||||
}
|
||||
|
||||
|
@ -71,9 +70,9 @@ public class EntryHolder extends RecyclerView.ViewHolder {
|
|||
_hiddenHandler = new Handler();
|
||||
}
|
||||
|
||||
public void setData(DatabaseEntry entry, boolean showAccountName, boolean showProgress, boolean tapToReveal) {
|
||||
public void setData(DatabaseEntry entry, boolean showAccountName, boolean showProgress, boolean hidden) {
|
||||
_entry = entry;
|
||||
_tapToReveal = tapToReveal;
|
||||
_hidden = hidden;
|
||||
|
||||
// only show the progress bar if there is no uniform period and the entry type is TotpInfo
|
||||
_progressBar.setVisibility(showProgress ? View.VISIBLE : View.GONE);
|
||||
|
@ -99,8 +98,11 @@ public class EntryHolder extends RecyclerView.ViewHolder {
|
|||
_profileDrawable.setImageDrawable(drawable);
|
||||
}
|
||||
|
||||
if (tapToReveal) {
|
||||
_profileCode.setText(_currentView.getContext().getResources().getString(R.string.tap_to_reveal));
|
||||
// cancel any scheduled hideCode calls
|
||||
_hiddenHandler.removeCallbacksAndMessages(null);
|
||||
|
||||
if (_hidden) {
|
||||
hideCode();
|
||||
} else {
|
||||
refreshCode();
|
||||
}
|
||||
|
@ -123,30 +125,31 @@ public class EntryHolder extends RecyclerView.ViewHolder {
|
|||
}
|
||||
|
||||
public void refreshCode() {
|
||||
if (!isCodeHidden()) {
|
||||
updateCode();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateCode() {
|
||||
String otp = _entry.getInfo().getOtp();
|
||||
String text = otp.substring(0, (otp.length() / 2)
|
||||
+ (otp.length() % 2)) + " "
|
||||
+ otp.substring(otp.length() / 2);
|
||||
_profileCode.setText(text);
|
||||
}
|
||||
|
||||
public void revealCode() {
|
||||
updateCode();
|
||||
_hiddenHandler.postDelayed(this::hideCode, _tapToRevealTime * 1000);
|
||||
_codeIsRevealed = true;
|
||||
_hidden = false;
|
||||
}
|
||||
|
||||
private void updateCode() {
|
||||
String otp = _entry.getInfo().getOtp();
|
||||
int offset = 0;
|
||||
if (otp.length() % 2 != 0) {
|
||||
offset = 1;
|
||||
}
|
||||
_profileCode.setText(otp.substring(0, (otp.length() / 2) + offset) + " " + otp.substring(otp.length() / 2));
|
||||
}
|
||||
|
||||
public void hideCode() {
|
||||
private void hideCode() {
|
||||
_profileCode.setText(_currentView.getContext().getResources().getString(R.string.tap_to_reveal));
|
||||
_codeIsRevealed = false;
|
||||
_hidden = true;
|
||||
}
|
||||
|
||||
public boolean codeIsRevealed() {
|
||||
return _codeIsRevealed;
|
||||
public boolean isCodeHidden() {
|
||||
return _hidden;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue