Prevent GoneOnInvisibleListener leak
This commit is contained in:
@@ -37,11 +37,13 @@ abstract class BasePageHolder<B : ViewBinding>(
|
|||||||
|
|
||||||
protected abstract fun onBind(data: ReaderPage)
|
protected abstract fun onBind(data: ReaderPage)
|
||||||
|
|
||||||
fun onAttachedToWindow() {
|
@CallSuper
|
||||||
|
open fun onAttachedToWindow() {
|
||||||
delegate.onAttachedToWindow()
|
delegate.onAttachedToWindow()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onDetachedFromWindow() {
|
@CallSuper
|
||||||
|
open fun onDetachedFromWindow() {
|
||||||
delegate.onDetachedFromWindow()
|
delegate.onDetachedFromWindow()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,12 +25,12 @@ class WebtoonHolder(
|
|||||||
View.OnClickListener {
|
View.OnClickListener {
|
||||||
|
|
||||||
private var scrollToRestore = 0
|
private var scrollToRestore = 0
|
||||||
|
private val goneOnInvisibleListener = GoneOnInvisibleListener(bindingInfo.progressBar)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
binding.ssiv.regionDecoderFactory = SkiaPooledImageRegionDecoder.Factory()
|
binding.ssiv.regionDecoderFactory = SkiaPooledImageRegionDecoder.Factory()
|
||||||
binding.ssiv.addOnImageEventListener(delegate)
|
binding.ssiv.addOnImageEventListener(delegate)
|
||||||
bindingInfo.buttonRetry.setOnClickListener(this)
|
bindingInfo.buttonRetry.setOnClickListener(this)
|
||||||
GoneOnInvisibleListener(bindingInfo.progressBar).attach()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBind(data: ReaderPage) {
|
override fun onBind(data: ReaderPage) {
|
||||||
@@ -42,6 +42,16 @@ class WebtoonHolder(
|
|||||||
binding.ssiv.recycle()
|
binding.ssiv.recycle()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onAttachedToWindow() {
|
||||||
|
super.onAttachedToWindow()
|
||||||
|
goneOnInvisibleListener.attach()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDetachedFromWindow() {
|
||||||
|
super.onDetachedFromWindow()
|
||||||
|
goneOnInvisibleListener.detach()
|
||||||
|
}
|
||||||
|
|
||||||
override fun onLoadingStarted() {
|
override fun onLoadingStarted() {
|
||||||
bindingInfo.layoutError.isVisible = false
|
bindingInfo.layoutError.isVisible = false
|
||||||
bindingInfo.progressBar.showCompat()
|
bindingInfo.progressBar.showCompat()
|
||||||
|
|||||||
@@ -19,5 +19,10 @@ class GoneOnInvisibleListener(
|
|||||||
|
|
||||||
fun attach() {
|
fun attach() {
|
||||||
view.viewTreeObserver.addOnGlobalLayoutListener(this)
|
view.viewTreeObserver.addOnGlobalLayoutListener(this)
|
||||||
|
onGlobalLayout()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
fun detach() {
|
||||||
|
view.viewTreeObserver.removeOnGlobalLayoutListener(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user