mirror of
https://github.com/mihonapp/mihon.git
synced 2024-12-27 11:28:23 +01: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
@ -45,7 +45,7 @@ class PagerPageHolder(
|
|||||||
/**
|
/**
|
||||||
* Loading progress bar to indicate the current progress.
|
* 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.
|
* Error layout to show when the image fails to load.
|
||||||
@ -60,7 +60,6 @@ class PagerPageHolder(
|
|||||||
private var loadJob: Job? = null
|
private var loadJob: Job? = null
|
||||||
|
|
||||||
init {
|
init {
|
||||||
addView(progressIndicator)
|
|
||||||
loadJob = scope.launch { loadPageAndProcessStatus() }
|
loadJob = scope.launch { loadPageAndProcessStatus() }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,6 +73,13 @@ class PagerPageHolder(
|
|||||||
loadJob = null
|
loadJob = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun initProgressIndicator() {
|
||||||
|
if (progressIndicator == null) {
|
||||||
|
progressIndicator = ReaderProgressIndicator(context)
|
||||||
|
addView(progressIndicator)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads the page and processes changes to the page's status.
|
* Loads the page and processes changes to the page's status.
|
||||||
*
|
*
|
||||||
@ -95,7 +101,7 @@ class PagerPageHolder(
|
|||||||
Page.State.DOWNLOAD_IMAGE -> {
|
Page.State.DOWNLOAD_IMAGE -> {
|
||||||
setDownloading()
|
setDownloading()
|
||||||
page.progressFlow.collectLatest { value ->
|
page.progressFlow.collectLatest { value ->
|
||||||
progressIndicator.setProgress(value)
|
progressIndicator?.setProgress(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Page.State.READY -> setImage()
|
Page.State.READY -> setImage()
|
||||||
@ -109,7 +115,8 @@ class PagerPageHolder(
|
|||||||
* Called when the page is queued.
|
* Called when the page is queued.
|
||||||
*/
|
*/
|
||||||
private fun setQueued() {
|
private fun setQueued() {
|
||||||
progressIndicator.show()
|
initProgressIndicator()
|
||||||
|
progressIndicator?.show()
|
||||||
removeErrorLayout()
|
removeErrorLayout()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,7 +124,8 @@ class PagerPageHolder(
|
|||||||
* Called when the page is loading.
|
* Called when the page is loading.
|
||||||
*/
|
*/
|
||||||
private fun setLoading() {
|
private fun setLoading() {
|
||||||
progressIndicator.show()
|
initProgressIndicator()
|
||||||
|
progressIndicator?.show()
|
||||||
removeErrorLayout()
|
removeErrorLayout()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,7 +133,8 @@ class PagerPageHolder(
|
|||||||
* Called when the page is downloading.
|
* Called when the page is downloading.
|
||||||
*/
|
*/
|
||||||
private fun setDownloading() {
|
private fun setDownloading() {
|
||||||
progressIndicator.show()
|
initProgressIndicator()
|
||||||
|
progressIndicator?.show()
|
||||||
removeErrorLayout()
|
removeErrorLayout()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,7 +142,7 @@ class PagerPageHolder(
|
|||||||
* Called when the page is ready.
|
* Called when the page is ready.
|
||||||
*/
|
*/
|
||||||
private suspend fun setImage() {
|
private suspend fun setImage() {
|
||||||
progressIndicator.setProgress(0)
|
progressIndicator?.setProgress(0)
|
||||||
|
|
||||||
val streamFn = page.stream ?: return
|
val streamFn = page.stream ?: return
|
||||||
|
|
||||||
@ -234,13 +243,13 @@ class PagerPageHolder(
|
|||||||
* Called when the page has an error.
|
* Called when the page has an error.
|
||||||
*/
|
*/
|
||||||
private fun setError() {
|
private fun setError() {
|
||||||
progressIndicator.hide()
|
progressIndicator?.hide()
|
||||||
showErrorLayout()
|
showErrorLayout()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onImageLoaded() {
|
override fun onImageLoaded() {
|
||||||
super.onImageLoaded()
|
super.onImageLoaded()
|
||||||
progressIndicator.hide()
|
progressIndicator?.hide()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user