diff options
Diffstat (limited to 'app/src/main/java')
-rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java | 14 | ||||
-rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/PasswordStore.java | 41 |
2 files changed, 54 insertions, 1 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java b/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java index 4e8ef5ef..4d433013 100644 --- a/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java +++ b/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java @@ -126,6 +126,20 @@ public class PasswordFragment extends Fragment{ ((ActionBarActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(false); } + public void filterAdapter(String filter) { + if (filter.isEmpty()) { + updateAdapter(); + return; + } + for (int i=0; i<recyclerAdapter.getItemCount(); i++) { + PasswordItem item = recyclerAdapter.getValues().get(i); + boolean matches = item.getName().toLowerCase().contains(filter); + if (!matches) { + recyclerAdapter.remove(i); + } + } + } + public void popBack() { recyclerView.scrollToPosition(scrollPosition.pop()); recyclerAdapter.clear(); diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java index 025435f4..a82aec2c 100644 --- a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java +++ b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java @@ -9,7 +9,9 @@ import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; import android.preference.PreferenceManager; +import android.support.v4.view.MenuItemCompat; import android.support.v7.app.ActionBarActivity; +import android.support.v7.widget.SearchView; import android.util.Log; import android.view.Menu; import android.view.MenuItem; @@ -68,7 +70,36 @@ public class PasswordStore extends ActionBarActivity { public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.pwdstore, menu); - return true; + MenuItem searchItem = menu.findItem(R.id.action_search); + SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem); + searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { + @Override + public boolean onQueryTextSubmit(String s) { + return true; + } + + @Override + public boolean onQueryTextChange(String s) { + filterListAdapter(s); + return true; + } + }); + + // When using the support library, the setOnActionExpandListener() method is + // static and accepts the MenuItem object as an argument + MenuItemCompat.setOnActionExpandListener(searchItem, new MenuItemCompat.OnActionExpandListener() { + @Override + public boolean onMenuItemActionCollapse(MenuItem item) { + refreshListAdapter(); + return true; + } + + @Override + public boolean onMenuItemActionExpand(MenuItem item) { + return true; + } + }); + return super.onCreateOptionsMenu(menu); } @Override @@ -376,6 +407,14 @@ public class PasswordStore extends ActionBarActivity { } } + public void filterListAdapter(String filter) { + PasswordFragment plist; + if (null != + (plist = (PasswordFragment) getFragmentManager().findFragmentByTag("PasswordsList"))) { + plist.filterAdapter(filter); + } + } + private File getCurrentDir() { return new File(((PasswordFragment) getFragmentManager().findFragmentByTag("PasswordsList")).getArguments().getString("Path")); } |