Clean up KFrescoController
@@ -143,9 +143,15 @@ class KFrescoController(
if (imageId != drawable.imageId) {
return
}
- if (dataSource.hasResult()) {
- val result: CloseableReference<CloseableImage> = dataSource.result ?: return
- if (CloseableReference.isValid(result)) {
+
+ val result: CloseableReference<CloseableImage>? = dataSource.result
+
+ if (result == null || !result.isValid) {
+ onFailure(dataSource)
+ result?.close()
+ return
+ }
+
// We avoid cloning result and closing the original for performance reasons
drawable.setCloseable(result)
val image = result.get()
@@ -161,29 +167,22 @@ class KFrescoController(
} else {
drawable.listenerManager.onIntermediateImageSet(imageId, imageRequest, image)
}
- } else {
- onFailure(dataSource)
- result.close()
- }
- }
uiThreadExecutor.execute { drawable.invalidateSelf() }
}
+
override fun onFailure(dataSource: DataSource<CloseableReference<CloseableImage>>) {
if (imageId != drawable.imageId) {
return
}
drawable.actualImageLayer.setError(imageRequest.resources, options)
if (notifyFinalResult(dataSource)) {
- val result = dataSource.result
- try {
+ dataSource.result.use { result ->
drawable.listenerManager.onFailure(
imageId,
imageRequest,
maybeGetDrawable(drawable.actualImageLayer.getDataModel()),
dataSource.failureCause,
drawable.obtainExtras(dataSource, result))
- } finally {
- result?.close()
}
} else {
drawable.listenerManager.onIntermediateImageFailed(
