XMLRequest.java 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package com.mylove.okhttp;
  2. import android.annotation.SuppressLint;
  3. import android.content.Context;
  4. import java.util.Map;
  5. import okhttp3.MediaType;
  6. /**
  7. * @author myLove
  8. * @time 2018/1/4 15:14
  9. * @e-mail love@yanyi.red
  10. * @overview
  11. */
  12. public class XMLRequest {
  13. @SuppressLint("StaticFieldLeak")
  14. private static XMLRequest instance;
  15. private static String url;
  16. @SuppressLint("StaticFieldLeak")
  17. private static Context mContext;
  18. private static RequestType requestType;
  19. private static MediaType mediaType;
  20. private XMLRequest() {
  21. }
  22. public static XMLRequest getInstance(Context context, String str, String mediaTypeStr, RequestType type) {
  23. if (instance == null) {
  24. synchronized (XMLRequest.class) {
  25. if (instance == null) {
  26. instance = new XMLRequest();
  27. }
  28. }
  29. }
  30. mContext = context;
  31. url = str;
  32. mediaType = MediaType.parse(str);
  33. requestType = type;
  34. return instance;
  35. }
  36. public void sync(String urlMsg, String labelStr, Map<Object, Object> map, onOkHttpListener onOkHttpListener) {
  37. ObservableRequest.getInstance(mediaType, urlMsg, labelStr, mContext, requestType, CallType.SYNC).request(url, map, onOkHttpListener);
  38. }
  39. public void async(String urlMsg, String labelStr, Map<Object, Object> map, onOkHttpListener onOkHttpListener) {
  40. ObservableRequest.getInstance(mediaType, urlMsg, labelStr, mContext, requestType, CallType.ASYNC).request(url, map, onOkHttpListener);
  41. }
  42. }