From f648940388582c994dea4df2a64513f990567195 Mon Sep 17 00:00:00 2001 From: inorichi Date: Thu, 5 Oct 2017 08:41:28 +0200 Subject: [PATCH] Fix wrong downloaded percentage when server doesn't send content length. Fixes #1019 --- app/src/main/java/eu/kanade/tachiyomi/source/model/Page.kt | 6 +++++- .../eu/kanade/tachiyomi/ui/reader/viewer/pager/PageView.kt | 6 +++++- .../tachiyomi/ui/reader/viewer/webtoon/WebtoonHolder.kt | 6 +++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/source/model/Page.kt b/app/src/main/java/eu/kanade/tachiyomi/source/model/Page.kt index 16a76b96b..2bf008d4c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/source/model/Page.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/source/model/Page.kt @@ -28,7 +28,11 @@ class Page( @Transient private var statusSubject: Subject? = null 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?) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PageView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PageView.kt index 6dcc2393e..1c2e3cd53 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PageView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PageView.kt @@ -130,7 +130,11 @@ class PageView @JvmOverloads constructor(context: Context, attrs: AttributeSet? .onBackpressureLatest() .observeOn(AndroidSchedulers.mainThread()) .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) + } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonHolder.kt index 5b814db1e..39958bd98 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonHolder.kt @@ -150,7 +150,11 @@ class WebtoonHolder(private val view: View, private val adapter: WebtoonAdapter) .onBackpressureLatest() .observeOn(AndroidSchedulers.mainThread()) .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)