ImportKeys: Use data binding to set CardView's content
This commit is contained in:
@@ -17,16 +17,12 @@
|
||||
|
||||
package org.sufficientlysecure.keychain.ui.adapter;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.databinding.BindingAdapter;
|
||||
import android.databinding.DataBindingUtil;
|
||||
import android.graphics.Color;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
@@ -44,8 +40,6 @@ import org.sufficientlysecure.keychain.operations.results.ImportKeyResult;
|
||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedKeyRing;
|
||||
import org.sufficientlysecure.keychain.service.ImportKeyringParcel;
|
||||
import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper;
|
||||
import org.sufficientlysecure.keychain.ui.util.FormattingUtils;
|
||||
import org.sufficientlysecure.keychain.ui.util.Highlighter;
|
||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils.State;
|
||||
import org.sufficientlysecure.keychain.ui.util.Notify;
|
||||
@@ -120,13 +114,7 @@ public class ImportKeysAdapter extends RecyclerView.Adapter<ImportKeysAdapter.Vi
|
||||
public ViewHolder(View view) {
|
||||
super(view);
|
||||
b = DataBindingUtil.bind(view);
|
||||
|
||||
b.setNonInteractive(mNonInteractive);
|
||||
|
||||
Resources resources = mActivity.getResources();
|
||||
b.setStandardColor(FormattingUtils.getColorFromAttr(mActivity, R.attr.colorText));
|
||||
b.setRevokedExpiredColor(resources.getColor(R.color.key_flag_gray));
|
||||
b.setSecretColor(Color.RED);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,10 +128,6 @@ public class ImportKeysAdapter extends RecyclerView.Adapter<ImportKeysAdapter.Vi
|
||||
public void onBindViewHolder(final ViewHolder holder, final int position) {
|
||||
final ImportKeysListItemBinding b = holder.b;
|
||||
final ImportKeysListEntry entry = mData.get(position);
|
||||
|
||||
Highlighter highlighter = new Highlighter(mActivity, entry.getQuery());
|
||||
b.setHighlighter(highlighter);
|
||||
|
||||
b.setEntry(entry);
|
||||
|
||||
if (entry.isRevoked()) {
|
||||
@@ -198,11 +182,6 @@ public class ImportKeysAdapter extends RecyclerView.Adapter<ImportKeysAdapter.Vi
|
||||
b.extraContainer.setVisibility(showed ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
|
||||
@BindingAdapter("app:keyId")
|
||||
public static void setKeyId(TextView textView, String keyId) {
|
||||
textView.setText(KeyFormattingUtils.beautifyKeyIdWithPrefix(keyId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mData != null ? mData.size() : 0;
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
package org.sufficientlysecure.keychain.ui.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.databinding.BindingAdapter;
|
||||
import android.graphics.Color;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.ui.util.Highlighter;
|
||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||
|
||||
public class ImportKeysAdapterBinding {
|
||||
|
||||
@BindingAdapter({"app:userId", "app:secret", "app:revokedOrExpired", "app:query"})
|
||||
public static void setUserId(TextView textView, CharSequence userId, boolean secret,
|
||||
boolean revokedOrExpired, String query) {
|
||||
|
||||
Context context = textView.getContext();
|
||||
Resources resources = context.getResources();
|
||||
|
||||
if (userId == null)
|
||||
userId = resources.getString(R.string.user_id_no_name);
|
||||
|
||||
if (secret) {
|
||||
userId = resources.getString(R.string.secret_key) + " " + userId;
|
||||
} else {
|
||||
Highlighter highlighter = new Highlighter(context, query);
|
||||
userId = highlighter.highlight(userId);
|
||||
}
|
||||
textView.setText(userId);
|
||||
|
||||
if (revokedOrExpired) {
|
||||
textView.setTextColor(resources.getColor(R.color.key_flag_gray));
|
||||
} else if (secret) {
|
||||
textView.setTextColor(Color.RED);
|
||||
}
|
||||
}
|
||||
|
||||
@BindingAdapter({"app:userEmail", "app:revokedOrExpired", "app:query"})
|
||||
public static void setUserEmail(TextView textView, CharSequence userEmail,
|
||||
boolean revokedOrExpired, String query) {
|
||||
|
||||
Context context = textView.getContext();
|
||||
|
||||
if (userEmail == null)
|
||||
userEmail = "";
|
||||
|
||||
Highlighter highlighter = new Highlighter(context, query);
|
||||
textView.setText(highlighter.highlight(userEmail));
|
||||
|
||||
if (revokedOrExpired) {
|
||||
Resources resources = context.getResources();
|
||||
textView.setTextColor(resources.getColor(R.color.key_flag_gray));
|
||||
}
|
||||
}
|
||||
|
||||
@BindingAdapter({"app:keyId", "app:revokedOrExpired"})
|
||||
public static void setKeyId(TextView textView, String keyId, boolean revokedOrExpired) {
|
||||
Context context = textView.getContext();
|
||||
|
||||
if (keyId == null)
|
||||
keyId = "";
|
||||
|
||||
if (revokedOrExpired) {
|
||||
Resources resources = context.getResources();
|
||||
textView.setTextColor(resources.getColor(R.color.key_flag_gray));
|
||||
}
|
||||
textView.setText(KeyFormattingUtils.beautifyKeyIdWithPrefix(keyId));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,10 +18,7 @@ public class Highlighter {
|
||||
mQuery = query;
|
||||
}
|
||||
|
||||
public Spannable highlight(String text) {
|
||||
if (text == null)
|
||||
return null;
|
||||
|
||||
public Spannable highlight(CharSequence text) {
|
||||
Spannable highlight = Spannable.Factory.getInstance().newSpannable(text);
|
||||
|
||||
if (mQuery == null) {
|
||||
|
||||
Reference in New Issue
Block a user