mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-11 11:35:07 -05:00
Merge pull request #384 from mb-14/search1
Highlight search query in SelectPublicKeyFragment and KeyListPublicFragment
This commit is contained in:
commit
70d1e01a2b
@ -272,8 +272,8 @@ public class KeyListPublicFragment extends Fragment implements SearchView.OnQuer
|
|||||||
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
|
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
|
||||||
// Swap the new cursor in. (The framework will take care of closing the
|
// Swap the new cursor in. (The framework will take care of closing the
|
||||||
// old cursor once we return.)
|
// old cursor once we return.)
|
||||||
|
mAdapter.setSearchQuery(mCurQuery);
|
||||||
mAdapter.swapCursor(data);
|
mAdapter.swapCursor(data);
|
||||||
|
|
||||||
mStickyList.setAdapter(mAdapter);
|
mStickyList.setAdapter(mAdapter);
|
||||||
|
|
||||||
// NOTE: Not supported by StickyListHeader, but reimplemented here
|
// NOTE: Not supported by StickyListHeader, but reimplemented here
|
||||||
|
@ -311,6 +311,7 @@ public class SelectPublicKeyFragment extends ListFragmentWorkaround implements T
|
|||||||
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
|
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
|
||||||
// Swap the new cursor in. (The framework will take care of closing the
|
// Swap the new cursor in. (The framework will take care of closing the
|
||||||
// old cursor once we return.)
|
// old cursor once we return.)
|
||||||
|
mAdapter.setSearchQuery(mCurQuery);
|
||||||
mAdapter.swapCursor(data);
|
mAdapter.swapCursor(data);
|
||||||
|
|
||||||
// The list should now be shown.
|
// The list should now be shown.
|
||||||
|
@ -0,0 +1,61 @@
|
|||||||
|
package org.sufficientlysecure.keychain.ui.adapter;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.text.Spannable;
|
||||||
|
import android.text.style.ForegroundColorSpan;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.support.v4.widget.CursorAdapter;
|
||||||
|
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
|
||||||
|
public class HighlightQueryCursorAdapter extends CursorAdapter {
|
||||||
|
|
||||||
|
private String mCurQuery;
|
||||||
|
|
||||||
|
public HighlightQueryCursorAdapter(Context context, Cursor c, int flags) {
|
||||||
|
super(context, c, flags);
|
||||||
|
mCurQuery = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View newView(Context context, Cursor cursor, ViewGroup parent) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void bindView(View view, Context context, Cursor cursor) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSearchQuery(String searchQuery){
|
||||||
|
mCurQuery = searchQuery;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSearchQuery(){
|
||||||
|
return mCurQuery;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Spannable highlightSearchKey(String text) {
|
||||||
|
Spannable highlight;
|
||||||
|
Pattern pattern;
|
||||||
|
Matcher matcher;
|
||||||
|
|
||||||
|
highlight = Spannable.Factory.getInstance().newSpannable(text);;
|
||||||
|
pattern = Pattern.compile("(?i)" + mCurQuery);
|
||||||
|
matcher = pattern.matcher(text);
|
||||||
|
if (matcher.find()) {
|
||||||
|
highlight.setSpan(
|
||||||
|
new ForegroundColorSpan(0xFF33B5E5),
|
||||||
|
matcher.start(),
|
||||||
|
matcher.end(),
|
||||||
|
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
|
}
|
||||||
|
return highlight;
|
||||||
|
}
|
||||||
|
}
|
@ -20,6 +20,7 @@ package org.sufficientlysecure.keychain.ui.adapter;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
|
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
|
||||||
@ -32,7 +33,6 @@ import android.annotation.SuppressLint;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.support.v4.widget.CursorAdapter;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@ -41,7 +41,7 @@ import android.widget.TextView;
|
|||||||
/**
|
/**
|
||||||
* Implements StickyListHeadersAdapter from library
|
* Implements StickyListHeadersAdapter from library
|
||||||
*/
|
*/
|
||||||
public class KeyListPublicAdapter extends CursorAdapter implements StickyListHeadersAdapter {
|
public class KeyListPublicAdapter extends HighlightQueryCursorAdapter implements StickyListHeadersAdapter {
|
||||||
private LayoutInflater mInflater;
|
private LayoutInflater mInflater;
|
||||||
private int mSectionColumnIndex;
|
private int mSectionColumnIndex;
|
||||||
private int mIndexUserId;
|
private int mIndexUserId;
|
||||||
@ -52,7 +52,6 @@ public class KeyListPublicAdapter extends CursorAdapter implements StickyListHea
|
|||||||
|
|
||||||
public KeyListPublicAdapter(Context context, Cursor c, int flags, int sectionColumnIndex) {
|
public KeyListPublicAdapter(Context context, Cursor c, int flags, int sectionColumnIndex) {
|
||||||
super(context, c, flags);
|
super(context, c, flags);
|
||||||
|
|
||||||
mInflater = LayoutInflater.from(context);
|
mInflater = LayoutInflater.from(context);
|
||||||
mSectionColumnIndex = sectionColumnIndex;
|
mSectionColumnIndex = sectionColumnIndex;
|
||||||
initIndex(c);
|
initIndex(c);
|
||||||
@ -110,6 +109,12 @@ public class KeyListPublicAdapter extends CursorAdapter implements StickyListHea
|
|||||||
} else {
|
} else {
|
||||||
revoked.setVisibility(View.GONE);
|
revoked.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
String query = getSearchQuery();
|
||||||
|
|
||||||
|
if(query != null){
|
||||||
|
mainUserId.setText(highlightSearchKey(userIdSplit[0]));
|
||||||
|
mainUserIdRest.setText(highlightSearchKey(userIdSplit[1]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -25,7 +25,6 @@ import org.sufficientlysecure.keychain.provider.KeychainContract.UserIds;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.support.v4.widget.CursorAdapter;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@ -33,7 +32,9 @@ import android.widget.CheckBox;
|
|||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
public class SelectKeyCursorAdapter extends CursorAdapter {
|
|
||||||
|
|
||||||
|
public class SelectKeyCursorAdapter extends HighlightQueryCursorAdapter {
|
||||||
|
|
||||||
protected int mKeyType;
|
protected int mKeyType;
|
||||||
|
|
||||||
@ -55,7 +56,6 @@ public class SelectKeyCursorAdapter extends CursorAdapter {
|
|||||||
mInflater = LayoutInflater.from(context);
|
mInflater = LayoutInflater.from(context);
|
||||||
mListView = listView;
|
mListView = listView;
|
||||||
mKeyType = keyType;
|
mKeyType = keyType;
|
||||||
|
|
||||||
initIndex(c);
|
initIndex(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,11 +158,15 @@ public class SelectKeyCursorAdapter extends CursorAdapter {
|
|||||||
mainUserIdRest.setEnabled(valid);
|
mainUserIdRest.setEnabled(valid);
|
||||||
keyId.setEnabled(valid);
|
keyId.setEnabled(valid);
|
||||||
status.setEnabled(valid);
|
status.setEnabled(valid);
|
||||||
|
String query = getSearchQuery();
|
||||||
|
if(query != null){
|
||||||
|
mainUserId.setText(highlightSearchKey(userIdSplit[0]));
|
||||||
|
mainUserIdRest.setText(highlightSearchKey(userIdSplit[1]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View newView(Context context, Cursor cursor, ViewGroup parent) {
|
public View newView(Context context, Cursor cursor, ViewGroup parent) {
|
||||||
return mInflater.inflate(R.layout.select_key_item, null);
|
return mInflater.inflate(R.layout.select_key_item, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user