use of com.funstill.kelefun.event.ActivitySpan in project keleFanfou by kelefun.
the class StatusAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
if (holder instanceof ItemViewHolder) {
ItemViewHolder itemHolder = (ItemViewHolder) holder;
if (data.size() != 0) {
Status status = data.get(position);
itemHolder.screenNameView.setText(status.getUser().getScreenName());
itemHolder.timeSourceView.setText(DateUtil.toAgo(status.getCreatedAt()) + Html.fromHtml(status.getSource()).toString());
// 处理文本点击跳转
// 格式化<a herf ,mobile等标签
Spannable statusSpan = (Spannable) Html.fromHtml(status.getText());
CharSequence text = statusSpan.toString();
statusSpan.getSpans(0, text.length(), TextAppearanceSpan.class);
URLSpan[] urls = statusSpan.getSpans(0, text.length(), URLSpan.class);
SpannableStringBuilder activitySpan = new SpannableStringBuilder(statusSpan);
activitySpan.clearSpans();
for (URLSpan url : urls) {
ActivitySpan myURLSpan = new ActivitySpan(url.getURL());
activitySpan.setSpan(myURLSpan, statusSpan.getSpanStart(url), statusSpan.getSpanEnd(url), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
itemHolder.statusView.setText(activitySpan);
// 使标签可点击
itemHolder.statusView.setOnTouchListener(TextLinkMovementMethod.getInstance());
// 图片加载
Glide.with(mContext).load(status.getUser().getProfileImageUrl()).into(itemHolder.avatarView);
if (status.getPhoto() != null) {
itemHolder.photoView.setVisibility(View.VISIBLE);
if (status.getPhoto().getLargeurl().endsWith("gif")) {
// 动图标签
itemHolder.photoView.setTagEnable(true);
} else {
itemHolder.photoView.setTagEnable(false);
}
Glide.with(mContext).load(status.getPhoto().getImageurl()).into(itemHolder.photoView);
} else {
itemHolder.photoView.setVisibility(View.GONE);
}
}
}
}
Aggregations