From 9cc2cf8360855511efba0b9d36573b0729707bea Mon Sep 17 00:00:00 2001 From: ganfra Date: Wed, 20 Feb 2019 16:14:12 +0100 Subject: [PATCH] Timeline: set empty item as fallback item --- .../RoomHistoryVisibilityItemFactory.kt | 4 ++-- .../timeline/TimelineEventController.kt | 2 +- .../detail/timeline/TimelineItemFactory.kt | 21 +++++++++++-------- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/RoomHistoryVisibilityItemFactory.kt b/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/RoomHistoryVisibilityItemFactory.kt index e692b81de2..91972af2cf 100644 --- a/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/RoomHistoryVisibilityItemFactory.kt +++ b/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/RoomHistoryVisibilityItemFactory.kt @@ -32,14 +32,14 @@ class RoomHistoryVisibilityItemFactory(private val stringProvider: StringProvide fun create(event: TimelineEvent): NoticeItem? { val roomMember = event.roomMember ?: return null - val noticeText = buildRoomMemberNotice(event.root, roomMember) ?: return null + val noticeText = buildNoticeText(event.root, roomMember) ?: return null return NoticeItem_() .noticeText(noticeText) .avatarUrl(roomMember.avatarUrl) .memberName(roomMember.displayName) } - private fun buildRoomMemberNotice(event: Event, roomMember: RoomMember): CharSequence? { + private fun buildNoticeText(event: Event, roomMember: RoomMember): CharSequence? { val content = event.content.toModel() ?: return null val formattedVisibility = when (content.historyVisibility) { RoomHistoryVisibility.SHARED -> stringProvider.getString(R.string.notice_room_visibility_shared) diff --git a/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/TimelineEventController.kt b/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/TimelineEventController.kt index 373612c1ac..0d12ae8e45 100644 --- a/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/TimelineEventController.kt +++ b/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/TimelineEventController.kt @@ -74,7 +74,7 @@ class TimelineEventController(private val roomId: String, val nextDate = nextEvent?.root?.localDateTime() val addDaySeparator = date.toLocalDate() != nextDate?.toLocalDate() - timelineItemFactory.create(event, nextEvent, callback)?.also { + timelineItemFactory.create(event, nextEvent, callback).also { it.id(event.localId) it.setOnVisibilityStateChanged(TimelineEventVisibilityStateChangedListener(callback, event, currentPosition)) epoxyModels.add(it) diff --git a/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/TimelineItemFactory.kt b/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/TimelineItemFactory.kt index 5909a01cf6..80ed553a51 100644 --- a/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/TimelineItemFactory.kt +++ b/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/TimelineItemFactory.kt @@ -31,29 +31,32 @@ class TimelineItemFactory(private val messageItemFactory: MessageItemFactory, fun create(event: TimelineEvent, nextEvent: TimelineEvent?, - callback: TimelineEventController.Callback?): RiotEpoxyModel<*>? { + callback: TimelineEventController.Callback?): RiotEpoxyModel<*> { - return try { + val computedModel = try { when (event.root.type) { EventType.MESSAGE -> messageItemFactory.create(event, nextEvent, callback) EventType.STATE_ROOM_NAME -> roomNameItemFactory.create(event) EventType.STATE_ROOM_TOPIC -> roomTopicItemFactory.create(event) EventType.STATE_ROOM_MEMBER -> roomMemberItemFactory.create(event) EventType.STATE_HISTORY_VISIBILITY -> roomHistoryVisibilityItemFactory.create(event) + EventType.CALL_INVITE, EventType.CALL_HANGUP, EventType.CALL_ANSWER -> callItemFactory.create(event) - EventType.STATE_ROOM_CREATE, - EventType.STATE_ROOM_POWER_LEVELS, - EventType.STATE_ROOM_JOIN_RULES, - EventType.STATE_ROOM_GUEST_ACCESS, - EventType.CALL_CANDIDATES, - EventType.REDACTION -> EmptyItem_() - else -> defaultItemFactory.create(event) + + EventType.ENCRYPTED, + EventType.ENCRYPTION, + EventType.STATE_ROOM_THIRD_PARTY_INVITE, + EventType.STICKER, + EventType.STATE_ROOM_CREATE -> defaultItemFactory.create(event) + + else -> null } } catch (e: Exception) { defaultItemFactory.create(event, e) } + return computedModel ?: EmptyItem_() } } \ No newline at end of file