package com.mylove.okhttp; import android.annotation.SuppressLint; import android.content.Context; import java.util.Map; import okhttp3.MediaType; /** * @author myLove * @time 2018/1/4 15:14 * @e-mail love@yanyi.red * @overview */ public class XMLRequest { @SuppressLint("StaticFieldLeak") private static XMLRequest instance; private static String url; @SuppressLint("StaticFieldLeak") private static Context mContext; private static RequestType requestType; private static MediaType mediaType; private XMLRequest() { } public static XMLRequest getInstance(Context context, String str, String mediaTypeStr, RequestType type) { if (instance == null) { synchronized (XMLRequest.class) { if (instance == null) { instance = new XMLRequest(); } } } mContext = context; url = str; mediaType = MediaType.parse(str); requestType = type; return instance; } public void sync(String urlMsg, String labelStr, Map map, onOkHttpListener onOkHttpListener) { ObservableRequest.getInstance(mediaType, urlMsg, labelStr, mContext, requestType, CallType.SYNC).request(url, map, onOkHttpListener); } public void async(String urlMsg, String labelStr, Map map, onOkHttpListener onOkHttpListener) { ObservableRequest.getInstance(mediaType, urlMsg, labelStr, mContext, requestType, CallType.ASYNC).request(url, map, onOkHttpListener); } }