Skip to content

Commit

Permalink
Merge pull request #2375 from DataDog/jmoskovich/rum-7024/expose-imag…
Browse files Browse the repository at this point in the history
…eviewmapper

RUM-7024: Make ImageViewMapper public
  • Loading branch information
jonathanmos authored Nov 13, 2024
2 parents a7c4f31 + 224eb7c commit b2a2856
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 40 deletions.
3 changes: 3 additions & 0 deletions features/dd-sdk-android-session-replay/api/apiSurface
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ class com.datadog.android.sessionreplay.recorder.mapper.EditTextMapper : TextVie
constructor(com.datadog.android.sessionreplay.utils.ViewIdentifierResolver, com.datadog.android.sessionreplay.utils.ColorStringFormatter, com.datadog.android.sessionreplay.utils.ViewBoundsResolver, com.datadog.android.sessionreplay.utils.DrawableToColorMapper)
override fun resolveCapturedText(android.widget.EditText, com.datadog.android.sessionreplay.TextAndInputPrivacy, Boolean): String
companion object
open class com.datadog.android.sessionreplay.recorder.mapper.ImageViewMapper : BaseAsyncBackgroundWireframeMapper<android.widget.ImageView>
constructor(com.datadog.android.sessionreplay.utils.ViewIdentifierResolver, com.datadog.android.sessionreplay.utils.ColorStringFormatter, com.datadog.android.sessionreplay.utils.ViewBoundsResolver, com.datadog.android.sessionreplay.utils.DrawableToColorMapper)
override fun map(android.widget.ImageView, com.datadog.android.sessionreplay.recorder.MappingContext, com.datadog.android.sessionreplay.utils.AsyncJobStatusCallback, com.datadog.android.api.InternalLogger): List<com.datadog.android.sessionreplay.model.MobileSegment.Wireframe>
open class com.datadog.android.sessionreplay.recorder.mapper.TextViewMapper<T: android.widget.TextView> : BaseAsyncBackgroundWireframeMapper<T>
constructor(com.datadog.android.sessionreplay.utils.ViewIdentifierResolver, com.datadog.android.sessionreplay.utils.ColorStringFormatter, com.datadog.android.sessionreplay.utils.ViewBoundsResolver, com.datadog.android.sessionreplay.utils.DrawableToColorMapper)
override fun map(T, com.datadog.android.sessionreplay.recorder.MappingContext, com.datadog.android.sessionreplay.utils.AsyncJobStatusCallback, com.datadog.android.api.InternalLogger): List<com.datadog.android.sessionreplay.model.MobileSegment.Wireframe>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1472,6 +1472,12 @@ public final class com/datadog/android/sessionreplay/recorder/mapper/EditTextMap
public final class com/datadog/android/sessionreplay/recorder/mapper/EditTextMapper$Companion {
}

public class com/datadog/android/sessionreplay/recorder/mapper/ImageViewMapper : com/datadog/android/sessionreplay/recorder/mapper/BaseAsyncBackgroundWireframeMapper {
public fun <init> (Lcom/datadog/android/sessionreplay/utils/ViewIdentifierResolver;Lcom/datadog/android/sessionreplay/utils/ColorStringFormatter;Lcom/datadog/android/sessionreplay/utils/ViewBoundsResolver;Lcom/datadog/android/sessionreplay/utils/DrawableToColorMapper;)V
public synthetic fun map (Landroid/view/View;Lcom/datadog/android/sessionreplay/recorder/MappingContext;Lcom/datadog/android/sessionreplay/utils/AsyncJobStatusCallback;Lcom/datadog/android/api/InternalLogger;)Ljava/util/List;
public fun map (Landroid/widget/ImageView;Lcom/datadog/android/sessionreplay/recorder/MappingContext;Lcom/datadog/android/sessionreplay/utils/AsyncJobStatusCallback;Lcom/datadog/android/api/InternalLogger;)Ljava/util/List;
}

public class com/datadog/android/sessionreplay/recorder/mapper/TextViewMapper : com/datadog/android/sessionreplay/recorder/mapper/BaseAsyncBackgroundWireframeMapper {
public fun <init> (Lcom/datadog/android/sessionreplay/utils/ViewIdentifierResolver;Lcom/datadog/android/sessionreplay/utils/ColorStringFormatter;Lcom/datadog/android/sessionreplay/utils/ViewBoundsResolver;Lcom/datadog/android/sessionreplay/utils/DrawableToColorMapper;)V
protected final fun createTextWireframe (Landroid/widget/TextView;Lcom/datadog/android/sessionreplay/recorder/MappingContext;Lcom/datadog/android/sessionreplay/utils/GlobalBounds;)Lcom/datadog/android/sessionreplay/model/MobileSegment$Wireframe$TextWireframe;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import com.datadog.android.sessionreplay.internal.recorder.mapper.ActionBarConta
import com.datadog.android.sessionreplay.internal.recorder.mapper.ButtonMapper
import com.datadog.android.sessionreplay.internal.recorder.mapper.CheckBoxMapper
import com.datadog.android.sessionreplay.internal.recorder.mapper.CheckedTextViewMapper
import com.datadog.android.sessionreplay.internal.recorder.mapper.ImageViewMapper
import com.datadog.android.sessionreplay.internal.recorder.mapper.NumberPickerMapper
import com.datadog.android.sessionreplay.internal.recorder.mapper.ProgressBarWireframeMapper
import com.datadog.android.sessionreplay.internal.recorder.mapper.RadioButtonMapper
Expand All @@ -45,6 +44,7 @@ import com.datadog.android.sessionreplay.internal.time.SessionReplayTimeProvider
import com.datadog.android.sessionreplay.internal.utils.ImageViewUtils
import com.datadog.android.sessionreplay.recorder.OptionSelectorDetector
import com.datadog.android.sessionreplay.recorder.mapper.EditTextMapper
import com.datadog.android.sessionreplay.recorder.mapper.ImageViewMapper
import com.datadog.android.sessionreplay.recorder.mapper.TextViewMapper
import com.datadog.android.sessionreplay.recorder.mapper.WireframeMapper
import com.datadog.android.sessionreplay.utils.ColorStringFormatter
Expand Down Expand Up @@ -97,11 +97,11 @@ internal class DefaultRecorderProvider(
val viewBoundsResolver: ViewBoundsResolver = DefaultViewBoundsResolver
val drawableToColorMapper: DrawableToColorMapper = DrawableToColorMapper.getDefault()
val imageViewMapper = ImageViewMapper(
ImageViewUtils,
viewIdentifierResolver,
colorStringFormatter,
viewBoundsResolver,
drawableToColorMapper
viewIdentifierResolver = viewIdentifierResolver,
colorStringFormatter = colorStringFormatter,
viewBoundsResolver = viewBoundsResolver,
drawableToColorMapper = drawableToColorMapper,
imageViewUtils = ImageViewUtils
)
val textViewMapper = TextViewMapper<TextView>(
viewIdentifierResolver,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ internal object ImageViewUtils {
}

internal fun resolveContentRectWithScaling(
view: ImageView,
imageView: ImageView,
drawable: Drawable
): Rect {
val drawableWidthPx = drawable.intrinsicWidth
val drawableHeightPx = drawable.intrinsicHeight

val parentRect = resolveParentRectAbsPosition(view)
val parentRect = resolveParentRectAbsPosition(imageView)

val childRect = Rect(
0,
Expand All @@ -79,7 +79,7 @@ internal object ImageViewUtils {

val resultRect: Rect

when (view.scaleType) {
when (imageView.scaleType) {
ImageView.ScaleType.FIT_START -> {
val contentRect = scaleRectToFitParent(parentRect, childRect)
resultRect = positionRectAtStart(parentRect, contentRect)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Copyright 2016-Present Datadog, Inc.
*/

package com.datadog.android.sessionreplay.internal.recorder.mapper
package com.datadog.android.sessionreplay.recorder.mapper

import android.widget.ImageView
import androidx.annotation.UiThread
Expand All @@ -13,26 +13,48 @@ import com.datadog.android.sessionreplay.internal.recorder.densityNormalized
import com.datadog.android.sessionreplay.internal.utils.ImageViewUtils
import com.datadog.android.sessionreplay.model.MobileSegment
import com.datadog.android.sessionreplay.recorder.MappingContext
import com.datadog.android.sessionreplay.recorder.mapper.BaseAsyncBackgroundWireframeMapper
import com.datadog.android.sessionreplay.utils.AsyncJobStatusCallback
import com.datadog.android.sessionreplay.utils.ColorStringFormatter
import com.datadog.android.sessionreplay.utils.DrawableToColorMapper
import com.datadog.android.sessionreplay.utils.ImageWireframeHelper
import com.datadog.android.sessionreplay.utils.ViewBoundsResolver
import com.datadog.android.sessionreplay.utils.ViewIdentifierResolver

internal class ImageViewMapper(
private val imageViewUtils: ImageViewUtils,
viewIdentifierResolver: ViewIdentifierResolver,
colorStringFormatter: ColorStringFormatter,
viewBoundsResolver: ViewBoundsResolver,
drawableToColorMapper: DrawableToColorMapper
) : BaseAsyncBackgroundWireframeMapper<ImageView>(
viewIdentifierResolver,
colorStringFormatter,
viewBoundsResolver,
drawableToColorMapper
) {
/**
* A [WireframeMapper] implementation to map an [ImageView] component.
*/
open class ImageViewMapper : BaseAsyncBackgroundWireframeMapper<ImageView> {
private val imageViewUtils: ImageViewUtils

@Suppress("Unused") // used by external mappers
constructor(
viewIdentifierResolver: ViewIdentifierResolver,
colorStringFormatter: ColorStringFormatter,
viewBoundsResolver: ViewBoundsResolver,
drawableToColorMapper: DrawableToColorMapper
) : this(
viewIdentifierResolver,
colorStringFormatter,
viewBoundsResolver,
drawableToColorMapper,
ImageViewUtils
)

internal constructor(
viewIdentifierResolver: ViewIdentifierResolver,
colorStringFormatter: ColorStringFormatter,
viewBoundsResolver: ViewBoundsResolver,
drawableToColorMapper: DrawableToColorMapper,
imageViewUtils: ImageViewUtils
) : super(
viewIdentifierResolver,
colorStringFormatter,
viewBoundsResolver,
drawableToColorMapper
) {
this.imageViewUtils = imageViewUtils
}

@UiThread
override fun map(
view: ImageView,
Expand All @@ -58,6 +80,7 @@ internal class ImageViewMapper(
} else {
null
}

val contentXPosInDp = contentRect.left.densityNormalized(density).toLong()
val contentYPosInDp = contentRect.top.densityNormalized(density).toLong()
val contentWidthPx = contentRect.width()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ internal class ImageViewUtilsTest {

// When
val result = testedImageViewUtils.resolveContentRectWithScaling(
view = mockImageView,
imageView = mockImageView,
drawable = mockDrawable
)

Expand Down Expand Up @@ -326,7 +326,7 @@ internal class ImageViewUtilsTest {

// When
val result = testedImageViewUtils.resolveContentRectWithScaling(
view = mockImageView,
imageView = mockImageView,
drawable = mockDrawable
)

Expand Down Expand Up @@ -374,7 +374,7 @@ internal class ImageViewUtilsTest {

// When
val result = testedImageViewUtils.resolveContentRectWithScaling(
view = mockImageView,
imageView = mockImageView,
drawable = mockDrawable
)

Expand Down Expand Up @@ -422,7 +422,7 @@ internal class ImageViewUtilsTest {

// When
val result = testedImageViewUtils.resolveContentRectWithScaling(
view = mockImageView,
imageView = mockImageView,
drawable = mockDrawable
)

Expand Down Expand Up @@ -477,7 +477,7 @@ internal class ImageViewUtilsTest {

// When
val result = testedImageViewUtils.resolveContentRectWithScaling(
view = mockImageView,
imageView = mockImageView,
drawable = mockDrawable
)

Expand Down Expand Up @@ -525,7 +525,7 @@ internal class ImageViewUtilsTest {

// When
val result = testedImageViewUtils.resolveContentRectWithScaling(
view = mockImageView,
imageView = mockImageView,
drawable = mockDrawable
)

Expand Down Expand Up @@ -577,7 +577,7 @@ internal class ImageViewUtilsTest {

// When
val result = testedImageViewUtils.resolveContentRectWithScaling(
view = mockImageView,
imageView = mockImageView,
drawable = mockDrawable
)

Expand Down Expand Up @@ -627,7 +627,7 @@ internal class ImageViewUtilsTest {

// When
val result = testedImageViewUtils.resolveContentRectWithScaling(
view = mockImageView,
imageView = mockImageView,
drawable = mockDrawable
)

Expand Down Expand Up @@ -673,7 +673,7 @@ internal class ImageViewUtilsTest {

// When
val result = testedImageViewUtils.resolveContentRectWithScaling(
view = mockImageView,
imageView = mockImageView,
drawable = mockDrawable
)

Expand Down Expand Up @@ -718,7 +718,7 @@ internal class ImageViewUtilsTest {

// When
val result = testedImageViewUtils.resolveContentRectWithScaling(
view = mockImageView,
imageView = mockImageView,
drawable = mockDrawable
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Copyright 2016-Present Datadog, Inc.
*/

package com.datadog.android.sessionreplay.internal.recorder.mapper
package com.datadog.android.sessionreplay.recorder.mapper

import android.content.Context
import android.content.res.Resources
Expand All @@ -22,7 +22,6 @@ import com.datadog.android.sessionreplay.internal.utils.ImageViewUtils
import com.datadog.android.sessionreplay.model.MobileSegment
import com.datadog.android.sessionreplay.recorder.MappingContext
import com.datadog.android.sessionreplay.recorder.SystemInformation
import com.datadog.android.sessionreplay.recorder.mapper.BaseAsyncBackgroundWireframeMapper
import com.datadog.android.sessionreplay.utils.AsyncJobStatusCallback
import com.datadog.android.sessionreplay.utils.ColorStringFormatter
import com.datadog.android.sessionreplay.utils.DrawableToColorMapper
Expand Down Expand Up @@ -194,11 +193,11 @@ internal class ImageViewMapperTest {
)

testedMapper = ImageViewMapper(
stubImageViewUtils,
mockViewIdentifierResolver,
mockColorStringFormatter,
mockViewBoundsResolver,
mockDrawableToColorMapper
viewIdentifierResolver = mockViewIdentifierResolver,
colorStringFormatter = mockColorStringFormatter,
viewBoundsResolver = mockViewBoundsResolver,
drawableToColorMapper = mockDrawableToColorMapper,
imageViewUtils = stubImageViewUtils
)
}

Expand Down

0 comments on commit b2a2856

Please sign in to comment.