package com.android.launcher3.settings.wifi;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.android.launcher3.R;
import com.android.launcher3.settings.BaseRecyclerViewAdapter;

import java.util.ArrayList;
import java.util.List;

public class WifiWhiteListAdapter  extends BaseRecyclerViewAdapter<WifiInfoBean> {
    private List<WifiInfoBean> mDeletePosition= new ArrayList<>();
    private boolean mIsShowCb=false;
    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        super.onBindViewHolder(holder, position);
        MyViewHolder myViewHolder= (MyViewHolder) holder;
        TextView tvMac=myViewHolder.get(R.id.tv_mac);
        TextView tvSsid=myViewHolder.get(R.id.tv_ssid);
        CheckBox checkBox=myViewHolder.get(R.id.cb_delete);
        if (mIsShowCb){
            checkBox.setVisibility(View.VISIBLE);
        }else {
            checkBox.setVisibility(View.INVISIBLE);
        }
        tvMac.setText(mList.get(position).getMac());
        tvSsid.setText(mList.get(position).getSsid());
        checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (buttonView.isPressed()) {
                    if (isChecked) {
                        if (!mDeletePosition.contains(mList.get(position))){
                            mDeletePosition.add(mList.get(position));
                        }
                    } else {
                        if (mDeletePosition.contains(mList.get(position))){
                            mDeletePosition.remove(mList.get(position));
                        }

                    }
                }
            }
        });

    }

    public List<WifiInfoBean> getDeletePosition(){
        return mDeletePosition;
    }
    public void clearDeletePosition(){
        mDeletePosition.clear();
    }


    public void  setIsShowCb(boolean isShowCb){
        mIsShowCb=isShowCb;
        notifyDataSetChanged();
    }
    public boolean ismIsShowCb(){
        return mIsShowCb;
    }
}
