diff --git a/app/src/main/java/com/beemdevelopment/aegis/Preferences.java b/app/src/main/java/com/beemdevelopment/aegis/Preferences.java index 0b00966c..e2339212 100644 --- a/app/src/main/java/com/beemdevelopment/aegis/Preferences.java +++ b/app/src/main/java/com/beemdevelopment/aegis/Preferences.java @@ -130,6 +130,8 @@ public class Preferences { 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); } diff --git a/app/src/main/java/com/beemdevelopment/aegis/ui/MainActivity.java b/app/src/main/java/com/beemdevelopment/aegis/ui/MainActivity.java index 1708fdff..50ddbac8 100644 --- a/app/src/main/java/com/beemdevelopment/aegis/ui/MainActivity.java +++ b/app/src/main/java/com/beemdevelopment/aegis/ui/MainActivity.java @@ -135,6 +135,7 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene _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()); @@ -273,6 +274,7 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene } 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(); @@ -281,6 +283,7 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene ViewMode viewMode = _prefs.getCurrentViewMode(); CopyBehavior copyBehavior = _prefs.getCopyBehavior(); _entryListView.setAccountNamePosition(accountNamePosition); + _entryListView.setOnlyShowNecessaryAccountNames(onlyShowNecessaryAccountNames); _entryListView.setShowIcon(showIcons); _entryListView.setCodeGroupSize(codeGroupSize); _entryListView.setHighlightEntry(highlightEntry); diff --git a/app/src/main/java/com/beemdevelopment/aegis/ui/fragments/preferences/AppearancePreferencesFragment.java b/app/src/main/java/com/beemdevelopment/aegis/ui/fragments/preferences/AppearancePreferencesFragment.java index 798a5e6e..4b8dc4b8 100644 --- a/app/src/main/java/com/beemdevelopment/aegis/ui/fragments/preferences/AppearancePreferencesFragment.java +++ b/app/src/main/java/com/beemdevelopment/aegis/ui/fragments/preferences/AppearancePreferencesFragment.java @@ -103,6 +103,12 @@ public class AppearancePreferencesFragment extends PreferencesFragment { 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])); diff --git a/app/src/main/java/com/beemdevelopment/aegis/ui/views/EntryAdapter.java b/app/src/main/java/com/beemdevelopment/aegis/ui/views/EntryAdapter.java index c3ff1ae8..8d284524 100644 --- a/app/src/main/java/com/beemdevelopment/aegis/ui/views/EntryAdapter.java +++ b/app/src/main/java/com/beemdevelopment/aegis/ui/views/EntryAdapter.java @@ -52,6 +52,7 @@ public class EntryAdapter extends RecyclerView.Adapter private Preferences.CodeGrouping _codeGroupSize; private AccountNamePosition _accountNamePosition; private boolean _showIcon; + private boolean _onlyShowNecessaryAccountNames; private boolean _highlightEntry; private boolean _tempHighlightEntry; private boolean _tapToReveal; @@ -96,6 +97,10 @@ public class EntryAdapter extends RecyclerView.Adapter _accountNamePosition = accountNamePosition; } + public void setOnlyShowNecessaryAccountNames(boolean onlyShowNecessaryAccountNames) { + _onlyShowNecessaryAccountNames = onlyShowNecessaryAccountNames; + } + public void setShowIcon(boolean showIcon) { _showIcon = showIcon; } @@ -424,7 +429,16 @@ public class EntryAdapter extends RecyclerView.Adapter 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() + .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)); diff --git a/app/src/main/java/com/beemdevelopment/aegis/ui/views/EntryListView.java b/app/src/main/java/com/beemdevelopment/aegis/ui/views/EntryListView.java index a33103c1..feacee14 100644 --- a/app/src/main/java/com/beemdevelopment/aegis/ui/views/EntryListView.java +++ b/app/src/main/java/com/beemdevelopment/aegis/ui/views/EntryListView.java @@ -330,6 +330,10 @@ public class EntryListView extends Fragment implements EntryAdapter.Listener { _adapter.setAccountNamePosition(accountNamePosition); } + public void setOnlyShowNecessaryAccountNames(boolean onlyShowNecessaryAccountNames) { + _adapter.setOnlyShowNecessaryAccountNames(onlyShowNecessaryAccountNames); + } + public void setShowIcon(boolean showIcon) { _adapter.setShowIcon(showIcon); } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 58a6a87f..233d1bca 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -43,6 +43,8 @@ Code digit grouping Select number of digits to group codes by Show the account name + Only show account name when necessary + Only show account names whenever they share the same issuer. Other account names will be hidden. Import from file Import tokens from a file Android cloud backups diff --git a/app/src/main/res/xml/preferences_appearance.xml b/app/src/main/res/xml/preferences_appearance.xml index 986be0b4..b3b53987 100644 --- a/app/src/main/res/xml/preferences_appearance.xml +++ b/app/src/main/res/xml/preferences_appearance.xml @@ -51,6 +51,13 @@ android:title="@string/pref_account_name_position_title" app:iconSpaceReserved="false"/> + +