Skip to content

Commit

Permalink
fix: Localised DateFormat in device info (#2785)
Browse files Browse the repository at this point in the history
Co-authored-by: boris <[email protected]>
Co-authored-by: Oussama Hassine <[email protected]>
Co-authored-by: Yamil Medina <[email protected]>
  • Loading branch information
4 people authored Mar 12, 2024
1 parent 07832e7 commit 04d6946
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import com.wire.android.ui.joinConversation.JoinConversationViaCodeState
import com.wire.android.ui.joinConversation.JoinConversationViaDeepLinkDialog
import com.wire.android.ui.joinConversation.JoinConversationViaInviteLinkError
import com.wire.android.ui.theme.WireTheme
import com.wire.android.util.formatMediumDateTime
import com.wire.android.util.deviceDateTimeFormat
import com.wire.android.util.ui.PreviewMultipleThemes
import com.wire.android.util.ui.UIText
import com.wire.kalium.logic.configuration.server.ServerConfig
Expand Down Expand Up @@ -319,7 +319,7 @@ fun NewClientDialog(
val devicesList = data.clientsInfo.map {
stringResource(
R.string.new_device_dialog_message_defice_info,
it.date.formatMediumDateTime() ?: "",
it.date.deviceDateTimeFormat() ?: "",
it.deviceInfo.asString()
)
}.joinToString("")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ import com.wire.android.ui.theme.wireDimensions
import com.wire.android.ui.theme.wireTypography
import com.wire.android.util.extension.formatAsFingerPrint
import com.wire.android.util.extension.formatAsString
import com.wire.android.util.formatMediumDateTime
import com.wire.android.util.deviceDateTimeFormat
import com.wire.android.util.ui.PreviewMultipleThemes
import com.wire.android.util.ui.UIText

Expand Down Expand Up @@ -227,14 +227,14 @@ private fun DeviceItemTexts(
stringResource(
R.string.remove_device_id_and_time_label_active_label,
device.clientId.formatAsString(),
device.registrationTime.formatMediumDateTime() ?: "",
device.registrationTime.deviceDateTimeFormat() ?: "",
device.lastActiveDescription() ?: ""
)
} else {
stringResource(
R.string.remove_device_id_and_time_label,
device.clientId.formatAsString(),
device.registrationTime.formatMediumDateTime() ?: ""
device.registrationTime.deviceDateTimeFormat() ?: ""
)
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import com.wire.android.ui.common.button.WireButtonState
import com.wire.android.ui.common.textfield.WirePasswordTextField
import com.wire.android.ui.common.textfield.WireTextFieldState
import com.wire.android.ui.theme.wireDimensions
import com.wire.android.util.formatMediumDateTime
import com.wire.android.util.deviceDateTimeFormat

@OptIn(ExperimentalComposeUiApi::class)
@Composable
Expand All @@ -63,7 +63,7 @@ fun RemoveDeviceDialog(
stringResource(
R.string.remove_device_id_and_time_label,
state.device.clientId.value,
state.device.registrationTime?.formatMediumDateTime() ?: ""
state.device.registrationTime?.deviceDateTimeFormat() ?: ""
),
onDismiss = onDialogDismissHideKeyboard,
dismissButtonProperties = WireDialogButtonProperties(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ import com.wire.android.util.CustomTabsHelper
import com.wire.android.util.dialogErrorStrings
import com.wire.android.util.extension.formatAsFingerPrint
import com.wire.android.util.extension.formatAsString
import com.wire.android.util.formatMediumDateTime
import com.wire.android.util.deviceDateTimeFormat
import com.wire.android.util.ui.UIText
import com.wire.kalium.logic.CoreFailure
import com.wire.kalium.logic.data.conversation.ClientId
Expand Down Expand Up @@ -216,7 +216,7 @@ fun DeviceDetailsContent(
Divider(color = MaterialTheme.wireColorScheme.background)
}

state.device.registrationTime?.formatMediumDateTime()?.let {
state.device.registrationTime?.deviceDateTimeFormat()?.let {
item {
DeviceDetailSectionContent(
stringResource(id = R.string.label_client_added_time),
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/kotlin/com/wire/android/util/DateTimeUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ private val serverDateTimeFormat = SimpleDateFormat(
).apply { timeZone = TimeZone.getTimeZone("UTC") }
private val mediumDateTimeFormat = DateFormat
.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM)
private val longDateShortTimeFormat = DateFormat
.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT)
private val mediumOnlyDateTimeFormat = DateFormat
.getDateInstance(DateFormat.MEDIUM)
private val messageTimeFormatter = DateFormat
Expand Down Expand Up @@ -61,6 +63,13 @@ fun String.formatMediumDateTime(): String? =
null
}

fun String.deviceDateTimeFormat(): String? =
try {
this.serverDate()?.let { longDateShortTimeFormat.format(it) }
} catch (e: ParseException) {
null
}

fun String.formatFullDateShortTime(): String? =
try {
this.serverDate()?.let { fullDateShortTimeFormatter.format(it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,16 @@ class DateTimeUtilKtTest {

@Test
fun `given a invalid date, when performing a transformation, then return null`() {
val result = "NOT_VALID".formatMediumDateTime()
val result = "NOT_VALID".deviceDateTimeFormat()
assertEquals(null, result)
}

@Test
fun `given a valid date, when performing a transformation for device, then return with medium format`() {
val result = "2022-03-24T18:02:30.360Z".deviceDateTimeFormat()
assertEquals("March 24, 2022, 6:02 PM", result)
}

@Test
fun `given a valid date, when performing a transformation, then return with medium format`() {
val result = "2022-03-24T18:02:30.360Z".formatMediumDateTime()
Expand Down
2 changes: 1 addition & 1 deletion kalium
Submodule kalium updated 50 files
+1 βˆ’1 gradle/libs.versions.toml
+6 βˆ’3 logic/src/commonMain/kotlin/com/wire/kalium/logic/CoreFailure.kt
+3 βˆ’4 logic/src/commonMain/kotlin/com/wire/kalium/logic/configuration/UserConfigRepository.kt
+11 βˆ’2 logic/src/commonMain/kotlin/com/wire/kalium/logic/data/call/CallRepository.kt
+1 βˆ’1 logic/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/ConversationGroupRepository.kt
+1 βˆ’1 logic/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/JoinExistingMLSConversationsUseCase.kt
+8 βˆ’3 logic/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/MLSConversationRepository.kt
+26 βˆ’0 logic/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/mls/KeyPackageClaimResult.kt
+18 βˆ’5 logic/src/commonMain/kotlin/com/wire/kalium/logic/data/keypackage/KeyPackageRepository.kt
+1 βˆ’1 logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/conversation/mls/OneOnOneResolver.kt
+3 βˆ’1 logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/e2ei/usecase/GetE2EICertificateUseCase.kt
+23 βˆ’13 logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/featureConfig/handler/E2EIConfigHandler.kt
+1 βˆ’1 logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/message/MLSMessageCreator.kt
+3 βˆ’3 logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/message/PendingProposalScheduler.kt
+1 βˆ’1 logic/src/commonTest/kotlin/com/wire/kalium/logic/data/conversation/ConversationGroupRepositoryTest.kt
+84 βˆ’28 logic/src/commonTest/kotlin/com/wire/kalium/logic/data/conversation/MLSConversationRepositoryTest.kt
+50 βˆ’8 logic/src/commonTest/kotlin/com/wire/kalium/logic/data/keypackage/KeyPackageRepositoryTest.kt
+1 βˆ’1 ...src/commonTest/kotlin/com/wire/kalium/logic/feature/conversation/JoinExistingMLSConversationsUseCaseTest.kt
+12 βˆ’4 monkeys/src/main/kotlin/com/wire/kalium/monkeys/ActionScheduler.kt
+18 βˆ’3 monkeys/src/main/kotlin/com/wire/kalium/monkeys/MetricsCollector.kt
+14 βˆ’14 monkeys/src/main/kotlin/com/wire/kalium/monkeys/MonkeyApplication.kt
+14 βˆ’1 monkeys/src/main/kotlin/com/wire/kalium/monkeys/ReplayApplication.kt
+2 βˆ’1 monkeys/src/main/kotlin/com/wire/kalium/monkeys/actions/Action.kt
+7 βˆ’4 monkeys/src/main/kotlin/com/wire/kalium/monkeys/actions/AddUserToConversationAction.kt
+3 βˆ’3 monkeys/src/main/kotlin/com/wire/kalium/monkeys/actions/CreateConversationAction.kt
+5 βˆ’5 monkeys/src/main/kotlin/com/wire/kalium/monkeys/actions/DestroyConversationAction.kt
+2 βˆ’1 monkeys/src/main/kotlin/com/wire/kalium/monkeys/actions/HandleExternalRequestAction.kt
+5 βˆ’5 monkeys/src/main/kotlin/com/wire/kalium/monkeys/actions/LeaveConversationAction.kt
+2 βˆ’1 monkeys/src/main/kotlin/com/wire/kalium/monkeys/actions/LoginAction.kt
+2 βˆ’1 monkeys/src/main/kotlin/com/wire/kalium/monkeys/actions/ReconnectAction.kt
+2 βˆ’1 monkeys/src/main/kotlin/com/wire/kalium/monkeys/actions/SendExternalRequestAction.kt
+5 βˆ’5 monkeys/src/main/kotlin/com/wire/kalium/monkeys/actions/SendMessageAction.kt
+2 βˆ’1 monkeys/src/main/kotlin/com/wire/kalium/monkeys/actions/SendRequestAction.kt
+5 βˆ’2 monkeys/src/main/kotlin/com/wire/kalium/monkeys/actions/replay/AddUserToConversationEventAction.kt
+2 βˆ’2 monkeys/src/main/kotlin/com/wire/kalium/monkeys/actions/replay/CreateConversationEventAction.kt
+2 βˆ’2 monkeys/src/main/kotlin/com/wire/kalium/monkeys/actions/replay/DestroyConversationEventAction.kt
+2 βˆ’2 monkeys/src/main/kotlin/com/wire/kalium/monkeys/actions/replay/LeaveConversationEventAction.kt
+2 βˆ’1 monkeys/src/main/kotlin/com/wire/kalium/monkeys/actions/replay/LogoutEventAction.kt
+2 βˆ’1 monkeys/src/main/kotlin/com/wire/kalium/monkeys/actions/replay/RequestResponseEventAction.kt
+2 βˆ’1 monkeys/src/main/kotlin/com/wire/kalium/monkeys/actions/replay/SendDirectMessageEventAction.kt
+2 βˆ’2 monkeys/src/main/kotlin/com/wire/kalium/monkeys/actions/replay/SendMessageEventAction.kt
+2 βˆ’1 monkeys/src/main/kotlin/com/wire/kalium/monkeys/actions/replay/SendRequestEventAction.kt
+4 βˆ’5 monkeys/src/main/kotlin/com/wire/kalium/monkeys/conversation/LocalMonkey.kt
+3 βˆ’2 monkeys/src/main/kotlin/com/wire/kalium/monkeys/conversation/Monkey.kt
+3 βˆ’4 monkeys/src/main/kotlin/com/wire/kalium/monkeys/conversation/MonkeyConversation.kt
+2 βˆ’2 monkeys/src/main/kotlin/com/wire/kalium/monkeys/conversation/RemoteMonkey.kt
+10 βˆ’4 monkeys/src/main/kotlin/com/wire/kalium/monkeys/pool/ConversationPool.kt
+7 βˆ’0 monkeys/src/main/kotlin/com/wire/kalium/monkeys/server/model/ServerModel.kt
+2 βˆ’16 monkeys/src/main/kotlin/com/wire/kalium/monkeys/server/routes/Monitoring.kt
+5 βˆ’5 monkeys/src/main/kotlin/com/wire/kalium/monkeys/server/routes/Monkey.kt

0 comments on commit 04d6946

Please sign in to comment.