From 121fd9a19dbe20421123bd5cc7ebd1e851b7776e Mon Sep 17 00:00:00 2001 From: ganfra Date: Tue, 22 Jun 2021 16:29:19 +0200 Subject: [PATCH 1/6] Jump to unread: implement new design --- .../main/res/values/styles_jump_to_unread.xml | 27 +++++++++ .../src/main/res/values/theme_dark.xml | 1 + .../src/main/res/values/theme_light.xml | 1 + .../app/core/ui/views/JumpToReadMarkerView.kt | 56 ------------------- .../home/room/detail/RoomDetailFragment.kt | 17 +++--- .../main/res/drawable/ic_jump_to_unread.xml | 10 ++++ .../main/res/layout/fragment_room_detail.xml | 36 +++++------- .../res/layout/view_jump_to_read_marker.xml | 41 -------------- vector/src/main/res/values/strings.xml | 2 +- 9 files changed, 63 insertions(+), 128 deletions(-) create mode 100644 library/ui-styles/src/main/res/values/styles_jump_to_unread.xml delete mode 100644 vector/src/main/java/im/vector/app/core/ui/views/JumpToReadMarkerView.kt create mode 100644 vector/src/main/res/drawable/ic_jump_to_unread.xml delete mode 100644 vector/src/main/res/layout/view_jump_to_read_marker.xml diff --git a/library/ui-styles/src/main/res/values/styles_jump_to_unread.xml b/library/ui-styles/src/main/res/values/styles_jump_to_unread.xml new file mode 100644 index 0000000000..d0561425ff --- /dev/null +++ b/library/ui-styles/src/main/res/values/styles_jump_to_unread.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/library/ui-styles/src/main/res/values/theme_dark.xml b/library/ui-styles/src/main/res/values/theme_dark.xml index b9965439ff..69f1b4d5cc 100644 --- a/library/ui-styles/src/main/res/values/theme_dark.xml +++ b/library/ui-styles/src/main/res/values/theme_dark.xml @@ -86,6 +86,7 @@ @style/Widget.Vector.SnackBar.Button @style/Widget.Vector.SnackBar.TextView @style/Widget.Vector.ActionMode + @style/Widget.Vector.JumpToUnread.Dark @style/Theme.Vector.BottomSheetDialog.Dark diff --git a/library/ui-styles/src/main/res/values/theme_light.xml b/library/ui-styles/src/main/res/values/theme_light.xml index 531f590b6c..db379028f3 100644 --- a/library/ui-styles/src/main/res/values/theme_light.xml +++ b/library/ui-styles/src/main/res/values/theme_light.xml @@ -86,6 +86,7 @@ @style/Widget.Vector.SnackBar.Button @style/Widget.Vector.SnackBar.TextView @style/Widget.Vector.ActionMode + @style/Widget.Vector.JumpToUnread.Light @style/Theme.Vector.BottomSheetDialog.Light diff --git a/vector/src/main/java/im/vector/app/core/ui/views/JumpToReadMarkerView.kt b/vector/src/main/java/im/vector/app/core/ui/views/JumpToReadMarkerView.kt deleted file mode 100644 index 28e23c0e50..0000000000 --- a/vector/src/main/java/im/vector/app/core/ui/views/JumpToReadMarkerView.kt +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2019 New Vector Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package im.vector.app.core.ui.views - -import android.content.Context -import android.util.AttributeSet -import android.view.View -import android.widget.RelativeLayout -import androidx.core.content.ContextCompat -import im.vector.app.R -import im.vector.app.databinding.ViewJumpToReadMarkerBinding - -class JumpToReadMarkerView @JvmOverloads constructor( - context: Context, - attrs: AttributeSet? = null, - defStyleAttr: Int = 0 -) : RelativeLayout(context, attrs, defStyleAttr) { - - interface Callback { - fun onJumpToReadMarkerClicked() - fun onClearReadMarkerClicked() - } - - var callback: Callback? = null - - init { - setupView() - } - - private fun setupView() { - inflate(context, R.layout.view_jump_to_read_marker, this) - val views = ViewJumpToReadMarkerBinding.bind(this) - setBackgroundColor(ContextCompat.getColor(context, R.color.notification_accent_color)) - views.jumpToReadMarkerLabelView.setOnClickListener { - callback?.onJumpToReadMarkerClicked() - } - views.closeJumpToReadMarkerView.setOnClickListener { - visibility = View.INVISIBLE - callback?.onClearReadMarkerClicked() - } - } -} diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt index 8307e93576..46a47f9be6 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt @@ -1,3 +1,4 @@ + /* * Copyright 2019 New Vector Ltd * @@ -94,7 +95,6 @@ import im.vector.app.core.resources.ColorProvider import im.vector.app.core.ui.views.ActiveConferenceView import im.vector.app.core.ui.views.CurrentCallsView import im.vector.app.core.ui.views.FailedMessagesWarningView -import im.vector.app.core.ui.views.JumpToReadMarkerView import im.vector.app.core.ui.views.KnownCallsViewHolder import im.vector.app.core.ui.views.NotificationAreaView import im.vector.app.core.utils.Debouncer @@ -239,7 +239,6 @@ class RoomDetailFragment @Inject constructor( VectorBaseFragment(), TimelineEventController.Callback, VectorInviteView.Callback, - JumpToReadMarkerView.Callback, AttachmentTypeSelectorView.Callback, AttachmentsHelper.Callback, GalleryOrCameraDialogHelper.Listener, @@ -725,7 +724,13 @@ class RoomDetailFragment @Inject constructor( } private fun setupJumpToReadMarkerView() { - views.jumpToReadMarkerView.callback = this + views.jumpToReadMarkerView.setOnClickListener { + onJumpToReadMarkerClicked() + } + views.jumpToReadMarkerView.setOnCloseIconClickListener { + views.jumpToReadMarkerView.isVisible = false + onClearReadMarkerClicked() + } } private fun setupActiveCallView() { @@ -1959,9 +1964,7 @@ class RoomDetailFragment @Inject constructor( roomDetailViewModel.handle(RoomDetailAction.RejectInvite) } -// JumpToReadMarkerView.Callback - - override fun onJumpToReadMarkerClicked() = withState(roomDetailViewModel) { + private fun onJumpToReadMarkerClicked() = withState(roomDetailViewModel) { views.jumpToReadMarkerView.isVisible = false if (it.unreadState is UnreadState.HasUnread) { roomDetailViewModel.handle(RoomDetailAction.NavigateToEvent(it.unreadState.firstUnreadEventId, false)) @@ -1971,7 +1974,7 @@ class RoomDetailFragment @Inject constructor( } } - override fun onClearReadMarkerClicked() { + private fun onClearReadMarkerClicked() { roomDetailViewModel.handle(RoomDetailAction.MarkAllAsRead) } diff --git a/vector/src/main/res/drawable/ic_jump_to_unread.xml b/vector/src/main/res/drawable/ic_jump_to_unread.xml new file mode 100644 index 0000000000..2c5b8b90c1 --- /dev/null +++ b/vector/src/main/res/drawable/ic_jump_to_unread.xml @@ -0,0 +1,10 @@ + + + diff --git a/vector/src/main/res/layout/fragment_room_detail.xml b/vector/src/main/res/layout/fragment_room_detail.xml index 19d85d5393..de0f95f583 100644 --- a/vector/src/main/res/layout/fragment_room_detail.xml +++ b/vector/src/main/res/layout/fragment_room_detail.xml @@ -127,32 +127,22 @@ app:layout_constraintTop_toBottomOf="@id/activeConferenceView" tools:listitem="@layout/item_timeline_event_base" /> - + app:layout_constraintTop_toBottomOf="@id/activeConferenceView" + tools:visibility="visible" /> - - - - - - - - - - - - - + app:layout_constraintTop_toBottomOf="@id/jumpToReadMarkerView"> - - - - - - - diff --git a/vector/src/main/res/values/strings.xml b/vector/src/main/res/values/strings.xml index 54356db664..5a95a96e5c 100644 --- a/vector/src/main/res/values/strings.xml +++ b/vector/src/main/res/values/strings.xml @@ -783,7 +783,7 @@ List members Open header Syncing… - Jump to first unread message. + Jump to unread You have been invited to join this room by %s From c3ef036dca4add53fa377babd335a77836b70986 Mon Sep 17 00:00:00 2001 From: ganfra Date: Tue, 22 Jun 2021 19:41:10 +0200 Subject: [PATCH 2/6] Read marker: fix some issues with jump to unread visibility. --- .../home/room/detail/RoomDetailFragment.kt | 25 ++++++++++--------- .../home/room/detail/RoomDetailViewModel.kt | 2 +- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt index 46a47f9be6..ddde469f2c 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt @@ -1,4 +1,3 @@ - /* * Copyright 2019 New Vector Ltd * @@ -355,6 +354,10 @@ class RoomDetailFragment @Inject constructor( renderTombstoneEventHandling(it) } + roomDetailViewModel.selectSubscribe(RoomDetailViewState::canShowJumpToReadMarker, RoomDetailViewState::unreadState) { _, _ -> + updateJumpToReadMarkerViewVisibility() + } + roomDetailViewModel.selectSubscribe(RoomDetailViewState::sendMode, RoomDetailViewState::canSendMessage) { mode, canSend -> if (!canSend) { return@selectSubscribe @@ -728,8 +731,7 @@ class RoomDetailFragment @Inject constructor( onJumpToReadMarkerClicked() } views.jumpToReadMarkerView.setOnCloseIconClickListener { - views.jumpToReadMarkerView.isVisible = false - onClearReadMarkerClicked() + roomDetailViewModel.handle(RoomDetailAction.MarkAllAsRead) } } @@ -1059,7 +1061,13 @@ class RoomDetailFragment @Inject constructor( timelineEventController.timeline = roomDetailViewModel.timeline views.timelineRecyclerView.trackItemsVisibilityChange() - layoutManager = LinearLayoutManager(context, RecyclerView.VERTICAL, true) + layoutManager = object : LinearLayoutManager(context, RecyclerView.VERTICAL, true) { + override fun onLayoutCompleted(state: RecyclerView.State?) { + super.onLayoutCompleted(state) + updateJumpToReadMarkerViewVisibility() + jumpToBottomViewVisibilityManager.maybeShowJumpToBottomViewVisibilityWithDelay() + } + } val stateRestorer = LayoutManagerStateRestorer(layoutManager).register() scrollOnNewMessageCallback = ScrollOnNewMessageCallback(layoutManager, timelineEventController) scrollOnHighlightedEventCallback = ScrollOnHighlightedEventCallback(views.timelineRecyclerView, layoutManager, timelineEventController) @@ -1070,8 +1078,6 @@ class RoomDetailFragment @Inject constructor( it.dispatchTo(stateRestorer) it.dispatchTo(scrollOnNewMessageCallback) it.dispatchTo(scrollOnHighlightedEventCallback) - updateJumpToReadMarkerViewVisibility() - jumpToBottomViewVisibilityManager.maybeShowJumpToBottomViewVisibilityWithDelay() } timelineEventController.addModelBuildListener(modelBuildListener) views.timelineRecyclerView.adapter = timelineEventController.adapter @@ -1127,7 +1133,7 @@ class RoomDetailFragment @Inject constructor( is UnreadState.ReadMarkerNotLoaded -> true is UnreadState.HasUnread -> { if (it.canShowJumpToReadMarker) { - val lastVisibleItem = layoutManager.findLastVisibleItemPosition() + val lastVisibleItem = layoutManager.findLastCompletelyVisibleItemPosition() val positionOfReadMarker = timelineEventController.getPositionOfReadMarker() if (positionOfReadMarker == null) { false @@ -1704,7 +1710,6 @@ class RoomDetailFragment @Inject constructor( } override fun onReadMarkerVisible() { - updateJumpToReadMarkerViewVisibility() roomDetailViewModel.handle(RoomDetailAction.EnterTrackingUnreadMessagesState) } @@ -1974,10 +1979,6 @@ class RoomDetailFragment @Inject constructor( } } - private fun onClearReadMarkerClicked() { - roomDetailViewModel.handle(RoomDetailAction.MarkAllAsRead) - } - // AttachmentTypeSelectorView.Callback private val typeSelectedActivityResultLauncher = registerForPermissionsResult { allGranted -> diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt index 751114c2d9..bc407d3deb 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt @@ -1244,6 +1244,7 @@ class RoomDetailViewModel @AssistedInject constructor( } private fun handleMarkAllAsRead() { + setState { copy(unreadState = UnreadState.HasNoUnread) } viewModelScope.launch { tryOrNull { room.markAsRead(ReadService.MarkAsReadParams.BOTH) } } @@ -1380,7 +1381,6 @@ class RoomDetailViewModel @AssistedInject constructor( } } .subscribe { - Timber.v("Unread state: $it") setState { copy(unreadState = it) } } .disposeOnClear() From d1ab116b1d8a1a14b73f62eb8ebe1e716bbc6400 Mon Sep 17 00:00:00 2001 From: ganfra Date: Wed, 23 Jun 2021 17:13:46 +0200 Subject: [PATCH 3/6] Jump to unread: add towncrier file. --- changelog.d/3547.feature | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/3547.feature diff --git a/changelog.d/3547.feature b/changelog.d/3547.feature new file mode 100644 index 0000000000..8921932067 --- /dev/null +++ b/changelog.d/3547.feature @@ -0,0 +1 @@ +Implements new design for Jump to unread and quick fix visibility issues. \ No newline at end of file From 1ba97fa9bee9929d0c7527800c194a2b33a55aba Mon Sep 17 00:00:00 2001 From: ganfra Date: Thu, 24 Jun 2021 17:40:45 +0200 Subject: [PATCH 4/6] Clean after Benoits review --- .../main/res/values/styles_jump_to_unread.xml | 2 +- .../ui-styles/src/main/res/values/theme_dark.xml | 4 +++- .../src/main/res/values/theme_light.xml | 4 +++- .../main/res/drawable-hdpi/arrow_up_circle.png | Bin 686 -> 0 bytes .../main/res/drawable-mdpi/arrow_up_circle.png | Bin 414 -> 0 bytes .../main/res/drawable-xhdpi/arrow_up_circle.png | Bin 869 -> 0 bytes .../main/res/drawable-xxhdpi/arrow_up_circle.png | Bin 1332 -> 0 bytes .../res/drawable-xxxhdpi/arrow_up_circle.png | Bin 1910 -> 0 bytes .../src/main/res/layout/fragment_room_detail.xml | 2 +- 9 files changed, 8 insertions(+), 4 deletions(-) delete mode 100755 vector/src/main/res/drawable-hdpi/arrow_up_circle.png delete mode 100755 vector/src/main/res/drawable-mdpi/arrow_up_circle.png delete mode 100755 vector/src/main/res/drawable-xhdpi/arrow_up_circle.png delete mode 100755 vector/src/main/res/drawable-xxhdpi/arrow_up_circle.png delete mode 100755 vector/src/main/res/drawable-xxxhdpi/arrow_up_circle.png diff --git a/library/ui-styles/src/main/res/values/styles_jump_to_unread.xml b/library/ui-styles/src/main/res/values/styles_jump_to_unread.xml index d0561425ff..21f0ebd5d4 100644 --- a/library/ui-styles/src/main/res/values/styles_jump_to_unread.xml +++ b/library/ui-styles/src/main/res/values/styles_jump_to_unread.xml @@ -1,7 +1,7 @@ - +