Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to only show names when necessary #1167

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/src/main/java/com/beemdevelopment/aegis/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ public void resetPasswordReminderTimestamp() {
setPasswordReminderTimestamp(new Date().getTime());
}

public boolean onlyShowNecessaryAccountNames() { return _prefs.getBoolean("pref_shared_issuer_account_name", false); }

public boolean isIconVisible() {
return _prefs.getBoolean("pref_show_icons", true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ protected void onCreate(Bundle savedInstanceState) {
_entryListView.setCodeGroupSize(_prefs.getCodeGroupSize());
_entryListView.setAccountNamePosition(_prefs.getAccountNamePosition());
_entryListView.setShowIcon(_prefs.isIconVisible());
_entryListView.setOnlyShowNecessaryAccountNames(_prefs.onlyShowNecessaryAccountNames());
_entryListView.setHighlightEntry(_prefs.isEntryHighlightEnabled());
_entryListView.setPauseFocused(_prefs.isPauseFocusedEnabled());
_entryListView.setTapToReveal(_prefs.isTapToRevealEnabled());
Expand Down Expand Up @@ -273,6 +274,7 @@ private void onPreferencesResult(Intent data) {
} else if (data.getBooleanExtra("needsRefresh", false)) {
AccountNamePosition accountNamePosition = _prefs.getAccountNamePosition();
boolean showIcons = _prefs.isIconVisible();
boolean onlyShowNecessaryAccountNames = _prefs.onlyShowNecessaryAccountNames();
Preferences.CodeGrouping codeGroupSize = _prefs.getCodeGroupSize();
boolean highlightEntry = _prefs.isEntryHighlightEnabled();
boolean pauseFocused = _prefs.isPauseFocusedEnabled();
Expand All @@ -281,6 +283,7 @@ private void onPreferencesResult(Intent data) {
ViewMode viewMode = _prefs.getCurrentViewMode();
CopyBehavior copyBehavior = _prefs.getCopyBehavior();
_entryListView.setAccountNamePosition(accountNamePosition);
_entryListView.setOnlyShowNecessaryAccountNames(onlyShowNecessaryAccountNames);
_entryListView.setShowIcon(showIcons);
_entryListView.setCodeGroupSize(codeGroupSize);
_entryListView.setHighlightEntry(highlightEntry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
return true;
});

Preference onlyShowNecessaryAccountNames = requirePreference("pref_shared_issuer_account_name");
onlyShowNecessaryAccountNames.setOnPreferenceChangeListener((preference, newValue) -> {
getResult().putExtra("needsRefresh", true);
return true;
});

int currentAccountNamePosition = _prefs.getAccountNamePosition().ordinal();
Preference currentAccountNamePositionPreference = requirePreference("pref_account_name_position");
currentAccountNamePositionPreference.setSummary(String.format("%s: %s", getString(R.string.selected), getResources().getStringArray(R.array.account_name_position_titles)[currentAccountNamePosition]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class EntryAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
private Preferences.CodeGrouping _codeGroupSize;
private AccountNamePosition _accountNamePosition;
private boolean _showIcon;
private boolean _onlyShowNecessaryAccountNames;
private boolean _highlightEntry;
private boolean _tempHighlightEntry;
private boolean _tapToReveal;
Expand Down Expand Up @@ -96,6 +97,10 @@ public void setAccountNamePosition(AccountNamePosition accountNamePosition) {
_accountNamePosition = accountNamePosition;
}

public void setOnlyShowNecessaryAccountNames(boolean onlyShowNecessaryAccountNames) {
_onlyShowNecessaryAccountNames = onlyShowNecessaryAccountNames;
}

public void setShowIcon(boolean showIcon) {
_showIcon = showIcon;
}
Expand Down Expand Up @@ -424,7 +429,16 @@ public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position)
boolean paused = _pauseFocused && entry == _focusedEntry;
boolean dimmed = (_highlightEntry || _tempHighlightEntry) && _focusedEntry != null && _focusedEntry != entry;
boolean showProgress = entry.getInfo() instanceof TotpInfo && ((TotpInfo) entry.getInfo()).getPeriod() != getMostFrequentPeriod();
entryHolder.setData(entry, _codeGroupSize, _accountNamePosition, _showIcon, showProgress, hidden, paused, dimmed);
boolean showAccountName = true;
if (_onlyShowNecessaryAccountNames) {
// Only show account name when there's multiple entries found with the same issuer.
showAccountName = _entries.stream()
michaelschattgen marked this conversation as resolved.
Show resolved Hide resolved
.filter(x -> x.getIssuer().equals(entry.getIssuer()))
.count() > 1;
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,10 @@ public void setAccountNamePosition(AccountNamePosition accountNamePosition) {
_adapter.setAccountNamePosition(accountNamePosition);
}

public void setOnlyShowNecessaryAccountNames(boolean onlyShowNecessaryAccountNames) {
_adapter.setOnlyShowNecessaryAccountNames(onlyShowNecessaryAccountNames);
}

public void setShowIcon(boolean showIcon) {
_adapter.setShowIcon(showIcon);
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
<string name="pref_code_group_size_title">Code digit grouping</string>
<string name="pref_code_group_size_summary">Select number of digits to group codes by</string>
<string name="pref_account_name_position_title">Show the account name</string>
<string name="pref_shared_issuer_account_name_title">Only show account name when necessary</string>
<string name="pref_shared_issuer_account_name_summary">Only show account names whenever they share the same issuer. Other account names will be hidden.</string>
<string name="pref_import_file_title">Import from file</string>
<string name="pref_import_file_summary">Import tokens from a file</string>
<string name="pref_android_backups_title">Android cloud backups</string>
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/xml/preferences_appearance.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@
android:title="@string/pref_account_name_position_title"
app:iconSpaceReserved="false"/>

<androidx.preference.SwitchPreferenceCompat
android:defaultValue="false"
android:key="pref_shared_issuer_account_name"
android:title="@string/pref_shared_issuer_account_name_title"
android:summary="@string/pref_shared_issuer_account_name_summary"
app:iconSpaceReserved="false"/>

<Preference
android:key="pref_groups"
android:title="@string/preference_manage_groups"
Expand Down