Skip to content

Commit

Permalink
Merge pull request beemdevelopment#201 from michaelschattgen/feature-…
Browse files Browse the repository at this point in the history
…usernamesearch

Add ability to search in account names
  • Loading branch information
alexbakker authored Sep 14, 2019
2 parents 0200287 + 445410f commit ac222c4
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 1 deletion.
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 @@ -19,6 +19,8 @@ public boolean isTapToRevealEnabled() {
return _prefs.getBoolean("pref_tap_to_reveal", false);
}

public boolean isSearchAccountNameEnabled() { return _prefs.getBoolean("pref_search_names", false); }

public boolean isSecureScreenEnabled() {
// screen security should be enabled by default, but not for debug builds
return _prefs.getBoolean("pref_secure_screen", !BuildConfig.DEBUG);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ protected void onCreate(Bundle savedInstanceState) {
_entryListView = (EntryListView) getSupportFragmentManager().findFragmentById(R.id.key_profiles);
_entryListView.setListener(this);
_entryListView.setShowAccountName(getPreferences().isAccountNameVisible());
_entryListView.setSearchAccountName(getPreferences().isSearchAccountNameEnabled());
_entryListView.setTapToReveal(getPreferences().isTapToRevealEnabled());
_entryListView.setTapToRevealTime(getPreferences().getTapToRevealTime());
_entryListView.setSortCategory(getPreferences().getCurrentSortCategory(), false);
Expand Down Expand Up @@ -216,10 +217,12 @@ private void onPreferencesResult(int resultCode, Intent data) {
recreate();
} else if (data.getBooleanExtra("needsRefresh", false)) {
boolean showAccountName = getPreferences().isAccountNameVisible();
boolean searchAccountName = getPreferences().isSearchAccountNameEnabled();
boolean tapToReveal = getPreferences().isTapToRevealEnabled();
int tapToRevealTime = getPreferences().getTapToRevealTime();
ViewMode viewMode = getPreferences().getCurrentViewMode();
_entryListView.setShowAccountName(showAccountName);
_entryListView.setSearchAccountName(searchAccountName);
_entryListView.setTapToReveal(tapToReveal);
_entryListView.setTapToRevealTime(tapToRevealTime);
_entryListView.setViewMode(viewMode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,12 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
}
});

Preference searchAccountNamePreference = findPreference("pref_search_names");
searchAccountNamePreference.setOnPreferenceChangeListener((preference, newValue) -> {
_result.putExtra("needsRefresh", true);
return true;
});

Preference tapToRevealPreference = findPreference("pref_tap_to_reveal");
tapToRevealPreference.setOnPreferenceChangeListener((preference, newValue) -> {
_result.putExtra("needsRefresh", true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class EntryAdapter extends RecyclerView.Adapter<EntryHolder> implements I
private List<DatabaseEntry> _shownEntries;
private DatabaseEntry _selectedEntry;
private boolean _showAccountName;
private boolean _searchAccountName;
private boolean _tapToReveal;
private int _tapToRevealTime;
private String _groupFilter;
Expand Down Expand Up @@ -63,6 +64,8 @@ public void setTapToRevealTime(int number) {
_tapToRevealTime = number;
}

public void setSearchAccountName(boolean searchAccountName) { _searchAccountName = searchAccountName; }

public DatabaseEntry getEntryAt(int position) {
return _shownEntries.get(position);
}
Expand Down Expand Up @@ -153,12 +156,17 @@ public void replaceEntry(DatabaseEntry oldEntry, DatabaseEntry newEntry) {
private boolean isEntryFiltered(DatabaseEntry entry) {
String group = entry.getGroup();
String issuer = entry.getIssuer().toLowerCase();
String name = entry.getName().toLowerCase();

if (_groupFilter != null && (group == null || !group.equals(_groupFilter))) {
return true;
}

return _searchFilter != null && !issuer.contains(_searchFilter);
if (_searchFilter == null) {
return false;
}

return !issuer.contains(_searchFilter) && !(_searchAccountName && name.contains(_searchFilter));
}

public void refresh(boolean hard) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ public void setShowAccountName(boolean showAccountName) {
_adapter.setShowAccountName(showAccountName);
}

public void setSearchAccountName(boolean searchAccountName) {
_adapter.setSearchAccountName(searchAccountName);
}

public void setTapToReveal(boolean tapToReveal) {
_adapter.setTapToReveal(tapToReveal);
}
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

<string name="settings">Preferences</string>
<string name="pref_appearance_group_title">Appearance</string>
<string name="pref_general_group_title">General</string>
<string name="pref_security_group_title">Security</string>
<string name="pref_tools_group_title">Tools</string>
<string name="pref_select_theme_title">Theme</string>
Expand Down Expand Up @@ -155,6 +156,8 @@
<string name="group_name_hint">Group name</string>
<string name="preference_manage_groups">Edit groups</string>
<string name="preference_manage_groups_summary">Manage and delete your groups here</string>
<string name="pref_search_name_title">Search in account names</string>
<string name="pref_search_name_summary">Include account name matches in the search results</string>
<string name="tap_to_reveal">Hidden</string>
<string name="selected">Selected</string>
<string name="dark_theme_title">Dark theme</string>
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@
app:iconSpaceReserved="false"/>
</PreferenceCategory>

<PreferenceCategory
android:title="@string/pref_general_group_title"
app:iconSpaceReserved="false">
<androidx.preference.SwitchPreferenceCompat
android:defaultValue="false"
android:key="pref_search_names"
android:title="@string/pref_search_name_title"
android:summary="@string/pref_search_name_summary"
app:iconSpaceReserved="false"/>
</PreferenceCategory>

<PreferenceCategory
android:title="@string/pref_security_group_title"
app:iconSpaceReserved="false">
Expand Down

0 comments on commit ac222c4

Please sign in to comment.