mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-21 20:47:03 -05:00
PagerPageHolder: lazy init loading indicator
Co-authored-by: ivan <12537387+ivaniskandar@users.noreply.github.com>
This commit is contained in:
parent
8f9a325895
commit
a45eb5e528
1 changed files with 18 additions and 9 deletions
|
@ -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()
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue