Skip to content

Commit

Permalink
feat: display when a self client was last active (#1958)
Browse files Browse the repository at this point in the history
  • Loading branch information
typfel authored Jul 19, 2023
1 parent 224feef commit 03cdb40
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import androidx.compose.ui.unit.dp
import com.wire.android.BuildConfig
import com.wire.android.R
import com.wire.android.ui.authentication.devices.model.Device
import com.wire.android.ui.authentication.devices.model.lastActiveDescription
import com.wire.android.ui.common.button.WireSecondaryButton
import com.wire.android.ui.common.button.getMinTouchMargins
import com.wire.android.ui.common.button.wireSecondaryButtonColors
Expand Down Expand Up @@ -199,11 +200,20 @@ private fun DeviceItemTexts(

Spacer(modifier = Modifier.height(MaterialTheme.wireDimensions.removeDeviceItemTitleVerticalPadding))
val details: String = if (!device.registrationTime.isNullOrBlank()) {
stringResource(
R.string.remove_device_id_and_time_label,
device.clientId.formatAsString(),
device.registrationTime.formatMediumDateTime() ?: ""
)
if (device.lastActiveInWholeWeeks != null) {
stringResource(
R.string.remove_device_id_and_time_label_active_label,
device.clientId.formatAsString(),
device.registrationTime.formatMediumDateTime() ?: "",
device.lastActiveDescription() ?: ""
)
} else {
stringResource(
R.string.remove_device_id_and_time_label,
device.clientId.formatAsString(),
device.registrationTime.formatMediumDateTime() ?: ""
)
}
} else {
stringResource(
R.string.remove_device_id_label,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,31 @@

package com.wire.android.ui.authentication.devices.model

import androidx.compose.runtime.Composable
import androidx.compose.runtime.Stable
import androidx.compose.ui.res.pluralStringResource
import androidx.compose.ui.res.stringResource
import com.wire.android.R
import com.wire.android.util.ui.UIText
import com.wire.kalium.logic.data.client.Client
import com.wire.kalium.logic.data.conversation.ClientId
import com.wire.kalium.logic.util.inWholeWeeks
import com.wire.kalium.util.DateTimeUtil.toIsoDateTimeString
import kotlinx.datetime.Clock

data class Device(
val name: UIText = UIText.DynamicString(""),
val clientId: ClientId = ClientId(""),
val registrationTime: String? = null,
val lastActiveInWholeWeeks: Int? = null,
val isValid: Boolean = true,
val isVerified: Boolean = false
) {
constructor(client: Client) : this(
client.displayName(),
client.id,
client.registrationTime?.toIsoDateTimeString(),
true,
client.lastActiveInWholeWeeks(),
client.isVerified
)
}
Expand All @@ -50,3 +56,21 @@ data class Device(
fun Client.displayName(): UIText = (model ?: deviceType?.name)?.let {
UIText.DynamicString(it)
} ?: UIText.StringResource(R.string.device_name_unknown)

fun Client.lastActiveInWholeWeeks(): Int? {
return lastActive?.let { (Clock.System.now() - it).inWholeWeeks.toInt() }
}

@Stable
@Composable
fun Device.lastActiveDescription(): String? =
lastActiveInWholeWeeks?.let {
if (it == 0) {
stringResource(R.string.label_client_last_active_time_zero_weeks)
} else {
stringResource(
R.string.label_client_last_active_time,
pluralStringResource(R.plurals.weeks_long_label, it, it)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import com.wire.android.BuildConfig
import com.wire.android.R
import com.wire.android.navigation.hiltSavedStateViewModel
import com.wire.android.ui.authentication.devices.model.Device
import com.wire.android.ui.authentication.devices.model.lastActiveDescription
import com.wire.android.ui.authentication.devices.remove.RemoveDeviceDialog
import com.wire.android.ui.authentication.devices.remove.RemoveDeviceDialogState
import com.wire.android.ui.authentication.devices.remove.RemoveDeviceError
Expand Down Expand Up @@ -156,6 +157,16 @@ fun DeviceDetailsContent(
}
}

state.device.lastActiveInWholeWeeks?.let {
item {
DeviceDetailSectionContent(
stringResource(id = R.string.label_client_last_active_label),
AnnotatedString(state.device.lastActiveDescription() ?: "")
)
Divider(color = MaterialTheme.wireColorScheme.background)
}
}

item {
DeviceIdItem(state, screenState::copyMessage)
Divider(color = MaterialTheme.wireColorScheme.background)
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@
</string>
<string name="remove_device_label">YOUR DEVICES</string>
<string name="remove_device_id_and_time_label">ID: %1$s\nAdded: %2$s</string>
<string name="remove_device_id_and_time_label_active_label">ID: %1$s\nAdded: %2$s\nActive: %3$s</string>
<string name="remove_device_id_label">ID: %1$s</string>
<string name="remove_device_dialog_title">Remove the following device?</string>
<string name="remove_device_invalid_password">Invalid password</string>
Expand Down Expand Up @@ -882,6 +883,9 @@
<string name="label_code_commit_id">Commit Hash: %1$s</string>
<string name="label_client_id">Client ID: %1$s</string>
<string name="label_client_added_time">ADDED</string>
<string name="label_client_last_active_label">LAST ACTIVE</string>
<string name="label_client_last_active_time_zero_weeks">Less than a week ago</string>
<string name="label_client_last_active_time">%1$s ago</string>
<string name="label_client_device_id">DEVICE ID</string>
<string name="label_key_packages_count">Key-packages count</string>
<string name="label_mls_client_id">MLS Client ID</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ object TestClient {
val CLIENT_ID = ClientId("test")

val CLIENT = Client(
CLIENT_ID, ClientType.Permanent, Instant.DISTANT_FUTURE, false,
CLIENT_ID, ClientType.Permanent, Instant.DISTANT_FUTURE, Instant.DISTANT_PAST, false,
isValid = true, DeviceType.Desktop, "label", null
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class RegisterDeviceViewModelTest {
companion object {
val CLIENT_ID = ClientId("test")
val CLIENT = Client(
CLIENT_ID, ClientType.Permanent, Instant.DISTANT_FUTURE, false,
CLIENT_ID, ClientType.Permanent, Instant.DISTANT_FUTURE, Instant.DISTANT_PAST, false,
isValid = true, DeviceType.Desktop, "label", null
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ class LoginEmailViewModelTest {
companion object {
val CLIENT_ID = ClientId("test")
val CLIENT = Client(
CLIENT_ID, ClientType.Permanent, Instant.DISTANT_FUTURE, false,
CLIENT_ID, ClientType.Permanent, Instant.DISTANT_FUTURE, Instant.DISTANT_PAST, false,
isValid = true, DeviceType.Desktop, "label", null
)
val SSO_ID: SsoId = SsoId("scim_id", null, null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ class LoginSSOViewModelTest {
CLIENT_ID,
ClientType.Permanent,
Instant.DISTANT_FUTURE,
Instant.DISTANT_PAST,
false,
isValid = true,
DeviceType.Desktop,
Expand Down

0 comments on commit 03cdb40

Please sign in to comment.