From 7ce56ced4d31a5d5c6029700f422377d6c72559b Mon Sep 17 00:00:00 2001 From: Maxime NATUREL Date: Thu, 13 Oct 2022 11:08:57 +0200 Subject: [PATCH] Replacing error prone takeIf structure --- .../devices/v2/list/SessionInfoView.kt | 53 +++++++++---------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/list/SessionInfoView.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/list/SessionInfoView.kt index bef3f5c9e4..9603085a57 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/list/SessionInfoView.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/list/SessionInfoView.kt @@ -162,34 +162,31 @@ class SessionInfoView @JvmOverloads constructor( drawableProvider: DrawableProvider, colorProvider: ColorProvider, ) { - deviceInfo.lastSeenTs - ?.takeIf { isLastSeenDetailsVisible } - ?.let { timestamp -> - views.sessionInfoLastActivityTextView.isVisible = true - views.sessionInfoLastActivityTextView.text = if (isInactive) { - val formattedTs = dateFormatter.format(timestamp, DateFormatKind.TIMELINE_DAY_DIVIDER) - context.resources.getQuantityString( - R.plurals.device_manager_other_sessions_description_inactive, - SESSION_IS_MARKED_AS_INACTIVE_AFTER_DAYS, - SESSION_IS_MARKED_AS_INACTIVE_AFTER_DAYS, - formattedTs - ) - } else { - val formattedTs = dateFormatter.format(timestamp, DateFormatKind.DEFAULT_DATE_AND_TIME) - context.getString(R.string.device_manager_session_last_activity, formattedTs) - } - val drawable = if (isInactive) { - val drawableColor = colorProvider.getColorFromAttribute(R.attr.vctr_content_secondary) - drawableProvider.getDrawable(R.drawable.ic_inactive_sessions, drawableColor) - } else { - null - } - views.sessionInfoLastActivityTextView.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null) - } - ?: run { - views.sessionInfoLastActivityTextView.isGone = true - } - + if (deviceInfo.lastSeenTs != null && isLastSeenDetailsVisible) { + val timestamp = deviceInfo.lastSeenTs + views.sessionInfoLastActivityTextView.isVisible = true + views.sessionInfoLastActivityTextView.text = if (isInactive) { + val formattedTs = dateFormatter.format(timestamp, DateFormatKind.TIMELINE_DAY_DIVIDER) + context.resources.getQuantityString( + R.plurals.device_manager_other_sessions_description_inactive, + SESSION_IS_MARKED_AS_INACTIVE_AFTER_DAYS, + SESSION_IS_MARKED_AS_INACTIVE_AFTER_DAYS, + formattedTs + ) + } else { + val formattedTs = dateFormatter.format(timestamp, DateFormatKind.DEFAULT_DATE_AND_TIME) + context.getString(R.string.device_manager_session_last_activity, formattedTs) + } + val drawable = if (isInactive) { + val drawableColor = colorProvider.getColorFromAttribute(R.attr.vctr_content_secondary) + drawableProvider.getDrawable(R.drawable.ic_inactive_sessions, drawableColor) + } else { + null + } + views.sessionInfoLastActivityTextView.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null) + } else { + views.sessionInfoLastActivityTextView.isGone = true + } views.sessionInfoLastIPAddressTextView.setTextOrHide(deviceInfo.lastSeenIp?.takeIf { isLastSeenDetailsVisible }) }