|
|
|
@ -6,6 +6,7 @@ import androidx.core.view.isVisible
|
|
|
|
import com.davemorrissey.labs.subscaleview.ImageSource
|
|
|
|
import com.davemorrissey.labs.subscaleview.ImageSource
|
|
|
|
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
|
|
|
|
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
|
|
|
|
import kotlinx.android.synthetic.main.item_page.*
|
|
|
|
import kotlinx.android.synthetic.main.item_page.*
|
|
|
|
|
|
|
|
import kotlinx.coroutines.*
|
|
|
|
import org.koitharu.kotatsu.R
|
|
|
|
import org.koitharu.kotatsu.R
|
|
|
|
import org.koitharu.kotatsu.core.model.MangaPage
|
|
|
|
import org.koitharu.kotatsu.core.model.MangaPage
|
|
|
|
import org.koitharu.kotatsu.ui.common.list.BaseViewHolder
|
|
|
|
import org.koitharu.kotatsu.ui.common.list.BaseViewHolder
|
|
|
|
@ -13,27 +14,36 @@ import org.koitharu.kotatsu.utils.ext.getDisplayMessage
|
|
|
|
|
|
|
|
|
|
|
|
class PageHolder(parent: ViewGroup, private val loader: PageLoader) :
|
|
|
|
class PageHolder(parent: ViewGroup, private val loader: PageLoader) :
|
|
|
|
BaseViewHolder<MangaPage, Unit>(parent, R.layout.item_page),
|
|
|
|
BaseViewHolder<MangaPage, Unit>(parent, R.layout.item_page),
|
|
|
|
SubsamplingScaleImageView.OnImageEventListener {
|
|
|
|
SubsamplingScaleImageView.OnImageEventListener, CoroutineScope by loader {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private var job: Job? = null
|
|
|
|
|
|
|
|
|
|
|
|
init {
|
|
|
|
init {
|
|
|
|
ssiv.setOnImageEventListener(this)
|
|
|
|
ssiv.setOnImageEventListener(this)
|
|
|
|
button_retry.setOnClickListener {
|
|
|
|
button_retry.setOnClickListener {
|
|
|
|
onBind(boundData ?: return@setOnClickListener, Unit)
|
|
|
|
doLoad(boundData ?: return@setOnClickListener, force = true)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override fun onBind(data: MangaPage, extra: Unit) {
|
|
|
|
override fun onBind(data: MangaPage, extra: Unit) {
|
|
|
|
layout_error.isVisible = false
|
|
|
|
doLoad(data, force = false)
|
|
|
|
progressBar.isVisible = true
|
|
|
|
}
|
|
|
|
ssiv.recycle()
|
|
|
|
|
|
|
|
loader.load(data.url) {
|
|
|
|
private fun doLoad(data: MangaPage, force: Boolean) {
|
|
|
|
val uri = it.getOrNull()?.toUri()
|
|
|
|
job?.cancel()
|
|
|
|
if (uri != null) {
|
|
|
|
job = launch {
|
|
|
|
|
|
|
|
layout_error.isVisible = false
|
|
|
|
|
|
|
|
progressBar.isVisible = true
|
|
|
|
|
|
|
|
ssiv.recycle()
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
val uri = withContext(Dispatchers.IO) {
|
|
|
|
|
|
|
|
loader.loadFile(data.url, force)
|
|
|
|
|
|
|
|
}.toUri()
|
|
|
|
ssiv.setImage(ImageSource.uri(uri))
|
|
|
|
ssiv.setImage(ImageSource.uri(uri))
|
|
|
|
}
|
|
|
|
} catch (e: CancellationException) {
|
|
|
|
val error = it.exceptionOrNull()
|
|
|
|
//do nothing
|
|
|
|
if (error != null) {
|
|
|
|
} catch (e: Exception) {
|
|
|
|
onError(error)
|
|
|
|
onError(e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|