From 52648d2abf0e849109129d2c8ba72a3bdf84a89e Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 2 Jan 2025 08:13:05 +0100 Subject: [PATCH] Fix quality checks --- .../knockrequests/impl/banner/AvatarRow.kt | 64 +++++++++---------- .../impl/banner/KnockRequestsBannerView.kt | 2 + .../tests/konsist/KonsistClassNameTest.kt | 1 + 3 files changed, 35 insertions(+), 32 deletions(-) diff --git a/features/knockrequests/impl/src/main/kotlin/io/element/android/features/knockrequests/impl/banner/AvatarRow.kt b/features/knockrequests/impl/src/main/kotlin/io/element/android/features/knockrequests/impl/banner/AvatarRow.kt index ee8d8000e2..4f4df5c876 100644 --- a/features/knockrequests/impl/src/main/kotlin/io/element/android/features/knockrequests/impl/banner/AvatarRow.kt +++ b/features/knockrequests/impl/src/main/kotlin/io/element/android/features/knockrequests/impl/banner/AvatarRow.kt @@ -29,9 +29,11 @@ import io.element.android.libraries.designsystem.components.avatar.AvatarSize import io.element.android.libraries.designsystem.preview.ElementPreview import io.element.android.libraries.designsystem.preview.PreviewsDayNight import io.element.android.libraries.designsystem.text.toPx +import kotlinx.collections.immutable.ImmutableList +import kotlinx.collections.immutable.toImmutableList /** - * Draw a row of avatars (they must all have the same size), from start to end + * Draw a row of avatars (they must all have the same size), from start to end. * @param avatarDataList the avatars to render. Note: they will all be rendered, the caller may * want to limit the list size * @param modifier Jetpack Compose modifier @@ -40,7 +42,7 @@ import io.element.android.libraries.designsystem.text.toPx */ @Composable fun AvatarRow( - avatarDataList: List, + avatarDataList: ImmutableList, modifier: Modifier = Modifier, overlapRatio: Float = 0.5f, ) { @@ -56,34 +58,34 @@ fun AvatarRow( .forEachIndexed { index, avatarData -> Avatar( modifier = Modifier - .padding(start = avatarSize * (1 - overlapRatio) * (lastItemIndex - index)) - .graphicsLayer { - compositingStrategy = CompositingStrategy.Offscreen - } - .drawWithContent { - // Draw content and clear the pixels for the avatar on the left (right in RTL). - drawContent() - val xOffset = if (isRtl) { - size.width - avatarSizePx * (overlapRatio - 0.5f) - } else { - 0f + avatarSizePx * (overlapRatio - 0.5f) + .padding(start = avatarSize * (1 - overlapRatio) * (lastItemIndex - index)) + .graphicsLayer { + compositingStrategy = CompositingStrategy.Offscreen } - if (index < lastItemIndex) { - drawCircle( - color = Color.Black, - center = Offset( - x = xOffset, - y = size.height / 2, - ), - radius = avatarSizePx / 2, - blendMode = BlendMode.Clear, - ) + .drawWithContent { + // Draw content and clear the pixels for the avatar on the left (right in RTL). + drawContent() + val xOffset = if (isRtl) { + size.width - avatarSizePx * (overlapRatio - 0.5f) + } else { + 0f + avatarSizePx * (overlapRatio - 0.5f) + } + if (index < lastItemIndex) { + drawCircle( + color = Color.Black, + center = Offset( + x = xOffset, + y = size.height / 2, + ), + radius = avatarSizePx / 2, + blendMode = BlendMode.Clear, + ) + } } - } - .size(size = avatarSize) - // Keep internal padding, it has the advantage to not reduce the size of the Avatar image, - // which is already small in our use case. - .padding(2.dp), + .size(size = avatarSize) + // Keep internal padding, it has the advantage to not reduce the size of the Avatar image, + // which is already small in our use case. + .padding(2.dp), avatarData = avatarData, ) } @@ -113,15 +115,13 @@ internal fun AvatarRowRtlPreview(@PreviewParameter(OverlapRatioProvider::class) @Composable private fun ContentToPreview(overlapRatio: Float) { AvatarRow( - avatarDataList = listOf( - "A", "B", "C" - ).map { + avatarDataList = listOf("A", "B", "C").map { AvatarData( id = it, name = it, size = AvatarSize.RoomListItem, ) - }, + }.toImmutableList(), overlapRatio = overlapRatio, ) } diff --git a/features/knockrequests/impl/src/main/kotlin/io/element/android/features/knockrequests/impl/banner/KnockRequestsBannerView.kt b/features/knockrequests/impl/src/main/kotlin/io/element/android/features/knockrequests/impl/banner/KnockRequestsBannerView.kt index a7307d605b..9dc4e63195 100644 --- a/features/knockrequests/impl/src/main/kotlin/io/element/android/features/knockrequests/impl/banner/KnockRequestsBannerView.kt +++ b/features/knockrequests/impl/src/main/kotlin/io/element/android/features/knockrequests/impl/banner/KnockRequestsBannerView.kt @@ -49,6 +49,7 @@ import io.element.android.libraries.designsystem.theme.components.Surface import io.element.android.libraries.designsystem.theme.components.Text import io.element.android.libraries.ui.strings.CommonStrings import kotlinx.collections.immutable.ImmutableList +import kotlinx.collections.immutable.toImmutableList private const val MAX_AVATAR_COUNT = 3 @@ -210,6 +211,7 @@ private fun KnockRequestAvatarListView( .map { knockRequest -> knockRequest.getAvatarData(AvatarSize.KnockRequestBanner) } + .toImmutableList() AvatarRow( avatarDataList = avatars, modifier = modifier, diff --git a/tests/konsist/src/test/kotlin/io/element/android/tests/konsist/KonsistClassNameTest.kt b/tests/konsist/src/test/kotlin/io/element/android/tests/konsist/KonsistClassNameTest.kt index 9d8e23e7dc..7a75ff9f1a 100644 --- a/tests/konsist/src/test/kotlin/io/element/android/tests/konsist/KonsistClassNameTest.kt +++ b/tests/konsist/src/test/kotlin/io/element/android/tests/konsist/KonsistClassNameTest.kt @@ -50,6 +50,7 @@ class KonsistClassNameTest { .withAllParentsOf(PreviewParameterProvider::class) .withoutName( "AspectRatioProvider", + "OverlapRatioProvider", ) .also { // Check that classes are actually found