From aa34c108b50e1afe2090e31563383cc606ac5958 Mon Sep 17 00:00:00 2001 From: SpiritCroc Date: Tue, 25 Apr 2023 14:15:47 +0200 Subject: [PATCH] Labs: setting to clear highlighted message on scroll Change-Id: If07012f29159bb10cbd90f410955b49684891945 --- library/ui-strings/src/main/res/values/strings_sc.xml | 3 +++ .../app/features/home/room/detail/TimelineFragment.kt | 5 +++++ .../app/features/home/room/detail/TimelineViewModel.kt | 6 ++++++ .../im/vector/app/features/settings/VectorPreferences.kt | 7 +++++++ vector/src/main/res/xml/vector_settings_labs.xml | 6 ++++++ 5 files changed, 27 insertions(+) diff --git a/library/ui-strings/src/main/res/values/strings_sc.xml b/library/ui-strings/src/main/res/values/strings_sc.xml index 4362b07c01..70c28740db 100644 --- a/library/ui-strings/src/main/res/values/strings_sc.xml +++ b/library/ui-strings/src/main/res/values/strings_sc.xml @@ -229,6 +229,9 @@ Send as sticker + Clear highlight on scroll + Remove highlight from messages when you scroll + Allow fallback call assist server Will use %s as assist when your homeserver does not offer one (your IP address will be seen by the stun server during a call diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineFragment.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineFragment.kt index 82d11380ea..62b5dbd09a 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineFragment.kt @@ -323,6 +323,8 @@ class TimelineFragment : private val lazyLoadedViews = RoomDetailLazyLoadedViews() + private val clearHighlightOnScroll by lazy { vectorPreferences.clearHighlightOnScroll() } + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) analyticsScreenName = MobileScreen.ScreenName.Room @@ -1335,6 +1337,9 @@ class TimelineFragment : // If we do not clear the focus manually, it will keep it forever? // We want to listen to new focus events to re-enable the stickToBottom though. messageComposerViewModel.handle(MessageComposerAction.ClearFocus) + if (clearHighlightOnScroll) { + timelineViewModel.clearHighlight() + } } super.onScrolled(recyclerView, dx, dy) } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineViewModel.kt index 12b81b6ae5..de6430cdeb 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineViewModel.kt @@ -1153,6 +1153,12 @@ class TimelineViewModel @AssistedInject constructor( _viewEvents.post(RoomDetailViewEvents.NavigateToEvent(targetEventId, action.isFirstUnreadEvent)) } + fun clearHighlight() = withState { state -> + if (state.highlightedEventId != null) { + setState { copy(highlightedEventId = null) } + } + } + private fun handleResendEvent(action: RoomDetailAction.ResendMessage) { if (room == null) return val targetEventId = action.eventId diff --git a/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt b/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt index 6ad1b65006..c3a2a1f8ad 100755 --- a/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt +++ b/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt @@ -263,6 +263,7 @@ class VectorPreferences @Inject constructor( const val SETTINGS_ROOM_SORT_ORDER_NULL = "SETTINGS_ROOM_SORT_ORDER_NULL" const val SETTINGS_ROOM_SORT_ORDER_NON_NULL = "SETTINGS_ROOM_SORT_ORDER_NON_NULL" private const val SETTINGS_ENABLE_MEMBER_NAME_CLICK = "SETTINGS_ENABLE_MEMBER_NAME_CLICK" + private const val SETTINGS_CLEAR_HIGHLIGHT_ON_SCROLL = "SETTINGS_CLEAR_HIGHLIGHT_ON_SCROLL" private const val DID_ASK_TO_ENABLE_SESSION_PUSH = "DID_ASK_TO_ENABLE_SESSION_PUSH" @@ -1258,6 +1259,11 @@ class VectorPreferences @Inject constructor( return defaultPrefs.getBoolean(SETTINGS_ENABLE_MEMBER_NAME_CLICK, true) } + // SC addition + fun clearHighlightOnScroll(): Boolean { + return defaultPrefs.getBoolean(SETTINGS_CLEAR_HIGHLIGHT_ON_SCROLL, false) + } + /** * I likely do more fresh installs of the app than anyone else, so a shortcut to change some of the default settings to @@ -1286,6 +1292,7 @@ class VectorPreferences @Inject constructor( .putBoolean(SETTINGS_FLOATING_DATE, true) .putBoolean(SETTINGS_FOLLOW_SYSTEM_LOCALE, true) .putBoolean(SETTINGS_ENABLE_MEMBER_NAME_CLICK, false) + .putBoolean(SETTINGS_CLEAR_HIGHLIGHT_ON_SCROLL, true) .apply() } diff --git a/vector/src/main/res/xml/vector_settings_labs.xml b/vector/src/main/res/xml/vector_settings_labs.xml index 205f3532e6..2971fb538a 100644 --- a/vector/src/main/res/xml/vector_settings_labs.xml +++ b/vector/src/main/res/xml/vector_settings_labs.xml @@ -37,6 +37,12 @@ android:title="@string/settings_read_receipt_follows_read_marker" android:summary="@string/settings_read_receipt_follows_read_marker_summary" /> + +