Replacing error prone takeIf structure

This commit is contained in:
Maxime NATUREL 2022-10-13 11:08:57 +02:00
parent 7be958e6a5
commit 7ce56ced4d
1 changed files with 25 additions and 28 deletions

View File

@ -162,9 +162,8 @@ class SessionInfoView @JvmOverloads constructor(
drawableProvider: DrawableProvider,
colorProvider: ColorProvider,
) {
deviceInfo.lastSeenTs
?.takeIf { isLastSeenDetailsVisible }
?.let { timestamp ->
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)
@ -185,11 +184,9 @@ class SessionInfoView @JvmOverloads constructor(
null
}
views.sessionInfoLastActivityTextView.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null)
}
?: run {
} else {
views.sessionInfoLastActivityTextView.isGone = true
}
views.sessionInfoLastIPAddressTextView.setTextOrHide(deviceInfo.lastSeenIp?.takeIf { isLastSeenDetailsVisible })
}