package com.sjkj.appthreefloor_tsgz.adapter;

import android.content.Context;
import android.text.TextUtils;

import com.sjkj.appthreefloor_tsgz.R;
import com.sjkj.appthreefloor_tsgz.bean.ResourceVisualizationBean;
import com.sjkj.appthreefloor_tsgz.databinding.ItemCommonDataListBinding;
import com.sjkj.appthreefloor_tsgz.utils.DoubleUtils;
import com.sjkj.base_lib.adapter.BaseRecAdapter;

import java.util.List;

public class CommonDataListAdapter extends BaseRecAdapter<ResourceVisualizationBean, ItemCommonDataListBinding> {

    public String Type_Name = "";

    public CommonDataListAdapter(Context context) {
        super(context);
    }

    public CommonDataListAdapter(Context context, List<ResourceVisualizationBean> list) {
        super(context, list);
    }

    public void setTypeName(String Type_Name) {
        this.Type_Name = Type_Name;

    }

    @Override
    protected int getLayoutResId(int viewType) {
        return R.layout.item_common_data_list;
    }

    @Override
    protected void onBindItem(ItemCommonDataListBinding binding, ResourceVisualizationBean bean, int position) {
        binding.setModel(bean);
        binding.executePendingBindings();
//        binding.titleTv TODO

        if (!TextUtils.isEmpty(bean.getDistance())) {
            if (Double.parseDouble(bean.getDistance()) > 1000) {
                binding.contentTv.setText(DoubleUtils.div(Double.parseDouble(bean.getDistance()), 1000, 2) + "km");
            } else {
                binding.contentTv.setText(bean.getDistance() + "m");
            }
        } else {
            binding.contentTv.setText("该资源暂无点位");
        }

        switch (this.Type_Name) {
            case "centerdata_t_farm_agricultural_cooperatives":
                //农民合作社
                binding.ivType.setBackground(context.getResources().getDrawable(R.drawable.ic_tongyong));
                break;

            default:
                binding.ivType.setBackground(context.getResources().getDrawable(R.drawable.ic_tongyong));
                break;

        }
    }


}
