mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-05-14 14:02:49 +00:00
Add ability to search for entries
Fix bug where new entries did not get filtered Fix IsEntryFiltered
This commit is contained in:
parent
b2995955b6
commit
187adfa738
5 changed files with 69 additions and 3 deletions
|
@ -15,8 +15,11 @@ import android.view.MenuItem;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.SubMenu;
|
import android.view.SubMenu;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.SearchView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.core.view.MenuItemCompat;
|
||||||
|
|
||||||
import com.beemdevelopment.aegis.AegisApplication;
|
import com.beemdevelopment.aegis.AegisApplication;
|
||||||
import com.beemdevelopment.aegis.R;
|
import com.beemdevelopment.aegis.R;
|
||||||
import com.beemdevelopment.aegis.SortCategory;
|
import com.beemdevelopment.aegis.SortCategory;
|
||||||
|
@ -67,8 +70,10 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
|
||||||
private DatabaseManager _db;
|
private DatabaseManager _db;
|
||||||
private boolean _loaded;
|
private boolean _loaded;
|
||||||
private String _checkedGroup;
|
private String _checkedGroup;
|
||||||
|
private boolean _searchSubmitted;
|
||||||
|
|
||||||
private Menu _menu;
|
private Menu _menu;
|
||||||
|
private SearchView _searchView;
|
||||||
private FloatingActionsMenu _fabMenu;
|
private FloatingActionsMenu _fabMenu;
|
||||||
private EntryListView _entryListView;
|
private EntryListView _entryListView;
|
||||||
|
|
||||||
|
@ -417,6 +422,16 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
|
if (!_searchView.isIconified() || _searchSubmitted ) {
|
||||||
|
_searchSubmitted = false;
|
||||||
|
_entryListView.setSearchFilter(null);
|
||||||
|
|
||||||
|
collapseSearchView();
|
||||||
|
setTitle("Aegis");
|
||||||
|
setGroupFilter(_checkedGroup);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (_app.isAutoLockEnabled()) {
|
if (_app.isAutoLockEnabled()) {
|
||||||
_app.lock();
|
_app.lock();
|
||||||
}
|
}
|
||||||
|
@ -477,6 +492,31 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
|
||||||
updateGroupFilterMenu();
|
updateGroupFilterMenu();
|
||||||
updateSortCategoryMenu();
|
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;
|
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) {
|
private boolean unlockDatabase(DatabaseFileCredentials creds) {
|
||||||
try {
|
try {
|
||||||
if (!_db.isLoaded()) {
|
if (!_db.isLoaded()) {
|
||||||
|
|
|
@ -31,6 +31,7 @@ public class EntryAdapter extends RecyclerView.Adapter<EntryHolder> implements I
|
||||||
private String _groupFilter;
|
private String _groupFilter;
|
||||||
private SortCategory _sortCategory;
|
private SortCategory _sortCategory;
|
||||||
private ViewMode _viewMode;
|
private ViewMode _viewMode;
|
||||||
|
private String _searchFilter;
|
||||||
private boolean _isPeriodUniform = true;
|
private boolean _isPeriodUniform = true;
|
||||||
|
|
||||||
// keeps track of the viewholders that are currently bound
|
// 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) {
|
private boolean isEntryFiltered(DatabaseEntry entry) {
|
||||||
String group = entry.getGroup();
|
String group = entry.getGroup();
|
||||||
if (_groupFilter == null) {
|
String issuer = entry.getIssuer().toLowerCase();
|
||||||
return false;
|
|
||||||
|
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) {
|
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() {
|
private void updateShownEntries() {
|
||||||
// clear the list of shown entries first
|
// clear the list of shown entries first
|
||||||
_shownEntries.clear();
|
_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) {
|
public void setViewMode(ViewMode mode) {
|
||||||
_adapter.setViewMode(mode);
|
_adapter.setViewMode(mode);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,12 @@
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
tools:context="com.beemdevelopment.aegis.com.impy.aegis.ui.MainActivity">
|
tools:context="com.beemdevelopment.aegis.com.impy.aegis.ui.MainActivity">
|
||||||
|
<item
|
||||||
|
android:id="@+id/mi_search"
|
||||||
|
android:title="@string/search"
|
||||||
|
app:showAsAction="always"
|
||||||
|
app:actionViewClass="android.widget.SearchView"
|
||||||
|
/>
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_lock"
|
android:id="@+id/action_lock"
|
||||||
android:icon="@drawable/ic_lock"
|
android:icon="@drawable/ic_lock"
|
||||||
|
|
|
@ -165,4 +165,5 @@
|
||||||
<string name="unable_to_read_qrcode">Unable to read and process QR code</string>
|
<string name="unable_to_read_qrcode">Unable to read and process QR code</string>
|
||||||
<string name="select_picture">Select picture</string>
|
<string name="select_picture">Select picture</string>
|
||||||
<string name="toggle_checkboxes">Toggle checkboxes</string>
|
<string name="toggle_checkboxes">Toggle checkboxes</string>
|
||||||
|
<string name="search">Search</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue