No Description

RNFetchBlobProgressConfig.java 1009B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package com.RNFetchBlob;
  2. /**
  3. * Created by wkh237 on 2016/9/24.
  4. */
  5. public class RNFetchBlobProgressConfig {
  6. enum ReportType {
  7. Upload,
  8. Download
  9. };
  10. private long lastTick = 0;
  11. private int tick = 0;
  12. private int count = -1;
  13. private int interval = -1;
  14. private boolean enable = false;
  15. private ReportType type = ReportType.Download;
  16. RNFetchBlobProgressConfig(boolean report, int interval, int count, ReportType type) {
  17. this.enable = report;
  18. this.interval = interval;
  19. this.type = type;
  20. this.count = count;
  21. }
  22. public boolean shouldReport(float progress) {
  23. boolean checkCount = true;
  24. if(count > 0 && progress > 0)
  25. checkCount = Math.floor(progress*count)> tick;
  26. boolean result = (System.currentTimeMillis() - lastTick> interval) && enable && checkCount;
  27. if(result) {
  28. tick++;
  29. lastTick = System.currentTimeMillis();
  30. }
  31. return result;
  32. }
  33. }