package com.mq.mylibrary.dialog;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.mq.mylibrary.R;


/**
 * 创建人 mQ
 * 创建时间 2019/8/7 0007 9:22
 * 文件名称 MyProgressDialog
 * 说明: 进度对话框
 **/
public class MyProgressDialog {

    Context mContext;
    private AlertDialog mDialog;
    private ProgressBar mProgressBar;
    private TextView mTvMessage;

    public MyProgressDialog(@NonNull Context context) {
        mContext = context;
        initDialog();
    }

    /**
     * 初始化对话框
     */
    private void initDialog() {
        mDialog = new AlertDialog.Builder(mContext).setView(getView())
                .create();
    }

    /**
     * 获取自定义布局
     */
    private View getView() {
        View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_progress, null, false);
        mProgressBar = (ProgressBar) view.findViewById(R.id.progressBar);
        mTvMessage = (TextView) view.findViewById(R.id.tv_message);
        return view;
    }

    /**
     * 设置文字
     */
    public MyProgressDialog setMessage(String message) {
        mTvMessage.setText(message);
        return this;
    }

    /**
     * 显示对话框
     */
    public MyProgressDialog show() {
        mDialog.show();
        return this;
    }

    /**
     * 隐藏对话框
     */
    public MyProgressDialog dismiss() {
        mDialog.dismiss();
        return this;
    }

    /**
     * 获取对话框
     *
     * @return
     */
    public AlertDialog getDialog() {
        return mDialog;
    }

}
