Remove string duplication
This commit is contained in:
@@ -19,6 +19,7 @@ import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.tooling.preview.PreviewParameter
|
||||
import androidx.compose.ui.unit.dp
|
||||
import io.element.android.compound.theme.ElementTheme
|
||||
import io.element.android.compound.tokens.generated.CompoundIcons
|
||||
@@ -71,8 +72,7 @@ fun CreateDmConfirmationBottomSheet(
|
||||
)
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
Text(
|
||||
// TODO Check if finally we do not want to remove string duplication
|
||||
text = stringResource(R.string.screen_bottom_sheet_create_dm_message_no_displayname, matrixUser.getFullName()),
|
||||
text = stringResource(R.string.screen_bottom_sheet_create_dm_message, matrixUser.getFullName()),
|
||||
style = ElementTheme.typography.fontBodyMdRegular,
|
||||
color = ElementTheme.colors.textSecondary,
|
||||
textAlign = TextAlign.Center,
|
||||
@@ -97,9 +97,9 @@ fun CreateDmConfirmationBottomSheet(
|
||||
|
||||
@PreviewsDayNight
|
||||
@Composable
|
||||
internal fun CreateDmConfirmationBottomSheetPreview() = ElementPreview {
|
||||
internal fun CreateDmConfirmationBottomSheetPreview(@PreviewParameter(MatrixUserProvider::class) matrixUser: MatrixUser) = ElementPreview {
|
||||
CreateDmConfirmationBottomSheet(
|
||||
matrixUser = aMatrixUser(),
|
||||
matrixUser = matrixUser,
|
||||
onSendInvite = {},
|
||||
onDismiss = {},
|
||||
)
|
||||
|
||||
@@ -7,9 +7,12 @@
|
||||
|
||||
package io.element.android.libraries.matrix.ui.model
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import io.element.android.libraries.designsystem.components.avatar.AvatarData
|
||||
import io.element.android.libraries.designsystem.components.avatar.AvatarSize
|
||||
import io.element.android.libraries.matrix.api.user.MatrixUser
|
||||
import io.element.android.libraries.ui.strings.CommonStrings
|
||||
|
||||
fun MatrixUser.getAvatarData(size: AvatarSize) = AvatarData(
|
||||
id = userId.value,
|
||||
@@ -22,10 +25,13 @@ fun MatrixUser.getBestName(): String {
|
||||
return displayName?.takeIf { it.isNotEmpty() } ?: userId.value
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun MatrixUser.getFullName(): String {
|
||||
return if (displayName.isNullOrBlank()) {
|
||||
userId.value
|
||||
} else {
|
||||
"$displayName ($userId)"
|
||||
return displayName.let { name ->
|
||||
if (name.isNullOrBlank()) {
|
||||
userId.value
|
||||
} else {
|
||||
stringResource(CommonStrings.common_name_and_id, name, userId.value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
|
||||
<string name="screen_bottom_sheet_create_dm_confirmation_button_title">"Send invite"</string>
|
||||
<string name="screen_bottom_sheet_create_dm_message">"Would you like to start a chat with %1$s (%2$s)?"</string>
|
||||
<string name="screen_bottom_sheet_create_dm_message_no_displayname">"Would you like to start a chat with %1$s?"</string>
|
||||
<string name="screen_bottom_sheet_create_dm_message">"Would you like to start a chat with %1$s?"</string>
|
||||
<string name="screen_bottom_sheet_create_dm_title">"Send invite?"</string>
|
||||
<string name="screen_invites_invited_you">"%1$s (%2$s) invited you"</string>
|
||||
</resources>
|
||||
|
||||
@@ -7,14 +7,27 @@
|
||||
|
||||
package io.element.android.libraries.matrix.ui.model
|
||||
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import app.cash.molecule.RecompositionMode
|
||||
import app.cash.molecule.moleculeFlow
|
||||
import app.cash.turbine.test
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import io.element.android.libraries.designsystem.components.avatar.AvatarData
|
||||
import io.element.android.libraries.designsystem.components.avatar.AvatarSize
|
||||
import io.element.android.libraries.matrix.api.user.MatrixUser
|
||||
import io.element.android.libraries.matrix.test.A_USER_ID
|
||||
import io.element.android.tests.testutils.WarmUpRule
|
||||
import io.element.android.tests.testutils.withConfigurationAndContext
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class MatrixUserExtensionsTest {
|
||||
@get:Rule
|
||||
val warmUpRule = WarmUpRule()
|
||||
|
||||
@Test
|
||||
fun `getAvatarData should return the expected value`() {
|
||||
val matrixUser = MatrixUser(
|
||||
@@ -59,20 +72,30 @@ class MatrixUserExtensionsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getFullName should return the display name is available and the userId`() {
|
||||
fun `getFullName should return the display name is available and the userId`() = runTest {
|
||||
val matrixUser = MatrixUser(
|
||||
userId = A_USER_ID,
|
||||
displayName = "displayName",
|
||||
)
|
||||
assertThat(matrixUser.getFullName()).isEqualTo("displayName (@alice:server.org)")
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
withConfigurationAndContext {
|
||||
matrixUser.getFullName()
|
||||
}
|
||||
}.test {
|
||||
assertThat(awaitItem()).isEqualTo("displayName (@alice:server.org)")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBestName should return only the id when name is not available`() {
|
||||
fun `getBestName should return only the id when name is not available`() = runTest {
|
||||
val matrixUser = MatrixUser(
|
||||
userId = A_USER_ID,
|
||||
displayName = null,
|
||||
)
|
||||
assertThat(matrixUser.getFullName()).isEqualTo(A_USER_ID.value)
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
matrixUser.getFullName()
|
||||
}.test {
|
||||
assertThat(awaitItem()).isEqualTo(A_USER_ID.value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,6 +193,7 @@ Reason: %1$s."</string>
|
||||
<string name="common_message_removed">"Message removed"</string>
|
||||
<string name="common_modern">"Modern"</string>
|
||||
<string name="common_mute">"Mute"</string>
|
||||
<string name="common_name_and_id">"%1$s (%2$s)"</string>
|
||||
<string name="common_no_results">"No results"</string>
|
||||
<string name="common_no_room_name">"No room name"</string>
|
||||
<string name="common_offline">"Offline"</string>
|
||||
|
||||
Reference in New Issue
Block a user