Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tools:src not working for WidgetImageView #3799

Merged
merged 2 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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