From c0b0ec10fc450b8abc4513132b81a81d94e9213d Mon Sep 17 00:00:00 2001 From: zeapo Date: Sat, 6 Dec 2014 01:55:21 +0100 Subject: Filter the passwords recursively, useful to search through the passwords from the root fixes #40 --- .../java/com/zeapo/pwdstore/PasswordFragment.java | 42 +++++++++++++++------- 1 file changed, 29 insertions(+), 13 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java b/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java index 2262b7d3..67fe79a6 100644 --- a/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java +++ b/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java @@ -150,25 +150,41 @@ public class PasswordFragment extends Fragment{ PasswordRepository.getPasswords(pathStack.peek())); } + /** + * filters the list adapter + * @param filter the filter to apply + */ public void filterAdapter(String filter) { Log.d("FRAG", "filter: " + filter); if (filter.isEmpty()) { refreshAdapter(); } else { - // on the root the pathStack is empty - List passwordItems = pathStack.isEmpty() ? - PasswordRepository.getPasswords() : - PasswordRepository.getPasswords(pathStack.peek()); - - for (PasswordItem item : passwordItems) { - boolean matches = item.toString().toLowerCase().contains(filter.toLowerCase()); - boolean inAdapter = recyclerAdapter.getValues().contains(item); - if (matches && !inAdapter) { - recyclerAdapter.add(item); - } else if (!matches && inAdapter) { - recyclerAdapter.remove(recyclerAdapter.getValues().indexOf(item)); - } + recursiveFilter(filter, pathStack.isEmpty() ? null : pathStack.peek()); + } + } + + /** + * recursively filters a directory and extract all the matching items + * @param filter the filter to apply + * @param dir the directory to filter + */ + private void recursiveFilter(String filter, File dir) { + // on the root the pathStack is empty + ArrayList passwordItems = dir == null ? + PasswordRepository.getPasswords() : + PasswordRepository.getPasswords(dir); + + for (PasswordItem item : passwordItems) { + if (item.getType() == PasswordItem.TYPE_CATEGORY) { + recursiveFilter(filter, item.getFile()); + } + boolean matches = item.toString().toLowerCase().contains(filter.toLowerCase()); + boolean inAdapter = recyclerAdapter.getValues().contains(item); + if (matches && !inAdapter) { + recyclerAdapter.add(item); + } else if (!matches && inAdapter) { + recyclerAdapter.remove(recyclerAdapter.getValues().indexOf(item)); } } } -- cgit v1.2.3 From 3f1caf89aa21b710ece3702f0217897baf8afe3a Mon Sep 17 00:00:00 2001 From: zeapo Date: Sat, 6 Dec 2014 18:03:43 +0100 Subject: Added preference to disable recursive filtering --- app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java | 7 ++++++- app/src/main/res/values/strings.xml | 4 +++- app/src/main/res/xml/preference.xml | 6 +++++- 3 files changed, 14 insertions(+), 3 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java b/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java index 67fe79a6..b2e06a1b 100644 --- a/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java +++ b/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java @@ -2,9 +2,11 @@ package com.zeapo.pwdstore; import android.app.Activity; import android.content.Intent; +import android.content.SharedPreferences; import android.net.Uri; import android.os.Bundle; import android.app.Fragment; +import android.preference.PreferenceManager; import android.support.v7.app.ActionBarActivity; import android.support.v7.internal.widget.AdapterViewCompat; import android.support.v7.widget.LinearLayoutManager; @@ -47,6 +49,7 @@ public class PasswordFragment extends Fragment{ private RecyclerView recyclerView; private RecyclerView.LayoutManager mLayoutManager; private OnFragmentInteractionListener mListener; + private SharedPreferences settings; /** * Mandatory empty constructor for the fragment manager to instantiate the @@ -60,6 +63,7 @@ public class PasswordFragment extends Fragment{ String path = getArguments().getString("Path"); + settings = PreferenceManager.getDefaultSharedPreferences(getActivity()); passListStack = new Stack>(); scrollPosition = new Stack(); pathStack = new Stack(); @@ -175,8 +179,9 @@ public class PasswordFragment extends Fragment{ PasswordRepository.getPasswords() : PasswordRepository.getPasswords(dir); + boolean rec = settings.getBoolean("filter_recursively", true); for (PasswordItem item : passwordItems) { - if (item.getType() == PasswordItem.TYPE_CATEGORY) { + if (item.getType() == PasswordItem.TYPE_CATEGORY && rec) { recursiveFilter(filter, item.getFile()); } boolean matches = item.toString().toLowerCase().contains(filter.toLowerCase()); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2f812e91..86885674 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -109,7 +109,9 @@ Automatically Copy Password Automatically copy the password to the clipboard after decryption was successful. Error while trying to import the ssh-key - Message : /n + Message : \n + Recursive filtering + Recursively find passwords of the current directory. OK diff --git a/app/src/main/res/xml/preference.xml b/app/src/main/res/xml/preference.xml index 1ad898a8..4c6e3157 100644 --- a/app/src/main/res/xml/preference.xml +++ b/app/src/main/res/xml/preference.xml @@ -22,10 +22,14 @@ + android:defaultValue="45" android:key="general_show_time" + android:inputType="number" /> + \ No newline at end of file -- cgit v1.2.3 From 0b0d14f26aeae922aed35f40e371724224ff6f69 Mon Sep 17 00:00:00 2001 From: zeapo Date: Sat, 6 Dec 2014 18:06:46 +0100 Subject: removed a dangerous log... --- app/src/main/java/com/zeapo/pwdstore/crypto/PgpHandler.java | 4 ---- 1 file changed, 4 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/com/zeapo/pwdstore/crypto/PgpHandler.java b/app/src/main/java/com/zeapo/pwdstore/crypto/PgpHandler.java index 178224b3..a9d11b90 100644 --- a/app/src/main/java/com/zeapo/pwdstore/crypto/PgpHandler.java +++ b/app/src/main/java/com/zeapo/pwdstore/crypto/PgpHandler.java @@ -322,9 +322,6 @@ public class PgpHandler extends ActionBarActivity implements OpenPgpServiceConne // encrypt/decrypt/sign/verify if (requestCode == REQUEST_CODE_DECRYPT_AND_VERIFY && os != null) { try { - Log.d(OpenPgpApi.TAG, "result: " + os.toByteArray().length - + " str=" + os.toString("UTF-8")); - if (returnToCiphertextField) { findViewById(R.id.crypto_container).setVisibility(View.VISIBLE); @@ -380,7 +377,6 @@ public class PgpHandler extends ActionBarActivity implements OpenPgpServiceConne String mKeys = keyIDs.split(",").length > 1 ? keyIDs : keyIDs.split(",")[0]; // ((TextView) findViewById(R.id.crypto_key_ids)).setText(mKeys); settings.edit().putString("openpgp_key_ids", keyIDs).apply(); - Log.i("PGP", mKeys); } setResult(RESULT_OK); finish(); -- cgit v1.2.3 From ad35b453f0a356af6ff6ac2028507d194f09e954 Mon Sep 17 00:00:00 2001 From: zeapo Date: Sat, 6 Dec 2014 18:11:11 +0100 Subject: formmating issue --- app/src/main/java/com/zeapo/pwdstore/crypto/PgpHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/src/main') diff --git a/app/src/main/java/com/zeapo/pwdstore/crypto/PgpHandler.java b/app/src/main/java/com/zeapo/pwdstore/crypto/PgpHandler.java index a9d11b90..1dfa2047 100644 --- a/app/src/main/java/com/zeapo/pwdstore/crypto/PgpHandler.java +++ b/app/src/main/java/com/zeapo/pwdstore/crypto/PgpHandler.java @@ -151,7 +151,7 @@ public class PgpHandler extends ActionBarActivity implements OpenPgpServiceConne clipboard.setPrimaryClip(clip); try { showToast(this.getResources().getString(R.string.clipboard_beginning_toast_text) - + Integer.parseInt(settings.getString("general_show_time", "45")) + + " " + Integer.parseInt(settings.getString("general_show_time", "45")) + " " + this.getResources().getString(R.string.clipboard_ending_toast_text)); } catch (NumberFormatException e) { -- cgit v1.2.3