mirror of
https://github.com/amir1376/ab-download-manager.git
synced 2025-02-20 11:43:24 +08:00
fix speed meter shows a high value incorrectly when opening window after a while
This commit is contained in:
parent
b51f91aa8c
commit
a6e3558440
@ -95,8 +95,16 @@ class DownloadMonitor(
|
||||
it.id to it.getDownloadedSize()
|
||||
}
|
||||
downloadSpeedFlow.value = newWrites.mapValues { (id, newWrite) ->
|
||||
val lastWrittenData = lastWrites.getOrElse(id) { 0L }
|
||||
val newSpeed = newWrite - lastWrittenData
|
||||
val lastWrittenData = lastWrites.getOrElse(id) { null }
|
||||
val newSpeed = when {
|
||||
lastWrittenData != null -> {
|
||||
newWrite - lastWrittenData
|
||||
}
|
||||
else -> {
|
||||
// this item seen for the first time
|
||||
0
|
||||
}
|
||||
}
|
||||
newSpeed
|
||||
}
|
||||
lastWrites = newWrites
|
||||
|
Loading…
x
Reference in New Issue
Block a user