From 5ec63858ed716e04436711ca1b5cf8c5d7d483d4 Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Fri, 1 Apr 2022 12:31:51 +0300 Subject: [PATCH] Refactor location sharing view events. --- .../features/home/room/detail/RoomDetailViewEvents.kt | 3 +-- .../app/features/home/room/detail/TimelineFragment.kt | 11 +++-------- .../features/home/room/detail/TimelineViewModel.kt | 4 ++-- 3 files changed, 6 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 a7819d3ddf..118c529574 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 @@ -83,6 +83,5 @@ sealed class RoomDetailViewEvents : VectorViewEvents { object StopChatEffects : RoomDetailViewEvents() object RoomReplacementStarted : RoomDetailViewEvents() - object ShowLocationSharingIndicator : RoomDetailViewEvents() - object HideLocationSharingIndicator : RoomDetailViewEvents() + data class ChangeLocationIndicator(val isVisible: Boolean) : RoomDetailViewEvents() } 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 00ddd8dcbd..7be50cea3e 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 @@ -482,8 +482,7 @@ class TimelineFragment @Inject constructor( RoomDetailViewEvents.StopChatEffects -> handleStopChatEffects() is RoomDetailViewEvents.DisplayAndAcceptCall -> acceptIncomingCall(it) RoomDetailViewEvents.RoomReplacementStarted -> handleRoomReplacement() - RoomDetailViewEvents.ShowLocationSharingIndicator -> handleShowLocationSharingIndicator() - RoomDetailViewEvents.HideLocationSharingIndicator -> handleHideLocationSharingIndicator() + is RoomDetailViewEvents.ChangeLocationIndicator -> handleChangeLocationIndicator(it) } } @@ -618,12 +617,8 @@ class TimelineFragment @Inject constructor( ) } - private fun handleShowLocationSharingIndicator() { - views.locationLiveStatusIndicator.isVisible = true - } - - private fun handleHideLocationSharingIndicator() { - views.locationLiveStatusIndicator.isVisible = false + private fun handleChangeLocationIndicator(event: RoomDetailViewEvents.ChangeLocationIndicator) { + views.locationLiveStatusIndicator.isVisible = event.isVisible } private fun displayErrorMessage(error: RoomDetailViewEvents.Failure) { 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 dc1df9a96e..455c3c69ec 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 @@ -1224,11 +1224,11 @@ class TimelineViewModel @AssistedInject constructor( } override fun onLocationServiceRunning() { - _viewEvents.post(RoomDetailViewEvents.ShowLocationSharingIndicator) + _viewEvents.post(RoomDetailViewEvents.ChangeLocationIndicator(isVisible = true)) } override fun onLocationServiceStopped() { - _viewEvents.post(RoomDetailViewEvents.HideLocationSharingIndicator) + _viewEvents.post(RoomDetailViewEvents.ChangeLocationIndicator(isVisible = false)) // Bind again in case user decides to share live location without leaving the room locationSharingServiceConnection.bind(this) }