package com.naz.sdkdemo.adaapter;

import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.naz.sdkdemo.R;
import com.naz.sdkdemo.bean.ScanRecycleInfo;
import com.naz.sdkdemo.bean.TrademarkInfo;
import com.naz.sdkdemo.utils.MyUtils;

import java.util.List;

public class RecycleTrademarkSelectAdapter extends BaseQuickAdapter<ScanRecycleInfo, BaseViewHolder> {
   public RecycleTrademarkSelectAdapter(@Nullable List<ScanRecycleInfo> data) {
      super(R.layout.item_recycle_trademark_select, data);
   }

   @Override
   protected void convert(@NonNull BaseViewHolder holder, ScanRecycleInfo info) {

      changeUi(holder, info.select);
   }

   @Override
   protected void convertPayloads(@NonNull BaseViewHolder helper, ScanRecycleInfo item, @NonNull List<Object> payloads) {
      super.convertPayloads(helper, item, payloads);
      Object payload = payloads.get(0);
      if (TextUtils.equals(payload.toString(), "change")) {
         item.select = !item.select;
         changeUi(helper, item.select);
      }
   }

   private void changeUi(BaseViewHolder helper, Boolean select) {
      if (select) {
         helper.itemView.setBackgroundResource(R.drawable.bg_item_select_red);
         helper.setImageResource(R.id.iv_select, R.mipmap.icon_selected);
      } else {
         helper.itemView.setBackgroundResource(R.mipmap.bg_white_round_background);
         helper.setImageResource(R.id.iv_select, R.mipmap.icon_unselect);
      }
      int size = MyUtils.dp2px(mContext, 16);
      helper.itemView.setPadding(size, 0, size, size);
   }
}
