From c7c76d1e67ba7bcd561a3f47610386a2f6abaa3b Mon Sep 17 00:00:00 2001 From: ganfra Date: Tue, 30 Mar 2021 20:04:26 +0200 Subject: [PATCH] Timeline: clean code and update CHANGES --- CHANGES.md | 3 ++- .../sdk/internal/database/mapper/TimelineEventMapper.kt | 1 - .../session/room/timeline/DefaultTimelineService.kt | 1 - .../sdk/internal/session/room/timeline/UIEchoManager.kt | 1 - .../vector/app/core/resources/UserPreferencesProvider.kt | 3 --- .../home/room/detail/ScrollOnHighlightedEventCallback.kt | 1 - .../home/room/detail/timeline/TimelineEventController.kt | 2 +- .../room/detail/timeline/factory/TimelineItemFactory.kt | 2 +- .../detail/timeline/factory/TimelineItemFactoryParams.kt | 4 ++-- .../detail/timeline/factory/VerificationItemFactory.kt | 2 +- .../detail/timeline/helper/TimelineDisplayableEvents.kt | 2 -- .../timeline/helper/TimelineEventVisibilityHelper.kt | 9 ++++----- .../home/room/detail/timeline/item/AbsBaseMessageItem.kt | 1 - .../home/room/detail/timeline/item/BaseEventItem.kt | 2 -- .../home/room/detail/timeline/item/BasedMergedItem.kt | 2 -- .../home/room/detail/timeline/item/DefaultItem.kt | 4 +--- .../home/room/detail/timeline/item/ItemWithEvents.kt | 1 - .../detail/timeline/item/MergedMembershipEventsItem.kt | 2 -- .../home/room/detail/timeline/item/NoticeItem.kt | 1 - 19 files changed, 12 insertions(+), 32 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 1a095d20be..1020401f91 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -13,6 +13,7 @@ Improvements 🙌: - Api interceptor to allow app developers peek responses (#2986) - Update reactions to Unicode 13.1 (#2998) - Be more robust when parsing some enums + - Improve timeline filtering (dissociate membership and profile events, display hidden events when highlighted, fix hidden item/read receipts behavior) Bugfix 🐛: - Fix bad theme change for the MainActivity @@ -23,7 +24,7 @@ Translations 🗣: - SDK API changes ⚠️: - - + - Removes filtering options on Timeline. Build 🧱: - diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/mapper/TimelineEventMapper.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/mapper/TimelineEventMapper.kt index 07954650b2..f3bea68c26 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/mapper/TimelineEventMapper.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/mapper/TimelineEventMapper.kt @@ -17,7 +17,6 @@ package org.matrix.android.sdk.internal.database.mapper import org.matrix.android.sdk.api.session.events.model.Event -import org.matrix.android.sdk.api.session.room.model.ReadReceipt import org.matrix.android.sdk.api.session.room.sender.SenderInfo import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent import org.matrix.android.sdk.internal.database.model.TimelineEventEntity diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/DefaultTimelineService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/DefaultTimelineService.kt index 6b50e2e8de..8de36d0427 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/DefaultTimelineService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/DefaultTimelineService.kt @@ -31,7 +31,6 @@ import org.matrix.android.sdk.api.session.room.timeline.TimelineService import org.matrix.android.sdk.api.session.room.timeline.TimelineSettings import org.matrix.android.sdk.api.util.Optional import org.matrix.android.sdk.internal.database.RealmSessionProvider -import org.matrix.android.sdk.internal.database.mapper.ReadReceiptsSummaryMapper import org.matrix.android.sdk.internal.database.mapper.TimelineEventMapper import org.matrix.android.sdk.internal.database.model.TimelineEventEntity import org.matrix.android.sdk.internal.database.model.TimelineEventEntityFields diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/UIEchoManager.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/UIEchoManager.kt index 44326ce1ac..4804fbd731 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/UIEchoManager.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/UIEchoManager.kt @@ -71,7 +71,6 @@ internal class UIEchoManager( } fun onLocalEchoCreated(timelineEvent: TimelineEvent) { - // Manage some ui echos (do it before filter because actual event could be filtered out) when (timelineEvent.root.getClearType()) { EventType.REDACTION -> { diff --git a/vector/src/main/java/im/vector/app/core/resources/UserPreferencesProvider.kt b/vector/src/main/java/im/vector/app/core/resources/UserPreferencesProvider.kt index 04da5394f2..9ab3b9bf45 100644 --- a/vector/src/main/java/im/vector/app/core/resources/UserPreferencesProvider.kt +++ b/vector/src/main/java/im/vector/app/core/resources/UserPreferencesProvider.kt @@ -48,7 +48,4 @@ class UserPreferencesProvider @Inject constructor(private val vectorPreferences: fun shouldShowAvatarDisplayNameChanges(): Boolean { return vectorPreferences.showAvatarDisplayNameChangeMessages() } - - - } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/ScrollOnHighlightedEventCallback.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/ScrollOnHighlightedEventCallback.kt index 72f827e469..5d3a91f18d 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/ScrollOnHighlightedEventCallback.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/ScrollOnHighlightedEventCallback.kt @@ -20,7 +20,6 @@ import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import im.vector.app.core.platform.DefaultListUpdateCallback import im.vector.app.features.home.room.detail.timeline.TimelineEventController -import org.matrix.android.sdk.api.session.room.timeline.Timeline import timber.log.Timber import java.util.concurrent.atomic.AtomicReference diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/TimelineEventController.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/TimelineEventController.kt index 6c19f30cf0..b67527c24c 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/TimelineEventController.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/TimelineEventController.kt @@ -428,7 +428,7 @@ class TimelineEventController @Inject constructor(private val dateFormatter: Vec private fun getReadReceiptsByShownEvent(): Map> { val receiptsByEvent = HashMap>() - if(!userPreferencesProvider.shouldShowReadReceipts()){ + if (!userPreferencesProvider.shouldShowReadReceipts()) { return receiptsByEvent } var lastShownEventId: String? = null diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/TimelineItemFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/TimelineItemFactory.kt index 09b17eb901..47bc60eb75 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/TimelineItemFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/TimelineItemFactory.kt @@ -60,7 +60,7 @@ class TimelineItemFactory @Inject constructor(private val messageItemFactory: Me EventType.STATE_ROOM_HISTORY_VISIBILITY, EventType.STATE_ROOM_SERVER_ACL, EventType.STATE_ROOM_GUEST_ACCESS, - EventType.REDACTION , + EventType.REDACTION, EventType.STATE_ROOM_ALIASES, EventType.KEY_VERIFICATION_ACCEPT, EventType.KEY_VERIFICATION_START, diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/TimelineItemFactoryParams.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/TimelineItemFactoryParams.kt index dfd9fd2370..caf7204a01 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/TimelineItemFactoryParams.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/TimelineItemFactoryParams.kt @@ -23,8 +23,8 @@ data class TimelineItemFactoryParams( val event: TimelineEvent, val prevEvent: TimelineEvent? = null, val nextEvent: TimelineEvent? = null, - val highlightedEventId: String? = null , - val lastSentEventIdWithoutReadReceipts: String? = null , + val highlightedEventId: String? = null, + val lastSentEventIdWithoutReadReceipts: String? = null, val callback: TimelineEventController.Callback? = null ) { diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/VerificationItemFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/VerificationItemFactory.kt index 51951fdc8d..e972ddcab5 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/VerificationItemFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/VerificationItemFactory.kt @@ -74,7 +74,7 @@ class VerificationItemFactory @Inject constructor( val referenceInformationData = messageInformationDataFactory.create(TimelineItemFactoryParams(refEvent)) val informationData = messageInformationDataFactory.create(params) - val attributes = messageItemAttributesFactory.create(null, informationData,params.callback) + val attributes = messageItemAttributesFactory.create(null, informationData, params.callback) when (event.root.getClearType()) { EventType.KEY_VERIFICATION_CANCEL -> { diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/TimelineDisplayableEvents.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/TimelineDisplayableEvents.kt index a597fb966e..053b804a82 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/TimelineDisplayableEvents.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/TimelineDisplayableEvents.kt @@ -16,7 +16,6 @@ package im.vector.app.features.home.room.detail.timeline.helper -import im.vector.app.core.extensions.localDateTime import org.matrix.android.sdk.api.session.events.model.EventType import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent @@ -53,7 +52,6 @@ object TimelineDisplayableEvents { EventType.KEY_VERIFICATION_DONE, EventType.KEY_VERIFICATION_CANCEL ) - } fun TimelineEvent.canBeMerged(): Boolean { diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/TimelineEventVisibilityHelper.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/TimelineEventVisibilityHelper.kt index e55b02fe85..580d7d18cf 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/TimelineEventVisibilityHelper.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/TimelineEventVisibilityHelper.kt @@ -29,14 +29,13 @@ import javax.inject.Inject class TimelineEventVisibilityHelper @Inject constructor(private val userPreferencesProvider: UserPreferencesProvider) { - /** * @param timelineEvents the events to search in * @param index the index to start computing (inclusive) * @param minSize the minimum number of same type events to have sequentially, otherwise will return an empty list * @param eventIdToHighlight used to compute visibility * - * @return a list of timeline events which have sequentially the same type following the next direction. + * @return a list of timeline events which have sequentially the same type following the next direction. */ fun nextSameTypeEvents(timelineEvents: List, index: Int, minSize: Int, eventIdToHighlight: String?): List { if (index >= timelineEvents.size - 1) { @@ -60,7 +59,7 @@ class TimelineEventVisibilityHelper @Inject constructor(private val userPreferen } else { nextSameDayEvents.subList(0, indexOfFirstDifferentEventType) } - val filteredSameTypeEvents = sameTypeEvents.filter { shouldShowEvent(it, eventIdToHighlight)} + val filteredSameTypeEvents = sameTypeEvents.filter { shouldShowEvent(it, eventIdToHighlight) } if (filteredSameTypeEvents.size < minSize) { return emptyList() } @@ -128,12 +127,12 @@ class TimelineEventVisibilityHelper @Inject constructor(private val userPreferen val content = root.getClearContent().toModel() val prevContent = root.resolvedPrevContent().toModel() - val isMembershipChanged = content?.membership != prevContent?.membership; + val isMembershipChanged = content?.membership != prevContent?.membership val isJoin = isMembershipChanged && content?.membership == Membership.JOIN val isPart = isMembershipChanged && content?.membership == Membership.LEAVE && root.stateKey == root.senderId val isProfileChanged = !isMembershipChanged && content?.membership == Membership.JOIN - val isDisplaynameChange = isProfileChanged && content?.displayName != prevContent?.displayName; + val isDisplaynameChange = isProfileChanged && content?.displayName != prevContent?.displayName val isAvatarChange = isProfileChanged && content?.avatarUrl !== prevContent?.avatarUrl return MembershipDiff( diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsBaseMessageItem.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsBaseMessageItem.kt index a5f3f7c547..39c04af089 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsBaseMessageItem.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsBaseMessageItem.kt @@ -24,7 +24,6 @@ import androidx.annotation.IdRes import androidx.core.view.isVisible import im.vector.app.R import im.vector.app.core.ui.views.ShieldImageView -import im.vector.app.core.utils.DebouncedClickListener import im.vector.app.features.home.AvatarRenderer import im.vector.app.features.home.room.detail.timeline.MessageColorProvider import im.vector.app.features.home.room.detail.timeline.TimelineEventController diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/BaseEventItem.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/BaseEventItem.kt index 85fcc306f6..7d539f9df7 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/BaseEventItem.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/BaseEventItem.kt @@ -26,7 +26,6 @@ import im.vector.app.R import im.vector.app.core.epoxy.VectorEpoxyHolder import im.vector.app.core.epoxy.VectorEpoxyModel import im.vector.app.core.platform.CheckableView -import im.vector.app.core.ui.views.ReadReceiptsView import im.vector.app.core.utils.DimensionConverter /** @@ -44,7 +43,6 @@ abstract class BaseEventItem : VectorEpoxyModel @EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) lateinit var dimensionConverter: DimensionConverter - @CallSuper override fun bind(holder: H) { super.bind(holder) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/BasedMergedItem.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/BasedMergedItem.kt index 8a49bd6803..1c56a0809e 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/BasedMergedItem.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/BasedMergedItem.kt @@ -19,10 +19,8 @@ package im.vector.app.features.home.room.detail.timeline.item import android.view.View import android.widget.TextView import androidx.annotation.IdRes -import androidx.core.view.isVisible import im.vector.app.R import im.vector.app.features.home.AvatarRenderer -import im.vector.app.features.home.room.detail.timeline.TimelineEventController import org.matrix.android.sdk.api.util.MatrixItem abstract class BasedMergedItem : BaseEventItem() { diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/DefaultItem.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/DefaultItem.kt index 580a56bf05..e6c6e1d372 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/DefaultItem.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/DefaultItem.kt @@ -22,9 +22,7 @@ import android.widget.TextView import com.airbnb.epoxy.EpoxyAttribute import com.airbnb.epoxy.EpoxyModelClass import im.vector.app.R -import im.vector.app.core.utils.DebouncedClickListener import im.vector.app.features.home.AvatarRenderer -import im.vector.app.features.home.room.detail.timeline.TimelineEventController @EpoxyModelClass(layout = R.layout.item_timeline_event_base_noinfo) abstract class DefaultItem : BaseEventItem() { @@ -59,7 +57,7 @@ abstract class DefaultItem : BaseEventItem() { val avatarRenderer: AvatarRenderer, val informationData: MessageInformationData, val text: CharSequence, - val itemLongClickListener: View.OnLongClickListener? = null, + val itemLongClickListener: View.OnLongClickListener? = null ) companion object { diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/ItemWithEvents.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/ItemWithEvents.kt index eeb3826ccd..050cba0d56 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/ItemWithEvents.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/ItemWithEvents.kt @@ -26,5 +26,4 @@ interface ItemWithEvents { fun canAppendReadMarker(): Boolean = true fun isVisible(): Boolean = true - } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MergedMembershipEventsItem.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MergedMembershipEventsItem.kt index 70a6864a1f..a52ddf8336 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MergedMembershipEventsItem.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MergedMembershipEventsItem.kt @@ -21,12 +21,10 @@ import android.view.ViewGroup import android.widget.ImageView import android.widget.TextView import androidx.core.view.children -import androidx.core.view.isVisible import com.airbnb.epoxy.EpoxyAttribute import com.airbnb.epoxy.EpoxyModelClass import im.vector.app.R import im.vector.app.features.home.AvatarRenderer -import im.vector.app.features.home.room.detail.timeline.TimelineEventController @EpoxyModelClass(layout = R.layout.item_timeline_event_base_noinfo) abstract class MergedMembershipEventsItem : BasedMergedItem() { diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/NoticeItem.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/NoticeItem.kt index b733d0ec32..4876e8e500 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/NoticeItem.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/NoticeItem.kt @@ -25,7 +25,6 @@ import im.vector.app.R import im.vector.app.core.epoxy.ClickListener import im.vector.app.core.epoxy.onClick import im.vector.app.core.ui.views.ShieldImageView -import im.vector.app.core.utils.DebouncedClickListener import im.vector.app.features.home.AvatarRenderer import im.vector.app.features.home.room.detail.timeline.TimelineEventController import org.matrix.android.sdk.api.crypto.RoomEncryptionTrustLevel