From 0f14bc1a1c2004005032130ecc227288eec9c577 Mon Sep 17 00:00:00 2001 From: Joe Groocock Date: Thu, 22 Aug 2024 10:35:19 +0100 Subject: [PATCH 1/3] Ensure consistent AggregatedReaction screenshots Different system locales can generate different screenshots, causing CI to be unhappy. Hardcoding a locale ensures the same date format is always used. Signed-off-by: Joe Groocock --- .../impl/timeline/model/AggregatedReactionProvider.kt | 4 ++-- ...eline.components.reactionsummary_SheetContent_Day_0_en.png | 4 ++-- ...ine.components.reactionsummary_SheetContent_Night_0_en.png | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/AggregatedReactionProvider.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/AggregatedReactionProvider.kt index 087de1753a..35baf24207 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/AggregatedReactionProvider.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/AggregatedReactionProvider.kt @@ -38,10 +38,10 @@ fun anAggregatedReaction( count: Int = 1, isHighlighted: Boolean = false, ): AggregatedReaction { + val timeFormatter = DateFormat.getTimeInstance(DateFormat.SHORT, java.util.Locale.US) + val date = Date(1_689_061_264L) val senders = buildList { repeat(count) { index -> - val timeFormatter = DateFormat.getTimeInstance(DateFormat.SHORT) - val date = Date(1_689_061_264L) add( AggregatedReactionSender( senderId = if (isHighlighted && index == 0) userId else UserId("@user$index:server.org"), diff --git a/tests/uitests/src/test/snapshots/images/features.messages.impl.timeline.components.reactionsummary_SheetContent_Day_0_en.png b/tests/uitests/src/test/snapshots/images/features.messages.impl.timeline.components.reactionsummary_SheetContent_Day_0_en.png index 3fdfe25ad2..d49c11a6a2 100644 --- a/tests/uitests/src/test/snapshots/images/features.messages.impl.timeline.components.reactionsummary_SheetContent_Day_0_en.png +++ b/tests/uitests/src/test/snapshots/images/features.messages.impl.timeline.components.reactionsummary_SheetContent_Day_0_en.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9490990c863318390d0f088ff82ad01a688c81cada63d749872b22b633fa12fe -size 23040 +oid sha256:65eb29b745fabe2587019c169a48a862b129a3ece30cf9bc82aff09c67878b35 +size 23180 diff --git a/tests/uitests/src/test/snapshots/images/features.messages.impl.timeline.components.reactionsummary_SheetContent_Night_0_en.png b/tests/uitests/src/test/snapshots/images/features.messages.impl.timeline.components.reactionsummary_SheetContent_Night_0_en.png index 1a24a720d8..df75d7f909 100644 --- a/tests/uitests/src/test/snapshots/images/features.messages.impl.timeline.components.reactionsummary_SheetContent_Night_0_en.png +++ b/tests/uitests/src/test/snapshots/images/features.messages.impl.timeline.components.reactionsummary_SheetContent_Night_0_en.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:730c2c5ab52209366611546dbdbbed62214f6f5e13328be66cce5f08d8f4f0e5 -size 23125 +oid sha256:c1cf0091d377d8018d14804433aaa67d1b0b510778b6f8a4e8a73faff2b4c782 +size 23280 From 671def23b85564f78f830c146d875c981956f127 Mon Sep 17 00:00:00 2001 From: SpiritCroc Date: Fri, 23 Aug 2024 14:46:19 +0100 Subject: [PATCH 2/3] Big emoji-only messages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adapted from SpiritCroc's SchildNext implementation from https://github.com/SchildiChat/schildichat-android-next/commit/7eba87f02e884b9b921aa4e74dd0a737e4da31ad Fixes: https://github.com/element-hq/element-x-android/issues/1438 Signed-off-by: Tobias BΓΌttner Signed-off-by: Joe Groocock --- features/messages/impl/build.gradle.kts | 1 + .../components/event/TimelineItemTextView.kt | 9 +++- .../event/TimelineItemEventContentProvider.kt | 1 + .../features/messages/impl/utils/Emoji.kt | 44 ++++++++++++++++++ .../features/messages/impl/utils/EmojiTest.kt | 45 +++++++++++++++++++ gradle/libs.versions.toml | 1 + ...s.impl.timeline_TimelineView_Day_17_en.png | 3 ++ ...impl.timeline_TimelineView_Night_17_en.png | 3 ++ 8 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/utils/Emoji.kt create mode 100644 features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/utils/EmojiTest.kt create mode 100644 tests/uitests/src/test/snapshots/images/features.messages.impl.timeline_TimelineView_Day_17_en.png create mode 100644 tests/uitests/src/test/snapshots/images/features.messages.impl.timeline_TimelineView_Night_17_en.png diff --git a/features/messages/impl/build.gradle.kts b/features/messages/impl/build.gradle.kts index c1d3067510..7f451a54a5 100644 --- a/features/messages/impl/build.gradle.kts +++ b/features/messages/impl/build.gradle.kts @@ -72,6 +72,7 @@ dependencies { implementation(libs.androidx.constraintlayout.compose) implementation(libs.androidx.media3.exoplayer) implementation(libs.androidx.media3.ui) + implementation(libs.sigpwned.emoji4j) implementation(libs.vanniktech.blurhash) implementation(libs.telephoto.zoomableimage) implementation(libs.matrix.emojibase.bindings) diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/event/TimelineItemTextView.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/event/TimelineItemTextView.kt index e691c1e549..d6d34418bd 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/event/TimelineItemTextView.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/event/TimelineItemTextView.kt @@ -35,6 +35,7 @@ import io.element.android.features.messages.impl.timeline.components.layout.Cont import io.element.android.features.messages.impl.timeline.components.layout.ContentAvoidingLayoutData import io.element.android.features.messages.impl.timeline.model.event.TimelineItemTextBasedContent import io.element.android.features.messages.impl.timeline.model.event.TimelineItemTextBasedContentProvider +import io.element.android.features.messages.impl.utils.containsOnlyEmojis import io.element.android.libraries.designsystem.preview.ElementPreview import io.element.android.libraries.designsystem.preview.PreviewsDayNight import io.element.android.libraries.matrix.api.core.UserId @@ -54,9 +55,15 @@ fun TimelineItemTextView( modifier: Modifier = Modifier, onContentLayoutChange: (ContentAvoidingLayoutData) -> Unit = {}, ) { + val emojiOnly = (content.formattedBody == null || content.formattedBody.toString() == content.body) && + content.body.replace(" ", "").containsOnlyEmojis() + val textStyle = when { + emojiOnly -> ElementTheme.typography.fontHeadingXlRegular + else -> ElementTheme.typography.fontBodyLgRegular + } CompositionLocalProvider( LocalContentColor provides ElementTheme.colors.textPrimary, - LocalTextStyle provides ElementTheme.typography.fontBodyLgRegular + LocalTextStyle provides textStyle ) { val body = getTextWithResolvedMentions(content) Box(modifier.semantics { contentDescription = content.plainText }) { diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/event/TimelineItemEventContentProvider.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/event/TimelineItemEventContentProvider.kt index 29fa048e1f..3cdfb73510 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/event/TimelineItemEventContentProvider.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/event/TimelineItemEventContentProvider.kt @@ -42,6 +42,7 @@ class TimelineItemEventContentProvider : PreviewParameterProvider Date: Wed, 4 Sep 2024 18:35:26 +0200 Subject: [PATCH 3/3] Remove unnecessary parenthesis --- .../io/element/android/features/messages/impl/utils/Emoji.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/utils/Emoji.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/utils/Emoji.kt index 9706651d57..5ab5d1e245 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/utils/Emoji.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/utils/Emoji.kt @@ -35,7 +35,7 @@ fun String.containsOnlyEmojis(): Boolean { m = matcher.toMatchResult() // Many non-"emoji" characters are pictographics. We only want to identify this specific range // https://en.wikipedia.org/wiki/Miscellaneous_Symbols_and_Pictographs - val isEmoji = m!!.grapheme().type == EMOJI || (m.grapheme().type == PICTOGRAPHIC && m.group() in "🌍".."πŸ—Ί") + val isEmoji = m!!.grapheme().type == EMOJI || m.grapheme().type == PICTOGRAPHIC && m.group() in "🌍".."πŸ—Ί" contiguous = isEmoji and (m.start() == previous) previous = m.end() }