package com.ysnows.base.widget.tablayout;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.ysnows.base.R;
import com.ysnows.base.databinding.WidgetMemuItemBinding;
import com.ysnows.base.view.BView;

import androidx.databinding.DataBindingUtil;


/**
 * Created by xianguangjin on 16/6/1.
 * 自定义
 */

public class MenuTabView extends LinearLayout {


    private BView view;
    private WidgetMemuItemBinding binding;


    public MenuTabView(Context context) {
        this(context, null);

    }

    public MenuTabView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);


    }

    public MenuTabView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context, attrs, defStyleAttr);

    }

    private void init(Context context, AttributeSet attrs, int defStyleAttr) {
        if (context instanceof BView) {
            this.view = (BView) context;
        }

        binding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.widget_memu_item, this, true);
        setLayoutParams(new LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT, 1));
    }

    public void setTab(Tab tab) {
        if (tab != null) {
            binding.setTab(tab);
        }
    }

    public void select(Boolean selected) {
        binding.getTab().setSelected(selected);
    }
}
