mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-05-15 22:42:51 +00:00
Make the behavior of highlighting and revealing entries consistent
I think this makes the highlight/reveal functionality feel a bit more consistent, by not allowing multiple entries to be revealed at the same time, just like you can't have multiple highlighted entries. Here's video of what it looks like: https://alexbakker.me/u/3a9dhplrj2.mp4.
This commit is contained in:
parent
a93ced6e34
commit
a6a5af781e
2 changed files with 41 additions and 47 deletions
|
@ -27,7 +27,7 @@ public class EntryAdapter extends RecyclerView.Adapter<EntryHolder> implements I
|
||||||
private List<DatabaseEntry> _entries;
|
private List<DatabaseEntry> _entries;
|
||||||
private List<DatabaseEntry> _shownEntries;
|
private List<DatabaseEntry> _shownEntries;
|
||||||
private DatabaseEntry _selectedEntry;
|
private DatabaseEntry _selectedEntry;
|
||||||
private DatabaseEntry _highlightedEntry;
|
private DatabaseEntry _focusedEntry;
|
||||||
private boolean _showAccountName;
|
private boolean _showAccountName;
|
||||||
private boolean _searchAccountName;
|
private boolean _searchAccountName;
|
||||||
private boolean _highlightEntry;
|
private boolean _highlightEntry;
|
||||||
|
@ -304,10 +304,10 @@ public class EntryAdapter extends RecyclerView.Adapter<EntryHolder> implements I
|
||||||
DatabaseEntry entry = _shownEntries.get(position);
|
DatabaseEntry entry = _shownEntries.get(position);
|
||||||
holder.setFocused(entry == _selectedEntry);
|
holder.setFocused(entry == _selectedEntry);
|
||||||
|
|
||||||
boolean dimmed = _highlightedEntry != null && _highlightedEntry != entry;
|
boolean hidden = _tapToReveal && entry != _focusedEntry;
|
||||||
|
boolean dimmed = _highlightEntry && _focusedEntry != null && _focusedEntry != entry;
|
||||||
boolean showProgress = !isPeriodUniform() && entry.getInfo() instanceof TotpInfo;
|
boolean showProgress = !isPeriodUniform() && entry.getInfo() instanceof TotpInfo;
|
||||||
holder.setData(entry, _showAccountName, showProgress, _tapToReveal, dimmed);
|
holder.setData(entry, _showAccountName, showProgress, hidden, dimmed);
|
||||||
holder.setTapToRevealTime(_tapToRevealTime);
|
|
||||||
holder.loadIcon(_view);
|
holder.loadIcon(_view);
|
||||||
|
|
||||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@ -316,16 +316,12 @@ public class EntryAdapter extends RecyclerView.Adapter<EntryHolder> implements I
|
||||||
boolean handled = false;
|
boolean handled = false;
|
||||||
|
|
||||||
if (_selectedEntry == null) {
|
if (_selectedEntry == null) {
|
||||||
if (_tapToReveal && holder.isCodeHidden()) {
|
if (_highlightEntry || _tapToReveal) {
|
||||||
holder.revealCode();
|
if (_focusedEntry == entry) {
|
||||||
}
|
resetFocus();
|
||||||
|
|
||||||
if (_highlightEntry) {
|
|
||||||
if (_highlightedEntry == entry) {
|
|
||||||
resetHighlight();
|
|
||||||
handled = true;
|
handled = true;
|
||||||
} else {
|
} else {
|
||||||
highlightEntry(entry);
|
focusEntry(entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -410,34 +406,49 @@ public class EntryAdapter extends RecyclerView.Adapter<EntryHolder> implements I
|
||||||
return period;
|
return period;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void highlightEntry(DatabaseEntry entry) {
|
private void focusEntry(DatabaseEntry entry) {
|
||||||
_highlightedEntry = entry;
|
_focusedEntry = entry;
|
||||||
_dimHandler.removeCallbacksAndMessages(null);
|
_dimHandler.removeCallbacksAndMessages(null);
|
||||||
|
|
||||||
for (EntryHolder holder : _holders) {
|
for (EntryHolder holder : _holders) {
|
||||||
if (holder.getEntry() != _highlightedEntry) {
|
if (holder.getEntry() != _focusedEntry) {
|
||||||
holder.dim();
|
if (_highlightEntry) {
|
||||||
|
holder.dim();
|
||||||
|
}
|
||||||
|
if (_tapToReveal) {
|
||||||
|
holder.hideCode();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
holder.highlight();
|
if (_highlightEntry) {
|
||||||
|
holder.highlight();
|
||||||
|
}
|
||||||
|
if (_tapToReveal) {
|
||||||
|
holder.revealCode();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_dimHandler.postDelayed(this::resetHighlight, _tapToRevealTime * 1000);
|
_dimHandler.postDelayed(this::resetFocus, _tapToRevealTime * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resetHighlight() {
|
private void resetFocus() {
|
||||||
_highlightedEntry = null;
|
|
||||||
|
|
||||||
for (EntryHolder holder : _holders) {
|
for (EntryHolder holder : _holders) {
|
||||||
holder.highlight();
|
if (_highlightEntry) {
|
||||||
|
holder.highlight();
|
||||||
|
}
|
||||||
|
if (_tapToReveal) {
|
||||||
|
holder.hideCode();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_focusedEntry = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSelectedEntry(DatabaseEntry entry) {
|
public void setSelectedEntry(DatabaseEntry entry) {
|
||||||
if (entry == null) {
|
if (entry == null) {
|
||||||
notifyItemChanged(_shownEntries.indexOf(_selectedEntry));
|
notifyItemChanged(_shownEntries.indexOf(_selectedEntry));
|
||||||
} else if (_highlightEntry) {
|
} else if (_highlightEntry) {
|
||||||
resetHighlight();
|
resetFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
_selectedEntry = entry;
|
_selectedEntry = entry;
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package com.beemdevelopment.aegis.ui.views;
|
package com.beemdevelopment.aegis.ui.views;
|
||||||
|
|
||||||
import android.graphics.PorterDuff;
|
import android.graphics.PorterDuff;
|
||||||
import android.os.Handler;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
@ -34,13 +33,11 @@ public class EntryHolder extends RecyclerView.ViewHolder {
|
||||||
private ImageView _buttonRefresh;
|
private ImageView _buttonRefresh;
|
||||||
|
|
||||||
private boolean _hidden;
|
private boolean _hidden;
|
||||||
private int _tapToRevealTime;
|
|
||||||
|
|
||||||
private PeriodProgressBar _progressBar;
|
private PeriodProgressBar _progressBar;
|
||||||
private View _view;
|
private View _view;
|
||||||
|
|
||||||
private UiRefresher _refresher;
|
private UiRefresher _refresher;
|
||||||
private Handler _hiddenHandler;
|
|
||||||
|
|
||||||
public EntryHolder(final View view) {
|
public EntryHolder(final View view) {
|
||||||
super(view);
|
super(view);
|
||||||
|
@ -61,7 +58,7 @@ public class EntryHolder extends RecyclerView.ViewHolder {
|
||||||
_refresher = new UiRefresher(new UiRefresher.Listener() {
|
_refresher = new UiRefresher(new UiRefresher.Listener() {
|
||||||
@Override
|
@Override
|
||||||
public void onRefresh() {
|
public void onRefresh() {
|
||||||
if (!isCodeHidden()) {
|
if (_hidden) {
|
||||||
refreshCode();
|
refreshCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,8 +70,6 @@ public class EntryHolder extends RecyclerView.ViewHolder {
|
||||||
return ((TotpInfo)_entry.getInfo()).getMillisTillNextRotation();
|
return ((TotpInfo)_entry.getInfo()).getMillisTillNextRotation();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
_hiddenHandler = new Handler();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setData(DatabaseEntry entry, boolean showAccountName, boolean showProgress, boolean hidden, boolean dimmed) {
|
public void setData(DatabaseEntry entry, boolean showAccountName, boolean showProgress, boolean hidden, boolean dimmed) {
|
||||||
|
@ -93,9 +88,6 @@ public class EntryHolder extends RecyclerView.ViewHolder {
|
||||||
_profileName.setText(" - " + entry.getName());
|
_profileName.setText(" - " + entry.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
// cancel any scheduled hideCode calls
|
|
||||||
_hiddenHandler.removeCallbacksAndMessages(null);
|
|
||||||
|
|
||||||
if (_hidden) {
|
if (_hidden) {
|
||||||
hideCode();
|
hideCode();
|
||||||
} else {
|
} else {
|
||||||
|
@ -127,10 +119,6 @@ public class EntryHolder extends RecyclerView.ViewHolder {
|
||||||
return _profileDrawable;
|
return _profileDrawable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTapToRevealTime(int number) {
|
|
||||||
_tapToRevealTime = number;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOnRefreshClickListener(View.OnClickListener listener) {
|
public void setOnRefreshClickListener(View.OnClickListener listener) {
|
||||||
_buttonRefresh.setOnClickListener(listener);
|
_buttonRefresh.setOnClickListener(listener);
|
||||||
}
|
}
|
||||||
|
@ -171,7 +159,7 @@ public class EntryHolder extends RecyclerView.ViewHolder {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refreshCode() {
|
public void refreshCode() {
|
||||||
if (!isCodeHidden()) {
|
if (!_hidden) {
|
||||||
updateCode();
|
updateCode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -196,10 +184,14 @@ public class EntryHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
public void revealCode() {
|
public void revealCode() {
|
||||||
updateCode();
|
updateCode();
|
||||||
_hiddenHandler.postDelayed(this::hideCode, _tapToRevealTime * 1000);
|
|
||||||
_hidden = false;
|
_hidden = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void hideCode() {
|
||||||
|
_profileCode.setText(R.string.tap_to_reveal);
|
||||||
|
_hidden = true;
|
||||||
|
}
|
||||||
|
|
||||||
public void dim() {
|
public void dim() {
|
||||||
animateAlphaTo(DIMMED_ALPHA);
|
animateAlphaTo(DIMMED_ALPHA);
|
||||||
}
|
}
|
||||||
|
@ -211,13 +203,4 @@ public class EntryHolder extends RecyclerView.ViewHolder {
|
||||||
private void animateAlphaTo(float alpha) {
|
private void animateAlphaTo(float alpha) {
|
||||||
itemView.animate().alpha(alpha).setDuration(200).start();
|
itemView.animate().alpha(alpha).setDuration(200).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void hideCode() {
|
|
||||||
_profileCode.setText(R.string.tap_to_reveal);
|
|
||||||
_hidden = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isCodeHidden() {
|
|
||||||
return _hidden;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue