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) {
this.page = page
launchLoadJob()
loadJob?.cancel()
loadJob = scope.launch { loadPageAndProcessStatus() }
refreshLayoutParams()
}
@ -118,24 +119,14 @@ class WebtoonPageHolder(
* Called when the view is recycled and added to the view pool.
*/
override fun recycle() {
cancelLoadJob()
cancelProgressJob()
loadJob?.cancel()
progressJob?.cancel()
removeErrorLayout()
frame.recycle()
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() {
val page = page ?: return
val loader = page.chapter.pageLoader ?: return
@ -149,7 +140,7 @@ class WebtoonPageHolder(
* Observes the progress of the page and updates view.
*/
private fun launchProgressJob() {
cancelProgressJob()
progressJob?.cancel()
val page = page ?: return
progressJob = scope.launch {
@ -172,29 +163,15 @@ class WebtoonPageHolder(
}
Page.State.READY -> {
setImage()
cancelProgressJob()
progressJob?.cancel()
}
Page.State.ERROR -> {
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.
*/