package br.com.codetec.saudesabor.utils.components.progressdialog;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.util.Log;

public class ProgresDialogUtil {

    private Context mContext;
    public ProgressDialog progress;

    public ProgresDialogUtil(Activity context){
        this.mContext = context;
    }

    public ProgresDialogUtil(Context context){
        this.mContext = context;
    }

    public void show(){
        createProgress("Aguarde","");
    }

    public void show(String mensagem){
        createProgress("InMais",mensagem);
    }

    public void show(String title, String message){
        createProgress(title,message);
    }

    public void dismiss(){
        try {
            if (this.progress != null && this.progress.isShowing()) {
                this.progress.dismiss();
            }
        }catch (Exception e){
            Log.e("", e.getMessage());
        }
    }

    private void createProgress(String title, String message){
        if(this.progress !=null) {
            configProgressDialog(title, message);
        }else{
            this.progress = new ProgressDialog(mContext, ProgressDialog.THEME_TRADITIONAL);
            configProgressDialog(title, message);
        }
    }

    private void configProgressDialog(String title, String message) {
        this.progress.setProgressStyle(ProgressDialog.STYLE_SPINNER);
//        this.progress.setTitle(title);
        this.progress.setMessage(message);
        this.progress.setIndeterminate(true);
        this.progress.setCancelable(false);
        this.progress.show();
    }

    public ProgressDialog getProgress() {
        return progress;
    }

    public void setProgress(ProgressDialog progress) {
        this.progress = progress;
    }

    public Context getmContext() {
        return mContext;
    }
}

