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 RecycleTrademarkAdapter extends BaseQuickAdapter<TrademarkInfo, BaseViewHolder> {
   public RecycleTrademarkAdapter(@Nullable List<TrademarkInfo> data) {
      super(R.layout.item_recycle_trademark, data);
   }

   @Override
   protected void convert(@NonNull BaseViewHolder holder, TrademarkInfo info) {
      changeUi(holder, info.select);
      holder.setText(R.id.tv_order_id, String.format("销售订单号：%s", info.no));
      holder.setText(R.id.tv_content, info.supplier_code_show);
      holder.setText(R.id.tv_total_num, String.format("商标数量：%d", (int)info.total_order_quantity));
      holder.setText(R.id.tv_apply_num, String.format("已领数量：%d", info.out_stock_qty_total));
   }

   @Override
   protected void convertPayloads(@NonNull BaseViewHolder helper, TrademarkInfo item, @NonNull List<Object> payloads) {
      super.convertPayloads(helper, item, payloads);
      Object payload = payloads.get(0);
      if (TextUtils.equals(payload.toString(), "select")) {
         changeUi(helper, true);
         item.select = true;
      } else if (TextUtils.equals(payload.toString(), "unselect")) {
         changeUi(helper, false);
         item.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);
   }
}
