mirror of
https://github.com/moparisthebest/open-keychain
synced 2025-02-07 10:30:14 -05:00
Highlight search query in SelectPublicKeyFragment and
KeyListPublicFragment
This commit is contained in:
parent
8d85aa5876
commit
b927c0f26a
@ -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.
|
||||||
|
@ -19,6 +19,8 @@ package org.sufficientlysecure.keychain.ui.adapter;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
@ -33,6 +35,9 @@ 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.support.v4.widget.CursorAdapter;
|
||||||
|
import android.text.Html;
|
||||||
|
import android.text.Spannable;
|
||||||
|
import android.text.style.ForegroundColorSpan;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@ -46,13 +51,14 @@ public class KeyListPublicAdapter extends CursorAdapter implements StickyListHea
|
|||||||
private int mSectionColumnIndex;
|
private int mSectionColumnIndex;
|
||||||
private int mIndexUserId;
|
private int mIndexUserId;
|
||||||
private int mIndexIsRevoked;
|
private int mIndexIsRevoked;
|
||||||
|
private String mCurQuery;
|
||||||
|
|
||||||
@SuppressLint("UseSparseArrays")
|
@SuppressLint("UseSparseArrays")
|
||||||
private HashMap<Integer, Boolean> mSelection = new HashMap<Integer, Boolean>();
|
private HashMap<Integer, Boolean> mSelection = new HashMap<Integer, Boolean>();
|
||||||
|
|
||||||
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);
|
||||||
|
mCurQuery = null;
|
||||||
mInflater = LayoutInflater.from(context);
|
mInflater = LayoutInflater.from(context);
|
||||||
mSectionColumnIndex = sectionColumnIndex;
|
mSectionColumnIndex = sectionColumnIndex;
|
||||||
initIndex(c);
|
initIndex(c);
|
||||||
@ -78,6 +84,10 @@ public class KeyListPublicAdapter extends CursorAdapter implements StickyListHea
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setSearchQuery(String searchQuery){
|
||||||
|
mCurQuery = searchQuery;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bind cursor data to the item list view
|
* Bind cursor data to the item list view
|
||||||
* <p/>
|
* <p/>
|
||||||
@ -110,6 +120,10 @@ public class KeyListPublicAdapter extends CursorAdapter implements StickyListHea
|
|||||||
} else {
|
} else {
|
||||||
revoked.setVisibility(View.GONE);
|
revoked.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
if(mCurQuery != null){
|
||||||
|
mainUserId.setText(highlightSearchKey(userIdSplit[0]));
|
||||||
|
mainUserIdRest.setText(highlightSearchKey(userIdSplit[1]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -228,5 +242,24 @@ public class KeyListPublicAdapter extends CursorAdapter implements StickyListHea
|
|||||||
}
|
}
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
private Spannable highlightSearchKey(String text) {
|
||||||
|
Spannable highlight;
|
||||||
|
Pattern pattern;
|
||||||
|
Matcher matcher;
|
||||||
|
String orig_str;
|
||||||
|
|
||||||
|
orig_str = Html.fromHtml(text).toString();
|
||||||
|
highlight = (Spannable) Html.fromHtml(text);
|
||||||
|
pattern = Pattern.compile("(?i)" + mCurQuery);
|
||||||
|
matcher = pattern.matcher(orig_str);
|
||||||
|
if (matcher.find()) {
|
||||||
|
highlight.setSpan(
|
||||||
|
new ForegroundColorSpan(0xFF33B5E5),
|
||||||
|
matcher.start(),
|
||||||
|
matcher.end(),
|
||||||
|
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
|
}
|
||||||
|
return highlight;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,9 @@ 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.support.v4.widget.CursorAdapter;
|
||||||
|
import android.text.Html;
|
||||||
|
import android.text.Spannable;
|
||||||
|
import android.text.style.ForegroundColorSpan;
|
||||||
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,6 +36,9 @@ import android.widget.CheckBox;
|
|||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class SelectKeyCursorAdapter extends CursorAdapter {
|
public class SelectKeyCursorAdapter extends CursorAdapter {
|
||||||
|
|
||||||
protected int mKeyType;
|
protected int mKeyType;
|
||||||
@ -47,6 +53,7 @@ public class SelectKeyCursorAdapter extends CursorAdapter {
|
|||||||
|
|
||||||
public final static String PROJECTION_ROW_AVAILABLE = "available";
|
public final static String PROJECTION_ROW_AVAILABLE = "available";
|
||||||
public final static String PROJECTION_ROW_VALID = "valid";
|
public final static String PROJECTION_ROW_VALID = "valid";
|
||||||
|
private String mCurQuery;
|
||||||
|
|
||||||
public SelectKeyCursorAdapter(Context context, Cursor c, int flags, ListView listView,
|
public SelectKeyCursorAdapter(Context context, Cursor c, int flags, ListView listView,
|
||||||
int keyType) {
|
int keyType) {
|
||||||
@ -55,7 +62,7 @@ public class SelectKeyCursorAdapter extends CursorAdapter {
|
|||||||
mInflater = LayoutInflater.from(context);
|
mInflater = LayoutInflater.from(context);
|
||||||
mListView = listView;
|
mListView = listView;
|
||||||
mKeyType = keyType;
|
mKeyType = keyType;
|
||||||
|
mCurQuery = null;
|
||||||
initIndex(c);
|
initIndex(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,6 +165,11 @@ public class SelectKeyCursorAdapter extends CursorAdapter {
|
|||||||
mainUserIdRest.setEnabled(valid);
|
mainUserIdRest.setEnabled(valid);
|
||||||
keyId.setEnabled(valid);
|
keyId.setEnabled(valid);
|
||||||
status.setEnabled(valid);
|
status.setEnabled(valid);
|
||||||
|
|
||||||
|
if(mCurQuery != null){
|
||||||
|
mainUserId.setText(highlightSearchKey(userIdSplit[0]));
|
||||||
|
mainUserIdRest.setText(highlightSearchKey(userIdSplit[1]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -165,4 +177,27 @@ public class SelectKeyCursorAdapter extends CursorAdapter {
|
|||||||
return mInflater.inflate(R.layout.select_key_item, null);
|
return mInflater.inflate(R.layout.select_key_item, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setSearchQuery(String searchQuery){
|
||||||
|
mCurQuery = searchQuery;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Spannable highlightSearchKey(String text) {
|
||||||
|
Spannable highlight;
|
||||||
|
Pattern pattern;
|
||||||
|
Matcher matcher;
|
||||||
|
String orig_str;
|
||||||
|
|
||||||
|
orig_str = Html.fromHtml(text).toString();
|
||||||
|
highlight = (Spannable) Html.fromHtml(text);
|
||||||
|
pattern = Pattern.compile("(?i)" + mCurQuery);
|
||||||
|
matcher = pattern.matcher(orig_str);
|
||||||
|
if (matcher.find()) {
|
||||||
|
highlight.setSpan(
|
||||||
|
new ForegroundColorSpan(0xFF33B5E5),
|
||||||
|
matcher.start(),
|
||||||
|
matcher.end(),
|
||||||
|
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
|
}
|
||||||
|
return highlight;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user