Replacing error prone takeIf structure
This commit is contained in:
parent
7be958e6a5
commit
7ce56ced4d
|
@ -162,34 +162,31 @@ 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)
|
context.resources.getQuantityString(
|
||||||
context.resources.getQuantityString(
|
R.plurals.device_manager_other_sessions_description_inactive,
|
||||||
R.plurals.device_manager_other_sessions_description_inactive,
|
SESSION_IS_MARKED_AS_INACTIVE_AFTER_DAYS,
|
||||||
SESSION_IS_MARKED_AS_INACTIVE_AFTER_DAYS,
|
SESSION_IS_MARKED_AS_INACTIVE_AFTER_DAYS,
|
||||||
SESSION_IS_MARKED_AS_INACTIVE_AFTER_DAYS,
|
formattedTs
|
||||||
formattedTs
|
)
|
||||||
)
|
} else {
|
||||||
} else {
|
val formattedTs = dateFormatter.format(timestamp, DateFormatKind.DEFAULT_DATE_AND_TIME)
|
||||||
val formattedTs = dateFormatter.format(timestamp, DateFormatKind.DEFAULT_DATE_AND_TIME)
|
context.getString(R.string.device_manager_session_last_activity, formattedTs)
|
||||||
context.getString(R.string.device_manager_session_last_activity, formattedTs)
|
}
|
||||||
}
|
val drawable = if (isInactive) {
|
||||||
val drawable = if (isInactive) {
|
val drawableColor = colorProvider.getColorFromAttribute(R.attr.vctr_content_secondary)
|
||||||
val drawableColor = colorProvider.getColorFromAttribute(R.attr.vctr_content_secondary)
|
drawableProvider.getDrawable(R.drawable.ic_inactive_sessions, drawableColor)
|
||||||
drawableProvider.getDrawable(R.drawable.ic_inactive_sessions, drawableColor)
|
} else {
|
||||||
} else {
|
null
|
||||||
null
|
}
|
||||||
}
|
views.sessionInfoLastActivityTextView.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null)
|
||||||
views.sessionInfoLastActivityTextView.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null)
|
} else {
|
||||||
}
|
views.sessionInfoLastActivityTextView.isGone = true
|
||||||
?: run {
|
}
|
||||||
views.sessionInfoLastActivityTextView.isGone = true
|
|
||||||
}
|
|
||||||
|
|
||||||
views.sessionInfoLastIPAddressTextView.setTextOrHide(deviceInfo.lastSeenIp?.takeIf { isLastSeenDetailsVisible })
|
views.sessionInfoLastIPAddressTextView.setTextOrHide(deviceInfo.lastSeenIp?.takeIf { isLastSeenDetailsVisible })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue