package com.unis.sxzcl.ui.policy;

import android.text.Html;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.module.LoadMoreModule;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.unis.model.bean.PolicyBean;
import com.unis.sxzcl.R;
import com.xyxsbj.mylibrary.tool.DateTool;

import org.jetbrains.annotations.NotNull;


/**
 * 政策制度列表适配器
 * 创建人: mQ
 * 时间: 2021/2/2 10:57
 */
public class PolicyListAdapter extends BaseQuickAdapter<PolicyBean, BaseViewHolder>
        implements LoadMoreModule {

    public PolicyListAdapter() {
        super(R.layout.item_list_policy);
    }

    @Override
    protected void convert(@NotNull BaseViewHolder holder, PolicyBean item) {

        holder.setText(R.id.tv_title, item.getTitle());

        TextView tvContent = holder.getView(R.id.tv_content);
        // 内容超出20个字截取
        String content = item.getContent() == null ? "" : item.getContent();
//        if (content != null && content.length() > 20)
//            content = item.getContent().substring(0, 20) + "...";
        tvContent.setText(Html.fromHtml(content, null, null));

        holder.setText(R.id.tv_source, item.getPublishOrgName());

        String publishTime = item.getPublishTime();
        try {
            publishTime = DateTool.formatDate(publishTime, DateTool.GLNZSJ_DATE, DateTool.YTDTD_DATE);
        } catch (Exception e) {
        }
        holder.setText(R.id.tv_time, publishTime);

    }

}
