Add filtering to password list
This commit is contained in:
parent
9aea6560b0
commit
df1109cde5
8 changed files with 64 additions and 3 deletions
|
@ -126,6 +126,20 @@ public class PasswordFragment extends Fragment{
|
||||||
((ActionBarActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(false);
|
((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() {
|
public void popBack() {
|
||||||
recyclerView.scrollToPosition(scrollPosition.pop());
|
recyclerView.scrollToPosition(scrollPosition.pop());
|
||||||
recyclerAdapter.clear();
|
recyclerAdapter.clear();
|
||||||
|
|
|
@ -9,7 +9,9 @@ import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
import android.support.v4.view.MenuItemCompat;
|
||||||
import android.support.v7.app.ActionBarActivity;
|
import android.support.v7.app.ActionBarActivity;
|
||||||
|
import android.support.v7.widget.SearchView;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
@ -68,7 +70,36 @@ public class PasswordStore extends ActionBarActivity {
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
// Inflate the menu; this adds items to the action bar if it is present.
|
// Inflate the menu; this adds items to the action bar if it is present.
|
||||||
getMenuInflater().inflate(R.menu.pwdstore, menu);
|
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
|
@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() {
|
private File getCurrentDir() {
|
||||||
return new File(((PasswordFragment) getFragmentManager().findFragmentByTag("PasswordsList")).getArguments().getString("Path"));
|
return new File(((PasswordFragment) getFragmentManager().findFragmentByTag("PasswordsList")).getArguments().getString("Path"));
|
||||||
}
|
}
|
||||||
|
|
BIN
app/src/main/res/drawable-hdpi/ic_action_search.png
Normal file
BIN
app/src/main/res/drawable-hdpi/ic_action_search.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 702 B |
BIN
app/src/main/res/drawable-mdpi/ic_action_search.png
Normal file
BIN
app/src/main/res/drawable-mdpi/ic_action_search.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 479 B |
BIN
app/src/main/res/drawable-xhdpi/ic_action_search.png
Normal file
BIN
app/src/main/res/drawable-xhdpi/ic_action_search.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 900 B |
BIN
app/src/main/res/drawable-xxhdpi/ic_action_search.png
Normal file
BIN
app/src/main/res/drawable-xxhdpi/ic_action_search.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
|
@ -1,10 +1,17 @@
|
||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
xmlns:pwstore="http://schemas.android.com/apk/res-auto"
|
||||||
tools:context=".pwdstore" >
|
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"
|
<item android:id="@+id/menu_add_password"
|
||||||
android:icon="@drawable/ico_add"
|
android:icon="@drawable/ico_add"
|
||||||
android:showAsAction="always"
|
pwstore:showAsAction="ifRoom"
|
||||||
android:title="New password"/>
|
android:title="New password"/>
|
||||||
|
|
||||||
<!--<item android:id="@+id/menu_add_category"-->
|
<!--<item android:id="@+id/menu_add_category"-->
|
||||||
|
@ -17,7 +24,7 @@
|
||||||
|
|
||||||
<item android:id="@+id/referesh"
|
<item android:id="@+id/referesh"
|
||||||
android:title="Refresh list"
|
android:title="Refresh list"
|
||||||
android:showAsAction="never"
|
pwstore:showAsAction="never"
|
||||||
android:icon="@drawable/ico_sync"/>
|
android:icon="@drawable/ico_sync"/>
|
||||||
|
|
||||||
<item android:id="@+id/user_pref"
|
<item android:id="@+id/user_pref"
|
||||||
|
|
|
@ -42,6 +42,7 @@
|
||||||
|
|
||||||
<!-- DECRYPT Layout -->
|
<!-- DECRYPT Layout -->
|
||||||
<string name="crypto_category">Category</string>
|
<string name="crypto_category">Category</string>
|
||||||
|
<string name="action_search">Search</string>
|
||||||
|
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in a new issue