From 6e9b2baf6f5b8f052c1bc01cf8c5a6b2d5bc3a36 Mon Sep 17 00:00:00 2001 From: Maxime NATUREL Date: Mon, 5 Sep 2022 09:40:02 +0200 Subject: [PATCH] Rendering inactive status in SessionInfoView --- .../res/values/styles_devices_management.xml | 1 + .../v2/VectorSettingsDevicesFragment.kt | 10 +++- .../devices/v2/list/SessionInfoView.kt | 46 ++++++++++++++++--- .../v2/overview/SessionOverviewFragment.kt | 8 +++- .../src/main/res/layout/view_session_info.xml | 10 ++-- 5 files changed, 61 insertions(+), 14 deletions(-) diff --git a/library/ui-styles/src/main/res/values/styles_devices_management.xml b/library/ui-styles/src/main/res/values/styles_devices_management.xml index 2a63c2ed36..6fb236d3e6 100644 --- a/library/ui-styles/src/main/res/values/styles_devices_management.xml +++ b/library/ui-styles/src/main/res/values/styles_devices_management.xml @@ -7,6 +7,7 @@ diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/VectorSettingsDevicesFragment.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/VectorSettingsDevicesFragment.kt index 2262f083da..10ebf3a42f 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/VectorSettingsDevicesFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/VectorSettingsDevicesFragment.kt @@ -34,6 +34,8 @@ import im.vector.app.R import im.vector.app.core.date.VectorDateFormatter import im.vector.app.core.dialogs.ManuallyVerifyDialog import im.vector.app.core.platform.VectorBaseFragment +import im.vector.app.core.resources.ColorProvider +import im.vector.app.core.resources.DrawableProvider import im.vector.app.databinding.FragmentSettingsDevicesBinding import im.vector.app.features.crypto.recover.SetupMode import im.vector.app.features.crypto.verification.VerificationBottomSheet @@ -41,9 +43,9 @@ import im.vector.app.features.settings.devices.DeviceFullInfo import im.vector.app.features.settings.devices.DevicesAction import im.vector.app.features.settings.devices.DevicesViewEvents import im.vector.app.features.settings.devices.DevicesViewModel +import im.vector.app.features.settings.devices.v2.list.OtherSessionsController import im.vector.app.features.settings.devices.v2.list.SESSION_IS_MARKED_AS_INACTIVE_AFTER_DAYS import im.vector.app.features.settings.devices.v2.list.SecurityRecommendationViewState -import im.vector.app.features.settings.devices.v2.list.OtherSessionsController import im.vector.app.features.settings.devices.v2.list.SessionInfoViewState import javax.inject.Inject @@ -58,6 +60,10 @@ class VectorSettingsDevicesFragment : @Inject lateinit var dateFormatter: VectorDateFormatter + @Inject lateinit var drawableProvider: DrawableProvider + + @Inject lateinit var colorProvider: ColorProvider + private val viewModel: DevicesViewModel by fragmentViewModel() override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentSettingsDevicesBinding { @@ -217,7 +223,7 @@ class VectorSettingsDevicesFragment : isCurrentSession = true, deviceFullInfo = it ) - views.deviceListCurrentSession.render(viewState, dateFormatter) + views.deviceListCurrentSession.render(viewState, dateFormatter, drawableProvider, colorProvider) views.deviceListCurrentSession.debouncedClicks { currentDeviceInfo.deviceInfo.deviceId?.let { deviceId -> navigateToSessionOverview(deviceId) } } 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 df50666b3b..767f09482b 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 @@ -25,6 +25,8 @@ import im.vector.app.R import im.vector.app.core.date.DateFormatKind import im.vector.app.core.date.VectorDateFormatter import im.vector.app.core.extensions.setTextWithColoredPart +import im.vector.app.core.resources.ColorProvider +import im.vector.app.core.resources.DrawableProvider import im.vector.app.databinding.ViewSessionInfoBinding import im.vector.app.features.themes.ThemeUtils import org.matrix.android.sdk.api.session.crypto.model.DeviceInfo @@ -47,14 +49,26 @@ class SessionInfoView @JvmOverloads constructor( val viewDetailsButton = views.sessionInfoViewDetailsButton - fun render(sessionInfoViewState: SessionInfoViewState, dateFormatter: VectorDateFormatter) { + fun render( + sessionInfoViewState: SessionInfoViewState, + dateFormatter: VectorDateFormatter, + drawableProvider: DrawableProvider, + colorProvider: ColorProvider, + ) { renderDeviceInfo(sessionInfoViewState.deviceFullInfo.deviceInfo.displayName.orEmpty()) renderVerificationStatus( sessionInfoViewState.deviceFullInfo.trustLevelForShield, sessionInfoViewState.isCurrentSession, - sessionInfoViewState.isLearnMoreLinkVisible + sessionInfoViewState.isLearnMoreLinkVisible, + ) + renderDeviceLastSeenDetails( + sessionInfoViewState.deviceFullInfo.isInactive, + sessionInfoViewState.deviceFullInfo.deviceInfo, + sessionInfoViewState.isLastSeenDetailsVisible, + dateFormatter, + drawableProvider, + colorProvider, ) - renderDeviceLastSeenDetails(sessionInfoViewState.deviceFullInfo.deviceInfo, dateFormatter, sessionInfoViewState.isLastSeenDetailsVisible) renderDetailsButton(sessionInfoViewState.isDetailsButtonVisible) } @@ -123,16 +137,36 @@ class SessionInfoView @JvmOverloads constructor( } private fun renderDeviceLastSeenDetails( + isInactive: Boolean, deviceInfo: DeviceInfo, - dateFormatter: VectorDateFormatter, isLastSeenDetailsVisible: Boolean, + dateFormatter: VectorDateFormatter, + drawableProvider: DrawableProvider, + colorProvider: ColorProvider, ) { deviceInfo.lastSeenTs ?.takeIf { isLastSeenDetailsVisible } ?.let { timestamp -> views.sessionInfoLastActivityTextView.isVisible = true - val formattedTs = dateFormatter.format(timestamp, DateFormatKind.DEFAULT_DATE_AND_TIME) - views.sessionInfoLastActivityTextView.text = context.getString(R.string.device_manager_session_last_activity, formattedTs) + 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 diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewFragment.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewFragment.kt index dbe75c94cc..a6bac6087b 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewFragment.kt @@ -31,6 +31,8 @@ import dagger.hilt.android.AndroidEntryPoint import im.vector.app.R import im.vector.app.core.date.VectorDateFormatter import im.vector.app.core.platform.VectorBaseFragment +import im.vector.app.core.resources.ColorProvider +import im.vector.app.core.resources.DrawableProvider import im.vector.app.databinding.FragmentSessionOverviewBinding import im.vector.app.features.settings.devices.DeviceFullInfo import im.vector.app.features.settings.devices.v2.list.SessionInfoViewState @@ -45,6 +47,10 @@ class SessionOverviewFragment : @Inject lateinit var dateFormatter: VectorDateFormatter + @Inject lateinit var drawableProvider: DrawableProvider + + @Inject lateinit var colorProvider: ColorProvider + private val viewModel: SessionOverviewViewModel by fragmentViewModel() override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentSessionOverviewBinding { @@ -96,7 +102,7 @@ class SessionOverviewFragment : isLearnMoreLinkVisible = true, isLastSeenDetailsVisible = true, ) - views.sessionOverviewInfo.render(viewState, dateFormatter) + views.sessionOverviewInfo.render(viewState, dateFormatter, drawableProvider, colorProvider) } private fun hideSessionInfo() { diff --git a/vector/src/main/res/layout/view_session_info.xml b/vector/src/main/res/layout/view_session_info.xml index 49e1ebbb77..18daae825a 100644 --- a/vector/src/main/res/layout/view_session_info.xml +++ b/vector/src/main/res/layout/view_session_info.xml @@ -79,13 +79,13 @@ android:layout_height="wrap_content" android:layout_marginHorizontal="32dp" android:layout_marginTop="12dp" - android:gravity="center" android:visibility="gone" - tools:visibility="visible" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/sessionInfoVerificationStatusDetailTextView" - tools:text="Last activity Fri 14:59" /> + app:layout_constraintWidth="wrap_content_constrained" + tools:text="Last activity Fri 14:59" + tools:visibility="visible" /> + tools:text="81.235.41.100 (United Kingdom)" + tools:visibility="visible" />