drake 3 سال پیش
والد
کامیت
44bcb54d94

+ 4 - 1
net/src/main/java/com/drake/net/body/NetResponseBody.kt

@@ -75,7 +75,10 @@ class NetResponseBody(
                     progressListeners.forEach { progressListener ->
                         progressListener.intervalByteCount += if (bytesRead != -1L) bytesRead else 0
                         val currentInterval = currentElapsedTime - progressListener.elapsedTime
-                        if (currentInterval >= progressListener.interval || readByteCount == contentLength) {
+                        if (!progress.finish && (currentInterval >= progressListener.interval || readByteCount == contentLength)) {
+                            if (readByteCount == contentLength) {
+                                progress.finish = true
+                            }
                             progressListener.onProgress(
                                 progress.apply {
                                     currentByteCount = readByteCount

+ 3 - 8
net/src/main/java/com/drake/net/component/Progress.kt

@@ -13,13 +13,15 @@ import com.drake.net.NetConfig
  * @property intervalByteCount 进度间隔时间内完成的字节数
  * @property intervalTime 距离上次进度变化间隔时间
  * @property startElapsedRealtime 开始下载的时间
+ * @property finish 是否完成
  */
 data class Progress(
     var currentByteCount: Long = 0,
     var totalByteCount: Long = 0,
     var intervalByteCount: Long = 0,
     var intervalTime: Long = 0,
-    val startElapsedRealtime: Long = SystemClock.elapsedRealtime()
+    val startElapsedRealtime: Long = SystemClock.elapsedRealtime(),
+    var finish: Boolean = false,
 ) {
 
     /**
@@ -81,13 +83,6 @@ data class Progress(
         }
     }
 
-    /**
-     * 是否完成
-     */
-    fun finish(): Boolean {
-        return currentByteCount == totalByteCount || totalByteCount <= 0
-    }
-
     /**
      * 已使用时间
      */