public void NotifyUpdateBytes(long totalBytesSoFar)
{
long timeRemaining;
long currentTime = SystemClock.UptimeMillis();
if (0 != this.millisecondsAtSample)
{
// we have a sample.
long timePassed = currentTime - this.millisecondsAtSample;
long bytesInSample = totalBytesSoFar - this.bytesAtSample;
float currentSpeedSample = bytesInSample / (float)timePassed;
if (Math.Abs(0 - this.averageDownloadSpeed) > SmoothingFactor)
{
float smoothSpeed = SmoothingFactor * currentSpeedSample;
float averageSpeed = (1 - SmoothingFactor) * this.averageDownloadSpeed;
this.averageDownloadSpeed = smoothSpeed + averageSpeed;
}
else
{
this.averageDownloadSpeed = currentSpeedSample;
}
timeRemaining = (long)((this.TotalLength - totalBytesSoFar) / this.averageDownloadSpeed);
}
else
{
timeRemaining = -1;
}
this.millisecondsAtSample = currentTime;
this.bytesAtSample = totalBytesSoFar;
this.downloadNotification.OnDownloadProgress(
new DownloadProgressInfo(this.TotalLength, totalBytesSoFar, timeRemaining, this.averageDownloadSpeed));
}