PagerPageHolder: lazy init loading indicator
Co-authored-by: ivan <12537387+ivaniskandar@users.noreply.github.com> (cherry picked from commit a45eb5e5288159dbbbbb5f92140ce0dd32a8f3ab) # Conflicts: # app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerPageHolder.kt
This commit is contained in:
parent
2f8efe0526
commit
efbaf1a4ca
@ -50,7 +50,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.
|
||||||
@ -70,7 +70,6 @@ class PagerPageHolder(
|
|||||||
private var extraLoadJob: Job? = null
|
private var extraLoadJob: Job? = null
|
||||||
|
|
||||||
init {
|
init {
|
||||||
addView(progressIndicator)
|
|
||||||
loadJob = scope.launch { loadPageAndProcessStatus(1) }
|
loadJob = scope.launch { loadPageAndProcessStatus(1) }
|
||||||
extraLoadJob = scope.launch { loadPageAndProcessStatus(2) }
|
extraLoadJob = scope.launch { loadPageAndProcessStatus(2) }
|
||||||
}
|
}
|
||||||
@ -87,6 +86,13 @@ class PagerPageHolder(
|
|||||||
extraLoadJob = null
|
extraLoadJob = 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.
|
||||||
*
|
*
|
||||||
@ -111,7 +117,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()
|
||||||
@ -125,7 +131,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()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,7 +140,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()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,7 +149,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()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,9 +159,9 @@ class PagerPageHolder(
|
|||||||
*/
|
*/
|
||||||
private suspend fun setImage() {
|
private suspend fun setImage() {
|
||||||
if (extraPage == null) {
|
if (extraPage == null) {
|
||||||
progressIndicator.setProgress(0)
|
progressIndicator?.setProgress(0)
|
||||||
} else {
|
} else {
|
||||||
progressIndicator.setProgress(95)
|
progressIndicator?.setProgress(95)
|
||||||
}
|
}
|
||||||
|
|
||||||
val streamFn = page.stream ?: return
|
val streamFn = page.stream ?: return
|
||||||
@ -269,7 +278,7 @@ class PagerPageHolder(
|
|||||||
return imageSource
|
return imageSource
|
||||||
}
|
}
|
||||||
|
|
||||||
scope.launch { progressIndicator.setProgress(96) }
|
scope.launch { progressIndicator?.setProgress(96) }
|
||||||
if (imageBitmap.height < imageBitmap.width) {
|
if (imageBitmap.height < imageBitmap.width) {
|
||||||
imageSource2.close()
|
imageSource2.close()
|
||||||
page.fullPage = true
|
page.fullPage = true
|
||||||
@ -287,7 +296,7 @@ class PagerPageHolder(
|
|||||||
return imageSource
|
return imageSource
|
||||||
}
|
}
|
||||||
|
|
||||||
scope.launch { progressIndicator.setProgress(97) }
|
scope.launch { progressIndicator?.setProgress(97) }
|
||||||
if (imageBitmap2.height < imageBitmap2.width) {
|
if (imageBitmap2.height < imageBitmap2.width) {
|
||||||
imageSource2.close()
|
imageSource2.close()
|
||||||
extraPage?.fullPage = true
|
extraPage?.fullPage = true
|
||||||
@ -342,9 +351,9 @@ class PagerPageHolder(
|
|||||||
private fun updateProgress(progress: Int) {
|
private fun updateProgress(progress: Int) {
|
||||||
scope.launch {
|
scope.launch {
|
||||||
if (progress == 100) {
|
if (progress == 100) {
|
||||||
progressIndicator.hide()
|
progressIndicator?.hide()
|
||||||
} else {
|
} else {
|
||||||
progressIndicator.setProgress(progress)
|
progressIndicator?.setProgress(progress)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -397,13 +406,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…
x
Reference in New Issue
Block a user