package com.unis.sxzcl.widget.menu;


import android.view.View;

import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.unis.sxzcl.R;

import java.util.List;

/**
 *
 * 包名: com.unis.sxzcl.widget.menu
 * 类名: MenuListAdapter
 * 作用描述:
 * 创建人: mQ
 * 创建时间: 2017/10/16 15:41
 * 更新人:
 * 更新时间: 2020/11/26 15:41
 * 更新说明:
 * 版本号: 1.0
 */
public class MenuListAdapter extends BaseQuickAdapter<String, BaseViewHolder> {

    private int selectPosition = 0;

    public MenuListAdapter(@Nullable List<String> data) {
        super(R.layout.menu_list_item_layout, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, String item) {
        helper.setText(R.id.tv_content, item);
        fillValue(helper);
        if (helper.getLayoutPosition() == getItemCount() - 1)
            helper.getView(R.id.line).setVisibility(View.GONE);
        else
            helper.getView(R.id.line).setVisibility(View.VISIBLE);
    }

    private void fillValue(BaseViewHolder helper) {
        if (selectPosition >= 0) {
            if (helper.getLayoutPosition() == selectPosition) {
                helper.setTextColor(R.id.tv_content, ContextCompat.getColor(getContext(), R.color.colorWhite));
                helper.setBackgroundColor(R.id.tv_content, ContextCompat.getColor(getContext(), R.color.colorAccent));
            } else {
                helper.setTextColor(R.id.tv_content, ContextCompat.getColor(getContext(), R.color.colorText1));
                helper.setBackgroundResource(R.id.tv_content, R.color.colorWhite);
            }
        }
    }

    public void setSelectPosition(int position) {
        selectPosition = position;
        notifyDataSetChanged();
    }
}
