Skip to content

Commit

Permalink
Add isValid to DrawableProperties
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanmos committed Sep 7, 2023
1 parent 0991681 commit e8430b3
Showing 1 changed file with 12 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,9 @@ internal class ImageWireframeHelper(
prefix: String = DRAWABLE_CHILD_NAME
): MobileSegment.Wireframe.ImageWireframe? {
val id = uniqueIdentifierGenerator.resolveChildUniqueIdentifier(view, prefix + currentWireframeIndex)
val (currentDrawable, drawableWidth, drawableHeight) = resolveDrawableProperties(view, drawable)

@Suppress("ComplexCondition")
if (
currentDrawable == null ||
id == null ||
drawableWidth <= 0 ||
drawableHeight <= 0
) {
return null
}
val drawableProperties = resolveDrawableProperties(view, drawable)

if (id == null || !drawableProperties.isValid()) return null

val displayMetrics = view.resources.displayMetrics
val applicationContext = view.context.applicationContext
Expand All @@ -70,12 +62,13 @@ internal class ImageWireframeHelper(
isEmpty = true
)

@Suppress("UnsafeCallOnNullableType") // drawable already checked for null in isValid
base64Serializer.handleBitmap(
applicationContext = applicationContext,
displayMetrics = displayMetrics,
drawable = currentDrawable,
drawableWidth,
drawableHeight,
drawable = drawableProperties.drawable!!,
drawableWidth = drawableProperties.drawableWidth,
drawableHeight = drawableProperties.drawableHeight,
imageWireframe = imageWireframe
)

Expand Down Expand Up @@ -168,7 +161,11 @@ internal class ImageWireframeHelper(
val drawable: Drawable?,
val drawableWidth: Int,
val drawableHeight: Int
)
) {
fun isValid(): Boolean {
return drawable != null && drawableWidth > 0 && drawableHeight > 0
}
}

internal companion object {
@VisibleForTesting internal const val DRAWABLE_CHILD_NAME = "drawable"
Expand Down

0 comments on commit e8430b3

Please sign in to comment.