package com.wd.workoffice.widget;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.wd.workoffice.R;

import androidx.core.view.ActionProvider;
import flexible.xd.android_base.utils.ScreenUtils;

public class BadgeCarProvider extends ActionProvider {

    private TextView tvBadge;

    private OnClickListener onClickListener;

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

    @Override
    public View onCreateActionView() {
        int size = getContext().getResources().getDimensionPixelSize(
                R.dimen.flexible_actionbar_size);
//
        ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ScreenUtils.getScreenWidth() / 5, size);
        View view = LayoutInflater.from(getContext())
                .inflate(R.layout.view_red, null, false);

        view.setLayoutParams(layoutParams);
        tvBadge = view.findViewById(R.id.tv_badge);
        view.setOnClickListener(onViewClickListener);
        return view;
    }

    // 点击处理。
    private View.OnClickListener onViewClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (onClickListener != null)
                onClickListener.onClick();
        }
    };

    // 外部设置监听。
    public void setOnClickListener(OnClickListener onClickListener) {
        this.onClickListener = onClickListener;
    }

    public interface OnClickListener {
        void onClick();
    }


    public void setBadgeVisibility(int visibility) {
        tvBadge.setVisibility(visibility);
    }
}