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, drawableProvider: DrawableProvider,
colorProvider: ColorProvider, colorProvider: ColorProvider,
) { ) {
deviceInfo.lastSeenTs if (deviceInfo.lastSeenTs != null && isLastSeenDetailsVisible) {
?.takeIf { isLastSeenDetailsVisible } val timestamp = deviceInfo.lastSeenTs
?.let { timestamp ->
views.sessionInfoLastActivityTextView.isVisible = true views.sessionInfoLastActivityTextView.isVisible = true
views.sessionInfoLastActivityTextView.text = if (isInactive) { views.sessionInfoLastActivityTextView.text = if (isInactive) {
val formattedTs = dateFormatter.format(timestamp, DateFormatKind.TIMELINE_DAY_DIVIDER) val formattedTs = dateFormatter.format(timestamp, DateFormatKind.TIMELINE_DAY_DIVIDER)
@ -185,11 +184,9 @@ class SessionInfoView @JvmOverloads constructor(
null null
} }
views.sessionInfoLastActivityTextView.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null) views.sessionInfoLastActivityTextView.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null)
} } else {
?: run {
views.sessionInfoLastActivityTextView.isGone = true views.sessionInfoLastActivityTextView.isGone = true
} }
views.sessionInfoLastIPAddressTextView.setTextOrHide(deviceInfo.lastSeenIp?.takeIf { isLastSeenDetailsVisible }) views.sessionInfoLastIPAddressTextView.setTextOrHide(deviceInfo.lastSeenIp?.takeIf { isLastSeenDetailsVisible })
} }