From 3ed66d636b7c6de94d7d7e055fc26dbe97341988 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 31 Aug 2022 11:15:32 +0200 Subject: [PATCH] Rework: avoid shortcut to access ViewModel state. --- .../home/room/detail/TimelineFragment.kt | 26 +++++++++++-------- .../home/room/detail/TimelineViewModel.kt | 2 -- 2 files changed, 15 insertions(+), 13 deletions(-) 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 b5eb0608d4..9de8f8ee4c 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 @@ -1224,12 +1224,12 @@ class TimelineFragment : } } - private fun handleSearchAction() { + private fun handleSearchAction() = withState(timelineViewModel) { state -> navigator.openSearch( context = requireContext(), roomId = timelineArgs.roomId, - roomDisplayName = timelineViewModel.getRoomSummary()?.displayName, - roomAvatarUrl = timelineViewModel.getRoomSummary()?.avatarUrl + roomDisplayName = state.asyncRoomSummary()?.displayName, + roomAvatarUrl = state.asyncRoomSummary()?.avatarUrl ) } @@ -2520,15 +2520,19 @@ class TimelineFragment : * Navigate to Threads timeline for the specified rootThreadEventId * using the ThreadsActivity. */ - private fun navigateToThreadTimeline(rootThreadEventId: String, startsThread: Boolean = false, showKeyboard: Boolean = false) { + private fun navigateToThreadTimeline( + rootThreadEventId: String, + startsThread: Boolean = false, + showKeyboard: Boolean = false, + ) = withState(timelineViewModel) { state -> analyticsTracker.capture(Interaction.Name.MobileRoomThreadSummaryItem.toAnalyticsInteraction()) context?.let { val roomThreadDetailArgs = ThreadTimelineArgs( startsThread = startsThread, roomId = timelineArgs.roomId, - displayName = timelineViewModel.getRoomSummary()?.displayName, - avatarUrl = timelineViewModel.getRoomSummary()?.avatarUrl, - roomEncryptionTrustLevel = timelineViewModel.getRoomSummary()?.roomEncryptionTrustLevel, + displayName = state.asyncRoomSummary()?.displayName, + avatarUrl = state.asyncRoomSummary()?.avatarUrl, + roomEncryptionTrustLevel = state.asyncRoomSummary()?.roomEncryptionTrustLevel, rootThreadEventId = rootThreadEventId, showKeyboard = showKeyboard ) @@ -2559,14 +2563,14 @@ class TimelineFragment : * Navigate to Threads list for the current room * using the ThreadsActivity. */ - private fun navigateToThreadList() { + private fun navigateToThreadList() = withState(timelineViewModel) { state -> analyticsTracker.capture(Interaction.Name.MobileRoomThreadListButton.toAnalyticsInteraction()) context?.let { val roomThreadDetailArgs = ThreadTimelineArgs( roomId = timelineArgs.roomId, - displayName = timelineViewModel.getRoomSummary()?.displayName, - roomEncryptionTrustLevel = timelineViewModel.getRoomSummary()?.roomEncryptionTrustLevel, - avatarUrl = timelineViewModel.getRoomSummary()?.avatarUrl + displayName = state.asyncRoomSummary()?.displayName, + roomEncryptionTrustLevel = state.asyncRoomSummary()?.roomEncryptionTrustLevel, + avatarUrl = state.asyncRoomSummary()?.avatarUrl ) navigator.openThreadList(it, roomThreadDetailArgs) } 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 5fa23c8f40..857902b50c 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 @@ -402,8 +402,6 @@ class TimelineViewModel @AssistedInject constructor( fun getOtherUserIds() = room.roomSummary()?.otherMemberIds - fun getRoomSummary() = room.roomSummary() - override fun handle(action: RoomDetailAction) { when (action) { is RoomDetailAction.ComposerFocusChange -> handleComposerFocusChange(action)