Merge pull request #1013 from orange-elephant/no-icons-view-mode

Add 'No Icons' view mode
This commit is contained in:
Alexander Bakker 2022-11-20 18:36:42 +01:00 committed by GitHub
commit 01e59d79a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 52 additions and 9 deletions

View File

@ -120,6 +120,10 @@ public class Preferences {
return _prefs.getBoolean("pref_account_name", true);
}
public boolean isIconVisible() {
return _prefs.getBoolean("pref_show_icons", true);
}
public CodeGrouping getCodeGroupSize() {
String value = _prefs.getString("pref_code_group_size_string", "GROUPING_THREES");

View File

@ -129,6 +129,7 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
_entryListView.setListener(this);
_entryListView.setCodeGroupSize(_prefs.getCodeGroupSize());
_entryListView.setShowAccountName(_prefs.isAccountNameVisible());
_entryListView.setShowIcon(_prefs.isIconVisible());
_entryListView.setHighlightEntry(_prefs.isEntryHighlightEnabled());
_entryListView.setPauseFocused(_prefs.isPauseFocusedEnabled());
_entryListView.setTapToReveal(_prefs.isTapToRevealEnabled());
@ -266,6 +267,7 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
recreate();
} else if (data.getBooleanExtra("needsRefresh", false)) {
boolean showAccountName = _prefs.isAccountNameVisible();
boolean showIcons = _prefs.isIconVisible();
Preferences.CodeGrouping codeGroupSize = _prefs.getCodeGroupSize();
boolean highlightEntry = _prefs.isEntryHighlightEnabled();
boolean pauseFocused = _prefs.isPauseFocusedEnabled();
@ -274,6 +276,7 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
ViewMode viewMode = _prefs.getCurrentViewMode();
boolean copyOnTap = _prefs.isCopyOnTapEnabled();
_entryListView.setShowAccountName(showAccountName);
_entryListView.setShowIcon(showIcons);
_entryListView.setCodeGroupSize(codeGroupSize);
_entryListView.setHighlightEntry(highlightEntry);
_entryListView.setPauseFocused(pauseFocused);

View File

@ -109,5 +109,11 @@ public class AppearancePreferencesFragment extends PreferencesFragment {
getResult().putExtra("needsRefresh", true);
return true;
});
Preference showIconsPreference = requirePreference("pref_show_icons");
showIconsPreference.setOnPreferenceChangeListener((preference, newValue) -> {
getResult().putExtra("needsRefresh", true);
return true;
});
}
}

View File

@ -45,6 +45,7 @@ public class EntryAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
private VaultEntry _focusedEntry;
private Preferences.CodeGrouping _codeGroupSize;
private boolean _showAccountName;
private boolean _showIcon;
private boolean _highlightEntry;
private boolean _tempHighlightEntry;
private boolean _tapToReveal;
@ -88,6 +89,10 @@ public class EntryAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
_showAccountName = showAccountName;
}
public void setShowIcon(boolean showIcon) {
_showIcon = showIcon;
}
public void setTapToReveal(boolean tapToReveal) {
_tapToReveal = tapToReveal;
}
@ -257,6 +262,7 @@ public class EntryAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
} else {
for (EntryHolder holder : _holders) {
holder.refresh();
holder.showIcon(_showIcon);
}
}
}
@ -375,13 +381,11 @@ public class EntryAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
RecyclerView.ViewHolder holder;
View view = inflater.inflate(viewType, parent, false);
if (viewType == R.layout.card_footer) {
holder = new FooterView(view);
} else {
EntryHolder entryHolder = new EntryHolder(view);
_view.setPreloadView(entryHolder.getIconView());
holder = entryHolder;
holder = viewType == R.layout.card_footer ? new FooterView(view) : new EntryHolder(view);
if (_showIcon && holder instanceof EntryHolder) {
_view.setPreloadView(((EntryHolder) holder).getIconView());
}
return holder;
}
@ -403,9 +407,12 @@ 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, _showAccountName, showProgress, hidden, paused, dimmed);
entryHolder.setData(entry, _codeGroupSize, _showAccountName, _showIcon, showProgress, hidden, paused, dimmed);
entryHolder.setFocused(_selectedEntries.contains(entry));
entryHolder.loadIcon(_view);
if (_showIcon) {
entryHolder.loadIcon(_view);
}
entryHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override

View File

@ -105,7 +105,7 @@ public class EntryHolder extends RecyclerView.ViewHolder {
});
}
public void setData(VaultEntry entry, Preferences.CodeGrouping groupSize, boolean showAccountName, boolean showProgress, boolean hidden, boolean paused, boolean dimmed) {
public void setData(VaultEntry entry, Preferences.CodeGrouping groupSize, boolean showAccountName, boolean showIcon, boolean showProgress, boolean hidden, boolean paused, boolean dimmed) {
_entry = entry;
_hidden = hidden;
_paused = paused;
@ -138,6 +138,8 @@ public class EntryHolder extends RecyclerView.ViewHolder {
refreshCode();
}
showIcon(showIcon);
itemView.setAlpha(dimmed ? DIMMED_ALPHA : DEFAULT_ALPHA);
}
@ -298,6 +300,14 @@ public class EntryHolder extends RecyclerView.ViewHolder {
_hidden = true;
}
public void showIcon(boolean show) {
if (show) {
_profileDrawable.setVisibility(View.VISIBLE);
} else {
_profileDrawable.setVisibility(View.GONE);
}
}
public void setPaused(boolean paused) {
_paused = paused;

View File

@ -297,6 +297,10 @@ public class EntryListView extends Fragment implements EntryAdapter.Listener {
_adapter.setShowAccountName(showAccountName);
}
public void setShowIcon(boolean showIcon) {
_adapter.setShowIcon(showIcon);
}
public void setHighlightEntry(boolean highlightEntry) {
_adapter.setHighlightEntry(highlightEntry);
}

View File

@ -38,6 +38,8 @@
<string name="pref_select_theme_title">Theme</string>
<string name="pref_view_mode_title">View mode</string>
<string name="pref_lang_title">Language</string>
<string name="pref_show_icons_title">Show icons</string>
<string name="pref_show_icons_summary">Display icons next to each entry</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_account_name_title">Show the account name</string>

View File

@ -30,6 +30,13 @@
android:title="@string/pref_view_mode_title"
app:iconSpaceReserved="false"/>
<androidx.preference.SwitchPreferenceCompat
android:defaultValue="true"
android:key="pref_show_icons"
android:title="@string/pref_show_icons_title"
android:summary="@string/pref_show_icons_summary"
app:iconSpaceReserved="false"/>
<ListPreference
android:key="pref_code_group_size_string"
android:title="@string/pref_code_group_size_title"