Skip to content

Commit 158e779

Browse files
committed
Ensure that room with long names renders correctly in the room list.
1 parent 0dfdafd commit 158e779

File tree

2 files changed

+6
-3
lines changed
  • features/home/impl/src/main/kotlin/io/element/android/features/home/impl/components
  • libraries/core/src/main/kotlin/io/element/android/libraries/core/extensions

2 files changed

+6
-3
lines changed

features/home/impl/src/main/kotlin/io/element/android/features/home/impl/components/RoomSummaryRow.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import io.element.android.features.home.impl.model.RoomListRoomSummaryProvider
4646
import io.element.android.features.home.impl.model.RoomSummaryDisplayType
4747
import io.element.android.features.home.impl.roomlist.RoomListEvents
4848
import io.element.android.libraries.core.extensions.orEmpty
49+
import io.element.android.libraries.core.extensions.toSafeLength
4950
import io.element.android.libraries.designsystem.atomic.atoms.UnreadIndicatorAtom
5051
import io.element.android.libraries.designsystem.atomic.molecules.InviteButtonsRowMolecule
5152
import io.element.android.libraries.designsystem.components.avatar.Avatar
@@ -227,7 +228,7 @@ private fun NameAndTimestampRow(
227228
// Name
228229
Text(
229230
style = ElementTheme.typography.fontBodyLgMedium,
230-
text = name ?: stringResource(id = CommonStrings.common_no_room_name),
231+
text = name?.toSafeLength(ellipsize = true) ?: stringResource(id = CommonStrings.common_no_room_name),
231232
fontStyle = FontStyle.Italic.takeIf { name == null },
232233
color = ElementTheme.colors.roomListRoomName,
233234
maxLines = 1,
@@ -380,7 +381,7 @@ private fun InviteNameAndIndicatorRow(
380381
Text(
381382
modifier = Modifier.weight(1f),
382383
style = ElementTheme.typography.fontBodyLgMedium,
383-
text = name ?: stringResource(id = CommonStrings.common_no_room_name),
384+
text = name?.toSafeLength(ellipsize = true) ?: stringResource(id = CommonStrings.common_no_room_name),
384385
fontStyle = FontStyle.Italic.takeIf { name == null },
385386
color = ElementTheme.colors.roomListRoomName,
386387
maxLines = 1,

libraries/core/src/main/kotlin/io/element/android/libraries/core/extensions/BasicExtensions.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,16 @@ fun String.containsRtLOverride() = contains(RTL_OVERRIDE_CHAR)
100100

101101
fun String.filterDirectionOverrides() = filterNot { it == RTL_OVERRIDE_CHAR || it == LTR_OVERRIDE_CHAR }
102102

103+
const val DEFAULT_SAFE_LENGTH = 500
104+
103105
/**
104106
* This works around https://github.com/element-hq/element-x-android/issues/2105.
105107
* @param maxLength Max characters to retrieve. Defaults to `500`.
106108
* @param ellipsize Whether to add an ellipsis (`…`) char at the end or not. Defaults to `false`.
107109
* @return The string truncated to [maxLength] characters, with an optional ellipsis if larger.
108110
*/
109111
fun String.toSafeLength(
110-
maxLength: Int = 500,
112+
maxLength: Int = DEFAULT_SAFE_LENGTH,
111113
ellipsize: Boolean = false,
112114
): String {
113115
return if (ellipsize) {

0 commit comments

Comments
 (0)