Fix ViewHolder in ImportKeysAdapter

This commit is contained in:
Dominik Schürmann 2014-04-15 23:08:41 +02:00
parent 1e22b28c2e
commit 9df498b714
2 changed files with 30 additions and 25 deletions

View File

@ -35,6 +35,7 @@ import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> { public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> {
@ -50,6 +51,8 @@ public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> {
public TextView fingerprint; public TextView fingerprint;
public TextView algorithm; public TextView algorithm;
public TextView status; public TextView status;
public LinearLayout userIdsList;
public CheckBox checkBox;
} }
public ImportKeysAdapter(Activity activity) { public ImportKeysAdapter(Activity activity) {
@ -106,10 +109,13 @@ public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> {
holder.fingerprint = (TextView) convertView.findViewById(R.id.fingerprint); holder.fingerprint = (TextView) convertView.findViewById(R.id.fingerprint);
holder.algorithm = (TextView) convertView.findViewById(R.id.algorithm); holder.algorithm = (TextView) convertView.findViewById(R.id.algorithm);
holder.status = (TextView) convertView.findViewById(R.id.status); 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); convertView.setTag(holder);
} else { } else {
holder = (ViewHolder) convertView.getTag(); holder = (ViewHolder) convertView.getTag();
} }
// main user id // main user id
String userId = entry.userIds.get(0); String userId = entry.userIds.get(0);
String[] userIdSplit = PgpKeyHelper.splitUserId(userId); String[] userIdSplit = PgpKeyHelper.splitUserId(userId);
@ -118,18 +124,22 @@ public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> {
if (userIdSplit[0] != null) { if (userIdSplit[0] != null) {
// show red user id if it is a secret key // show red user id if it is a secret key
if (entry.secretKey) { 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); holder.mainUserId.setTextColor(Color.RED);
} else {
holder.mainUserId.setText(userIdSplit[0]);
holder.mainUserId.setTextColor(Color.BLACK);
} }
holder.mainUserId.setText(userIdSplit[0]);
} else { } else {
holder.mainUserId.setTextColor(Color.BLACK);
holder.mainUserId.setText(R.string.user_id_no_name); holder.mainUserId.setText(R.string.user_id_no_name);
} }
// email // email
if (userIdSplit[1] != null) { if (userIdSplit[1] != null) {
holder.mainUserIdRest.setText(userIdSplit[1]);
holder.mainUserIdRest.setVisibility(View.VISIBLE); holder.mainUserIdRest.setVisibility(View.VISIBLE);
holder.mainUserIdRest.setText(userIdSplit[1]);
} else { } else {
holder.mainUserIdRest.setVisibility(View.GONE); holder.mainUserIdRest.setVisibility(View.GONE);
} }
@ -137,8 +147,8 @@ public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> {
holder.keyId.setText(entry.keyIdHex); holder.keyId.setText(entry.keyIdHex);
if (entry.fingerPrintHex != null) { if (entry.fingerPrintHex != null) {
holder.fingerprint.setText(PgpKeyHelper.colorizeFingerprint(entry.fingerPrintHex));
holder.fingerprint.setVisibility(View.VISIBLE); holder.fingerprint.setVisibility(View.VISIBLE);
holder.fingerprint.setText(PgpKeyHelper.colorizeFingerprint(entry.fingerPrintHex));
} else { } else {
holder.fingerprint.setVisibility(View.GONE); holder.fingerprint.setVisibility(View.GONE);
} }
@ -146,39 +156,33 @@ public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> {
holder.algorithm.setText("" + entry.bitStrength + "/" + entry.algorithm); holder.algorithm.setText("" + entry.bitStrength + "/" + entry.algorithm);
if (entry.revoked) { if (entry.revoked) {
holder.status.setVisibility(View.VISIBLE);
holder.status.setText(R.string.revoked); holder.status.setText(R.string.revoked);
} else { } else {
holder.status.setVisibility(View.GONE); holder.status.setVisibility(View.GONE);
} }
LinearLayout userIdsLL = (LinearLayout) convertView.findViewById(R.id.user_ids_list);
userIdsLL.removeAllViews();
if (entry.userIds.size() == 1) { if (entry.userIds.size() == 1) {
userIdsLL.setVisibility(View.GONE); holder.userIdsList.setVisibility(View.GONE);
} else { } else {
boolean first = true; holder.userIdsList.setVisibility(View.VISIBLE);
boolean second = true;
for (String uid : entry.userIds) { // clear view from holder
if (first) { holder.userIdsList.removeAllViews();
first = false;
continue; Iterator<String> it = entry.userIds.iterator();
} // skip primary user id
if (!second) { it.next();
View sep = new View(mActivity); while (it.hasNext()) {
sep.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 1)); String uid = it.next();
sep.setBackgroundResource(android.R.drawable.divider_horizontal_dark);
userIdsLL.addView(sep);
}
TextView uidView = (TextView) mInflater.inflate( TextView uidView = (TextView) mInflater.inflate(
R.layout.import_keys_list_entry_user_id, null); R.layout.import_keys_list_entry_user_id, null);
uidView.setText(uid); uidView.setText(uid);
userIdsLL.addView(uidView); holder.userIdsList.addView(uidView);
second = false;
} }
} }
CheckBox cBox = (CheckBox) convertView.findViewById(R.id.selected); holder.checkBox.setChecked(entry.isSelected());
cBox.setChecked(entry.isSelected());
return convertView; return convertView;
} }

View File

@ -18,7 +18,6 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal" android:orientation="horizontal"
android:paddingLeft="4dp"
android:paddingRight="?android:attr/scrollbarSize" android:paddingRight="?android:attr/scrollbarSize"
android:singleLine="true"> android:singleLine="true">
@ -26,6 +25,8 @@
android:id="@+id/selected" android:id="@+id/selected"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:clickable="false" android:clickable="false"
android:focusable="false" android:focusable="false"
android:focusableInTouchMode="false" /> android:focusableInTouchMode="false" />