From 27e217fce51648a1ab18bcf129b58e33dae64d02 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 7 Feb 2020 19:41:23 +0100 Subject: [PATCH] Convert to ViewEvents -> RoomDetailViewModel part 3 --- .../home/room/detail/RoomDetailFragment.kt | 21 ++++++++++--------- .../home/room/detail/RoomDetailViewEvents.kt | 2 ++ .../home/room/detail/RoomDetailViewModel.kt | 6 +----- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt index 9ef92a345b..620f980ada 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt @@ -261,16 +261,6 @@ class RoomDetailFragment @Inject constructor( } .disposeOnDestroyView() - roomDetailViewModel.navigateToEvent.observeEvent(this) { - val scrollPosition = timelineEventController.searchPositionOfEvent(it) - if (scrollPosition == null) { - scrollOnHighlightedEventCallback.scheduleScrollTo(it) - } else { - recyclerView.stopScroll() - layoutManager.scrollToPosition(scrollPosition) - } - } - roomDetailViewModel.fileTooBigEvent.observeEvent(this) { displayFileTooBigWarning(it) } @@ -309,6 +299,7 @@ class RoomDetailFragment @Inject constructor( is RoomDetailViewEvents.ActionSuccess -> displayRoomDetailActionSuccess(it) is RoomDetailViewEvents.ActionFailure -> displayRoomDetailActionFailure(it) is RoomDetailViewEvents.ShowMessage -> showSnackWithMessage(it.message, Snackbar.LENGTH_LONG) + is RoomDetailViewEvents.NavigateToEvent -> navigateToEvent(it) is RoomDetailViewEvents.SendMessageResult -> renderSendMessageResult(it) }.exhaustive } @@ -364,6 +355,16 @@ class RoomDetailFragment @Inject constructor( jumpToReadMarkerView.callback = this } + private fun navigateToEvent(action: RoomDetailViewEvents.NavigateToEvent) { + val scrollPosition = timelineEventController.searchPositionOfEvent(action.eventId) + if (scrollPosition == null) { + scrollOnHighlightedEventCallback.scheduleScrollTo(action.eventId) + } else { + recyclerView.stopScroll() + layoutManager.scrollToPosition(scrollPosition) + } + } + private fun displayFileTooBigWarning(error: FileTooBigError) { AlertDialog.Builder(requireActivity()) .setTitle(R.string.dialog_title_error) diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewEvents.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewEvents.kt index 63f3cdded9..62a9e324d1 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewEvents.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewEvents.kt @@ -32,6 +32,8 @@ sealed class RoomDetailViewEvents : VectorViewEvents { data class ShowMessage(val message: String) : RoomDetailViewEvents() + data class NavigateToEvent(val eventId: String) : RoomDetailViewEvents() + abstract class SendMessageResult : RoomDetailViewEvents() object MessageSent : SendMessageResult() diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewModel.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewModel.kt index 50422d9199..5237679b0c 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewModel.kt @@ -314,10 +314,6 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro } // TODO Cleanup this and use ViewEvents - private val _navigateToEvent = MutableLiveData>() - val navigateToEvent: LiveData> - get() = _navigateToEvent - private val _fileTooBigEvent = MutableLiveData>() val fileTooBigEvent: LiveData> get() = _fileTooBigEvent @@ -735,7 +731,7 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro if (action.highlight) { setState { copy(highlightedEventId = correctedEventId) } } - _navigateToEvent.postLiveEvent(correctedEventId) + _viewEvents.post(RoomDetailViewEvents.NavigateToEvent(correctedEventId)) } private fun handleResendEvent(action: RoomDetailAction.ResendMessage) {