summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java16
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/PasswordStore.java41
-rw-r--r--app/src/main/res/drawable-hdpi/ic_action_search.pngbin0 -> 650 bytes
-rw-r--r--app/src/main/res/drawable-mdpi/ic_action_search.pngbin0 -> 449 bytes
-rw-r--r--app/src/main/res/drawable-xhdpi/ic_action_search.pngbin0 -> 827 bytes
-rw-r--r--app/src/main/res/drawable-xxhdpi/ic_action_search.pngbin0 -> 1152 bytes
-rw-r--r--app/src/main/res/menu/pwdstore.xml8
-rw-r--r--app/src/main/res/values/strings.xml1
8 files changed, 64 insertions, 2 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..6058d169 100644
--- a/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java
+++ b/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java
@@ -126,6 +126,22 @@ public class PasswordFragment extends Fragment{
((ActionBarActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(false);
}
+ public void filterAdapter(String filter) {
+ if (filter.isEmpty()) {
+ updateAdapter();
+ } else {
+ for (PasswordItem item : PasswordRepository.getPasswords()) {
+ boolean matches = item.getName().toLowerCase().contains(filter);
+ boolean inAdapter = recyclerAdapter.getValues().contains(item);
+ if (matches && !inAdapter) {
+ recyclerAdapter.add(item);
+ } else if (!matches && inAdapter) {
+ recyclerAdapter.remove(recyclerAdapter.getValues().indexOf(item));
+ }
+ }
+ }
+ }
+
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 274960a7..759b0989 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;
@@ -67,7 +69,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
@@ -375,6 +406,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"));
}
diff --git a/app/src/main/res/drawable-hdpi/ic_action_search.png b/app/src/main/res/drawable-hdpi/ic_action_search.png
new file mode 100644
index 00000000..772e3598
--- /dev/null
+++ b/app/src/main/res/drawable-hdpi/ic_action_search.png
Binary files differ
diff --git a/app/src/main/res/drawable-mdpi/ic_action_search.png b/app/src/main/res/drawable-mdpi/ic_action_search.png
new file mode 100644
index 00000000..4edb1ff9
--- /dev/null
+++ b/app/src/main/res/drawable-mdpi/ic_action_search.png
Binary files differ
diff --git a/app/src/main/res/drawable-xhdpi/ic_action_search.png b/app/src/main/res/drawable-xhdpi/ic_action_search.png
new file mode 100644
index 00000000..19658e4a
--- /dev/null
+++ b/app/src/main/res/drawable-xhdpi/ic_action_search.png
Binary files differ
diff --git a/app/src/main/res/drawable-xxhdpi/ic_action_search.png b/app/src/main/res/drawable-xxhdpi/ic_action_search.png
new file mode 100644
index 00000000..a1086388
--- /dev/null
+++ b/app/src/main/res/drawable-xxhdpi/ic_action_search.png
Binary files differ
diff --git a/app/src/main/res/menu/pwdstore.xml b/app/src/main/res/menu/pwdstore.xml
index d6f81b73..d5d4361d 100644
--- a/app/src/main/res/menu/pwdstore.xml
+++ b/app/src/main/res/menu/pwdstore.xml
@@ -3,9 +3,15 @@
xmlns:pwstore="http://schemas.android.com/apk/res-auto"
tools:context=".pwdstore" >
+ <item android:id="@+id/action_search"
+ android:title="@string/action_search"
+ android:icon="@drawable/ic_action_search"
+ pwstore:showAsAction="ifRoom|collapseActionView"
+ pwstore:actionViewClass="android.support.v7.widget.SearchView" />
+
<item android:id="@+id/menu_add_password"
android:icon="@drawable/ico_add"
- pwstore:showAsAction="always"
+ pwstore:showAsAction="ifRoom"
android:title="New password"/>
<!--<item android:id="@+id/menu_add_category"-->
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index c35514ec..07c6b3fd 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -42,6 +42,7 @@
<!-- DECRYPT Layout -->
<string name="crypto_category">Category</string>
+ <string name="action_search">Search</string>
</resources>