Skip to content

Commit

Permalink
Fix tools:src not working for WidgetImageView (#3799)
Browse files Browse the repository at this point in the history
This broke when WidgetImageView was changed to no longer be derived from
ImageView in #3787. Since WidgetImageView passes all view attributes to
its internal ImageView instance, let the framework know that this is the
case.

* Make WidgetImageView.InternalImageView.loadProgressCallback nullable

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 authored Aug 19, 2024
1 parent fa17008 commit a323f8f
Show file tree
Hide file tree
Showing 2 changed files with 6 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
1 change: 1 addition & 0 deletions mobile/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<enum name="scaleToFitWithViewAdjustment" value="2" />
<enum name="scaleToFitWithViewAdjustmentDownscaleOnly" value="3" />
</attr>
<attr name="android:src" />
</declare-styleable>

<declare-styleable name="ItemAndTogglePreference">
Expand Down

0 comments on commit a323f8f

Please sign in to comment.