Implement search for SelectPublicKeyFragment
This commit is contained in:
@@ -38,17 +38,22 @@ import android.os.Bundle;
|
|||||||
import android.support.v4.app.LoaderManager;
|
import android.support.v4.app.LoaderManager;
|
||||||
import android.support.v4.content.CursorLoader;
|
import android.support.v4.content.CursorLoader;
|
||||||
import android.support.v4.content.Loader;
|
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;
|
import android.widget.ListView;
|
||||||
|
|
||||||
public class SelectPublicKeyFragment extends ListFragmentWorkaround implements
|
public class SelectPublicKeyFragment extends ListFragmentWorkaround implements TextWatcher,
|
||||||
LoaderManager.LoaderCallbacks<Cursor> {
|
LoaderManager.LoaderCallbacks<Cursor> {
|
||||||
public static final String ARG_PRESELECTED_KEY_IDS = "preselected_key_ids";
|
public static final String ARG_PRESELECTED_KEY_IDS = "preselected_key_ids";
|
||||||
|
|
||||||
private Activity mActivity;
|
private Activity mActivity;
|
||||||
private SelectKeyCursorAdapter mAdapter;
|
private SelectKeyCursorAdapter mAdapter;
|
||||||
private ListView mListView;
|
private ListView mListView;
|
||||||
|
private EditText mSearchView;
|
||||||
private long mSelectedMasterKeyIds[];
|
private long mSelectedMasterKeyIds[];
|
||||||
|
private String mCurQuery;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates new instance of this fragment
|
* Creates new instance of this fragment
|
||||||
@@ -67,7 +72,8 @@ public class SelectPublicKeyFragment extends ListFragmentWorkaround implements
|
|||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
mSearchView = (EditText)getActivity().findViewById(R.id.select_public_key_search);
|
||||||
|
mSearchView.addTextChangedListener(this);
|
||||||
mSelectedMasterKeyIds = getArguments().getLongArray(ARG_PRESELECTED_KEY_IDS);
|
mSelectedMasterKeyIds = getArguments().getLongArray(ARG_PRESELECTED_KEY_IDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,7 +88,6 @@ public class SelectPublicKeyFragment extends ListFragmentWorkaround implements
|
|||||||
mListView = getListView();
|
mListView = getListView();
|
||||||
|
|
||||||
mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
|
mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
|
||||||
|
|
||||||
// Give some text to display if there is no data. In a real
|
// Give some text to display if there is no data. In a real
|
||||||
// application this would come from a resource.
|
// application this would come from a resource.
|
||||||
setEmptyText(getString(R.string.list_empty));
|
setEmptyText(getString(R.string.list_empty));
|
||||||
@@ -220,10 +225,14 @@ public class SelectPublicKeyFragment extends ListFragmentWorkaround implements
|
|||||||
// sort by selected master keys
|
// sort by selected master keys
|
||||||
orderBy = inMasterKeyList + " DESC, " + orderBy;
|
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
|
// Now create and return a CursorLoader that will take care of
|
||||||
// creating a Cursor for the data being displayed.
|
// 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
|
@Override
|
||||||
@@ -250,4 +259,21 @@ public class SelectPublicKeyFragment extends ListFragmentWorkaround implements
|
|||||||
// longer using it.
|
// longer using it.
|
||||||
mAdapter.swapCursor(null);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,16 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_centerHorizontal="true" >
|
android:layout_centerHorizontal="true" >
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/select_public_key_search"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="@string/menu_search"
|
||||||
|
android:drawableLeft="@drawable/ic_action_search"/>
|
||||||
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:id="@+id/select_public_key_fragment_container"
|
android:id="@+id/select_public_key_fragment_container"
|
||||||
|
android:layout_below="@id/select_public_key_search"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent" />
|
android:layout_height="match_parent" />
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user