mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-05 16:55:05 -05:00
Fix ViewHolder in ImportKeysAdapter
This commit is contained in:
parent
1e22b28c2e
commit
9df498b714
@ -35,6 +35,7 @@ import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> {
|
||||
@ -50,6 +51,8 @@ public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> {
|
||||
public TextView fingerprint;
|
||||
public TextView algorithm;
|
||||
public TextView status;
|
||||
public LinearLayout userIdsList;
|
||||
public CheckBox checkBox;
|
||||
}
|
||||
|
||||
public ImportKeysAdapter(Activity activity) {
|
||||
@ -106,10 +109,13 @@ public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> {
|
||||
holder.fingerprint = (TextView) convertView.findViewById(R.id.fingerprint);
|
||||
holder.algorithm = (TextView) convertView.findViewById(R.id.algorithm);
|
||||
holder.status = (TextView) convertView.findViewById(R.id.status);
|
||||
holder.userIdsList = (LinearLayout) convertView.findViewById(R.id.user_ids_list);
|
||||
holder.checkBox = (CheckBox) convertView.findViewById(R.id.selected);
|
||||
convertView.setTag(holder);
|
||||
} else {
|
||||
holder = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
|
||||
// main user id
|
||||
String userId = entry.userIds.get(0);
|
||||
String[] userIdSplit = PgpKeyHelper.splitUserId(userId);
|
||||
@ -118,18 +124,22 @@ public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> {
|
||||
if (userIdSplit[0] != null) {
|
||||
// show red user id if it is a secret key
|
||||
if (entry.secretKey) {
|
||||
userIdSplit[0] = mActivity.getString(R.string.secret_key) + " " + userIdSplit[0];
|
||||
holder.mainUserId.setText(mActivity.getString(R.string.secret_key)
|
||||
+ " " + userIdSplit[0]);
|
||||
holder.mainUserId.setTextColor(Color.RED);
|
||||
} else {
|
||||
holder.mainUserId.setText(userIdSplit[0]);
|
||||
holder.mainUserId.setTextColor(Color.BLACK);
|
||||
}
|
||||
holder.mainUserId.setText(userIdSplit[0]);
|
||||
} else {
|
||||
holder.mainUserId.setTextColor(Color.BLACK);
|
||||
holder.mainUserId.setText(R.string.user_id_no_name);
|
||||
}
|
||||
|
||||
// email
|
||||
if (userIdSplit[1] != null) {
|
||||
holder.mainUserIdRest.setText(userIdSplit[1]);
|
||||
holder.mainUserIdRest.setVisibility(View.VISIBLE);
|
||||
holder.mainUserIdRest.setText(userIdSplit[1]);
|
||||
} else {
|
||||
holder.mainUserIdRest.setVisibility(View.GONE);
|
||||
}
|
||||
@ -137,8 +147,8 @@ public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> {
|
||||
holder.keyId.setText(entry.keyIdHex);
|
||||
|
||||
if (entry.fingerPrintHex != null) {
|
||||
holder.fingerprint.setText(PgpKeyHelper.colorizeFingerprint(entry.fingerPrintHex));
|
||||
holder.fingerprint.setVisibility(View.VISIBLE);
|
||||
holder.fingerprint.setText(PgpKeyHelper.colorizeFingerprint(entry.fingerPrintHex));
|
||||
} else {
|
||||
holder.fingerprint.setVisibility(View.GONE);
|
||||
}
|
||||
@ -146,39 +156,33 @@ public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> {
|
||||
holder.algorithm.setText("" + entry.bitStrength + "/" + entry.algorithm);
|
||||
|
||||
if (entry.revoked) {
|
||||
holder.status.setVisibility(View.VISIBLE);
|
||||
holder.status.setText(R.string.revoked);
|
||||
} else {
|
||||
holder.status.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
LinearLayout userIdsLL = (LinearLayout) convertView.findViewById(R.id.user_ids_list);
|
||||
userIdsLL.removeAllViews();
|
||||
if (entry.userIds.size() == 1) {
|
||||
userIdsLL.setVisibility(View.GONE);
|
||||
holder.userIdsList.setVisibility(View.GONE);
|
||||
} else {
|
||||
boolean first = true;
|
||||
boolean second = true;
|
||||
for (String uid : entry.userIds) {
|
||||
if (first) {
|
||||
first = false;
|
||||
continue;
|
||||
}
|
||||
if (!second) {
|
||||
View sep = new View(mActivity);
|
||||
sep.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 1));
|
||||
sep.setBackgroundResource(android.R.drawable.divider_horizontal_dark);
|
||||
userIdsLL.addView(sep);
|
||||
}
|
||||
holder.userIdsList.setVisibility(View.VISIBLE);
|
||||
|
||||
// clear view from holder
|
||||
holder.userIdsList.removeAllViews();
|
||||
|
||||
Iterator<String> it = entry.userIds.iterator();
|
||||
// skip primary user id
|
||||
it.next();
|
||||
while (it.hasNext()) {
|
||||
String uid = it.next();
|
||||
TextView uidView = (TextView) mInflater.inflate(
|
||||
R.layout.import_keys_list_entry_user_id, null);
|
||||
uidView.setText(uid);
|
||||
userIdsLL.addView(uidView);
|
||||
second = false;
|
||||
holder.userIdsList.addView(uidView);
|
||||
}
|
||||
}
|
||||
|
||||
CheckBox cBox = (CheckBox) convertView.findViewById(R.id.selected);
|
||||
cBox.setChecked(entry.isSelected());
|
||||
holder.checkBox.setChecked(entry.isSelected());
|
||||
|
||||
return convertView;
|
||||
}
|
||||
|
@ -18,7 +18,6 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:paddingLeft="4dp"
|
||||
android:paddingRight="?android:attr/scrollbarSize"
|
||||
android:singleLine="true">
|
||||
|
||||
@ -26,6 +25,8 @@
|
||||
android:id="@+id/selected"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginLeft="4dp"
|
||||
android:layout_marginRight="4dp"
|
||||
android:clickable="false"
|
||||
android:focusable="false"
|
||||
android:focusableInTouchMode="false" />
|
||||
|
Loading…
Reference in New Issue
Block a user