From 82391aa28128cacf9b67572fcdd58a75cf7f275e Mon Sep 17 00:00:00 2001 From: Maxime NATUREL Date: Wed, 13 Jul 2022 13:48:54 +0200 Subject: [PATCH] Replacing ViewEvent by a ViewState property --- .../home/room/detail/RoomDetailViewEvents.kt | 2 -- .../home/room/detail/RoomDetailViewState.kt | 3 ++- .../features/home/room/detail/TimelineFragment.kt | 14 +++++++------- .../features/home/room/detail/TimelineViewModel.kt | 4 ++-- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewEvents.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewEvents.kt index 4d57647a1d..dcfee2d919 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewEvents.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewEvents.kt @@ -84,6 +84,4 @@ sealed class RoomDetailViewEvents : VectorViewEvents { data class StartChatEffect(val type: ChatEffect) : RoomDetailViewEvents() object StopChatEffects : RoomDetailViewEvents() object RoomReplacementStarted : RoomDetailViewEvents() - - data class ChangeLocationIndicator(val isVisible: Boolean) : RoomDetailViewEvents() } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewState.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewState.kt index 3ec7166739..8500d1ed96 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewState.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewState.kt @@ -75,7 +75,8 @@ data class RoomDetailViewState( val switchToParentSpace: Boolean = false, val rootThreadEventId: String? = null, val threadNotificationBadgeState: ThreadNotificationBadgeState = ThreadNotificationBadgeState(), - val typingUsers: List? = null + val typingUsers: List? = null, + val isSharingLiveLocation: Boolean = false, ) : MavericksState { constructor(args: TimelineArgs) : this( 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 e86a7fe227..31c1004ef9 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 @@ -498,7 +498,6 @@ class TimelineFragment @Inject constructor( RoomDetailViewEvents.StopChatEffects -> handleStopChatEffects() is RoomDetailViewEvents.DisplayAndAcceptCall -> acceptIncomingCall(it) RoomDetailViewEvents.RoomReplacementStarted -> handleRoomReplacement() - is RoomDetailViewEvents.ChangeLocationIndicator -> handleChangeLocationIndicator(it) } } @@ -663,10 +662,6 @@ class TimelineFragment @Inject constructor( ) } - private fun handleChangeLocationIndicator(event: RoomDetailViewEvents.ChangeLocationIndicator) { - views.locationLiveStatusIndicator.isVisible = event.isVisible - } - private fun displayErrorMessage(error: RoomDetailViewEvents.Failure) { if (error.showInDialog) displayErrorDialog(error.throwable) else showErrorInSnackbar(error.throwable) } @@ -1686,6 +1681,11 @@ class TimelineFragment @Inject constructor( } else if (mainState.asyncInviter.complete) { vectorBaseActivity.finish() } + updateLiveLocationIndicator(mainState.isSharingLiveLocation) + } + + private fun updateLiveLocationIndicator(isSharingLiveLocation: Boolean) { + views.locationLiveStatusIndicator.isVisible = isSharingLiveLocation } private fun FragmentTimelineBinding.hideComposerViews() { @@ -1706,7 +1706,7 @@ class TimelineFragment @Inject constructor( private fun renderToolbar(roomSummary: RoomSummary?) { when { - isLocalRoom() -> { + isLocalRoom() -> { views.includeRoomToolbar.roomToolbarContentView.isVisible = false views.includeThreadToolbar.roomToolbarThreadConstraintLayout.isVisible = false setupToolbar(views.roomToolbar) @@ -1724,7 +1724,7 @@ class TimelineFragment @Inject constructor( } views.includeThreadToolbar.roomToolbarThreadTitleTextView.text = resources.getText(R.string.thread_timeline_title) } - else -> { + else -> { views.includeRoomToolbar.roomToolbarContentView.isVisible = true views.includeThreadToolbar.roomToolbarThreadConstraintLayout.isVisible = false if (roomSummary == null) { 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 e305ccbec1..1d2b778764 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 @@ -1295,11 +1295,11 @@ class TimelineViewModel @AssistedInject constructor( } override fun onLocationServiceRunning() { - _viewEvents.post(RoomDetailViewEvents.ChangeLocationIndicator(isVisible = true)) + setState { copy(isSharingLiveLocation = true) } } override fun onLocationServiceStopped() { - _viewEvents.post(RoomDetailViewEvents.ChangeLocationIndicator(isVisible = false)) + setState { copy(isSharingLiveLocation = false) } // Bind again in case user decides to share live location without leaving the room locationSharingServiceConnection.bind(this) }