package com.android.chmo.ui.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.android.chmo.R;

/**
 * Created by Administrator on 2018/8/1.
 */

public class EmptyView extends LinearLayout {
    private ImageView imageView;
    private TextView emptyText;
    private int imgResId;
    private String emptyStr;

    public EmptyView(Context context, AttributeSet attrs) {
        super(context, attrs);
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.EmptyView);
        if (typedArray != null) {
            emptyStr = typedArray.getString(R.styleable.EmptyView_empty);
            imgResId = typedArray.getResourceId(R.styleable.EmptyView_image, R.mipmap.empty_follow);
            typedArray.recycle();
        }
        init();
    }

    private void init() {
        LayoutInflater.from(getContext()).inflate(R.layout.empty_layout,this);
        imageView = (ImageView) findViewById(R.id.image);
        emptyText = (TextView) findViewById(R.id.text);

        imageView.setImageResource(imgResId);
        if(!TextUtils.isEmpty(emptyStr)) {
            emptyText.setText(emptyStr);
        }
    }


    public void setEmptyText(String text) {
        emptyText.setText(text);
    }


}
