Skip to content

Commit

Permalink
Merge pull request #1507 from michaelschattgen/feature/show-next-code
Browse files Browse the repository at this point in the history
Add ability to show next code
  • Loading branch information
alexbakker authored Oct 9, 2024
2 parents 0573dbb + e4c9a58 commit 413e793
Show file tree
Hide file tree
Showing 12 changed files with 218 additions and 73 deletions.
4 changes: 4 additions & 0 deletions app/src/main/java/com/beemdevelopment/aegis/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ public boolean isIconVisible() {
return _prefs.getBoolean("pref_show_icons", true);
}

public boolean getShowNextCode() {
return _prefs.getBoolean("pref_show_next_code", false);
}

public boolean getShowExpirationState() {
return _prefs.getBoolean("pref_expiration_state", true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ public String getOtp() throws OtpInfoException {
}
}

public String getOtp(long time) {
public String getOtp(long time) throws OtpInfoException {
checkSecret();

try {
OTP otp = TOTP.generateOTP(getSecret(), getAlgorithm(true), getDigits(), getPeriod(), time);
return otp.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ protected void onCreate(Bundle savedInstanceState) {
_entryListView.setAccountNamePosition(_prefs.getAccountNamePosition());
_entryListView.setShowIcon(_prefs.isIconVisible());
_entryListView.setShowExpirationState(_prefs.getShowExpirationState());
_entryListView.setShowNextCode(_prefs.getShowNextCode());
_entryListView.setOnlyShowNecessaryAccountNames(_prefs.onlyShowNecessaryAccountNames());
_entryListView.setHighlightEntry(_prefs.isEntryHighlightEnabled());
_entryListView.setPauseFocused(_prefs.isPauseFocusedEnabled());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public class EntryAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
private Preferences.CodeGrouping _codeGroupSize;
private AccountNamePosition _accountNamePosition;
private boolean _showIcon;
private boolean _showNextCode;
private boolean _showExpirationState;
private boolean _onlyShowNecessaryAccountNames;
private boolean _highlightEntry;
Expand Down Expand Up @@ -116,6 +117,10 @@ public void setShowIcon(boolean showIcon) {
_showIcon = showIcon;
}

public void setShowNextCode(boolean showNextCode) {
_showNextCode = showNextCode;
}

public void setShowExpirationState(boolean showExpirationState) {
_showExpirationState = showExpirationState;
}
Expand Down Expand Up @@ -544,7 +549,7 @@ public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position)
}

AccountNamePosition accountNamePosition = showAccountName ? _accountNamePosition : AccountNamePosition.HIDDEN;
entryHolder.setData(entry, _codeGroupSize, _viewMode, accountNamePosition, _showIcon, showProgress, hidden, paused, dimmed, _showExpirationState);
entryHolder.setData(entry, _codeGroupSize, _viewMode, accountNamePosition, _showIcon, showProgress, hidden, paused, dimmed, _showExpirationState, _showNextCode);
entryHolder.setFocused(_selectedEntries.contains(entry));
entryHolder.setShowDragHandle(isEntryDraggable(entry));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class EntryHolder extends RecyclerView.ViewHolder {
private View _favoriteIndicator;
private TextView _profileName;
private TextView _profileCode;
private TextView _nextProfileCode;
private TextView _profileIssuer;
private TextView _profileCopied;
private ImageView _profileDrawable;
Expand All @@ -74,6 +75,7 @@ public class EntryHolder extends RecyclerView.ViewHolder {
private UiRefresher _refresher;
private Handler _animationHandler;
private AnimatorSet _expirationAnimSet;
private boolean _showNextCode;
private boolean _showExpirationState;

private Animation _scaleIn;
Expand All @@ -85,6 +87,7 @@ public EntryHolder(final View view) {
_view = (MaterialCardView) view;
_profileName = view.findViewById(R.id.profile_account_name);
_profileCode = view.findViewById(R.id.profile_code);
_nextProfileCode = view.findViewById(R.id.next_profile_code);
_profileIssuer = view.findViewById(R.id.profile_issuer);
_profileCopied = view.findViewById(R.id.profile_copied);
_description = view.findViewById(R.id.description);
Expand Down Expand Up @@ -115,7 +118,7 @@ public long getMillisTillNextRefresh() {
});
}

public void setData(VaultEntry entry, Preferences.CodeGrouping groupSize, ViewMode viewMode, AccountNamePosition accountNamePosition, boolean showIcon, boolean showProgress, boolean hidden, boolean paused, boolean dimmed, boolean showExpirationState) {
public void setData(VaultEntry entry, Preferences.CodeGrouping groupSize, ViewMode viewMode, AccountNamePosition accountNamePosition, boolean showIcon, boolean showProgress, boolean hidden, boolean paused, boolean dimmed, boolean showExpirationState, boolean showNextCode) {
_entry = entry;
_hidden = hidden;
_paused = paused;
Expand All @@ -131,6 +134,7 @@ public void setData(VaultEntry entry, Preferences.CodeGrouping groupSize, ViewMo
_selected.setVisibility(View.GONE);
_selectedHandler.removeCallbacksAndMessages(null);
_animationHandler.removeCallbacksAndMessages(null);
_showNextCode = entry.getInfo() instanceof TotpInfo && showNextCode;
_showExpirationState = _entry.getInfo() instanceof TotpInfo && showExpirationState;

_favoriteIndicator.setVisibility(_entry.isFavorite() ? View.VISIBLE : View.INVISIBLE);
Expand All @@ -140,6 +144,7 @@ public void setData(VaultEntry entry, Preferences.CodeGrouping groupSize, ViewMo

// only show the button if this entry is of type HotpInfo
_buttonRefresh.setVisibility(entry.getInfo() instanceof HotpInfo ? View.VISIBLE : View.GONE);
_nextProfileCode.setVisibility(_showNextCode ? View.VISIBLE : View.GONE);

String profileIssuer = entry.getIssuer();
String profileName = entry.getName();
Expand Down Expand Up @@ -284,16 +289,24 @@ public void refresh() {

public void refreshCode() {
if (!_hidden && !_paused) {
updateCode();
updateCodes();
startExpirationAnimation();
}
}

private void updateCode() {
private void updateCodes() {
_profileCode.setText(getOtp());

if (_showNextCode) {
_nextProfileCode.setText(getOtp(1));
}
}

private String getOtp() {
return getOtp(0);
}

private String getOtp(int offset) {
OtpInfo info = _entry.getInfo();

// In previous versions of Aegis, it was possible to import entries with an empty
Expand All @@ -302,7 +315,12 @@ private String getOtp() {
// the OTP, instead of crashing.
String otp;
try {
otp = info.getOtp();
if (info instanceof TotpInfo) {
otp = ((TotpInfo)info).getOtp((System.currentTimeMillis() / 1000) + ((long) (offset) * ((TotpInfo) _entry.getInfo()).getPeriod()));
} else {
otp = info.getOtp();
}

if (!(info instanceof SteamInfo || info instanceof YandexInfo)) {
otp = formatCode(otp);
}
Expand Down Expand Up @@ -343,7 +361,7 @@ private String formatCode(String code) {
}

public void revealCode() {
updateCode();
updateCodes();
startExpirationAnimation();
_hidden = false;
}
Expand All @@ -352,6 +370,7 @@ public void hideCode() {
String code = getOtp();
String hiddenText = code.replaceAll("\\S", Character.toString(HIDDEN_CHAR));
updateTextViewWithDots(_profileCode, hiddenText, code);
updateTextViewWithDots(_nextProfileCode, hiddenText, code);
stopExpirationAnimation();
_hidden = true;
}
Expand Down Expand Up @@ -480,7 +499,7 @@ public void setPaused(boolean paused) {
if (_paused) {
stopExpirationAnimation();
} else if (!_hidden) {
updateCode();
updateCodes();
startExpirationAnimation();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,10 @@ public void setShowIcon(boolean showIcon) {
_adapter.setShowIcon(showIcon);
}

public void setShowNextCode(boolean showNextCode) {
_adapter.setShowNextCode(showNextCode);
}

public void setShowExpirationState(boolean showExpirationState) {
_showExpirationState = showExpirationState;
_adapter.setShowExpirationState(showExpirationState);
Expand Down
58 changes: 41 additions & 17 deletions app/src/main/res/layout/card_entry.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/description"
android:layout_alignStart="@+id/profile_code">
android:layout_alignStart="@+id/profile_codes_layout">

<TextView
android:layout_width="wrap_content"
Expand Down Expand Up @@ -109,23 +109,47 @@
android:textSize="16sp"
android:visibility="invisible" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:fontFamily="sans-serif-light"
tools:text="012 345"
android:id="@+id/profile_code"
android:layoutDirection="ltr"
<LinearLayout
android:orientation="vertical"
android:layout_marginBottom="0dp"
android:paddingBottom="0dp"
android:id="@+id/profile_codes_layout"
android:layout_below="@id/description"
android:includeFontPadding="false"
android:fallbackLineSpacing="false"
android:textSize="34sp"
android:textColor="?attr/colorCode"
android:layout_marginStart="6dp"
android:layout_alignParentStart="true"
android:layout_marginTop="0dp"
android:textStyle="normal|bold"/>
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:fontFamily="sans-serif-light"
tools:text="012 345"
android:id="@+id/profile_code"
android:layoutDirection="ltr"
android:textSize="34sp"
android:layout_below="@id/description"
android:textColor="?attr/colorCode"
android:includeFontPadding="false"
android:fallbackLineSpacing="false"
android:layout_alignParentStart="true"
android:layout_marginTop="0dp"
android:textStyle="normal|bold"/>

<TextView
android:id="@+id/next_profile_code"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="0dp"
android:paddingTop="0dp"
android:paddingStart="2dp"
android:layout_alignParentStart="true"
android:textColor="?attr/colorOnSurfaceDim"
android:textSize="20sp"
android:textStyle="normal|bold"
android:includeFontPadding="false"
android:fallbackLineSpacing="false"
tools:text="412 643"/>
</LinearLayout>

</RelativeLayout>

Expand Down
61 changes: 44 additions & 17 deletions app/src/main/res/layout/card_entry_compact.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/description"
android:layout_alignStart="@+id/profile_code">

android:layout_alignStart="@+id/profile_codes_layout">

<TextView
android:layout_width="wrap_content"
Expand All @@ -95,6 +94,7 @@
android:text="@string/issuer"
android:textStyle="bold"
android:includeFontPadding="false"
android:fallbackLineSpacing="false"
android:textSize="13sp"
android:ellipsize="end"
android:maxLines="1"/>
Expand All @@ -112,23 +112,50 @@
</RelativeLayout>


<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:fontFamily="sans-serif-light"
tools:text="012 345"
android:id="@+id/profile_code"
android:layoutDirection="ltr"
<LinearLayout
android:orientation="vertical"
android:layout_marginBottom="0dp"
android:paddingBottom="0dp"
android:id="@+id/profile_codes_layout"
android:layout_below="@id/description"
android:includeFontPadding="false"
android:fallbackLineSpacing="false"
android:textSize="26sp"
android:textColor="?attr/colorCode"
android:layout_marginStart="6dp"
android:layout_alignParentStart="true"
android:layout_marginTop="0dp"
android:textStyle="normal|bold"/>
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:fontFamily="sans-serif-light"
tools:text="012 345"
android:id="@+id/profile_code"
android:layoutDirection="ltr"
android:layout_below="@id/description"
android:includeFontPadding="false"
android:fallbackLineSpacing="false"
android:textSize="26sp"
android:textColor="?attr/colorCode"
android:layout_alignParentStart="true"
android:layout_marginTop="0dp"
android:textStyle="normal|bold"/>

<TextView
android:id="@+id/next_profile_code"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:letterSpacing="-0.01"
android:layout_marginTop="0dp"
android:paddingTop="0dp"
android:paddingStart="2dp"
android:textColor="?attr/colorOnSurfaceDim"
android:textSize="16sp"
android:textStyle="normal|bold"
android:fallbackLineSpacing="false"
android:includeFontPadding="false"
tools:text="412 643"/>
</LinearLayout>



</RelativeLayout>

Expand Down
Loading

0 comments on commit 413e793

Please sign in to comment.