Ver código fonte

修复gzip启用情况下载进度始终为0

drake 3 anos atrás
pai
commit
0624546096

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

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

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

@@ -78,7 +78,7 @@ data class Progress(
      */
     fun progress(): Int {
         return when {
-            currentByteCount == totalByteCount -> 100
+            finish || currentByteCount == totalByteCount -> 100
             totalByteCount <= 0 -> 0
             else -> (currentByteCount * 100 / totalByteCount).toInt()
         }