From 1a1d4c295760780ef4c86bb84fa14abee1b89d64 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 21 Jul 2023 16:04:55 +0200 Subject: [PATCH] Fix code quality check failures after new rules from #935 has been merged on develop. --- .../api/internal/MapTilerStaticMapUrlBuilder.kt | 14 +++++++------- .../timeline/components/TimelineItemEventRow.kt | 1 - .../components/TimelineItemReactionsLayout.kt | 2 +- .../members/RoomMemberListPresenterTests.kt | 14 +++++--------- 4 files changed, 13 insertions(+), 18 deletions(-) diff --git a/features/location/api/src/main/kotlin/io/element/android/features/location/api/internal/MapTilerStaticMapUrlBuilder.kt b/features/location/api/src/main/kotlin/io/element/android/features/location/api/internal/MapTilerStaticMapUrlBuilder.kt index 72fcaeb06c..927e890248 100644 --- a/features/location/api/src/main/kotlin/io/element/android/features/location/api/internal/MapTilerStaticMapUrlBuilder.kt +++ b/features/location/api/src/main/kotlin/io/element/android/features/location/api/internal/MapTilerStaticMapUrlBuilder.kt @@ -46,13 +46,13 @@ internal class MapTilerStaticMapUrlBuilder( density: Float ): String { val mapId = if (darkMode) darkMapId else lightMapId - val zoom = zoom.coerceIn(zoomRange) + val finalZoom = zoom.coerceIn(zoomRange) // Request @2x density for xhdpi and above (xhdpi == 320dpi == 2x density). val is2x = density >= 2 // Scale requested width/height according to the reported display density. - val (width, height) = coerceWidthAndHeight( + val (finalWidth, finalHeight) = coerceWidthAndHeight( width = (width / density).roundToInt(), height = (height / density).roundToInt(), is2x = is2x, @@ -65,7 +65,7 @@ internal class MapTilerStaticMapUrlBuilder( // image smaller than the available space in pixels. // The resulting image will have to be scaled to fit the available space in order // to keep the perceived content size constant at the expense of sharpness. - return "$MAPTILER_BASE_URL/${mapId}/static/${lon},${lat},${zoom}/${width}x${height}${scale}.webp?key=${apiKey}&attribution=bottomleft" + return "$MAPTILER_BASE_URL/${mapId}/static/${lon},${lat},${finalZoom}/${finalWidth}x${finalHeight}${scale}.webp?key=${apiKey}&attribution=bottomleft" } } @@ -78,12 +78,12 @@ private fun coerceWidthAndHeight(width: Int, height: Int, is2x: Boolean): Pair= height) { - width.coerceIn(range).let { width -> - width to (width / aspectRatio).roundToInt() + width.coerceIn(range).let { coercedWidth -> + coercedWidth to (coercedWidth / aspectRatio).roundToInt() } } else { - height.coerceIn(range).let { height -> - (height * aspectRatio).roundToInt() to height + height.coerceIn(range).let { coercedHeight -> + (coercedHeight * aspectRatio).roundToInt() to coercedHeight } } } diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemEventRow.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemEventRow.kt index 5143b92f07..a74b37efc5 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemEventRow.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemEventRow.kt @@ -59,7 +59,6 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.zIndex import androidx.constraintlayout.compose.ConstrainScope import androidx.constraintlayout.compose.ConstraintLayout -import com.google.accompanist.flowlayout.FlowMainAxisAlignment import io.element.android.features.messages.impl.timeline.aTimelineItemEvent import io.element.android.features.messages.impl.timeline.aTimelineItemReactions import io.element.android.features.messages.impl.timeline.components.event.TimelineItemEventContentView diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemReactionsLayout.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemReactionsLayout.kt index 8fe0ab1bef..851389c6bd 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemReactionsLayout.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemReactionsLayout.kt @@ -91,7 +91,7 @@ fun TimelineItemReactionsLayout( lastRow.forEachIndexed { i, placeable -> val horizontalSpacing = if (i == 0) 0 else itemSpacing.toPx().toInt() rowX += placeable.width + horizontalSpacing - if (rowX > (constraints.maxWidth - (buttonsWidth + horizontalSpacing))) { + if (rowX > constraints.maxWidth - (buttonsWidth + horizontalSpacing)) { val lastRowWithButton = lastRow.take(i) + listOf(expandButton, addMoreButton) rows[rows.size - 1] = lastRowWithButton return rows diff --git a/features/roomdetails/impl/src/test/kotlin/io/element/android/features/roomdetails/members/RoomMemberListPresenterTests.kt b/features/roomdetails/impl/src/test/kotlin/io/element/android/features/roomdetails/members/RoomMemberListPresenterTests.kt index 5a3141ea09..9de035d017 100644 --- a/features/roomdetails/impl/src/test/kotlin/io/element/android/features/roomdetails/members/RoomMemberListPresenterTests.kt +++ b/features/roomdetails/impl/src/test/kotlin/io/element/android/features/roomdetails/members/RoomMemberListPresenterTests.kt @@ -52,7 +52,6 @@ class RoomMemberListPresenterTests { Truth.assertThat(initialState.searchQuery).isEmpty() Truth.assertThat(initialState.searchResults).isInstanceOf(SearchBarResultState.NotSearching::class.java) Truth.assertThat(initialState.isSearchActive).isFalse() - val loadedState = awaitItem() Truth.assertThat(loadedState.roomMembers).isInstanceOf(Async.Success::class.java) Truth.assertThat((loadedState.roomMembers as Async.Success).data.invited).isEqualTo(listOf(aVictor(), aWalter())) @@ -66,11 +65,9 @@ class RoomMemberListPresenterTests { moleculeFlow(RecompositionMode.Immediate) { presenter.present() }.test { - val initialState = awaitItem() + skipItems(1) val loadedState = awaitItem() - loadedState.eventSink(RoomMemberListEvents.OnSearchActiveChanged(true)) - val searchActiveState = awaitItem() Truth.assertThat(searchActiveState.isSearchActive).isTrue() } @@ -82,11 +79,11 @@ class RoomMemberListPresenterTests { moleculeFlow(RecompositionMode.Immediate) { presenter.present() }.test { - val initialState = awaitItem() + skipItems(1) val loadedState = awaitItem() loadedState.eventSink(RoomMemberListEvents.OnSearchActiveChanged(true)) val searchActiveState = awaitItem() - loadedState.eventSink(RoomMemberListEvents.UpdateSearchQuery("something")) + searchActiveState.eventSink(RoomMemberListEvents.UpdateSearchQuery("something")) val searchQueryUpdatedState = awaitItem() Truth.assertThat(searchQueryUpdatedState.searchQuery).isEqualTo("something") val searchSearchResultDelivered = awaitItem() @@ -100,18 +97,17 @@ class RoomMemberListPresenterTests { moleculeFlow(RecompositionMode.Immediate) { presenter.present() }.test { - val initialState = awaitItem() + skipItems(1) val loadedState = awaitItem() loadedState.eventSink(RoomMemberListEvents.OnSearchActiveChanged(true)) val searchActiveState = awaitItem() - loadedState.eventSink(RoomMemberListEvents.UpdateSearchQuery("Alice")) + searchActiveState.eventSink(RoomMemberListEvents.UpdateSearchQuery("Alice")) val searchQueryUpdatedState = awaitItem() Truth.assertThat(searchQueryUpdatedState.searchQuery).isEqualTo("Alice") val searchSearchResultDelivered = awaitItem() Truth.assertThat(searchSearchResultDelivered.searchResults).isInstanceOf(SearchBarResultState.Results::class.java) Truth.assertThat((searchSearchResultDelivered.searchResults as SearchBarResultState.Results).results.joined.first().displayName) .isEqualTo("Alice") - } }