Merge pull request #1167 from michaelschattgen/feature/hide-account-name

Add ability to only show names when necessary
This commit is contained in:
Alexander Bakker 2023-08-22 23:26:20 +02:00 committed by GitHub
commit 94a38e82e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 39 additions and 1 deletions

View File

@ -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);
}

View File

@ -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);

View File

@ -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]));

View File

@ -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;
@ -96,6 +97,10 @@ public class EntryAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
_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<RecyclerView.ViewHolder>
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));

View File

@ -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);
}

View File

@ -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>

View File

@ -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"