From cb05d10824790d3e583560ece25b35146d3e841b Mon Sep 17 00:00:00 2001 From: ganfra Date: Wed, 16 Jan 2019 10:41:32 +0100 Subject: [PATCH] Timeline : fix minor UI issues --- .../room/detail/timeline/MessageItemFactory.kt | 17 +++++++++++++---- .../detail/timeline/TimelineEventController.kt | 2 +- .../room/detail/timeline/TimelineItemFactory.kt | 5 +---- .../res/layout/item_timeline_event_notice.xml | 4 +++- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/MessageItemFactory.kt b/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/MessageItemFactory.kt index 2122e5457f..c1917b5aca 100644 --- a/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/MessageItemFactory.kt +++ b/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/MessageItemFactory.kt @@ -4,10 +4,11 @@ import android.text.SpannableStringBuilder import android.text.util.Linkify import im.vector.matrix.android.api.permalinks.MatrixLinkify import im.vector.matrix.android.api.permalinks.MatrixPermalinkSpan +import im.vector.matrix.android.api.session.events.model.EventType import im.vector.matrix.android.api.session.events.model.TimelineEvent import im.vector.matrix.android.api.session.events.model.toModel import im.vector.matrix.android.api.session.room.model.MessageContent -import org.threeten.bp.LocalDateTime +import im.vector.riotredesign.core.extensions.localDateTime class MessageItemFactory(private val timelineDateFormatter: TimelineDateFormatter) { @@ -15,8 +16,6 @@ class MessageItemFactory(private val timelineDateFormatter: TimelineDateFormatte fun create(event: TimelineEvent, nextEvent: TimelineEvent?, - addDaySeparator: Boolean, - date: LocalDateTime, callback: TimelineEventController.Callback? ): MessageItem? { @@ -26,7 +25,17 @@ class MessageItemFactory(private val timelineDateFormatter: TimelineDateFormatte return null } val nextRoomMember = nextEvent?.roomMember - if (addDaySeparator || nextRoomMember != roomMember) { + + val date = event.root.localDateTime() + val nextDate = nextEvent?.root?.localDateTime() + val addDaySeparator = date.toLocalDate() != nextDate?.toLocalDate() + val isNextMessageReceivedMoreThanOneHourAgo = nextDate?.isBefore(date.minusMinutes(60)) + ?: false + + if (addDaySeparator + || nextRoomMember != roomMember + || nextEvent.root.type != EventType.MESSAGE + || isNextMessageReceivedMoreThanOneHourAgo) { messagesDisplayedWithInformation.add(event.root.eventId) } 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 b388f3ab0a..caede52053 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 @@ -49,7 +49,7 @@ class TimelineEventController(private val roomId: String, val nextDate = nextEvent?.root?.localDateTime() val addDaySeparator = date.toLocalDate() != nextDate?.toLocalDate() - timelineItemFactory.create(event, nextEvent, addDaySeparator, date, callback)?.also { + timelineItemFactory.create(event, nextEvent, callback)?.also { it.id(event.localId) 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 fadc226822..0d8e1f86ae 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 @@ -3,7 +3,6 @@ package im.vector.riotredesign.features.home.room.detail.timeline import com.airbnb.epoxy.EpoxyModel import im.vector.matrix.android.api.session.events.model.EventType import im.vector.matrix.android.api.session.events.model.TimelineEvent -import org.threeten.bp.LocalDateTime class TimelineItemFactory(private val messageItemFactory: MessageItemFactory, private val roomNameItemFactory: RoomNameItemFactory, @@ -13,12 +12,10 @@ class TimelineItemFactory(private val messageItemFactory: MessageItemFactory, fun create(event: TimelineEvent, nextEvent: TimelineEvent?, - addDaySeparator: Boolean, - date: LocalDateTime, callback: TimelineEventController.Callback?): EpoxyModel<*>? { return when (event.root.type) { - EventType.MESSAGE -> messageItemFactory.create(event, nextEvent, addDaySeparator, date, callback) + 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) diff --git a/app/src/main/res/layout/item_timeline_event_notice.xml b/app/src/main/res/layout/item_timeline_event_notice.xml index 169fe15656..5edd7d345c 100644 --- a/app/src/main/res/layout/item_timeline_event_notice.xml +++ b/app/src/main/res/layout/item_timeline_event_notice.xml @@ -4,7 +4,9 @@ xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" - android:layout_height="wrap_content"> + android:layout_height="wrap_content" + android:paddingLeft="16dp" + android:paddingRight="16dp">