Add ability to only show names when necessary

This commit is contained in:
Michael Schättgen 2023-08-21 00:24:10 +02:00
parent 6009c09607
commit edb1d8d76f
7 changed files with 39 additions and 1 deletions

View file

@ -130,6 +130,8 @@ public class Preferences {
setPasswordReminderTimestamp(new Date().getTime()); setPasswordReminderTimestamp(new Date().getTime());
} }
public boolean onlyShowNecessaryAccountNames() { return _prefs.getBoolean("pref_shared_issuer_account_name", false); }
public boolean isIconVisible() { public boolean isIconVisible() {
return _prefs.getBoolean("pref_show_icons", true); return _prefs.getBoolean("pref_show_icons", true);
} }

View file

@ -135,6 +135,7 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
_entryListView.setCodeGroupSize(_prefs.getCodeGroupSize()); _entryListView.setCodeGroupSize(_prefs.getCodeGroupSize());
_entryListView.setAccountNamePosition(_prefs.getAccountNamePosition()); _entryListView.setAccountNamePosition(_prefs.getAccountNamePosition());
_entryListView.setShowIcon(_prefs.isIconVisible()); _entryListView.setShowIcon(_prefs.isIconVisible());
_entryListView.setOnlyShowNecessaryAccountNames(_prefs.onlyShowNecessaryAccountNames());
_entryListView.setHighlightEntry(_prefs.isEntryHighlightEnabled()); _entryListView.setHighlightEntry(_prefs.isEntryHighlightEnabled());
_entryListView.setPauseFocused(_prefs.isPauseFocusedEnabled()); _entryListView.setPauseFocused(_prefs.isPauseFocusedEnabled());
_entryListView.setTapToReveal(_prefs.isTapToRevealEnabled()); _entryListView.setTapToReveal(_prefs.isTapToRevealEnabled());
@ -273,6 +274,7 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
} else if (data.getBooleanExtra("needsRefresh", false)) { } else if (data.getBooleanExtra("needsRefresh", false)) {
AccountNamePosition accountNamePosition = _prefs.getAccountNamePosition(); AccountNamePosition accountNamePosition = _prefs.getAccountNamePosition();
boolean showIcons = _prefs.isIconVisible(); boolean showIcons = _prefs.isIconVisible();
boolean onlyShowNecessaryAccountNames = _prefs.onlyShowNecessaryAccountNames();
Preferences.CodeGrouping codeGroupSize = _prefs.getCodeGroupSize(); Preferences.CodeGrouping codeGroupSize = _prefs.getCodeGroupSize();
boolean highlightEntry = _prefs.isEntryHighlightEnabled(); boolean highlightEntry = _prefs.isEntryHighlightEnabled();
boolean pauseFocused = _prefs.isPauseFocusedEnabled(); boolean pauseFocused = _prefs.isPauseFocusedEnabled();
@ -281,6 +283,7 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
ViewMode viewMode = _prefs.getCurrentViewMode(); ViewMode viewMode = _prefs.getCurrentViewMode();
CopyBehavior copyBehavior = _prefs.getCopyBehavior(); CopyBehavior copyBehavior = _prefs.getCopyBehavior();
_entryListView.setAccountNamePosition(accountNamePosition); _entryListView.setAccountNamePosition(accountNamePosition);
_entryListView.setOnlyShowNecessaryAccountNames(onlyShowNecessaryAccountNames);
_entryListView.setShowIcon(showIcons); _entryListView.setShowIcon(showIcons);
_entryListView.setCodeGroupSize(codeGroupSize); _entryListView.setCodeGroupSize(codeGroupSize);
_entryListView.setHighlightEntry(highlightEntry); _entryListView.setHighlightEntry(highlightEntry);

View file

@ -103,6 +103,12 @@ public class AppearancePreferencesFragment extends PreferencesFragment {
return true; 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(); int currentAccountNamePosition = _prefs.getAccountNamePosition().ordinal();
Preference currentAccountNamePositionPreference = requirePreference("pref_account_name_position"); 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])); currentAccountNamePositionPreference.setSummary(String.format("%s: %s", getString(R.string.selected), getResources().getStringArray(R.array.account_name_position_titles)[currentAccountNamePosition]));

View file

@ -52,6 +52,7 @@ public class EntryAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
private Preferences.CodeGrouping _codeGroupSize; private Preferences.CodeGrouping _codeGroupSize;
private AccountNamePosition _accountNamePosition; private AccountNamePosition _accountNamePosition;
private boolean _showIcon; private boolean _showIcon;
private boolean _onlyShowNecessaryAccountNames;
private boolean _highlightEntry; private boolean _highlightEntry;
private boolean _tempHighlightEntry; private boolean _tempHighlightEntry;
private boolean _tapToReveal; private boolean _tapToReveal;
@ -96,6 +97,10 @@ public class EntryAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
_accountNamePosition = accountNamePosition; _accountNamePosition = accountNamePosition;
} }
public void setOnlyShowNecessaryAccountNames(boolean onlyShowNecessaryAccountNames) {
_onlyShowNecessaryAccountNames = onlyShowNecessaryAccountNames;
}
public void setShowIcon(boolean showIcon) { public void setShowIcon(boolean showIcon) {
_showIcon = showIcon; _showIcon = showIcon;
} }
@ -424,7 +429,16 @@ public class EntryAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
boolean paused = _pauseFocused && entry == _focusedEntry; boolean paused = _pauseFocused && entry == _focusedEntry;
boolean dimmed = (_highlightEntry || _tempHighlightEntry) && _focusedEntry != null && _focusedEntry != entry; boolean dimmed = (_highlightEntry || _tempHighlightEntry) && _focusedEntry != null && _focusedEntry != entry;
boolean showProgress = entry.getInfo() instanceof TotpInfo && ((TotpInfo) entry.getInfo()).getPeriod() != getMostFrequentPeriod(); 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.setFocused(_selectedEntries.contains(entry));
entryHolder.setShowDragHandle(isEntryDraggable(entry)); entryHolder.setShowDragHandle(isEntryDraggable(entry));

View file

@ -330,6 +330,10 @@ public class EntryListView extends Fragment implements EntryAdapter.Listener {
_adapter.setAccountNamePosition(accountNamePosition); _adapter.setAccountNamePosition(accountNamePosition);
} }
public void setOnlyShowNecessaryAccountNames(boolean onlyShowNecessaryAccountNames) {
_adapter.setOnlyShowNecessaryAccountNames(onlyShowNecessaryAccountNames);
}
public void setShowIcon(boolean showIcon) { public void setShowIcon(boolean showIcon) {
_adapter.setShowIcon(showIcon); _adapter.setShowIcon(showIcon);
} }

View file

@ -43,6 +43,8 @@
<string name="pref_code_group_size_title">Code digit grouping</string> <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_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_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_title">Import from file</string>
<string name="pref_import_file_summary">Import tokens from a file</string> <string name="pref_import_file_summary">Import tokens from a file</string>
<string name="pref_android_backups_title">Android cloud backups</string> <string name="pref_android_backups_title">Android cloud backups</string>

View file

@ -51,6 +51,13 @@
android:title="@string/pref_account_name_position_title" android:title="@string/pref_account_name_position_title"
app:iconSpaceReserved="false"/> 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 <Preference
android:key="pref_groups" android:key="pref_groups"
android:title="@string/preference_manage_groups" android:title="@string/preference_manage_groups"