DownloadRequest.java 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package com.mylove.okhttp;
  2. import android.annotation.SuppressLint;
  3. import android.content.Context;
  4. import com.mylove.okhttp.listener.OnDownloadListener;
  5. /**
  6. * @author myLove
  7. */
  8. public class DownloadRequest {
  9. @SuppressLint("StaticFieldLeak")
  10. private static DownloadRequest instance;
  11. private static String url;
  12. @SuppressLint("StaticFieldLeak")
  13. private static Context mContext;
  14. public static DownloadRequest getInstance(Context context, String str) {
  15. if (instance == null) {
  16. synchronized (DownloadRequest.class) {
  17. if (instance == null) {
  18. instance = new DownloadRequest();
  19. }
  20. }
  21. }
  22. mContext = context;
  23. url = str;
  24. return instance;
  25. }
  26. /**
  27. * @param filePath 储存下载文件的SDCard目录
  28. * @param onDownloadListener 监听
  29. */
  30. @Deprecated
  31. public void download(String filePath, OnDownloadListener onDownloadListener) {
  32. //saveDir判断不能为空
  33. if (FormatUtil.isEmpty(filePath)) {
  34. throw new NullPointerException("filePath is the SDCard directory of the downloaded file, cannot be empty.");
  35. }
  36. DownloadObservable.getInstance(mContext).request(url, filePath, "", onDownloadListener);
  37. }
  38. /**
  39. * @param filePath 储存下载文件的SDCard目录
  40. * @param fileName 文件名称
  41. * @param onDownloadListener 监听
  42. */
  43. @Deprecated
  44. public void download(String filePath, String fileName, OnDownloadListener onDownloadListener) {
  45. //saveDir判断不能为空
  46. if (FormatUtil.isEmpty(filePath)) {
  47. throw new NullPointerException("filePath is the SDCard directory of the downloaded file, cannot be empty.");
  48. }
  49. DownloadObservable.getInstance(mContext).request(url, filePath, fileName, onDownloadListener);
  50. }
  51. }