@Override public View getView(int position, View convertView, ViewGroup parent) { View details = convertView; StatusHolder holder = null; if (details == null) { LayoutInflater inflater = getLayoutInflater(); details = inflater.inflate(R.layout.status_row, parent, false); holder = new StatusHolder(details); details.setTag(holder); } else { holder = (StatusHolder) details.getTag(); } holder.populateFrom(friends.get(position)); return details; }
public static View fillConvertView(View convertView, Status status) { if (convertView == null || status == null) { return null; } Context context = convertView.getContext(); StatusHolder holder = (StatusHolder) convertView.getTag(); if (holder == null) { return null; } holder.reset(); boolean isNetEase = status.getServiceProvider() == ServiceProvider.NetEase; User user = status.getUser(); if (user == null) { // 微博已经删除 if (StringUtil.isNotEmpty(status.getText())) { Spannable textSpan = EmotionLoader.getEmotionSpannable(status.getServiceProvider(), status.getText()); holder.tvText.setText(textSpan); } return convertView; } if (GlobalVars.IS_SHOW_HEAD) { holder.ivProfilePicture.setVisibility(View.VISIBLE); holder.headClickListener.setUser(user); String profileUrl = user.getProfileImageUrl(); if (StringUtil.isNotEmpty(profileUrl)) { ImageLoad4HeadTask headTask = new ImageLoad4HeadTask(holder.ivProfilePicture, profileUrl, true); holder.headTask = headTask; headTask.execute(); } } else { holder.ivProfilePicture.setVisibility(View.GONE); } holder.tvScreenName.setText(user.getScreenName()); if (status.getUser().isVerified()) { holder.ivVerify.setVisibility(View.VISIBLE); } if (status.getLocation() != null) { holder.ivLocation.setVisibility(View.VISIBLE); } if (status.isFavorited()) { holder.ivFavorite.setVisibility(View.VISIBLE); } holder.tvCreatedAt.setText(TimeSpanUtil.toTimeSpanString(status.getCreatedAt())); Spannable textSpan = EmotionLoader.getEmotionSpannable(status.getServiceProvider(), status.getText()); holder.tvText.setText(textSpan); Status retweet = status.getRetweetedStatus(); if (retweet != null) { holder.llRetweet.setVisibility(View.VISIBLE); holder.tvRetweetText.setVisibility(View.VISIBLE); String retweetText = ""; if (retweet.getUser() != null) { retweetText = retweet.getUser().getMentionTitleName() + ": " + retweet.getText(); } Spannable retweetTextSpan = EmotionLoader.getEmotionSpannable(status.getServiceProvider(), retweetText); holder.tvRetweetText.setText(retweetTextSpan); } String thumbnailUrl = status.getThumbnailPictureUrl(); ImageView ivTempThumbnail = holder.ivThumbnail; if (retweet != null) { thumbnailUrl = retweet.getThumbnailPictureUrl(); ivTempThumbnail = holder.ivRetweetThumbnail; } if (StringUtil.isNotEmpty(thumbnailUrl)) { holder.ivAttachment.setVisibility(View.VISIBLE); if (GlobalVars.IS_SHOW_THUMBNAIL && !isNetEase) { ivTempThumbnail.setVisibility(View.VISIBLE); ImageLoad4ThumbnailTask thumbnailTask = new ImageLoad4ThumbnailTask(ivTempThumbnail, thumbnailUrl); holder.thumbnailTask = thumbnailTask; // thumbnailTask.execute(status); ivTempThumbnail.setOnClickListener(new ImageClickListener(status)); } } String source = String.format(GlobalResource.getStatusSourceFormat(context), status.getSource()); holder.tvSource.setText(Html.fromHtml(source).toString()); String responseFormat = GlobalResource.getStatusResponseFormat(context); int retweetCount = status.getRetweetCount() == null ? 0 : status.getRetweetCount(); int commentCount = status.getCommentCount() == null ? 0 : status.getCommentCount(); String responseText = String.format(responseFormat, retweetCount, commentCount); holder.tvResponse.setText(responseText); if (status.getRetweetCount() == null || status.getRetweetCount() != null) { holder.tvResponse.setText(responseText); QueryResponseCountTask responseCountTask = new QueryResponseCountTask(context, status, holder.tvResponse); holder.responseCountTask = responseCountTask; // countTask.execute(); } return convertView; }
@SuppressWarnings("deprecation") // context.getDrawable is api lvl 21, need to use deprecated public static void setStatus(Context context, StatusHolder holder, DecryptVerifyResult result) { OpenPgpSignatureResult signatureResult = result.getSignatureResult(); if (holder.hasEncrypt()) { int encText, encIcon, encColor; if (signatureResult != null && signatureResult.isSignatureOnly()) { encIcon = R.drawable.status_lock_open_24dp; encText = R.string.decrypt_result_not_encrypted; encColor = R.color.android_red_light; } else { encIcon = R.drawable.status_lock_closed_24dp; encText = R.string.decrypt_result_encrypted; encColor = R.color.android_green_light; } int encColorRes = context.getResources().getColor(encColor); holder.getEncryptionStatusIcon().setColorFilter(encColorRes, PorterDuff.Mode.SRC_IN); holder .getEncryptionStatusIcon() .setImageDrawable(context.getResources().getDrawable(encIcon)); holder.getEncryptionStatusText().setText(encText); holder.getEncryptionStatusText().setTextColor(encColorRes); } int sigText, sigIcon, sigColor; int sigActionText, sigActionIcon; if (signatureResult == null) { sigText = R.string.decrypt_result_no_signature; sigIcon = R.drawable.status_signature_invalid_cutout_24dp; sigColor = R.color.bg_gray; // won't be used, but makes compiler happy sigActionText = 0; sigActionIcon = 0; } else switch (signatureResult.getStatus()) { case OpenPgpSignatureResult.SIGNATURE_SUCCESS_CERTIFIED: { sigText = R.string.decrypt_result_signature_certified; sigIcon = R.drawable.status_signature_verified_cutout_24dp; sigColor = R.color.android_green_light; sigActionText = R.string.decrypt_result_action_show; sigActionIcon = R.drawable.ic_vpn_key_grey_24dp; break; } case OpenPgpSignatureResult.SIGNATURE_SUCCESS_UNCERTIFIED: { sigText = R.string.decrypt_result_signature_uncertified; sigIcon = R.drawable.status_signature_unverified_cutout_24dp; sigColor = R.color.android_orange_light; sigActionText = R.string.decrypt_result_action_show; sigActionIcon = R.drawable.ic_vpn_key_grey_24dp; break; } case OpenPgpSignatureResult.SIGNATURE_KEY_REVOKED: { sigText = R.string.decrypt_result_signature_revoked_key; sigIcon = R.drawable.status_signature_revoked_cutout_24dp; sigColor = R.color.android_red_light; sigActionText = R.string.decrypt_result_action_show; sigActionIcon = R.drawable.ic_vpn_key_grey_24dp; break; } case OpenPgpSignatureResult.SIGNATURE_KEY_EXPIRED: { sigText = R.string.decrypt_result_signature_expired_key; sigIcon = R.drawable.status_signature_expired_cutout_24dp; sigColor = R.color.android_red_light; sigActionText = R.string.decrypt_result_action_show; sigActionIcon = R.drawable.ic_vpn_key_grey_24dp; break; } case OpenPgpSignatureResult.SIGNATURE_KEY_MISSING: { sigText = R.string.decrypt_result_signature_missing_key; sigIcon = R.drawable.status_signature_unknown_cutout_24dp; sigColor = R.color.android_red_light; sigActionText = R.string.decrypt_result_action_Lookup; sigActionIcon = R.drawable.ic_file_download_grey_24dp; break; } default: case OpenPgpSignatureResult.SIGNATURE_ERROR: { sigText = R.string.decrypt_result_invalid_signature; sigIcon = R.drawable.status_signature_invalid_cutout_24dp; sigColor = R.color.android_red_light; sigActionText = R.string.decrypt_result_action_show; sigActionIcon = R.drawable.ic_vpn_key_grey_24dp; break; } } int sigColorRes = context.getResources().getColor(sigColor); holder.getSignatureStatusIcon().setColorFilter(sigColorRes, PorterDuff.Mode.SRC_IN); holder.getSignatureStatusIcon().setImageDrawable(context.getResources().getDrawable(sigIcon)); holder.getSignatureStatusText().setText(sigText); holder.getSignatureStatusText().setTextColor(sigColorRes); if (signatureResult != null) { holder.getSignatureLayout().setVisibility(View.VISIBLE); holder.getSignatureAction().setText(sigActionText); holder.getSignatureAction().setCompoundDrawablesWithIntrinsicBounds(0, 0, sigActionIcon, 0); String userId = signatureResult.getPrimaryUserId(); KeyRing.UserId userIdSplit = KeyRing.splitUserId(userId); if (userIdSplit.name != null) { holder.getSignatureUserName().setText(userIdSplit.name); } else { holder.getSignatureUserName().setText(R.string.user_id_no_name); } if (userIdSplit.email != null) { holder.getSignatureUserEmail().setVisibility(View.VISIBLE); holder.getSignatureUserEmail().setText(userIdSplit.email); } else { holder.getSignatureUserEmail().setVisibility(View.GONE); } } else { holder.getSignatureLayout().setVisibility(View.GONE); } }