package com.common.im.adapter;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import io.rong.imkit.utils.helper.ChatGroupHelper;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.module.BaseLoadMoreModule;
import com.chad.library.adapter.base.module.LoadMoreModule;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.common.im.bean.GroupNoticeBean;
import com.common.im.bean.MusicSheetListBean;
import com.common.im_ui.R;
import com.cooleshow.base.common.BaseApplication;
import com.cooleshow.base.utils.DateUtil;
import com.cooleshow.base.utils.GlideUtils;

import java.util.List;

/**
 * 创建日期：2022/6/11 18:34
 *
 * @author Ryan
 * 类说明：
 */
public class NoticeListAdapter extends BaseQuickAdapter<GroupNoticeBean.RowsBean, BaseViewHolder> implements LoadMoreModule {

    public NoticeListAdapter(List<GroupNoticeBean.RowsBean> data) {
        super(R.layout.notice_list_item, data);
    }


    @Override
    protected void convert(BaseViewHolder helper, GroupNoticeBean.RowsBean bean) {
        ImageView ivPortrait = helper.getView(R.id.iv_portrait);
        TextView tvName = helper.getView(R.id.tv_name);
        TextView tvTime = helper.getView(R.id.tv_time);
        TextView tvRoof = helper.getView(R.id.tv_roof);
        ImageView ivSetting = helper.getView(R.id.iv_setting);
        TextView tvTitle = helper.getView(R.id.tv_title);
        TextView tvContent = helper.getView(R.id.tv_content);
        TextView tvRead = helper.getView(R.id.tv_read);
        int chatGroupAvatarFromId = ChatGroupHelper.getChatGroupAvatarFromId(bean.groupId);
        ivPortrait.setImageResource(chatGroupAvatarFromId);
        tvName.setText(bean.username);

        tvTime.setText(DateUtil.dateFormatNoSecond(TextUtils.isEmpty(bean.updateTime) ? bean.createTime : bean.updateTime));
        if (bean.topFlag) {
            tvRoof.setVisibility(View.VISIBLE);
        } else {
            tvRoof.setVisibility(View.GONE);
        }
        tvTitle.setText(bean.title);
        tvContent.setText(bean.content);
        if (BaseApplication.Companion.isTeacherClient()) {
            ivSetting.setVisibility(View.VISIBLE);
        } else {
            ivSetting.setVisibility(View.GONE);
        }
        ivSetting.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != mSettingClickListener) {
                    mSettingClickListener.onSettingClick(v, bean);
                }
            }
        });
    }

    @NonNull
    @Override
    public BaseLoadMoreModule addLoadMoreModule(@NonNull BaseQuickAdapter<?, ?> baseQuickAdapter) {
        return new BaseLoadMoreModule(baseQuickAdapter);
    }


    public interface SettingClickListener {
        void onSettingClick(View v, GroupNoticeBean.RowsBean bean);
    }

    private SettingClickListener mSettingClickListener;

    public void setmSettingClickListener(SettingClickListener mSettingClickListener) {
        this.mSettingClickListener = mSettingClickListener;
    }
}
