package com.unis.sxzcl.widget.dialog;

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

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;

import com.unis.sxzcl.R;


/**
 * 创建人 mQ
 * 创建时间 2019/7/24 0024 10:34
 * 文件名称 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 = view.findViewById(R.id.progressBar);
        mTvMessage = 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;
    }

}
