From 7932dd8a81345f4f4cc10a4618c8f0856d9f45d1 Mon Sep 17 00:00:00 2001 From: Miroojin Bakshi Date: Thu, 6 Mar 2014 03:37:04 +0530 Subject: [PATCH] Implement search for SelectPublicKeyFragment --- .../keychain/ui/SelectPublicKeyFragment.java | 36 ++++++++++++++++--- .../res/layout/select_public_key_activity.xml | 8 +++++ 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/SelectPublicKeyFragment.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/SelectPublicKeyFragment.java index 59b46dd00..e3e5c55fb 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/SelectPublicKeyFragment.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/SelectPublicKeyFragment.java @@ -38,17 +38,22 @@ import android.os.Bundle; import android.support.v4.app.LoaderManager; import android.support.v4.content.CursorLoader; import android.support.v4.content.Loader; +import android.text.Editable; +import android.text.TextUtils; +import android.text.TextWatcher; +import android.widget.EditText; import android.widget.ListView; -public class SelectPublicKeyFragment extends ListFragmentWorkaround implements +public class SelectPublicKeyFragment extends ListFragmentWorkaround implements TextWatcher, LoaderManager.LoaderCallbacks { public static final String ARG_PRESELECTED_KEY_IDS = "preselected_key_ids"; private Activity mActivity; private SelectKeyCursorAdapter mAdapter; private ListView mListView; - + private EditText mSearchView; private long mSelectedMasterKeyIds[]; + private String mCurQuery; /** * Creates new instance of this fragment @@ -67,7 +72,8 @@ public class SelectPublicKeyFragment extends ListFragmentWorkaround implements @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - + mSearchView = (EditText)getActivity().findViewById(R.id.select_public_key_search); + mSearchView.addTextChangedListener(this); mSelectedMasterKeyIds = getArguments().getLongArray(ARG_PRESELECTED_KEY_IDS); } @@ -82,7 +88,6 @@ public class SelectPublicKeyFragment extends ListFragmentWorkaround implements mListView = getListView(); mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); - // Give some text to display if there is no data. In a real // application this would come from a resource. setEmptyText(getString(R.string.list_empty)); @@ -220,10 +225,14 @@ public class SelectPublicKeyFragment extends ListFragmentWorkaround implements // sort by selected master keys orderBy = inMasterKeyList + " DESC, " + orderBy; } + String where = null; + if(mCurQuery != null) + where = UserIds.USER_ID + " LIKE \"" + mCurQuery + "%\""; + // Now create and return a CursorLoader that will take care of // creating a Cursor for the data being displayed. - return new CursorLoader(getActivity(), baseUri, projection, null, null, orderBy); + return new CursorLoader(getActivity(), baseUri, projection, where, null, orderBy); } @Override @@ -250,4 +259,21 @@ public class SelectPublicKeyFragment extends ListFragmentWorkaround implements // longer using it. mAdapter.swapCursor(null); } + + @Override + public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { + + } + + @Override + public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) { + + } + + @Override + public void afterTextChanged(Editable editable) { + String newQuery = !TextUtils.isEmpty(editable.toString()) ? editable.toString() : null; + mCurQuery = newQuery; + getLoaderManager().restartLoader(0, null, this); + } } diff --git a/OpenPGP-Keychain/src/main/res/layout/select_public_key_activity.xml b/OpenPGP-Keychain/src/main/res/layout/select_public_key_activity.xml index a18ce46fc..5337433c6 100644 --- a/OpenPGP-Keychain/src/main/res/layout/select_public_key_activity.xml +++ b/OpenPGP-Keychain/src/main/res/layout/select_public_key_activity.xml @@ -4,8 +4,16 @@ android:layout_height="match_parent" android:layout_centerHorizontal="true" > + +