Fix description of inactive sessions.

This commit is contained in:
Onuray Sahin 2022-08-31 19:11:12 +03:00 committed by Maxime NATUREL
parent 396da93a93
commit ed1244aa8f
5 changed files with 21 additions and 2 deletions

View file

@ -3225,6 +3225,7 @@
<string name="device_manager_other_sessions_view_all">View All (%1$d)</string>
<string name="device_manager_other_sessions_description_verified">Verified · Last activity %1$s</string>
<string name="device_manager_other_sessions_description_unverified">Unverified · Last activity %1$s</string>
<string name="device_manager_other_sessions_description_inactive">Inactive for %1$d+ days (%2$s)</string>
<string name="device_manager_header_section_security_recommendations_title">Security recommendations</string>
<string name="device_manager_header_section_security_recommendations_description">Improve your account security by following these recommendations.</string>
<string name="device_manager_unverified_sessions_title">Unverified sessions</string>

View file

@ -91,6 +91,7 @@ data class DeviceFullInfo(
val deviceInfo: DeviceInfo,
val cryptoDeviceInfo: CryptoDeviceInfo?,
val trustLevelForShield: RoomEncryptionTrustLevel,
val isInactive: Boolean,
)
class DevicesViewModel @AssistedInject constructor(
@ -148,7 +149,8 @@ class DevicesViewModel @AssistedInject constructor(
deviceTrustLevel = cryptoDeviceInfo?.trustLevel,
isCurrentDevice = deviceInfo.deviceId == session.sessionParams.deviceId
)
DeviceFullInfo(deviceInfo, cryptoDeviceInfo, trustLevelForShield)
val isInactive = checkIfSessionIsInactiveUseCase.execute(deviceInfo.lastSeenTs ?: 0)
DeviceFullInfo(deviceInfo, cryptoDeviceInfo, trustLevelForShield, isInactive)
}
}
.distinctUntilChanged()

View file

@ -16,6 +16,7 @@
package im.vector.app.features.settings.devices.v2.list
import android.graphics.drawable.Drawable
import android.widget.ImageView
import android.widget.TextView
import com.airbnb.epoxy.EpoxyAttribute
@ -42,6 +43,9 @@ abstract class OtherSessionItem : VectorEpoxyModel<OtherSessionItem.Holder>(R.la
@EpoxyAttribute
var sessionDescription: String? = null
@EpoxyAttribute
var sessionDescriptionDrawable: Drawable? = null
@EpoxyAttribute
lateinit var stringProvider: StringProvider
@ -68,6 +72,7 @@ abstract class OtherSessionItem : VectorEpoxyModel<OtherSessionItem.Holder>(R.la
holder.otherSessionVerificationStatusImageView.render(roomEncryptionTrustLevel)
holder.otherSessionNameTextView.text = sessionName
holder.otherSessionDescriptionTextView.text = sessionDescription
holder.otherSessionDescriptionTextView.setCompoundDrawablesWithIntrinsicBounds(sessionDescriptionDrawable, null, null, null)
}
class Holder : VectorEpoxyHolder() {

View file

@ -21,6 +21,7 @@ import im.vector.app.R
import im.vector.app.core.date.DateFormatKind
import im.vector.app.core.date.VectorDateFormatter
import im.vector.app.core.epoxy.noResultItem
import im.vector.app.core.resources.DrawableProvider
import im.vector.app.core.resources.StringProvider
import im.vector.app.features.settings.devices.DeviceFullInfo
import org.matrix.android.sdk.api.session.crypto.model.RoomEncryptionTrustLevel
@ -29,6 +30,7 @@ import javax.inject.Inject
class OtherSessionsController @Inject constructor(
private val stringProvider: StringProvider,
private val dateFormatter: VectorDateFormatter,
private val drawableProvider: DrawableProvider,
) : TypedEpoxyController<List<DeviceFullInfo>>() {
override fun buildModels(data: List<DeviceFullInfo>?) {
@ -42,11 +44,18 @@ class OtherSessionsController @Inject constructor(
} else {
data.take(NUMBER_OF_OTHER_DEVICES_TO_RENDER).forEach { device ->
val formattedLastActivityDate = host.dateFormatter.format(device.deviceInfo.lastSeenTs, DateFormatKind.DEFAULT_DATE_AND_TIME)
val description = if (device.trustLevelForShield == RoomEncryptionTrustLevel.Trusted) {
val description = if (device.isInactive) {
stringProvider.getString(
R.string.device_manager_other_sessions_description_inactive,
SESSION_IS_MARKED_AS_INACTIVE_AFTER_DAYS,
formattedLastActivityDate
)
} else if (device.trustLevelForShield == RoomEncryptionTrustLevel.Trusted) {
stringProvider.getString(R.string.device_manager_other_sessions_description_verified, formattedLastActivityDate)
} else {
stringProvider.getString(R.string.device_manager_other_sessions_description_unverified, formattedLastActivityDate)
}
val descriptionDrawable = if (device.isInactive) drawableProvider.getDrawable(R.drawable.ic_inactive_sessions) else null
otherSessionItem {
id(device.deviceInfo.deviceId)
@ -54,6 +63,7 @@ class OtherSessionsController @Inject constructor(
roomEncryptionTrustLevel(device.trustLevelForShield)
sessionName(device.deviceInfo.displayName)
sessionDescription(description)
sessionDescriptionDrawable(descriptionDrawable)
stringProvider(this@OtherSessionsController.stringProvider)
}
}

View file

@ -50,6 +50,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:drawablePadding="8dp"
app:layout_constraintStart_toStartOf="@id/otherSessionNameTextView"
app:layout_constraintTop_toBottomOf="@id/otherSessionNameTextView"
tools:text="@string/device_manager_verification_status_verified" />