package com.example.iot_controlhost.adapter;


import android.view.View;
import android.widget.AdapterView;

import com.example.iot_controlhost.base.BaseRecyclerAdapter;
import com.example.iot_controlhost.databinding.ItemSetBinding;
import com.example.iot_controlhost.model.Set;

import java.util.List;

/**
 * @Author：DuanKaiji
 * @Date：2023-06-08/09:38
 * @Declaration：设置界面-单项
 */
public class SetAdapter extends BaseRecyclerAdapter<Set, ItemSetBinding> {

    public SetAdapter(List<Set> dataList, Class<ItemSetBinding> bindingClass) {
        super(dataList, bindingClass);
    }

    @Override
    protected void bindData(ItemSetBinding binding, Set data) {
        if(data.getOnClickListener()==null){
            binding.ivRight.setVisibility(View.INVISIBLE);
        }else{
            binding.ivRight.setVisibility(View.VISIBLE);
        }
        //设置-普通显示主副内容点击事件
        binding.tvSetTitle.setText(data.getTitle());
        binding.tvSetDetail.setText(data.getDetail());
        binding.clSet.setOnClickListener(data.getOnClickListener());
        //设置-开关事件
        // 先设置为null，否则会触发事件
        binding.switcher.setOnCheckedChangeListener(null);
        if (data.getOnCheckedChangeListener() != null) {
            //开关事件
            binding.switcher.setChecked(data.isChecked());
            binding.switcher.setOnCheckedChangeListener(data.getOnCheckedChangeListener());
            binding.switcher.setVisibility(View.VISIBLE);
        }else{
            binding.switcher.setVisibility(View.GONE);
        }
    }

}
