Skip to content

Commit

Permalink
Rendering inactive status in SessionInfoView
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxime NATUREL committed Sep 5, 2022
1 parent 1c501a0 commit af48481
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

<style name="TextAppearance.Vector.Body.DevicesManagement">
<item name="android:textColor">?vctr_content_secondary</item>
<item name="android:drawablePadding">12dp</item>
</style>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,18 @@ 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
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

Expand All @@ -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 {
Expand Down Expand Up @@ -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) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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() {
Expand Down
10 changes: 5 additions & 5 deletions vector/src/main/res/layout/view_session_info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />

<TextView
android:id="@+id/sessionInfoLastIPAddressTextView"
Expand All @@ -95,11 +95,11 @@
android:layout_marginHorizontal="32dp"
android:gravity="center"
android:visibility="gone"
tools:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/sessionInfoLastActivityTextView"
tools:text="81.235.41.100 (United Kingdom)" />
tools:text="81.235.41.100 (United Kingdom)"
tools:visibility="visible" />

<Button
android:id="@+id/sessionInfoVerifySessionButton"
Expand Down

0 comments on commit af48481

Please sign in to comment.