Skip to content

Commit

Permalink
Make WidgetImageView.InternalImageView.loadProgressCallback nullable
Browse files Browse the repository at this point in the history
It's invoked via ImageView() -> setImageDrawable() ->
prepareForNonHttpImage(), at which time the initializer of
loadProgressCallback hasn't run yet.

Signed-off-by: Danny Baumann <[email protected]>
  • Loading branch information
maniac103 committed Aug 16, 2024
1 parent b177f67 commit 0afdfb0
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class WidgetImageView(context: Context, attrs: AttributeSet?, private val imageV
attrs: AttributeSet?
) : AppCompatImageView(context, attrs), WidgetImageViewIntf {
private var scope: CoroutineScope? = null
var loadProgressCallback: (loading: Boolean) -> Unit = {}
var loadProgressCallback: ((loading: Boolean) -> Unit)? = null
private val fallback: Drawable?

private var originalScaleType: ScaleType? = null
Expand Down Expand Up @@ -270,7 +270,7 @@ class WidgetImageView(context: Context, attrs: AttributeSet?, private val imageV
cancelRefresh()
lastRequest = null
refreshInterval = 0
loadProgressCallback.invoke(false)
loadProgressCallback?.invoke(false)
}

private fun doLoad(client: HttpClient, url: HttpUrl, timeoutMillis: Long, forceLoad: Boolean) {
Expand All @@ -285,7 +285,7 @@ class WidgetImageView(context: Context, attrs: AttributeSet?, private val imageV
if (cached != null) {
applyLoadedBitmap(cached)
} else if (lastRequest?.statelessUrlEquals(url) != true) {
loadProgressCallback.invoke(true)
loadProgressCallback?.invoke(true)
}

if (cached == null || forceLoad) {
Expand Down Expand Up @@ -317,7 +317,7 @@ class WidgetImageView(context: Context, attrs: AttributeSet?, private val imageV
}

private fun applyLoadedBitmap(bitmap: Bitmap) {
loadProgressCallback.invoke(false)
loadProgressCallback?.invoke(false)
if (imageScalingType == ImageScalingType.ScaleToFitWithViewAdjustmentDownscaleOnly) {
// Make sure that view only shrinks to accommodate bitmap size, but doesn't enlarge ... that is,
// adjust view bounds only if width is larger than target size or height is larger than the maximum height
Expand Down Expand Up @@ -390,7 +390,7 @@ class WidgetImageView(context: Context, attrs: AttributeSet?, private val imageV
if (context.getPrefs().isDebugModeEnabled()) {
Log.d(TAG, "Failed to load image '$url', HTTP code ${e.statusCode}", e)
}
loadProgressCallback.invoke(false)
loadProgressCallback?.invoke(false)
applyFallbackDrawable()
}
}
Expand Down

0 comments on commit 0afdfb0

Please sign in to comment.