|
| 1 | +package com.thomas.andfun.article.adapter; |
| 2 | + |
| 3 | +import android.text.TextUtils; |
| 4 | + |
| 5 | +import androidx.annotation.NonNull; |
| 6 | +import androidx.annotation.Nullable; |
| 7 | +import androidx.core.text.HtmlCompat; |
| 8 | + |
| 9 | +import com.chad.library.adapter.base.BaseQuickAdapter; |
| 10 | +import com.chad.library.adapter.base.BaseViewHolder; |
| 11 | +import com.thomas.andfun.article.R; |
| 12 | +import com.thomas.andfun.article.bean.ResultBean; |
| 13 | +import com.thomas.sdk.helper.ImageHelper; |
| 14 | + |
| 15 | +import java.util.List; |
| 16 | + |
| 17 | +/** |
| 18 | + * @author Thomas |
| 19 | + * @describe |
| 20 | + * @date 2019/12/12 |
| 21 | + * @updatelog |
| 22 | + * @since |
| 23 | + */ |
| 24 | +public class ResultAdapter extends BaseQuickAdapter<ResultBean.DatasBean, BaseViewHolder> { |
| 25 | + public ResultAdapter(@Nullable List<ResultBean.DatasBean> data) { |
| 26 | + super(R.layout.item_square, data); |
| 27 | + } |
| 28 | + |
| 29 | + @Override |
| 30 | + protected void convert(@NonNull BaseViewHolder helper, ResultBean.DatasBean item) { |
| 31 | + helper.setText(R.id.tv_title, HtmlCompat.fromHtml(item.getTitle(), HtmlCompat.FROM_HTML_MODE_COMPACT)); |
| 32 | + |
| 33 | + if (TextUtils.isEmpty(item.getAuthor())) { |
| 34 | + helper.setText(R.id.tv_author, "分享人:" + item.getShareUser()); |
| 35 | + helper.setText(R.id.tv_date, item.getNiceShareDate()); |
| 36 | + } else { |
| 37 | + helper.setText(R.id.tv_author, "作者:" + item.getAuthor()); |
| 38 | + helper.setText(R.id.tv_date, item.getNiceDate()); |
| 39 | + } |
| 40 | + if (item.getLink().contains("jianshu")) { |
| 41 | + ImageHelper.showSimpleSquare(helper.itemView.findViewById(R.id.iv_from), R.mipmap.ic_jianshu); |
| 42 | + } else if (item.getLink().contains("juejin")) { |
| 43 | + ImageHelper.showSimpleSquare(helper.itemView.findViewById(R.id.iv_from), R.mipmap.ic_juejin); |
| 44 | + } else if (item.getLink().contains("csdn")) { |
| 45 | + ImageHelper.showSimpleSquare(helper.itemView.findViewById(R.id.iv_from), R.mipmap.ic_csdn); |
| 46 | + } else if (item.getLink().contains("weixin")) { |
| 47 | + ImageHelper.showSimpleSquare(helper.itemView.findViewById(R.id.iv_from), R.mipmap.ic_weixin); |
| 48 | + } else { |
| 49 | + ImageHelper.showSimpleSquare(helper.itemView.findViewById(R.id.iv_from), R.mipmap.ic_launcher_round); |
| 50 | + } |
| 51 | + } |
| 52 | +} |
0 commit comments