do not update speed reading if the sampling is too frequent

pull/53/head
Zlatin Balevsky 2020-10-06 20:25:56 +01:00
parent cac3ff0bcf
commit 56e02c4981
No known key found for this signature in database
GPG Key ID: A72832072D525E41
1 changed files with 9 additions and 8 deletions

View File

@ -164,14 +164,15 @@ public class Downloader {
public int speed() {
int currSpeed = 0
if (getCurrentState() == DownloadState.DOWNLOADING) {
long dataRead = dataSinceLastRead.getAndSet(0)
long now = System.currentTimeMillis()
if (now > lastSpeedRead)
currSpeed = (int) (dataRead * 1000.0d / (now - lastSpeedRead))
lastSpeedRead = now
}
if (getCurrentState() != DownloadState.DOWNLOADING)
return currSpeed
long now = System.currentTimeMillis()
if (now < lastSpeedRead + 50)
return speedArr.average()
long dataRead = dataSinceLastRead.getAndSet(0)
currSpeed = (int) (dataRead * 1000.0d / (now - lastSpeedRead))
lastSpeedRead = now
// this is not very accurate since each slot may hold more than a second
if (speedArr.size() != downloadManager.muSettings.speedSmoothSeconds) {
speedArr.clear()