mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-05-04 20:30:36 +00:00
Merge pull request #109 from michaelschattgen/feature-entrysearch
Add ability to search for entries in vault
This commit is contained in:
commit
cca35bd5e5
5 changed files with 69 additions and 3 deletions
|
@ -15,8 +15,11 @@ import android.view.MenuItem;
|
|||
import android.view.MotionEvent;
|
||||
import android.view.SubMenu;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.SearchView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.core.view.MenuItemCompat;
|
||||
|
||||
import com.beemdevelopment.aegis.AegisApplication;
|
||||
import com.beemdevelopment.aegis.R;
|
||||
import com.beemdevelopment.aegis.SortCategory;
|
||||
|
@ -67,8 +70,10 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
|
|||
private DatabaseManager _db;
|
||||
private boolean _loaded;
|
||||
private String _checkedGroup;
|
||||
private boolean _searchSubmitted;
|
||||
|
||||
private Menu _menu;
|
||||
private SearchView _searchView;
|
||||
private FloatingActionsMenu _fabMenu;
|
||||
private EntryListView _entryListView;
|
||||
|
||||
|
@ -417,6 +422,16 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
|
|||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (!_searchView.isIconified() || _searchSubmitted ) {
|
||||
_searchSubmitted = false;
|
||||
_entryListView.setSearchFilter(null);
|
||||
|
||||
collapseSearchView();
|
||||
setTitle("Aegis");
|
||||
setGroupFilter(_checkedGroup);
|
||||
return;
|
||||
}
|
||||
|
||||
if (_app.isAutoLockEnabled()) {
|
||||
_app.lock();
|
||||
}
|
||||
|
@ -477,6 +492,31 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
|
|||
updateGroupFilterMenu();
|
||||
updateSortCategoryMenu();
|
||||
}
|
||||
|
||||
MenuItem searchViewMenuItem = menu.findItem(R.id.mi_search);
|
||||
|
||||
_searchView = (SearchView) searchViewMenuItem.getActionView();
|
||||
_searchView.setFocusable(false);
|
||||
_searchView.setQueryHint(getString(R.string.search));
|
||||
_searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
||||
@Override
|
||||
public boolean onQueryTextSubmit(String s) {
|
||||
setTitle(getString(R.string.search));
|
||||
getSupportActionBar().setSubtitle(s);
|
||||
_searchSubmitted = true;
|
||||
collapseSearchView();
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextChange(String s) {
|
||||
if (!_searchSubmitted) {
|
||||
_entryListView.setSearchFilter(s);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -531,6 +571,11 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
|
|||
}
|
||||
}
|
||||
|
||||
private void collapseSearchView() {
|
||||
_searchView.setQuery(null, false);
|
||||
_searchView.setIconified(true);
|
||||
}
|
||||
|
||||
private boolean unlockDatabase(DatabaseFileCredentials creds) {
|
||||
try {
|
||||
if (!_db.isLoaded()) {
|
||||
|
|
|
@ -31,6 +31,7 @@ public class EntryAdapter extends RecyclerView.Adapter<EntryHolder> implements I
|
|||
private String _groupFilter;
|
||||
private SortCategory _sortCategory;
|
||||
private ViewMode _viewMode;
|
||||
private String _searchFilter;
|
||||
private boolean _isPeriodUniform = true;
|
||||
|
||||
// keeps track of the viewholders that are currently bound
|
||||
|
@ -141,10 +142,13 @@ public class EntryAdapter extends RecyclerView.Adapter<EntryHolder> implements I
|
|||
|
||||
private boolean isEntryFiltered(DatabaseEntry entry) {
|
||||
String group = entry.getGroup();
|
||||
if (_groupFilter == null) {
|
||||
return false;
|
||||
String issuer = entry.getIssuer().toLowerCase();
|
||||
|
||||
if (_groupFilter != null && (group == null || !group.equals(_groupFilter))) {
|
||||
return true;
|
||||
}
|
||||
return group == null || !group.equals(_groupFilter);
|
||||
|
||||
return _searchFilter != null && !issuer.contains(_searchFilter);
|
||||
}
|
||||
|
||||
private DatabaseEntry getEntryByUUID(UUID uuid) {
|
||||
|
@ -187,6 +191,11 @@ public class EntryAdapter extends RecyclerView.Adapter<EntryHolder> implements I
|
|||
}
|
||||
}
|
||||
|
||||
public void setSearchFilter(String search) {
|
||||
_searchFilter = search != null ? search.toLowerCase() : null;
|
||||
updateShownEntries();
|
||||
}
|
||||
|
||||
private void updateShownEntries() {
|
||||
// clear the list of shown entries first
|
||||
_shownEntries.clear();
|
||||
|
|
|
@ -100,6 +100,11 @@ public class EntryListView extends Fragment implements EntryAdapter.Listener {
|
|||
}
|
||||
}
|
||||
|
||||
public void setSearchFilter(String search) {
|
||||
_touchCallback.setIsLongPressDragEnabled(search == null);
|
||||
_adapter.setSearchFilter(search);
|
||||
}
|
||||
|
||||
public void setViewMode(ViewMode mode) {
|
||||
_adapter.setViewMode(mode);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue