|
|
|
@ -1,6 +1,8 @@
|
|
|
|
package org.koitharu.kotatsu.core.util.progress
|
|
|
|
package org.koitharu.kotatsu.core.util.progress
|
|
|
|
|
|
|
|
|
|
|
|
import android.os.SystemClock
|
|
|
|
import android.os.SystemClock
|
|
|
|
|
|
|
|
import androidx.collection.IntList
|
|
|
|
|
|
|
|
import androidx.collection.MutableIntList
|
|
|
|
import java.util.concurrent.TimeUnit
|
|
|
|
import java.util.concurrent.TimeUnit
|
|
|
|
import kotlin.math.roundToInt
|
|
|
|
import kotlin.math.roundToInt
|
|
|
|
import kotlin.math.roundToLong
|
|
|
|
import kotlin.math.roundToLong
|
|
|
|
@ -10,7 +12,7 @@ private const val NO_TIME = -1L
|
|
|
|
|
|
|
|
|
|
|
|
class TimeLeftEstimator {
|
|
|
|
class TimeLeftEstimator {
|
|
|
|
|
|
|
|
|
|
|
|
private var times = ArrayList<Int>()
|
|
|
|
private var times = MutableIntList()
|
|
|
|
private var lastTick: Tick? = null
|
|
|
|
private var lastTick: Tick? = null
|
|
|
|
private val tooLargeTime = TimeUnit.DAYS.toMillis(1)
|
|
|
|
private val tooLargeTime = TimeUnit.DAYS.toMillis(1)
|
|
|
|
|
|
|
|
|
|
|
|
@ -50,6 +52,15 @@ class TimeLeftEstimator {
|
|
|
|
return if (etl == NO_TIME) NO_TIME else System.currentTimeMillis() + etl
|
|
|
|
return if (etl == NO_TIME) NO_TIME else System.currentTimeMillis() + etl
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun IntList.average(): Double {
|
|
|
|
|
|
|
|
if (isEmpty()) {
|
|
|
|
|
|
|
|
return 0.0
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var acc = 0L
|
|
|
|
|
|
|
|
forEach { acc += it }
|
|
|
|
|
|
|
|
return acc / size.toDouble()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private class Tick(
|
|
|
|
private class Tick(
|
|
|
|
@JvmField val value: Int,
|
|
|
|
@JvmField val value: Int,
|
|
|
|
@JvmField val total: Int,
|
|
|
|
@JvmField val total: Int,
|
|
|
|
|