refactor(WebtoonPageHolder): Remove unnecessary functions

This commit is contained in:
Ahmad Ansori Palembani 2024-08-05 09:46:57 +07:00
parent 4789a1652a
commit 28a8a675ad
Signed by: null2264
GPG key ID: BA64F8B60AF3EFB6

View file

@ -98,7 +98,8 @@ class WebtoonPageHolder(
*/ */
fun bind(page: ReaderPage) { fun bind(page: ReaderPage) {
this.page = page this.page = page
launchLoadJob() loadJob?.cancel()
loadJob = scope.launch { loadPageAndProcessStatus() }
refreshLayoutParams() refreshLayoutParams()
} }
@ -118,24 +119,14 @@ class WebtoonPageHolder(
* Called when the view is recycled and added to the view pool. * Called when the view is recycled and added to the view pool.
*/ */
override fun recycle() { override fun recycle() {
cancelLoadJob() loadJob?.cancel()
cancelProgressJob() progressJob?.cancel()
removeErrorLayout() removeErrorLayout()
frame.recycle() frame.recycle()
progressIndicator.setProgress(0) progressIndicator.setProgress(0)
} }
/**
* Observes the status of the page and notify the changes.
*
* @see processStatus
*/
private fun launchLoadJob() {
cancelLoadJob()
loadJob = scope.launch { loadPageAndProcessStatus() }
}
private suspend fun loadPageAndProcessStatus() { private suspend fun loadPageAndProcessStatus() {
val page = page ?: return val page = page ?: return
val loader = page.chapter.pageLoader ?: return val loader = page.chapter.pageLoader ?: return
@ -149,7 +140,7 @@ class WebtoonPageHolder(
* Observes the progress of the page and updates view. * Observes the progress of the page and updates view.
*/ */
private fun launchProgressJob() { private fun launchProgressJob() {
cancelProgressJob() progressJob?.cancel()
val page = page ?: return val page = page ?: return
progressJob = scope.launch { progressJob = scope.launch {
@ -172,29 +163,15 @@ class WebtoonPageHolder(
} }
Page.State.READY -> { Page.State.READY -> {
setImage() setImage()
cancelProgressJob() progressJob?.cancel()
} }
Page.State.ERROR -> { Page.State.ERROR -> {
setError() setError()
cancelProgressJob() progressJob?.cancel()
} }
} }
} }
/**
* Cancels loading the page and processing changes to the page's status.
*/
private fun cancelLoadJob() {
loadJob?.cancel()
}
/**
* Unsubscribes from the progress subscription.
*/
private fun cancelProgressJob() {
progressJob?.cancel()
}
/** /**
* Called when the page is queued. * Called when the page is queued.
*/ */