package com.cooleshow.base.widgets;

import android.content.Context;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.cooleshow.base.R;

import androidx.annotation.Nullable;

/**
 * Author by pq, Date on 2022/5/5.
 */
public class EmptyViewLayout extends LinearLayout {

    private ImageView mIvEmptyIcon;
    private TextView mTvEmptyTip;

    public EmptyViewLayout(Context context) {
        this(context, null);
    }

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

    public EmptyViewLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        setOrientation(VERTICAL);
        setGravity(Gravity.CENTER);
        LayoutInflater.from(getContext()).inflate(R.layout.empty_layout, this);
        mIvEmptyIcon = findViewById(R.id.iv_empty_icon);
        mTvEmptyTip = findViewById(R.id.tv_empty_tip);
    }

    public void setContent(int drawableRes, String text) {
        if (mIvEmptyIcon != null) {
            mIvEmptyIcon.setImageResource(drawableRes);
        }
        if (mTvEmptyTip != null) {
            mTvEmptyTip.setText(text);
        }
    }
}
