package com.cooleshow.teacher.widgets;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.cooleshow.teacher.R;

import cz.msebera.android.httpclient.client.protocol.ClientContextConfigurer;

/**
 * @author dengqw
 * @time 2022/6/26 16:55
 * @describe：
 **/
public class StyleEmptyView extends FrameLayout {

    private ImageView mEmptyIcon;
    private TextView mEmptyText;
    private TextView mOpeBtn;
    private int mEmptyIconRes;
    private String mEmptyTextString;
    private String mOpeBtnTextString;

    public StyleEmptyView(@NonNull Context context) {
        this(context, null, -1);
    }

    public StyleEmptyView(@NonNull Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, -1);
    }

    public StyleEmptyView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.teacher_main_style);
        mEmptyIconRes = array.getResourceId(R.styleable.teacher_main_style_empty_icon, 0);
        mEmptyTextString = array.getString(R.styleable.teacher_main_style_empty_text);
        mOpeBtnTextString = array.getString(R.styleable.teacher_main_style_ope_btn);
        array.recycle();
        initView();
    }

    private void initView() {
        View view = View.inflate(getContext(), R.layout.teacher_empty_view, this);
        mEmptyIcon = view.findViewById(R.id.empty_icon);
        mEmptyText = view.findViewById(R.id.empty_text);
        mOpeBtn = view.findViewById(R.id.ope_btn);

        mEmptyIcon.setImageResource(mEmptyIconRes);
        mEmptyText.setText(mEmptyTextString);
        mOpeBtn.setText(mOpeBtnTextString);
    }

    public static StyleEmptyView getInstance(Context context) {
        StyleEmptyView emptyView = new StyleEmptyView(context);
        return emptyView;
    }

    public StyleEmptyView setEmptyIcon(int resId) {
        mEmptyIcon.setImageResource(resId);
        return this;
    }

    public StyleEmptyView setEmptyText(String text) {
        mEmptyText.setText(text);
        return this;
    }

    public StyleEmptyView setOpeBtn(String text) {
        mOpeBtn.setText(text);
        return this;
    }

    public StyleEmptyView setOpeBtnClickListener(OnClickListener listener) {
        mOpeBtn.setOnClickListener(listener);
        return this;
    }
}
