Fix wrong downloaded percentage when server doesn't send content length. Fixes #1019
This commit is contained in:
parent
5aae17754f
commit
f648940388
3 changed files with 15 additions and 3 deletions
|
@ -28,7 +28,11 @@ class Page(
|
||||||
@Transient private var statusSubject: Subject<Int, Int>? = null
|
@Transient private var statusSubject: Subject<Int, Int>? = null
|
||||||
|
|
||||||
override fun update(bytesRead: Long, contentLength: Long, done: Boolean) {
|
override fun update(bytesRead: Long, contentLength: Long, done: Boolean) {
|
||||||
progress = (100 * bytesRead / contentLength).toInt()
|
progress = if (contentLength > 0) {
|
||||||
|
(100 * bytesRead / contentLength).toInt()
|
||||||
|
} else {
|
||||||
|
-1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setStatusSubject(subject: Subject<Int, Int>?) {
|
fun setStatusSubject(subject: Subject<Int, Int>?) {
|
||||||
|
|
|
@ -130,7 +130,11 @@ class PageView @JvmOverloads constructor(context: Context, attrs: AttributeSet?
|
||||||
.onBackpressureLatest()
|
.onBackpressureLatest()
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe { progress ->
|
.subscribe { progress ->
|
||||||
progress_text.text = context.getString(R.string.download_progress, progress)
|
progress_text.text = if (progress > 0) {
|
||||||
|
context.getString(R.string.download_progress, progress)
|
||||||
|
} else {
|
||||||
|
context.getString(R.string.downloading)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -150,7 +150,11 @@ class WebtoonHolder(private val view: View, private val adapter: WebtoonAdapter)
|
||||||
.onBackpressureLatest()
|
.onBackpressureLatest()
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe { progress ->
|
.subscribe { progress ->
|
||||||
view.progress_text.text = view.context.getString(R.string.download_progress, progress)
|
view.progress_text.text = if (progress > 0) {
|
||||||
|
view.context.getString(R.string.download_progress, progress)
|
||||||
|
} else {
|
||||||
|
view.context.getString(R.string.downloading)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addSubscription(progressSubscription)
|
addSubscription(progressSubscription)
|
||||||
|
|
Reference in a new issue