package com.ytpm.hydtw.loading;

import android.app.Activity;
import android.content.Context;

import java.util.Timer;
import java.util.TimerTask;

public class GlobalLoading {
    private Timer timer = null;
    private TimerTask task = null;
    private static GlobalLoading instance;
    private LoadingDialog loadingDialog;

    private GlobalLoading() {
    }

    public static GlobalLoading getInstance() {
        if (instance == null) {
            synchronized (GlobalLoading.class) {
                if (instance == null) {
                    instance = new GlobalLoading();
                }
            }
        }
        return instance;
    }

    /**
     * 显示Loading
     *
     * @param context 上下文
     * @param message 加载信息
     */
    public void show(Context context, String message) {
        if (loadingDialog == null) {
            loadingDialog = new LoadingDialog(context);
        }

        if (!loadingDialog.isShowing()) {
            loadingDialog.setMessage(message);
            loadingDialog.show();
        }
    }

    /**
     * 显示默认Loading
     */
    public void show(Context context) {
        show(context, "加载中...");
    }

    /**
     * 隐藏Loading
     */
    public void dismiss() {
        if (loadingDialog != null && loadingDialog.isShowing()) {
            loadingDialog.dismiss();
        }
    }
}

