package com.sobot.network.apiUtils;

import android.content.Context;

/**
 * @Description: 全局上下文
 * @Author: znw
 * @Date: 2021/7/19 下午2:17
 * @Version: 1.0
 */
public class SobotHttpGlobalContext {
    private Context mApplicationContext;

    private SobotHttpGlobalContext() {
    }

    public static SobotHttpGlobalContext getInstance(Context context) {
        if (GlobalContext.globalContext.mApplicationContext == null && context != null) {
            GlobalContext.globalContext.mApplicationContext = context;
        }
        return GlobalContext.globalContext;
    }

    public static Context getAppContext(Context context) {
        if (GlobalContext.globalContext.mApplicationContext == null && context != null) {
            GlobalContext.globalContext.mApplicationContext = context.getApplicationContext();
        }
        return GlobalContext.globalContext.mApplicationContext;
    }

    public static Context getAppContext() {
        return GlobalContext.globalContext.mApplicationContext;
    }

    private static class GlobalContext {
        private static final SobotHttpGlobalContext globalContext = new SobotHttpGlobalContext();

        private GlobalContext() {
        }
    }
}