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 6371440d1a..b5c24a4480 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,7 +16,6 @@ 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 @@ -39,7 +38,6 @@ 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 @@ -53,6 +51,14 @@ abstract class MergedRoomCreationItem : BasedMergedItem { this.marginEnd = leftGuideline } if (attributes.isEncryptionAlgorithmSecure) { - holder.e2eTitleTextView.text = holder.expandView.resources.getString(R.string.encryption_enabled) - 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), - null, null, null - ) + renderE2ESecureTile(holder) } else { - holder.e2eTitleTextView.text = holder.expandView.resources.getString(R.string.encryption_not_enabled) - holder.e2eTitleDescriptionView.text = holder.expandView.resources.getString(R.string.encryption_unknown_algorithm_tile_description) - holder.e2eTitleTextView.setCompoundDrawablesWithIntrinsicBounds( - ContextCompat.getDrawable(holder.view.context, R.drawable.ic_shield_warning), - null, null, null - ) + renderE2EUnsecureTile(holder) } } else { holder.encryptionTile.isVisible = false } } - private fun getE2ESecureDescriptionText(resources: Resources, data: Data?): String { - val isDirectRoom = data?.isDirectRoom.orFalse() - return when { + private fun renderE2ESecureTile(holder: Holder) { + val resources = holder.expandView.resources + val description = when { isDirectRoom -> { if (attributes.isLocalRoom) { resources.getString(R.string.direct_room_encryption_enabled_tile_description_future) @@ -143,65 +138,36 @@ abstract class MergedRoomCreationItem : BasedMergedItem { - if (attributes.isLocalRoom) { - holder.roomDescriptionText.text = holder.view.resources.getString( - R.string.send_your_first_msg_to_invite, - roomSummary?.displayName.orEmpty() - ) - } else { - holder.roomDescriptionText.text = holder.view.resources.getString( - R.string.this_is_the_beginning_of_dm, - roomSummary?.displayName.orEmpty() - ) - } - } - roomDisplayName.isNullOrBlank() || roomSummary.name.isBlank() -> { - holder.roomDescriptionText.text = holder.view.resources.getString(R.string.this_is_the_beginning_of_room_no_name) - } - else -> { - holder.roomDescriptionText.text = holder.view.resources.getString(R.string.this_is_the_beginning_of_room, roomDisplayName) - } - } - - val topic = roomSummary?.topic - if (topic.isNullOrBlank()) { - // do not show hint for DMs or group DMs - val canSetTopic = attributes.canChangeTopic && !isDirect - if (canSetTopic) { - val addTopicLink = holder.view.resources.getString(R.string.add_a_topic_link_text) - val styledText = SpannableString(holder.view.resources.getString(R.string.room_created_summary_no_topic_creation_text, addTopicLink)) - holder.roomTopicText.setTextOrHide(styledText.tappableMatchingText(addTopicLink, object : ClickableSpan() { - override fun onClick(widget: View) { - attributes.callback?.onTimelineItemAction(RoomDetailAction.QuickActionSetTopic) - } - })) - } - } else { - holder.roomTopicText.setTextOrHide( - span { - span(holder.view.resources.getString(R.string.topic_prefix)) { - textStyle = "bold" - } - +topic.linkify(attributes.callback) - } - ) - } - holder.roomTopicText.movementMethod = movementMethod + holder.roomNameText.setTextOrHide(roomDisplayName) + renderRoomDescription(holder) + renderRoomTopic(holder) val roomItem = roomSummary?.toMatrixItem() val shouldSetAvatar = attributes.canChangeAvatar && - (roomSummary?.isDirect == false || (isDirect && membersCount >= 2)) && + (roomSummary?.isDirect == false || (isDirectRoom && membersCount >= 2)) && roomItem?.avatarUrl.isNullOrBlank() holder.roomAvatarImageView.isVisible = roomItem != null @@ -224,7 +190,7 @@ abstract class MergedRoomCreationItem : BasedMergedItem { + if (attributes.isLocalRoom) { + holder.roomDescriptionText.text = holder.view.resources.getString( + R.string.send_your_first_msg_to_invite, + roomSummary?.displayName.orEmpty() + ) + } else { + holder.roomDescriptionText.text = holder.view.resources.getString( + R.string.this_is_the_beginning_of_dm, + roomSummary?.displayName.orEmpty() + ) + } + } + roomDisplayName.isNullOrBlank() || roomSummary?.name.isNullOrBlank() -> { + holder.roomDescriptionText.text = holder.view.resources.getString(R.string.this_is_the_beginning_of_room_no_name) + } + else -> { + holder.roomDescriptionText.text = holder.view.resources.getString(R.string.this_is_the_beginning_of_room, roomDisplayName) + } + } + } + + private fun renderRoomTopic(holder: Holder) { + val topic = roomSummary?.topic + if (topic.isNullOrBlank()) { + // do not show hint for DMs or group DMs + val canSetTopic = attributes.canChangeTopic && !isDirectRoom + if (canSetTopic) { + val addTopicLink = holder.view.resources.getString(R.string.add_a_topic_link_text) + val styledText = SpannableString(holder.view.resources.getString(R.string.room_created_summary_no_topic_creation_text, addTopicLink)) + holder.roomTopicText.setTextOrHide(styledText.tappableMatchingText(addTopicLink, object : ClickableSpan() { + override fun onClick(widget: View) { + attributes.callback?.onTimelineItemAction(RoomDetailAction.QuickActionSetTopic) + } + })) + } + } else { + holder.roomTopicText.setTextOrHide( + span { + span(holder.view.resources.getString(R.string.topic_prefix)) { + textStyle = "bold" + } + +topic.linkify(attributes.callback) + } + ) + } + holder.roomTopicText.movementMethod = movementMethod + } + class Holder : BasedMergedItem.Holder(STUB_ID) { val mergedView by bind(R.id.mergedSumContainer) val summaryView by bind(R.id.itemNoticeTextView)