ImportKeys: Extract ImportUserIdsView to decouple it from CardView
This commit is contained in:
@@ -25,7 +25,6 @@ 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;
|
||||
@@ -55,9 +54,7 @@ import org.sufficientlysecure.keychain.util.ParcelableFileCache;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ImportKeysAdapter extends RecyclerView.Adapter<ImportKeysAdapter.ViewHolder> implements ImportKeysResultListener {
|
||||
|
||||
@@ -151,7 +148,7 @@ public class ImportKeysAdapter extends RecyclerView.Adapter<ImportKeysAdapter.Vi
|
||||
b.setExpired(entry.isExpired());
|
||||
b.setRevoked(entry.isRevoked());
|
||||
|
||||
String userId = entry.getPrimaryUserId(); // main user id
|
||||
String userId = entry.getPrimaryUserId();
|
||||
OpenPgpUtils.UserId userIdSplit = KeyRing.splitUserId(userId);
|
||||
|
||||
b.setAlgorithm(entry.getAlgorithm());
|
||||
@@ -205,46 +202,10 @@ public class ImportKeysAdapter extends RecyclerView.Adapter<ImportKeysAdapter.Vi
|
||||
b.expand.setRotation(rotation);
|
||||
}
|
||||
|
||||
b.extraContainer.setVisibility(showed ? View.VISIBLE : View.GONE);
|
||||
if (showed) {
|
||||
b.userIdsList.removeAllViews();
|
||||
// we want conventional gpg UserIDs first, then Keybase ”proofs”
|
||||
ArrayList<Map.Entry<String, HashSet<String>>> sortedIds = entry.getSortedUserIds();
|
||||
for (Map.Entry<String, HashSet<String>> pair : sortedIds) {
|
||||
String cUserId = pair.getKey();
|
||||
HashSet<String> cEmails = pair.getValue();
|
||||
|
||||
LayoutInflater inflater = LayoutInflater.from(mActivity);
|
||||
|
||||
TextView uidView = (TextView) inflater.inflate(
|
||||
R.layout.import_keys_list_entry_user_id, null);
|
||||
uidView.setText(highlighter.highlight(cUserId));
|
||||
uidView.setPadding(0, 0, FormattingUtils.dpToPx(mActivity, 8), 0);
|
||||
|
||||
if (entry.isRevoked() || entry.isExpired()) {
|
||||
uidView.setTextColor(mActivity.getResources().getColor(R.color.key_flag_gray));
|
||||
} else {
|
||||
uidView.setTextColor(FormattingUtils.getColorFromAttr(mActivity, R.attr.colorText));
|
||||
}
|
||||
b.userIdsList.addView(uidView);
|
||||
|
||||
for (String email : cEmails) {
|
||||
TextView emailView = (TextView) inflater.inflate(
|
||||
R.layout.import_keys_list_entry_user_id, null);
|
||||
emailView.setPadding(
|
||||
FormattingUtils.dpToPx(mActivity, 16), 0,
|
||||
FormattingUtils.dpToPx(mActivity, 8), 0);
|
||||
emailView.setText(highlighter.highlight(email));
|
||||
|
||||
if (entry.isRevoked() || entry.isExpired()) {
|
||||
emailView.setTextColor(mActivity.getResources().getColor(R.color.key_flag_gray));
|
||||
} else {
|
||||
emailView.setTextColor(FormattingUtils.getColorFromAttr(mActivity, R.attr.colorText));
|
||||
}
|
||||
b.userIdsList.addView(emailView);
|
||||
}
|
||||
}
|
||||
b.extraUserIds.setEntry(entry);
|
||||
}
|
||||
b.extraContainer.setVisibility(showed ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
package org.sufficientlysecure.keychain.ui.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.keyimport.ImportKeysListEntry;
|
||||
import org.sufficientlysecure.keychain.ui.util.FormattingUtils;
|
||||
import org.sufficientlysecure.keychain.ui.util.Highlighter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
|
||||
public class ImportUserIdsView extends LinearLayout {
|
||||
|
||||
public ImportUserIdsView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
setOrientation(VERTICAL);
|
||||
}
|
||||
|
||||
public void setEntry(ImportKeysListEntry entry) {
|
||||
removeAllViews();
|
||||
|
||||
Context context = getContext();
|
||||
Highlighter highlighter = new Highlighter(context, entry.getQuery());
|
||||
|
||||
// we want conventional gpg UserIDs first, then Keybase ”proofs”
|
||||
ArrayList<Map.Entry<String, HashSet<String>>> sortedIds = entry.getSortedUserIds();
|
||||
for (Map.Entry<String, HashSet<String>> pair : sortedIds) {
|
||||
String cUserId = pair.getKey();
|
||||
HashSet<String> cEmails = pair.getValue();
|
||||
|
||||
LayoutInflater inflater = LayoutInflater.from(context);
|
||||
|
||||
TextView uidView = (TextView) inflater.inflate(
|
||||
R.layout.import_keys_list_entry_user_id, null);
|
||||
uidView.setText(highlighter.highlight(cUserId));
|
||||
uidView.setPadding(0, 0, FormattingUtils.dpToPx(context, 8), 0);
|
||||
|
||||
if (entry.isRevoked() || entry.isExpired()) {
|
||||
uidView.setTextColor(context.getResources().getColor(R.color.key_flag_gray));
|
||||
} else {
|
||||
uidView.setTextColor(FormattingUtils.getColorFromAttr(context, R.attr.colorText));
|
||||
}
|
||||
addView(uidView);
|
||||
|
||||
for (String email : cEmails) {
|
||||
TextView emailView = (TextView) inflater.inflate(
|
||||
R.layout.import_keys_list_entry_user_id, null);
|
||||
emailView.setPadding(
|
||||
FormattingUtils.dpToPx(context, 16), 0,
|
||||
FormattingUtils.dpToPx(context, 8), 0);
|
||||
emailView.setText(highlighter.highlight(email));
|
||||
|
||||
if (entry.isRevoked() || entry.isExpired()) {
|
||||
emailView.setTextColor(context.getResources().getColor(R.color.key_flag_gray));
|
||||
} else {
|
||||
emailView.setTextColor(FormattingUtils.getColorFromAttr(context, R.attr.colorText));
|
||||
}
|
||||
addView(emailView);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,24 +1,58 @@
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<data>
|
||||
|
||||
<import type="android.view.View" />
|
||||
|
||||
<import type="org.sufficientlysecure.keychain.ui.util.Highlighter" />
|
||||
|
||||
<variable name="nonInteractive" type="boolean" />
|
||||
<variable
|
||||
name="nonInteractive"
|
||||
type="boolean" />
|
||||
|
||||
<variable name="standardColor" type="int" />
|
||||
<variable name="revokedExpiredColor" type="int" />
|
||||
<variable name="secretColor" type="int" />
|
||||
<variable name="highlighter" type="Highlighter" />
|
||||
<variable
|
||||
name="standardColor"
|
||||
type="int" />
|
||||
|
||||
<variable name="secret" type="boolean" />
|
||||
<variable name="revoked" type="boolean" />
|
||||
<variable name="expired" type="boolean" />
|
||||
<variable
|
||||
name="revokedExpiredColor"
|
||||
type="int" />
|
||||
|
||||
<variable name="algorithm" type="String" />
|
||||
<variable name="userId" type="String" />
|
||||
<variable name="userIdEmail" type="String" />
|
||||
<variable name="keyId" type="String" />
|
||||
<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" />
|
||||
</data>
|
||||
|
||||
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
|
||||
@@ -139,11 +173,11 @@
|
||||
android:paddingTop="16dp"
|
||||
android:visibility="gone">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/user_ids_list"
|
||||
<org.sufficientlysecure.keychain.ui.widget.ImportUserIdsView
|
||||
android:id="@+id/extra_user_ids"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical" />
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
Reference in New Issue
Block a user