package com.naz.sdkdemo.adaapter;

import android.text.TextUtils;

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.TrademarkInfo;
import com.naz.sdkdemo.utils.MyUtils;

import java.util.List;

public class RepairTrademarkAdapter extends BaseQuickAdapter<TrademarkInfo, BaseViewHolder> {
   public RepairTrademarkAdapter(@Nullable List<TrademarkInfo> data) {
      super(R.layout.item_repair_trademark, data);
   }

   @Override
   protected void convert(@NonNull BaseViewHolder holder, TrademarkInfo info) {
      changeUi(holder, info.select);
      holder.setText(R.id.tv_order_id, "销售订单号："+info.no);
      holder.setText(R.id.tv_content, info.customer_name);
      holder.setText(R.id.tv_total_num, "商标数量：" + info.getTotalOrderQuantity());
      holder.setText(R.id.tv_apply_num, "已领数量："+ info.out_stock_qty_total);
   }

   @Override
   protected void convertPayloads(@NonNull BaseViewHolder holder, TrademarkInfo info, @NonNull List<Object> payloads) {
      super.convertPayloads(holder, info, payloads);
      Object payload = payloads.get(0);
      if (TextUtils.equals(payload.toString(), "select")) {
         changeUi(holder, true);
         info.select = true;
      } else if (TextUtils.equals(payload.toString(), "unselect")) {
         changeUi(holder, false);
         info.select = false;
      }
   }

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