Commit a97972aa authored by topjohnwu's avatar topjohnwu

Update notification once per second

parent 094c3d55
...@@ -10,12 +10,21 @@ class ProgInputStream( ...@@ -10,12 +10,21 @@ class ProgInputStream(
) : FilterInputStream(base) { ) : FilterInputStream(base) {
private var bytesRead = 0L private var bytesRead = 0L
private var lastUpdate = 0L
private fun emitProgress() {
val cur = System.currentTimeMillis()
if (cur - lastUpdate > 1000) {
lastUpdate = cur
UiThreadHandler.run { progressEmitter(bytesRead) }
}
}
override fun read(): Int { override fun read(): Int {
val b = read() val b = read()
if (b >= 0) { if (b >= 0) {
bytesRead++ bytesRead++
UiThreadHandler.run { progressEmitter(bytesRead) } emitProgress()
} }
return b return b
} }
...@@ -28,7 +37,7 @@ class ProgInputStream( ...@@ -28,7 +37,7 @@ class ProgInputStream(
val sz = super.read(b, off, len) val sz = super.read(b, off, len)
if (sz > 0) { if (sz > 0) {
bytesRead += sz bytesRead += sz
UiThreadHandler.run { progressEmitter(bytesRead) } emitProgress()
} }
return sz return sz
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment