Fix memleak for archive

This commit is contained in:
tarsin committed 2022-12-20 19:58:40 +08:00
1 parent f06167ba4b
commit 54bd6f6ed8
7 files changed
+22 -6

No files matched your search

@@ -91,6 +91,7 @@ public class ArchivePageLoader extends PageLoader2 {
@Override
public void stop() {
super.stop();
if (archiveThread != null) {
archiveThread.interrupt();
archiveThread = null;
@@ -81,6 +81,7 @@ public class DirPageLoader extends PageLoader2 implements Runnable {
@Override
public void stop() {
super.stop();
if (mBgThread != null) {
mBgThread.interrupt();
mBgThread = null;
@@ -53,6 +53,7 @@ public class EhPageLoader extends PageLoader2 implements SpiderQueen.OnSpiderLis
@Override
public void stop() {
super.stop();
if (mSpiderQueen != null) {
mSpiderQueen.removeOnSpiderListener(this);
// Activity recreate may called, so wait 3000s
@@ -78,6 +78,9 @@ class Image private constructor(source: Source?, val release: () -> Unit = {}) {
}
}
val isRecycled: Boolean
get() = (mObtainedDrawable as? BitmapDrawable)?.bitmap?.isRecycled ?: (mObtainedDrawable as? AnimatedImageDrawable)?.isRunning?.not() ?: true
companion object {
val screenWidth = EhApplication.application.resources.displayMetrics.widthPixels
val screenHeight = EhApplication.application.resources.displayMetrics.heightPixels
@@ -1,5 +1,6 @@
package eu.kanade.tachiyomi.ui.reader.loader
import androidx.annotation.CallSuper
import com.hippo.image.Image
import eu.kanade.tachiyomi.source.model.Page
import eu.kanade.tachiyomi.ui.reader.model.ReaderPage
@@ -17,12 +18,22 @@ abstract class PageLoader {
abstract fun start()
abstract fun stop()
@CallSuper
open fun stop() {
mPages.forEach { it.image?.recycle() }
}
abstract fun size(): Int
fun request(index: Int) {
onRequest(index)
if (mPages[index].image?.isRecycled == false)
notifyPageSucceed(index, mPages[index].image!!)
else
onRequest(index)
}
fun retryPage(index: Int) {
onForceRequest(index)
}
protected abstract fun onRequest(index: Int)
@@ -52,7 +63,7 @@ abstract class PageLoader {
}
fun notifyPageSucceed(index: Int, image: Image) {
val priv = mPages[index].image
val priv = if (image != mPages[index].image) mPages[index].image else null
mPages[index].image = image
mPages[index].status.value = Page.State.READY
priv?.recycle()
@@ -202,7 +202,7 @@ class PagerPageHolder(
errorLayout = ReaderErrorBinding.inflate(LayoutInflater.from(context), this, true)
errorLayout?.actionRetry?.viewer = viewer
errorLayout?.actionRetry?.setOnClickListener {
viewer.activity.mGalleryProvider?.request(page.index)
viewer.activity.mGalleryProvider?.retryPage(page.index)
}
}
errorLayout?.root?.isVisible = true
@@ -117,7 +117,6 @@ class WebtoonPageHolder(
removeErrorLayout()
frame.recycle()
page?.image?.recycle()
progressIndicator.setProgress(0, animated = false)
}
@@ -255,7 +254,7 @@ class WebtoonPageHolder(
errorLayout = ReaderErrorBinding.inflate(LayoutInflater.from(context), frame, true)
errorLayout?.root?.layoutParams = FrameLayout.LayoutParams(MATCH_PARENT, (parentHeight * 0.8).toInt())
errorLayout?.actionRetry?.setOnClickListener {
viewer.activity.mGalleryProvider?.request(page!!.index)
viewer.activity.mGalleryProvider?.retryPage(page!!.index)
}
}
return errorLayout!!