ImportKeys: Refactoring CardView

This commit is contained in:
Andrea Torlaschi
2016-08-04 00:06:33 +02:00
parent 5322fa71b7
commit 0325c27987
7 changed files with 48 additions and 77 deletions

View File

@@ -17,8 +17,6 @@
package org.sufficientlysecure.keychain.ui;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
@@ -58,6 +56,8 @@ import org.sufficientlysecure.keychain.ui.util.Notify;
import org.sufficientlysecure.keychain.ui.util.Notify.Style;
import org.sufficientlysecure.keychain.util.Preferences;
import java.util.ArrayList;
public abstract class DecryptFragment extends Fragment implements LoaderManager.LoaderCallbacks<Cursor> {
public static final int LOADER_ID_UNIFIED = 0;
@@ -319,7 +319,7 @@ public abstract class DecryptFragment extends Fragment implements LoaderManager.
mSignatureEmail.setText(userIdSplit.email);
} else {
mSignatureEmail.setText(KeyFormattingUtils.beautifyKeyIdWithPrefix(
getActivity(), mSignatureResult.getKeyId()));
mSignatureResult.getKeyId()));
}
// NOTE: Don't use revoked and expired fields from database, they don't show
@@ -429,7 +429,7 @@ public abstract class DecryptFragment extends Fragment implements LoaderManager.
mSignatureEmail.setText(userIdSplit.email);
} else {
mSignatureEmail.setText(KeyFormattingUtils.beautifyKeyIdWithPrefix(
getActivity(), mSignatureResult.getKeyId()));
mSignatureResult.getKeyId()));
}
switch (mSignatureResult.getResult()) {

View File

@@ -225,7 +225,8 @@ public class ViewKeyAdvActivity extends BaseActivity implements
// get key id from MASTER_KEY_ID
long masterKeyId = data.getLong(INDEX_MASTER_KEY_ID);
getSupportActionBar().setSubtitle(KeyFormattingUtils.beautifyKeyIdWithPrefix(this, masterKeyId));
String formattedKeyId = KeyFormattingUtils.beautifyKeyIdWithPrefix(masterKeyId);
getSupportActionBar().setSubtitle(formattedKeyId);
mHasSecret = data.getInt(INDEX_HAS_ANY_SECRET) != 0;
boolean isRevoked = data.getInt(INDEX_IS_REVOKED) > 0;

View File

@@ -237,7 +237,8 @@ public class ViewKeyAdvCertsFragment extends LoaderFragment implements
TextView wSignerName = (TextView) view.findViewById(R.id.signerName);
TextView wSignStatus = (TextView) view.findViewById(R.id.signStatus);
String signerKeyId = KeyFormattingUtils.beautifyKeyIdWithPrefix(getActivity(), cursor.getLong(mIndexSignerKeyId));
String signerKeyId = KeyFormattingUtils.beautifyKeyIdWithPrefix(
cursor.getLong(mIndexSignerKeyId));
OpenPgpUtils.UserId userId = KeyRing.splitUserId(cursor.getString(mIndexSignerUserId));
if (userId.name != null) {
wSignerName.setText(userId.name);

View File

@@ -18,6 +18,7 @@
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;
@@ -25,6 +26,7 @@ import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import org.openintents.openpgp.util.OpenPgpUtils;
import org.sufficientlysecure.keychain.Constants;
@@ -115,12 +117,18 @@ public class ImportKeysAdapter extends RecyclerView.Adapter<ImportKeysAdapter.Vi
}
public class ViewHolder extends RecyclerView.ViewHolder {
public ImportKeysListItemBinding binding;
public ImportKeysListItemBinding b;
public ViewHolder(View view) {
super(view);
binding = DataBindingUtil.bind(view);
binding.setNonInteractive(mNonInteractive);
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);
}
}
@@ -134,27 +142,18 @@ public class ImportKeysAdapter extends RecyclerView.Adapter<ImportKeysAdapter.Vi
@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
final ImportKeysListItemBinding b = holder.binding;
final ImportKeysListItemBinding b = holder.b;
final ImportKeysListEntry entry = mData.get(position);
Resources resources = mActivity.getResources();
Highlighter highlighter = new Highlighter(mActivity, entry.getQuery());
b.setStandardColor(FormattingUtils.getColorFromAttr(mActivity, R.attr.colorText));
b.setRevokedExpiredColor(resources.getColor(R.color.key_flag_gray));
b.setSecretColor(Color.RED);
b.setHighlighter(highlighter);
b.setSecret(entry.isSecretKey());
b.setExpired(entry.isExpired());
b.setRevoked(entry.isRevoked());
String userId = entry.getPrimaryUserId();
OpenPgpUtils.UserId userIdSplit = KeyRing.splitUserId(userId);
b.setAlgorithm(entry.getAlgorithm());
b.setEntry(entry);
b.setUserId(userIdSplit.name);
b.setUserIdEmail(userIdSplit.email);
b.setKeyId(KeyFormattingUtils.beautifyKeyIdWithPrefix(mActivity, entry.getKeyIdHex()));
if (entry.isRevoked()) {
KeyFormattingUtils.setStatusImage(mActivity, b.status, null,
@@ -208,6 +207,11 @@ 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;

View File

@@ -312,12 +312,12 @@ public class KeyFormattingUtils {
return beautifyKeyId(convertKeyIdToHex(keyId));
}
public static String beautifyKeyIdWithPrefix(Context context, String idHex) {
public static String beautifyKeyIdWithPrefix(String idHex) {
return "Key ID: " + beautifyKeyId(idHex);
}
public static String beautifyKeyIdWithPrefix(Context context, long keyId) {
return beautifyKeyIdWithPrefix(context, convertKeyIdToHex(keyId));
public static String beautifyKeyIdWithPrefix(long keyId) {
return beautifyKeyIdWithPrefix(convertKeyIdToHex(keyId));
}
public static SpannableStringBuilder colorizeFingerprint(String fingerprint) {

View File

@@ -19,6 +19,7 @@ public class ImportUserIdsView extends LinearLayout {
public ImportUserIdsView(Context context, AttributeSet attrs) {
super(context, attrs);
setOrientation(VERTICAL);
}

View File

@@ -1,58 +1,22 @@
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<import type="android.view.View" />
<import type="org.sufficientlysecure.keychain.ui.util.Highlighter" />
<import type="org.sufficientlysecure.keychain.keyimport.ImportKeysListEntry" />
<variable
name="nonInteractive"
type="boolean" />
<variable name="nonInteractive" type="boolean" />
<variable
name="standardColor"
type="int" />
<variable name="standardColor" type="int" />
<variable name="revokedExpiredColor" type="int" />
<variable name="secretColor" type="int" />
<variable
name="revokedExpiredColor"
type="int" />
<variable name="highlighter" type="Highlighter" />
<variable
name="secretColor"
type="int" />
<variable
name="highlighter"
type="Highlighter" />
<variable
name="secret"
type="boolean" />
<variable
name="revoked"
type="boolean" />
<variable
name="expired"
type="boolean" />
<variable
name="algorithm"
type="String" />
<variable
name="userId"
type="String" />
<variable
name="userIdEmail"
type="String" />
<variable
name="keyId"
type="String" />
<variable name="entry" type="ImportKeysListEntry" />
<variable name="userId" type="String" />
<variable name="userIdEmail" type="String" />
</data>
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
@@ -91,15 +55,15 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{algorithm}"
android:text="@{entry.algorithm}"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text='@{secret ? @string/secret_key + " " + (userId ?? @string/user_id_no_name) : highlighter.highlight(userId ?? @string/user_id_no_name)}'
android:text='@{entry.secretKey ? @string/secret_key + " " + (userId ?? @string/user_id_no_name) : highlighter.highlight(userId ?? @string/user_id_no_name)}'
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@{revoked || expired ? revokedExpiredColor : (secret ? secretColor : standardColor)}" />
android:textColor="@{entry.revoked || entry.expired ? revokedExpiredColor : (entry.secretKey ? secretColor : standardColor)}" />
<TextView
android:layout_width="wrap_content"
@@ -107,14 +71,14 @@
android:layout_marginTop="4dp"
android:text="@{highlighter.highlight(userIdEmail)}"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@{revoked || expired ? revokedExpiredColor : standardColor}" />
android:textColor="@{entry.revoked || entry.expired ? revokedExpiredColor : standardColor}" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text='@{keyId != null ? "Key ID: " + keyId : ""}'
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@{revoked || expired ? revokedExpiredColor : standardColor}" />
android:textColor="@{entry.revoked || entry.expired ? revokedExpiredColor : standardColor}"
app:keyId='@{entry.keyIdHex ?? ""}' />
</LinearLayout>
@@ -124,7 +88,7 @@
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:visibility="@{revoked || expired ? View.VISIBLE : View.GONE}" />
android:visibility="@{entry.revoked || entry.expired ? View.VISIBLE : View.GONE}" />
</RelativeLayout>