Cleanup code, search with preceeding %

This commit is contained in:
Dominik Schürmann 2014-03-07 19:50:36 +01:00
parent 59067f9f8b
commit ba61e69a7d
2 changed files with 14 additions and 34 deletions

View File

@ -180,7 +180,7 @@ public class KeyListPublicFragment extends Fragment implements SearchView.OnQuer
case R.id.menu_key_list_public_multi_select_all: { case R.id.menu_key_list_public_multi_select_all: {
//Select all //Select all
int localCount = mStickyList.getCount(); int localCount = mStickyList.getCount();
for(int k = 0; k < localCount; k++) { for (int k = 0; k < localCount; k++) {
mStickyList.setItemChecked(k, true); mStickyList.setItemChecked(k, true);
} }
break; break;
@ -243,9 +243,9 @@ public class KeyListPublicFragment extends Fragment implements SearchView.OnQuer
Uri baseUri = KeyRings.buildPublicKeyRingsUri(); Uri baseUri = KeyRings.buildPublicKeyRingsUri();
String where = null; String where = null;
String whereArgs[] = null; String whereArgs[] = null;
if(mCurQuery != null){ if (mCurQuery != null) {
where = KeychainContract.UserIds.USER_ID + " LIKE ?"; where = KeychainContract.UserIds.USER_ID + " LIKE ?";
whereArgs = new String[]{mCurQuery+"%"}; whereArgs = new String[]{"%" + 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.
@ -291,7 +291,7 @@ public class KeyListPublicFragment extends Fragment implements SearchView.OnQuer
viewIntent.setData(KeychainContract.KeyRings.buildPublicKeyRingsUri(Long.toString(id))); viewIntent.setData(KeychainContract.KeyRings.buildPublicKeyRingsUri(Long.toString(id)));
startActivity(viewIntent); startActivity(viewIntent);
} }
@TargetApi(11) @TargetApi(11)
public void encrypt(ActionMode mode, long[] keyRingRowIds) { public void encrypt(ActionMode mode, long[] keyRingRowIds) {
// get master key ids from row ids // get master key ids from row ids
@ -352,7 +352,6 @@ public class KeyListPublicFragment extends Fragment implements SearchView.OnQuer
@Override @Override
public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) { public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) {
// Get the searchview // Get the searchview
MenuItem searchItem = menu.findItem(R.id.menu_key_list_public_search); MenuItem searchItem = menu.findItem(R.id.menu_key_list_public_search);
mSearchView = (SearchView) MenuItemCompat.getActionView(searchItem); mSearchView = (SearchView) MenuItemCompat.getActionView(searchItem);
@ -361,7 +360,6 @@ public class KeyListPublicFragment extends Fragment implements SearchView.OnQuer
mSearchView.setOnQueryTextListener(this); mSearchView.setOnQueryTextListener(this);
super.onCreateOptionsMenu(menu, inflater); super.onCreateOptionsMenu(menu, inflater);
} }
@Override @Override
@ -374,8 +372,7 @@ public class KeyListPublicFragment extends Fragment implements SearchView.OnQuer
// Called when the action bar search text has changed. Update // Called when the action bar search text has changed. Update
// the search filter, and restart the loader to do a new query // the search filter, and restart the loader to do a new query
// with this filter. // with this filter.
String newQuery = !TextUtils.isEmpty(s) ? s : null; mCurQuery = !TextUtils.isEmpty(s) ? s : null;
mCurQuery = newQuery;
getLoaderManager().restartLoader(0, null, this); getLoaderManager().restartLoader(0, null, this);
return true; return true;
} }

View File

@ -72,7 +72,7 @@ public class SelectPublicKeyFragment extends ListFragmentWorkaround implements T
@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 = (EditText) getActivity().findViewById(R.id.select_public_key_search);
mSearchView.addTextChangedListener(this); mSearchView.addTextChangedListener(this);
mSelectedMasterKeyIds = getArguments().getLongArray(ARG_PRESELECTED_KEY_IDS); mSelectedMasterKeyIds = getArguments().getLongArray(ARG_PRESELECTED_KEY_IDS);
} }
@ -106,7 +106,7 @@ public class SelectPublicKeyFragment extends ListFragmentWorkaround implements T
/** /**
* Selects items based on master key ids in list view * Selects items based on master key ids in list view
* *
* @param masterKeyIds * @param masterKeyIds
*/ */
private void preselectMasterKeyIds(long[] masterKeyIds) { private void preselectMasterKeyIds(long[] masterKeyIds) {
@ -125,7 +125,7 @@ public class SelectPublicKeyFragment extends ListFragmentWorkaround implements T
/** /**
* Returns all selected master key ids * Returns all selected master key ids
* *
* @return * @return
*/ */
public long[] getSelectedMasterKeyIds() { public long[] getSelectedMasterKeyIds() {
@ -149,7 +149,7 @@ public class SelectPublicKeyFragment extends ListFragmentWorkaround implements T
/** /**
* Returns all selected user ids * Returns all selected user ids
* *
* @return * @return
*/ */
public String[] getSelectedUserIds() { public String[] getSelectedUserIds() {
@ -173,7 +173,7 @@ public class SelectPublicKeyFragment extends ListFragmentWorkaround implements T
// These are the rows that we will retrieve. // These are the rows that we will retrieve.
long now = new Date().getTime() / 1000; long now = new Date().getTime() / 1000;
String[] projection = new String[] { String[] projection = new String[]{
KeyRings._ID, KeyRings._ID,
KeyRings.MASTER_KEY_ID, KeyRings.MASTER_KEY_ID,
UserIds.USER_ID, UserIds.USER_ID,
@ -190,7 +190,7 @@ public class SelectPublicKeyFragment extends ListFragmentWorkaround implements T
+ Keys.CAN_ENCRYPT + " = '1' AND valid_keys." + Keys.CREATION + " <= '" + Keys.CAN_ENCRYPT + " = '1' AND valid_keys." + Keys.CREATION + " <= '"
+ now + "' AND " + "(valid_keys." + Keys.EXPIRY + " IS NULL OR valid_keys." + now + "' AND " + "(valid_keys." + Keys.EXPIRY + " IS NULL OR valid_keys."
+ Keys.EXPIRY + " >= '" + now + "')) AS " + Keys.EXPIRY + " >= '" + now + "')) AS "
+ SelectKeyCursorAdapter.PROJECTION_ROW_VALID, }; + SelectKeyCursorAdapter.PROJECTION_ROW_VALID,};
String inMasterKeyList = null; String inMasterKeyList = null;
if (mSelectedMasterKeyIds != null && mSelectedMasterKeyIds.length > 0) { if (mSelectedMasterKeyIds != null && mSelectedMasterKeyIds.length > 0) {
@ -204,22 +204,6 @@ public class SelectPublicKeyFragment extends ListFragmentWorkaround implements T
inMasterKeyList += ")"; inMasterKeyList += ")";
} }
// if (searchString != null && searchString.trim().length() > 0) {
// String[] chunks = searchString.trim().split(" +");
// qb.appendWhere("(EXISTS (SELECT tmp." + UserIds._ID + " FROM " + UserIds.TABLE_NAME
// + " AS tmp WHERE " + "tmp." + UserIds.KEY_ID + " = " + Keys.TABLE_NAME + "."
// + Keys._ID);
// for (int i = 0; i < chunks.length; ++i) {
// qb.appendWhere(" AND tmp." + UserIds.USER_ID + " LIKE ");
// qb.appendWhereEscapeString("%" + chunks[i] + "%");
// }
// qb.appendWhere("))");
//
// if (inIdList != null) {
// qb.appendWhere(" OR (" + inIdList + ")");
// }
// }
String orderBy = UserIds.USER_ID + " ASC"; String orderBy = UserIds.USER_ID + " ASC";
if (inMasterKeyList != null) { if (inMasterKeyList != null) {
// sort by selected master keys // sort by selected master keys
@ -227,9 +211,9 @@ public class SelectPublicKeyFragment extends ListFragmentWorkaround implements T
} }
String where = null; String where = null;
String whereArgs[] = null; String whereArgs[] = null;
if(mCurQuery != null){ if (mCurQuery != null) {
where = UserIds.USER_ID + " LIKE ?"; where = UserIds.USER_ID + " LIKE ?";
whereArgs = new String[]{mCurQuery+"%"}; whereArgs = new String[]{"%" + mCurQuery + "%"};
} }
// Now create and return a CursorLoader that will take care of // Now create and return a CursorLoader that will take care of
@ -274,8 +258,7 @@ public class SelectPublicKeyFragment extends ListFragmentWorkaround implements T
@Override @Override
public void afterTextChanged(Editable editable) { public void afterTextChanged(Editable editable) {
String newQuery = !TextUtils.isEmpty(editable.toString()) ? editable.toString() : null; mCurQuery = !TextUtils.isEmpty(editable.toString()) ? editable.toString() : null;
mCurQuery = newQuery;
getLoaderManager().restartLoader(0, null, this); getLoaderManager().restartLoader(0, null, this);
} }
} }