Skip to content

Commit 11155d6

Browse files
committed
RUM-6195: Small refactoring
1 parent 1f3e4af commit 11155d6

File tree

11 files changed

+85
-88
lines changed

11 files changed

+85
-88
lines changed

dd-sdk-android-internal/src/main/java/com/datadog/android/internal/utils/ImageViewUtils.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import android.widget.ImageView
1919
object ImageViewUtils {
2020
/**
2121
* Resolves the absolute position on the screen of the given [View].
22-
* @param view: the [View].
22+
* @param view the [View].
2323
* @return the [Rect] representing the absolute position of the view.
2424
*/
2525
fun resolveParentRectAbsPosition(view: View): Rect {
@@ -42,9 +42,9 @@ object ImageViewUtils {
4242
/**
4343
* Calculates the clipping [Rect] of the given child [Rect] using its parent [Rect] and
4444
* the screen density.
45-
* @param parentRect: the parent [Rect].
46-
* @param childRect: the child [Rect].
47-
* @param density: the screen density.
45+
* @param parentRect the parent [Rect].
46+
* @param childRect the child [Rect].
47+
* @param density the screen density.
4848
* @return the clipping [Rect].
4949
*/
5050
fun calculateClipping(parentRect: Rect, childRect: Rect, density: Float): Rect {
@@ -78,9 +78,9 @@ object ImageViewUtils {
7878

7979
/**
8080
* Resolves the [Drawable] content [Rect] using the given [ImageView] scale type.
81-
* @param imageView: the [ImageView].
82-
* @param drawable: the [Drawable].
83-
* @param customScaleType: optional custom [ImageView.ScaleType].
81+
* @param imageView the [ImageView].
82+
* @param drawable the [Drawable].
83+
* @param customScaleType optional custom [ImageView.ScaleType].
8484
* @return the resolved content [Rect].
8585
*/
8686
fun resolveContentRectWithScaling(

features/dd-sdk-android-session-replay-compose/src/main/kotlin/com/datadog/android/sessionreplay/compose/internal/mappers/semantics/CheckboxSemanticsNodeMapper.kt

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ internal class CheckboxSemanticsNodeMapper(
4646
)
4747
)
4848
} else {
49-
createCheckboxWireframe(
49+
createCheckboxWireframes(
5050
parentContext = parentContext,
5151
asyncJobStatusCallback = asyncJobStatusCallback,
5252
semanticsNode = semanticsNode,
@@ -78,7 +78,7 @@ internal class CheckboxSemanticsNodeMapper(
7878
)
7979
}
8080

81-
private fun createCheckboxWireframe(
81+
private fun createCheckboxWireframes(
8282
parentContext: UiContext,
8383
asyncJobStatusCallback: AsyncJobStatusCallback,
8484
semanticsNode: SemanticsNode,
@@ -140,7 +140,7 @@ internal class CheckboxSemanticsNodeMapper(
140140
}
141141

142142
// if we failed to create a wireframe from the path
143-
return createManualCheckedWireframe(
143+
return createManualCheckedWireframes(
144144
semanticsNode = semanticsNode,
145145
globalBounds = globalBounds,
146146
backgroundColor = fillColorRgba,
@@ -162,15 +162,15 @@ internal class CheckboxSemanticsNodeMapper(
162162
} ?: DEFAULT_COLOR_BLACK
163163
}
164164

165-
private fun createManualCheckedWireframe(
165+
private fun createManualCheckedWireframes(
166166
semanticsNode: SemanticsNode,
167167
globalBounds: GlobalBounds,
168168
backgroundColor: String,
169169
borderColor: String
170170
): List<MobileSegment.Wireframe> {
171171
val strokeColor = getFallbackCheckmarkColor(backgroundColor)
172172

173-
val wireframesList = mutableListOf<MobileSegment.Wireframe>()
173+
val wireframes = mutableListOf<MobileSegment.Wireframe>()
174174

175175
val background = createUncheckedState(
176176
semanticsNode = semanticsNode,
@@ -180,7 +180,7 @@ internal class CheckboxSemanticsNodeMapper(
180180
currentIndex = 0
181181
)
182182

183-
wireframesList.add(background)
183+
wireframes.add(background)
184184

185185
val checkmarkWidth = globalBounds.width * CHECKMARK_SIZE_FACTOR
186186
val checkmarkHeight = globalBounds.height * CHECKMARK_SIZE_FACTOR
@@ -203,8 +203,8 @@ internal class CheckboxSemanticsNodeMapper(
203203
)
204204
)
205205

206-
wireframesList.add(foreground)
207-
return wireframesList
206+
wireframes.add(foreground)
207+
return wireframes
208208
}
209209

210210
private fun createUncheckedState(
@@ -213,24 +213,22 @@ internal class CheckboxSemanticsNodeMapper(
213213
backgroundColor: String,
214214
borderColor: String,
215215
currentIndex: Int
216-
): MobileSegment.Wireframe {
217-
return MobileSegment.Wireframe.ShapeWireframe(
218-
id = resolveId(semanticsNode, currentIndex),
219-
x = globalBounds.x,
220-
y = globalBounds.y,
221-
width = CHECKBOX_SIZE_DP.toLong(),
222-
height = CHECKBOX_SIZE_DP.toLong(),
223-
shapeStyle = MobileSegment.ShapeStyle(
224-
backgroundColor = backgroundColor,
225-
opacity = 1f,
226-
cornerRadius = CHECKBOX_CORNER_RADIUS
227-
),
228-
border = MobileSegment.ShapeBorder(
229-
color = borderColor,
230-
width = BOX_BORDER_WIDTH_DP
231-
)
216+
) = MobileSegment.Wireframe.ShapeWireframe(
217+
id = resolveId(semanticsNode, currentIndex),
218+
x = globalBounds.x,
219+
y = globalBounds.y,
220+
width = CHECKBOX_SIZE_DP.toLong(),
221+
height = CHECKBOX_SIZE_DP.toLong(),
222+
shapeStyle = MobileSegment.ShapeStyle(
223+
backgroundColor = backgroundColor,
224+
opacity = 1f,
225+
cornerRadius = CHECKBOX_CORNER_RADIUS
226+
),
227+
border = MobileSegment.ShapeBorder(
228+
color = borderColor,
229+
width = BOX_BORDER_WIDTH_DP
232230
)
233-
}
231+
)
234232

235233
private fun isCheckboxChecked(semanticsNode: SemanticsNode): Boolean =
236234
semanticsNode.config.getOrNull(SemanticsProperties.ToggleableState) == ToggleableState.On

features/dd-sdk-android-session-replay-compose/src/main/kotlin/com/datadog/android/sessionreplay/compose/internal/utils/ColorUtils.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,24 @@ internal class ColorUtils(
2828
}
2929
}
3030

31-
internal fun convertRgbaToArgb(rgbaString: String): String {
32-
if (rgbaString.length < 2) return rgbaString
31+
internal fun convertRgbaToArgb(input: String): String {
32+
if (input.length < RGBA_LENGTH) return input
3333

3434
// for takeLast: n > 0
3535
@Suppress("UnsafeThirdPartyFunctionCall")
36-
val alphaValue = rgbaString.takeLast(2)
36+
val alphaValue = input.takeLast(2)
3737

3838
// for substring: length is necessarily > 1 at this point
3939
// for dropLast: n > 0
4040
@Suppress("UnsafeThirdPartyFunctionCall")
41-
val rgbColor = rgbaString
41+
val rgbColor = input
4242
.substring(1)
4343
.dropLast(2)
4444
return "#$alphaValue$rgbColor"
4545
}
4646

4747
internal companion object {
4848
internal const val COLOR_PARSE_ERROR = "Failed to parse color: %s"
49+
internal const val RGBA_LENGTH = 8
4950
}
5051
}

features/dd-sdk-android-session-replay-compose/src/main/kotlin/com/datadog/android/sessionreplay/compose/internal/utils/SemanticsUtils.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,7 @@ internal class SemanticsUtils(private val reflectionUtils: ReflectionUtils = Ref
332332
}
333333
}
334334

335-
val result = (color?.value as? Color)
336-
?.value
335+
val result = (color?.value as? Color)?.value
337336

338337
return result?.toLong()
339338
}

features/dd-sdk-android-session-replay-compose/src/test/kotlin/com/datadog/android/sessionreplay/compose/internal/mappers/semantics/CheckboxSemanticsNodeMapperTest.kt

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ internal class CheckboxSemanticsNodeMapperTest : AbstractSemanticsNodeMapperTest
161161
asyncJobStatusCallback = mockAsyncJobStatusCallback
162162
)
163163

164-
val actualWireframe = semanticsWireframe.wireframes[0] as? MobileSegment.Wireframe.ShapeWireframe
164+
// Then
165+
val actualWireframe = semanticsWireframe.wireframes[0] as MobileSegment.Wireframe.ShapeWireframe
165166

166167
val expectedShapeBorder = MobileSegment.ShapeBorder(
167168
color = fakeBorderColorHexString,
@@ -174,9 +175,8 @@ internal class CheckboxSemanticsNodeMapperTest : AbstractSemanticsNodeMapperTest
174175
cornerRadius = CHECKBOX_CORNER_RADIUS
175176
)
176177

177-
// Then
178-
assertThat(actualWireframe?.border).isEqualTo(expectedShapeBorder)
179-
assertThat(actualWireframe?.shapeStyle).isEqualTo(expectedShapeStyle)
178+
assertThat(actualWireframe.border).isEqualTo(expectedShapeBorder)
179+
assertThat(actualWireframe.shapeStyle).isEqualTo(expectedShapeStyle)
180180
}
181181

182182
@Test
@@ -195,7 +195,8 @@ internal class CheckboxSemanticsNodeMapperTest : AbstractSemanticsNodeMapperTest
195195
asyncJobStatusCallback = mockAsyncJobStatusCallback
196196
)
197197

198-
val actualWireframe = semanticsWireframe.wireframes[0] as? MobileSegment.Wireframe.ShapeWireframe
198+
// Then
199+
val actualWireframe = semanticsWireframe.wireframes[0] as MobileSegment.Wireframe.ShapeWireframe
199200

200201
val expectedShapeBorder = MobileSegment.ShapeBorder(
201202
color = DEFAULT_COLOR_BLACK,
@@ -208,9 +209,8 @@ internal class CheckboxSemanticsNodeMapperTest : AbstractSemanticsNodeMapperTest
208209
cornerRadius = CHECKBOX_CORNER_RADIUS
209210
)
210211

211-
// Then
212-
assertThat(actualWireframe?.border).isEqualTo(expectedShapeBorder)
213-
assertThat(actualWireframe?.shapeStyle).isEqualTo(expectedShapeStyle)
212+
assertThat(actualWireframe.border).isEqualTo(expectedShapeBorder)
213+
assertThat(actualWireframe.shapeStyle).isEqualTo(expectedShapeStyle)
214214
}
215215

216216
@Test
@@ -229,7 +229,8 @@ internal class CheckboxSemanticsNodeMapperTest : AbstractSemanticsNodeMapperTest
229229
asyncJobStatusCallback = mockAsyncJobStatusCallback
230230
)
231231

232-
val backgroundWireframe = semanticsWireframe.wireframes[0] as? MobileSegment.Wireframe.ShapeWireframe
232+
// Then
233+
val backgroundWireframe = semanticsWireframe.wireframes[0] as MobileSegment.Wireframe.ShapeWireframe
233234

234235
val expectedBgShapeBorder = MobileSegment.ShapeBorder(
235236
color = fakeBorderColorHexString,
@@ -242,9 +243,8 @@ internal class CheckboxSemanticsNodeMapperTest : AbstractSemanticsNodeMapperTest
242243
cornerRadius = CHECKBOX_CORNER_RADIUS
243244
)
244245

245-
// Then
246-
assertThat(backgroundWireframe?.border).isEqualTo(expectedBgShapeBorder)
247-
assertThat(backgroundWireframe?.shapeStyle).isEqualTo(expectedBgShapeStyle)
246+
assertThat(backgroundWireframe.border).isEqualTo(expectedBgShapeBorder)
247+
assertThat(backgroundWireframe.shapeStyle).isEqualTo(expectedBgShapeStyle)
248248
}
249249

250250
@Test
@@ -266,15 +266,15 @@ internal class CheckboxSemanticsNodeMapperTest : AbstractSemanticsNodeMapperTest
266266
asyncJobStatusCallback = mockAsyncJobStatusCallback
267267
)
268268

269-
val foregroundWireframe = semanticsWireframe.wireframes[1] as? MobileSegment.Wireframe.ShapeWireframe
269+
// Then
270+
val foregroundWireframe = semanticsWireframe.wireframes[1] as MobileSegment.Wireframe.ShapeWireframe
270271
val expectedShapeStyle = MobileSegment.ShapeStyle(
271272
backgroundColor = DEFAULT_COLOR_WHITE,
272273
opacity = 1f,
273274
cornerRadius = CHECKBOX_CORNER_RADIUS
274275
)
275276

276-
// Then
277-
assertThat(foregroundWireframe?.shapeStyle).isEqualTo(expectedShapeStyle)
277+
assertThat(foregroundWireframe.shapeStyle).isEqualTo(expectedShapeStyle)
278278
}
279279

280280
@Test
@@ -295,17 +295,18 @@ internal class CheckboxSemanticsNodeMapperTest : AbstractSemanticsNodeMapperTest
295295
parentContext = mockUiContext,
296296
asyncJobStatusCallback = mockAsyncJobStatusCallback
297297
)
298+
299+
// Then
298300
assertThat(semanticsWireframe.wireframes).hasSize(2)
299301

300-
val foregroundWireframe = semanticsWireframe.wireframes[1] as? MobileSegment.Wireframe.ShapeWireframe
302+
val foregroundWireframe = semanticsWireframe.wireframes[1] as MobileSegment.Wireframe.ShapeWireframe
301303
val expectedShapeStyle = MobileSegment.ShapeStyle(
302304
backgroundColor = DEFAULT_COLOR_BLACK,
303305
opacity = 1f,
304306
cornerRadius = CHECKBOX_CORNER_RADIUS
305307
)
306308

307-
// Then
308-
assertThat(foregroundWireframe?.shapeStyle).isEqualTo(expectedShapeStyle)
309+
assertThat(foregroundWireframe.shapeStyle).isEqualTo(expectedShapeStyle)
309310
}
310311

311312
@Test
@@ -321,15 +322,15 @@ internal class CheckboxSemanticsNodeMapperTest : AbstractSemanticsNodeMapperTest
321322
asyncJobStatusCallback = mockAsyncJobStatusCallback
322323
)
323324

324-
val foregroundWireframe = semanticsWireframe.wireframes[1] as? MobileSegment.Wireframe.ShapeWireframe
325+
// Then
326+
val foregroundWireframe = semanticsWireframe.wireframes[1] as MobileSegment.Wireframe.ShapeWireframe
325327
val expectedShapeStyle = MobileSegment.ShapeStyle(
326328
backgroundColor = DEFAULT_COLOR_BLACK,
327329
opacity = 1f,
328330
cornerRadius = CHECKBOX_CORNER_RADIUS
329331
)
330332

331-
// Then
332-
assertThat(foregroundWireframe?.shapeStyle).isEqualTo(expectedShapeStyle)
333+
assertThat(foregroundWireframe.shapeStyle).isEqualTo(expectedShapeStyle)
333334
}
334335

335336
@Test
@@ -345,15 +346,15 @@ internal class CheckboxSemanticsNodeMapperTest : AbstractSemanticsNodeMapperTest
345346
asyncJobStatusCallback = mockAsyncJobStatusCallback
346347
)
347348

348-
val foregroundWireframe = semanticsWireframe.wireframes[1] as? MobileSegment.Wireframe.ShapeWireframe
349+
// Then
350+
val foregroundWireframe = semanticsWireframe.wireframes[1] as MobileSegment.Wireframe.ShapeWireframe
349351
val expectedShapeStyle = MobileSegment.ShapeStyle(
350352
backgroundColor = DEFAULT_COLOR_BLACK,
351353
opacity = 1f,
352354
cornerRadius = CHECKBOX_CORNER_RADIUS
353355
)
354356

355-
// Then
356-
assertThat(foregroundWireframe?.shapeStyle).isEqualTo(expectedShapeStyle)
357+
assertThat(foregroundWireframe.shapeStyle).isEqualTo(expectedShapeStyle)
357358
}
358359

359360
@Test
@@ -400,6 +401,7 @@ internal class CheckboxSemanticsNodeMapperTest : AbstractSemanticsNodeMapperTest
400401
asyncJobStatusCallback = mockAsyncJobStatusCallback
401402
)
402403

404+
// Then
403405
val expectedShapeStyle = MobileSegment.ShapeStyle(
404406
backgroundColor = fakeFillColorHexString,
405407
opacity = 1f,
@@ -411,7 +413,6 @@ internal class CheckboxSemanticsNodeMapperTest : AbstractSemanticsNodeMapperTest
411413
width = BOX_BORDER_WIDTH_DP
412414
)
413415

414-
// Then
415416
verify(mockUiContext.imageWireframeHelper).createImageWireframeByPath(
416417
id = any(),
417418
globalBounds = eq(fakeGlobalBounds),
@@ -492,11 +493,12 @@ internal class CheckboxSemanticsNodeMapperTest : AbstractSemanticsNodeMapperTest
492493
parentContext = mockUiContext,
493494
asyncJobStatusCallback = mockAsyncJobStatusCallback
494495
)
496+
497+
// Then
495498
assertThat(wireframes.wireframes).hasSize(1)
496-
val actualWireframe = wireframes.wireframes[0] as? MobileSegment.Wireframe.ShapeWireframe
499+
val actualWireframe = wireframes.wireframes[0] as MobileSegment.Wireframe.ShapeWireframe
497500
assertThat(actualWireframe).isNotNull
498501

499-
// Then
500502
verify(mockUiContext.imageWireframeHelper, never()).createImageWireframeByBitmap(
501503
id = any(),
502504
globalBounds = any(),
@@ -509,7 +511,7 @@ internal class CheckboxSemanticsNodeMapperTest : AbstractSemanticsNodeMapperTest
509511
shapeStyle = anyOrNull(),
510512
border = anyOrNull()
511513
)
512-
assertThat(actualWireframe?.shapeStyle?.backgroundColor).isEqualTo(DEFAULT_COLOR_WHITE)
513-
assertThat(actualWireframe?.border?.color).isEqualTo(DEFAULT_COLOR_BLACK)
514+
assertThat(actualWireframe.shapeStyle?.backgroundColor).isEqualTo(DEFAULT_COLOR_WHITE)
515+
assertThat(actualWireframe.border?.color).isEqualTo(DEFAULT_COLOR_BLACK)
514516
}
515517
}

0 commit comments

Comments
 (0)