From 1b82a1a24d277a1c2cbd2446b9d4e637a636d7a3 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 6 Sep 2019 15:52:29 +0200 Subject: [PATCH] Cleanup --- .../timeline/format/NoticeEventFormatter.kt | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/format/NoticeEventFormatter.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/format/NoticeEventFormatter.kt index 33306dcb..da5a3d41 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/format/NoticeEventFormatter.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/format/NoticeEventFormatter.kt @@ -16,7 +16,6 @@ package im.vector.riotx.features.home.room.detail.timeline.format -import android.text.TextUtils import im.vector.matrix.android.api.session.events.model.Event import im.vector.matrix.android.api.session.events.model.EventType import im.vector.matrix.android.api.session.events.model.toModel @@ -76,10 +75,10 @@ class NoticeEventFormatter @Inject constructor(private val sessionHolder: Active private fun formatRoomNameEvent(event: Event, senderName: String?): CharSequence? { val content = event.getClearContent().toModel() ?: return null - return if (!TextUtils.isEmpty(content.name)) { - stringProvider.getString(R.string.notice_room_name_changed, senderName, content.name) - } else { + return if (content.name.isNullOrBlank()) { stringProvider.getString(R.string.notice_room_name_removed, senderName) + } else { + stringProvider.getString(R.string.notice_room_name_changed, senderName, content.name) } } @@ -139,7 +138,7 @@ class NoticeEventFormatter @Inject constructor(private val sessionHolder: Active private fun buildProfileNotice(event: Event, senderName: String?, eventContent: RoomMember?, prevEventContent: RoomMember?): String? { val displayText = StringBuilder() // Check display name has been changed - if (!TextUtils.equals(eventContent?.displayName, prevEventContent?.displayName)) { + if (eventContent?.displayName != prevEventContent?.displayName) { val displayNameText = when { prevEventContent?.displayName.isNullOrEmpty() -> stringProvider.getString(R.string.notice_display_name_set, event.senderId, eventContent?.displayName) @@ -152,7 +151,7 @@ class NoticeEventFormatter @Inject constructor(private val sessionHolder: Active displayText.append(displayNameText) } // Check whether the avatar has been changed - if (!TextUtils.equals(eventContent?.avatarUrl, prevEventContent?.avatarUrl)) { + if (eventContent?.avatarUrl != prevEventContent?.avatarUrl) { val displayAvatarText = if (displayText.isNotEmpty()) { displayText.append(" ") stringProvider.getString(R.string.notice_avatar_changed_too) @@ -171,16 +170,16 @@ class NoticeEventFormatter @Inject constructor(private val sessionHolder: Active Membership.INVITE == eventContent?.membership -> { val selfUserId = sessionHolder.getSafeActiveSession()?.myUserId when { - eventContent.thirdPartyInvite != null -> { + eventContent.thirdPartyInvite != null -> { val userWhoHasAccepted = eventContent.thirdPartyInvite?.signed?.mxid ?: event.stateKey stringProvider.getString(R.string.notice_room_third_party_registered_invite, userWhoHasAccepted, eventContent.thirdPartyInvite?.displayName) } - TextUtils.equals(event.stateKey, selfUserId) -> + event.stateKey == selfUserId -> stringProvider.getString(R.string.notice_room_invite_you, senderDisplayName) - event.stateKey.isNullOrEmpty() -> + event.stateKey.isNullOrEmpty() -> stringProvider.getString(R.string.notice_room_invite_no_invitee, senderDisplayName) - else -> + else -> stringProvider.getString(R.string.notice_room_invite, senderDisplayName, targetDisplayName) } } @@ -188,7 +187,7 @@ class NoticeEventFormatter @Inject constructor(private val sessionHolder: Active stringProvider.getString(R.string.notice_room_join, senderDisplayName) Membership.LEAVE == eventContent?.membership -> // 2 cases here: this member may have left voluntarily or they may have been "left" by someone else ie. kicked - return if (TextUtils.equals(event.senderId, event.stateKey)) { + return if (event.senderId == event.stateKey) { if (prevEventContent?.membership == Membership.INVITE) { stringProvider.getString(R.string.notice_room_reject, senderDisplayName) } else {