From a45eb5e5288159dbbbbb5f92140ce0dd32a8f3ab Mon Sep 17 00:00:00 2001 From: AntsyLich <59261191+AntsyLich@users.noreply.github.com> Date: Mon, 2 Sep 2024 21:13:52 +0600 Subject: [PATCH] PagerPageHolder: lazy init loading indicator Co-authored-by: ivan <12537387+ivaniskandar@users.noreply.github.com> --- .../ui/reader/viewer/pager/PagerPageHolder.kt | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerPageHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerPageHolder.kt index 71d499c38..59b20c095 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerPageHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerPageHolder.kt @@ -45,7 +45,7 @@ class PagerPageHolder( /** * Loading progress bar to indicate the current progress. */ - private val progressIndicator: ReaderProgressIndicator = ReaderProgressIndicator(readerThemedContext) + private var progressIndicator: ReaderProgressIndicator? = null // = ReaderProgressIndicator(readerThemedContext) /** * Error layout to show when the image fails to load. @@ -60,7 +60,6 @@ class PagerPageHolder( private var loadJob: Job? = null init { - addView(progressIndicator) loadJob = scope.launch { loadPageAndProcessStatus() } } @@ -74,6 +73,13 @@ class PagerPageHolder( loadJob = null } + private fun initProgressIndicator() { + if (progressIndicator == null) { + progressIndicator = ReaderProgressIndicator(context) + addView(progressIndicator) + } + } + /** * Loads the page and processes changes to the page's status. * @@ -95,7 +101,7 @@ class PagerPageHolder( Page.State.DOWNLOAD_IMAGE -> { setDownloading() page.progressFlow.collectLatest { value -> - progressIndicator.setProgress(value) + progressIndicator?.setProgress(value) } } Page.State.READY -> setImage() @@ -109,7 +115,8 @@ class PagerPageHolder( * Called when the page is queued. */ private fun setQueued() { - progressIndicator.show() + initProgressIndicator() + progressIndicator?.show() removeErrorLayout() } @@ -117,7 +124,8 @@ class PagerPageHolder( * Called when the page is loading. */ private fun setLoading() { - progressIndicator.show() + initProgressIndicator() + progressIndicator?.show() removeErrorLayout() } @@ -125,7 +133,8 @@ class PagerPageHolder( * Called when the page is downloading. */ private fun setDownloading() { - progressIndicator.show() + initProgressIndicator() + progressIndicator?.show() removeErrorLayout() } @@ -133,7 +142,7 @@ class PagerPageHolder( * Called when the page is ready. */ private suspend fun setImage() { - progressIndicator.setProgress(0) + progressIndicator?.setProgress(0) val streamFn = page.stream ?: return @@ -234,13 +243,13 @@ class PagerPageHolder( * Called when the page has an error. */ private fun setError() { - progressIndicator.hide() + progressIndicator?.hide() showErrorLayout() } override fun onImageLoaded() { super.onImageLoaded() - progressIndicator.hide() + progressIndicator?.hide() } /**