From d42a3da5b7b5dc664fd0f01f847fe5f0d013f07c Mon Sep 17 00:00:00 2001 From: Florian Renaud Date: Tue, 14 Jun 2022 15:16:17 +0200 Subject: [PATCH] Reduce code smell --- .../timeline/item/MergedRoomCreationItem.kt | 82 +++++++++++-------- 1 file changed, 46 insertions(+), 36 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MergedRoomCreationItem.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MergedRoomCreationItem.kt index 5b7c4efc7f..cd60057379 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MergedRoomCreationItem.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MergedRoomCreationItem.kt @@ -16,6 +16,7 @@ package im.vector.app.features.home.room.detail.timeline.item +import android.content.res.Resources import android.text.SpannableString import android.text.method.MovementMethod import android.text.style.ClickableSpan @@ -25,7 +26,6 @@ import android.widget.ImageView import android.widget.TextView import androidx.constraintlayout.widget.ConstraintLayout import androidx.core.content.ContextCompat -import androidx.core.view.isGone import androidx.core.view.isVisible import androidx.core.view.updateLayoutParams import com.airbnb.epoxy.EpoxyAttribute @@ -39,6 +39,7 @@ import im.vector.app.features.home.room.detail.RoomDetailAction import im.vector.app.features.home.room.detail.timeline.TimelineEventController import im.vector.app.features.home.room.detail.timeline.tools.linkify import me.gujun.android.span.span +import org.matrix.android.sdk.api.extensions.orFalse import org.matrix.android.sdk.api.session.room.model.RoomSummary import org.matrix.android.sdk.api.session.room.model.localecho.RoomLocalEcho import org.matrix.android.sdk.api.util.toMatrixItem @@ -62,44 +63,45 @@ abstract class MergedRoomCreationItem : BasedMergedItem { - holder.expandView.resources.getString(R.string.direct_room_encryption_enabled_tile_description_future) - } - data?.isDirectRoom == true -> { - holder.expandView.resources.getString(R.string.direct_room_encryption_enabled_tile_description) - } - else -> { - holder.expandView.resources.getString(R.string.encryption_enabled_tile_description) - } - } + holder.e2eTitleDescriptionView.text = getE2ESecureDescriptionText(holder.expandView.resources, data) holder.e2eTitleDescriptionView.textAlignment = View.TEXT_ALIGNMENT_CENTER holder.e2eTitleTextView.setCompoundDrawablesWithIntrinsicBounds( ContextCompat.getDrawable(holder.view.context, R.drawable.ic_shield_black), @@ -137,17 +129,32 @@ abstract class MergedRoomCreationItem : BasedMergedItem { + if (attributes.isLocalRoom) { + resources.getString(R.string.direct_room_encryption_enabled_tile_description_future) + } else { + resources.getString(R.string.direct_room_encryption_enabled_tile_description) + } + } + else -> { + resources.getString(R.string.encryption_enabled_tile_description) + } + } + } + private fun bindCreationSummaryTile(holder: Holder) { val roomSummary = attributes.roomSummary val roomDisplayName = roomSummary?.displayName holder.roomNameText.setTextOrHide(roomDisplayName) val isDirect = roomSummary?.isDirect == true - val isLocalRoom = RoomLocalEcho.isLocalEchoId(roomSummary?.roomId.orEmpty()) val membersCount = roomSummary?.otherMemberIds?.size ?: 0 when { isDirect -> { - if (isLocalRoom) { + if (attributes.isLocalRoom) { holder.roomDescriptionText.text = holder.view.resources.getString( R.string.send_your_first_msg_to_invite, roomSummary?.displayName.orEmpty() @@ -261,5 +268,8 @@ abstract class MergedRoomCreationItem : BasedMergedItem