Cache instances of KeyInfoFormatter
This commit is contained in:
@@ -110,6 +110,11 @@ public class DebugActionsActivity extends Activity {
|
||||
new Intent(), BuildConfig.APPLICATION_ID, getPackageSig(), "test@openkeychain.org", false);
|
||||
startPendingIntent(pendingIntent);
|
||||
});
|
||||
addButtonToLayout(context, verticalLayout, "Select Authentication Key").setOnClickListener((v) -> {
|
||||
PendingIntent pendingIntent = pendingIntentFactory.createSelectAuthenticationKeyIdPendingIntent(
|
||||
new Intent(), BuildConfig.APPLICATION_ID);
|
||||
startPendingIntent(pendingIntent);
|
||||
});
|
||||
addButtonToLayout(context, verticalLayout, "Select Signing Key (Autocrypt)").setOnClickListener((v) -> {
|
||||
PendingIntent pendingIntent = pendingIntentFactory.createSelectSignKeyIdPendingIntent(
|
||||
new Intent(), BuildConfig.APPLICATION_ID, getPackageSig(), "test@openkeychain.org", true);
|
||||
|
||||
@@ -75,6 +75,7 @@ import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper;
|
||||
import org.sufficientlysecure.keychain.ui.base.RecyclerFragment;
|
||||
import org.sufficientlysecure.keychain.ui.keyview.GenericViewModel;
|
||||
import org.sufficientlysecure.keychain.ui.keyview.ViewKeyActivity;
|
||||
import org.sufficientlysecure.keychain.ui.util.KeyInfoFormatter;
|
||||
import org.sufficientlysecure.keychain.ui.util.Notify;
|
||||
import org.sufficientlysecure.keychain.ui.util.Notify.Style;
|
||||
import org.sufficientlysecure.keychain.util.FabContainer;
|
||||
@@ -141,6 +142,7 @@ public class KeyListFragment extends RecyclerFragment<FlexibleAdapter<FlexibleKe
|
||||
}
|
||||
};
|
||||
private FastScroller fastScroller;
|
||||
private KeyInfoFormatter keyInfoFormatter;
|
||||
|
||||
private void multiSelectDelete(long[] keyIds, boolean hasSecret) {
|
||||
Intent intent = new Intent(getActivity(), DeleteKeyDialogActivity.class);
|
||||
|
||||
@@ -75,6 +75,7 @@ public class FlexibleKeyDetailsItem extends FlexibleSectionableKeyItem<FlexibleK
|
||||
private final TextView vCreationDate;
|
||||
private final ImageView vStatusIcon;
|
||||
private final ImageView vTrustIdIcon;
|
||||
private final KeyInfoFormatter keyInfoFormatter;
|
||||
|
||||
FlexibleKeyItemViewHolder(View itemView, FlexibleAdapter adapter) {
|
||||
super(itemView, adapter);
|
||||
@@ -84,12 +85,15 @@ public class FlexibleKeyDetailsItem extends FlexibleSectionableKeyItem<FlexibleK
|
||||
vStatusIcon = itemView.findViewById(R.id.key_list_item_status_icon);
|
||||
vCreationDate = itemView.findViewById(R.id.key_list_item_creation);
|
||||
vTrustIdIcon = itemView.findViewById(R.id.key_list_item_tid_icon);
|
||||
|
||||
keyInfoFormatter = new KeyInfoFormatter(itemView.getContext());
|
||||
}
|
||||
|
||||
public void bind(UnifiedKeyInfo keyInfo, String highlightString) {
|
||||
setEnabled(true);
|
||||
|
||||
KeyInfoFormatter keyInfoFormatter = new KeyInfoFormatter(itemView.getContext(), keyInfo, highlightString);
|
||||
keyInfoFormatter.setKeyInfo(keyInfo);
|
||||
keyInfoFormatter.setHighlightString(highlightString);
|
||||
keyInfoFormatter.formatUserId(vMainUserId, vMainUserIdRest);
|
||||
keyInfoFormatter.formatCreationDate(vCreationDate);
|
||||
keyInfoFormatter.greyInvalidKeys(Arrays.asList(vMainUserId, vMainUserIdRest, vCreationDate));
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
package org.sufficientlysecure.keychain.ui.adapter;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
@@ -10,21 +17,14 @@ import android.widget.RadioButton;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.model.SubKey.UnifiedKeyInfo;
|
||||
import org.sufficientlysecure.keychain.ui.adapter.KeyChoiceAdapter.KeyChoiceItem;
|
||||
import org.sufficientlysecure.keychain.ui.util.KeyInfoFormatter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import eu.davidea.flexibleadapter.FlexibleAdapter;
|
||||
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem;
|
||||
import eu.davidea.flexibleadapter.items.IFlexible;
|
||||
import eu.davidea.viewholders.FlexibleViewHolder;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.model.SubKey.UnifiedKeyInfo;
|
||||
import org.sufficientlysecure.keychain.ui.adapter.KeyChoiceAdapter.KeyChoiceItem;
|
||||
import org.sufficientlysecure.keychain.ui.util.KeyInfoFormatter;
|
||||
|
||||
|
||||
public class KeyChoiceAdapter extends FlexibleAdapter<KeyChoiceItem> {
|
||||
@@ -34,41 +34,40 @@ public class KeyChoiceAdapter extends FlexibleAdapter<KeyChoiceItem> {
|
||||
private final KeyDisabledPredicate keyDisabledPredicate;
|
||||
@Nullable
|
||||
private Integer activeItem;
|
||||
private KeyInfoFormatter keyInfoFormatter;
|
||||
|
||||
public static KeyChoiceAdapter createSingleClickableAdapter(List<UnifiedKeyInfo> items,
|
||||
OnKeyClickListener onKeyClickListener) {
|
||||
return new KeyChoiceAdapter(items, Objects.requireNonNull(onKeyClickListener), Mode.IDLE, null);
|
||||
public static KeyChoiceAdapter createSingleClickableAdapter(Context context, List<UnifiedKeyInfo> items,
|
||||
OnKeyClickListener onKeyClickListener,
|
||||
KeyDisabledPredicate keyDisabledPredicate) {
|
||||
return new KeyChoiceAdapter(context, items, Objects.requireNonNull(onKeyClickListener), Mode.IDLE,
|
||||
keyDisabledPredicate
|
||||
);
|
||||
}
|
||||
|
||||
public static KeyChoiceAdapter createSingleClickableAdapter(List<UnifiedKeyInfo> items,
|
||||
OnKeyClickListener onKeyClickListener,
|
||||
KeyDisabledPredicate keyDisabledPredicate) {
|
||||
return new KeyChoiceAdapter(items, Objects.requireNonNull(onKeyClickListener), Mode.IDLE, keyDisabledPredicate);
|
||||
public static KeyChoiceAdapter createSingleChoiceAdapter(Context context, List<UnifiedKeyInfo> items,
|
||||
KeyDisabledPredicate keyDisabledPredicate) {
|
||||
return new KeyChoiceAdapter(context, items, null, Mode.SINGLE, keyDisabledPredicate);
|
||||
}
|
||||
|
||||
public static KeyChoiceAdapter createSingleChoiceAdapter(List<UnifiedKeyInfo> items) {
|
||||
return new KeyChoiceAdapter(items, null, Mode.SINGLE, null);
|
||||
public static KeyChoiceAdapter createMultiChoiceAdapter(Context context, List<UnifiedKeyInfo> items,
|
||||
KeyDisabledPredicate keyDisabledPredicate) {
|
||||
return new KeyChoiceAdapter(context, items, null, Mode.MULTI, keyDisabledPredicate);
|
||||
}
|
||||
|
||||
public static KeyChoiceAdapter createSingleChoiceAdapter(List<UnifiedKeyInfo> items, KeyDisabledPredicate keyDisabledPredicate) {
|
||||
return new KeyChoiceAdapter(items, null, Mode.SINGLE, keyDisabledPredicate);
|
||||
}
|
||||
|
||||
public static KeyChoiceAdapter createMultiChoiceAdapter(List<UnifiedKeyInfo> items, KeyDisabledPredicate keyDisabledPredicate) {
|
||||
return new KeyChoiceAdapter(items, null, Mode.MULTI, keyDisabledPredicate);
|
||||
}
|
||||
|
||||
private KeyChoiceAdapter(List<UnifiedKeyInfo> items, @Nullable OnKeyClickListener onKeyClickListener, int idle,
|
||||
private KeyChoiceAdapter(Context context, List<UnifiedKeyInfo> items,
|
||||
@Nullable OnKeyClickListener onKeyClickListener, int idle,
|
||||
@Nullable KeyDisabledPredicate keyDisabledPredicate) {
|
||||
super(getKeyChoiceItems(items, keyDisabledPredicate));
|
||||
super(null, null, true);
|
||||
setMode(idle);
|
||||
addListener((OnItemClickListener) (view, position) -> onClickItem(position));
|
||||
updateDataSet(getKeyChoiceItems(items, keyDisabledPredicate), false);
|
||||
this.keyInfoFormatter = new KeyInfoFormatter(context);
|
||||
this.onKeyClickListener = onKeyClickListener;
|
||||
this.keyDisabledPredicate = keyDisabledPredicate;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static ArrayList<KeyChoiceItem> getKeyChoiceItems(@Nullable List<UnifiedKeyInfo> items,
|
||||
private ArrayList<KeyChoiceItem> getKeyChoiceItems(@Nullable List<UnifiedKeyInfo> items,
|
||||
@Nullable KeyDisabledPredicate keyDisabledPredicate) {
|
||||
if (items == null) {
|
||||
return null;
|
||||
@@ -174,7 +173,7 @@ public class KeyChoiceAdapter extends FlexibleAdapter<KeyChoiceItem> {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static class KeyChoiceItem extends AbstractFlexibleItem<KeyChoiceViewHolder> {
|
||||
public class KeyChoiceItem extends AbstractFlexibleItem<KeyChoiceViewHolder> {
|
||||
private UnifiedKeyInfo keyInfo;
|
||||
@StringRes
|
||||
private Integer disabledStringRes;
|
||||
@@ -220,7 +219,7 @@ public class KeyChoiceAdapter extends FlexibleAdapter<KeyChoiceItem> {
|
||||
}
|
||||
}
|
||||
|
||||
public static class KeyChoiceViewHolder extends FlexibleViewHolder {
|
||||
public class KeyChoiceViewHolder extends FlexibleViewHolder {
|
||||
private final TextView vName;
|
||||
private final TextView vCreation;
|
||||
private final CheckBox vCheckbox;
|
||||
@@ -236,9 +235,10 @@ public class KeyChoiceAdapter extends FlexibleAdapter<KeyChoiceItem> {
|
||||
}
|
||||
|
||||
void bind(UnifiedKeyInfo keyInfo, int choiceMode, boolean isActive, boolean isEnabled) {
|
||||
keyInfoFormatter.setKeyInfo(keyInfo);
|
||||
|
||||
vName.setText(keyInfo.user_id());
|
||||
|
||||
KeyInfoFormatter keyInfoFormatter = new KeyInfoFormatter(itemView.getContext(), keyInfo, null);
|
||||
keyInfoFormatter.formatCreationDate(vCreation);
|
||||
|
||||
switch (choiceMode) {
|
||||
|
||||
@@ -31,7 +31,8 @@ public class ImportKeysBindingsUtils {
|
||||
public static Highlighter getHighlighter(Context context, String query) {
|
||||
Highlighter highlighter = highlighterCache.get(query);
|
||||
if (highlighter == null) {
|
||||
highlighter = new Highlighter(context, query);
|
||||
highlighter = new Highlighter(context);
|
||||
highlighter.setQuery(query);
|
||||
highlighterCache.put(query, highlighter);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,11 +21,13 @@ import org.sufficientlysecure.keychain.ui.util.KeyInfoFormatter;
|
||||
|
||||
public class EncryptRecipientDropdownAdapter extends ChipsInput.ChipDropdownAdapter<EncryptRecipientChip, ItemViewHolder> {
|
||||
private final LayoutInflater layoutInflater;
|
||||
private final KeyInfoFormatter keyInfoFormatter;
|
||||
|
||||
EncryptRecipientDropdownAdapter(Context context, List<EncryptRecipientChip> keyInfoChips) {
|
||||
super(keyInfoChips);
|
||||
|
||||
layoutInflater = LayoutInflater.from(context);
|
||||
keyInfoFormatter = new KeyInfoFormatter(context);
|
||||
}
|
||||
|
||||
class ItemViewHolder extends RecyclerView.ViewHolder {
|
||||
@@ -42,6 +44,14 @@ public class EncryptRecipientDropdownAdapter extends ChipsInput.ChipDropdownAdap
|
||||
vStatusIcon = itemView.findViewById(R.id.key_list_item_status_icon);
|
||||
vCreationDate = itemView.findViewById(R.id.key_list_item_creation);
|
||||
}
|
||||
|
||||
public void bind(EncryptRecipientChip chip) {
|
||||
keyInfoFormatter.setKeyInfo(chip.keyInfo);
|
||||
|
||||
keyInfoFormatter.formatUserId(vMainUserId, vMainUserIdRest);
|
||||
keyInfoFormatter.formatCreationDate(vCreationDate);
|
||||
keyInfoFormatter.formatStatusIcon(vStatusIcon);
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@@ -54,10 +64,6 @@ public class EncryptRecipientDropdownAdapter extends ChipsInput.ChipDropdownAdap
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull ItemViewHolder holder, int position) {
|
||||
EncryptRecipientChip chip = getItem(position);
|
||||
|
||||
KeyInfoFormatter keyInfoFormatter = new KeyInfoFormatter(layoutInflater.getContext(), chip.keyInfo, null);
|
||||
keyInfoFormatter.formatUserId(holder.vMainUserId, holder.vMainUserIdRest);
|
||||
keyInfoFormatter.formatCreationDate(holder.vCreationDate);
|
||||
keyInfoFormatter.formatStatusIcon(holder.vStatusIcon);
|
||||
holder.bind(chip);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,9 +30,12 @@ public class Highlighter {
|
||||
private Context mContext;
|
||||
private String mQuery;
|
||||
|
||||
public Highlighter(Context context, String query) {
|
||||
public Highlighter(Context context) {
|
||||
mContext = context;
|
||||
mQuery = query;
|
||||
}
|
||||
|
||||
public void setQuery(String mQuery) {
|
||||
this.mQuery = mQuery;
|
||||
}
|
||||
|
||||
public Spannable highlight(CharSequence text) {
|
||||
|
||||
@@ -11,6 +11,7 @@ import android.widget.TextView;
|
||||
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.model.SubKey;
|
||||
import org.sufficientlysecure.keychain.model.SubKey.UnifiedKeyInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -19,13 +20,20 @@ public class KeyInfoFormatter {
|
||||
private static final long JUST_NOW_THRESHOLD = DateUtils.MINUTE_IN_MILLIS * 5;
|
||||
|
||||
private Context context;
|
||||
private SubKey.UnifiedKeyInfo keyInfo;
|
||||
private Highlighter highlighter;
|
||||
private UnifiedKeyInfo keyInfo;
|
||||
|
||||
public KeyInfoFormatter(Context context, SubKey.UnifiedKeyInfo keyInfo, String highlightString) {
|
||||
public KeyInfoFormatter(Context context) {
|
||||
this.context = context;
|
||||
highlighter = new Highlighter(context);
|
||||
}
|
||||
|
||||
public void setKeyInfo(UnifiedKeyInfo keyInfo) {
|
||||
this.keyInfo = keyInfo;
|
||||
highlighter = new Highlighter(context, highlightString);
|
||||
}
|
||||
|
||||
public void setHighlightString(String highlight) {
|
||||
highlighter.setQuery(highlight);
|
||||
}
|
||||
|
||||
public void formatUserId(TextView name, TextView email) {
|
||||
|
||||
@@ -19,14 +19,17 @@ import java.util.List;
|
||||
|
||||
|
||||
class KeyChoiceSpinnerAdapter extends BaseAdapter {
|
||||
private final LayoutInflater layoutInflater;
|
||||
private final KeyInfoFormatter keyInfoFormatter;
|
||||
|
||||
private Integer noneItemString;
|
||||
private List<UnifiedKeyInfo> data;
|
||||
private final LayoutInflater layoutInflater;
|
||||
|
||||
KeyChoiceSpinnerAdapter(Context context) {
|
||||
super();
|
||||
|
||||
layoutInflater = LayoutInflater.from(context);
|
||||
keyInfoFormatter = new KeyInfoFormatter(context);
|
||||
}
|
||||
|
||||
public void setData(List<UnifiedKeyInfo> data) {
|
||||
@@ -114,28 +117,26 @@ class KeyChoiceSpinnerAdapter extends BaseAdapter {
|
||||
}
|
||||
|
||||
UnifiedKeyInfo keyInfo = getItem(position);
|
||||
viewHolder.bind(view.getContext(), keyInfo, isEnabled(position));
|
||||
viewHolder.bind(keyInfo, isEnabled(position));
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
public static class KeyChoiceViewHolder {
|
||||
private View mView;
|
||||
public class KeyChoiceViewHolder {
|
||||
private TextView mMainUserId;
|
||||
private TextView mMainUserIdRest;
|
||||
private TextView mCreationDate;
|
||||
private ImageView mStatus;
|
||||
|
||||
KeyChoiceViewHolder(View view) {
|
||||
mView = view;
|
||||
mMainUserId = view.findViewById(R.id.key_list_item_name);
|
||||
mMainUserIdRest = view.findViewById(R.id.key_list_item_email);
|
||||
mStatus = view.findViewById(R.id.key_list_item_status_icon);
|
||||
mCreationDate = view.findViewById(R.id.key_list_item_creation);
|
||||
}
|
||||
|
||||
public void bind(Context context, UnifiedKeyInfo keyInfo, boolean enabled) {
|
||||
KeyInfoFormatter keyInfoFormatter = new KeyInfoFormatter(context, keyInfo, null);
|
||||
public void bind(UnifiedKeyInfo keyInfo, boolean enabled) {
|
||||
keyInfoFormatter.setKeyInfo(keyInfo);
|
||||
keyInfoFormatter.formatUserId(mMainUserId, mMainUserIdRest);
|
||||
keyInfoFormatter.formatCreationDate(mCreationDate);
|
||||
keyInfoFormatter.formatStatusIcon(mStatus);
|
||||
|
||||
Reference in New Issue
Block a user