package com.unis.sxzcl.ui.announce;

import android.text.Html;
import android.view.View;
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.AnnounceBean;
import com.unis.sxzcl.R;
import com.xyxsbj.mylibrary.tool.DateTool;

import org.jetbrains.annotations.NotNull;


/**
 * 公告列表适配器
 * 创建人: mQ
 * 时间: 2020/12/5 11:08
 */
public class AnnounceListAdapter extends BaseQuickAdapter<AnnounceBean, BaseViewHolder>
        implements LoadMoreModule {

    public AnnounceListAdapter() {
        super(R.layout.item_list_announce);
    }

    @Override
    protected void convert(@NotNull BaseViewHolder holder, AnnounceBean 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);

        //未读标记的显示/隐藏
        boolean state = item.getReadStatus() == null ? false : item.getReadStatus();
        holder.getView(R.id.v_flag).setVisibility(state ? View.INVISIBLE : View.VISIBLE);
    }

}
