From 33714b850f5d22ccea6d7eeed31def34400322ad Mon Sep 17 00:00:00 2001 From: Maxime NATUREL Date: Wed, 13 Jul 2022 14:42:48 +0200 Subject: [PATCH] Make the status bar only visible in rooms where there is an active live --- .../home/room/detail/TimelineViewModel.kt | 4 ++-- .../location/LocationSharingAndroidService.kt | 7 +++++++ .../LocationSharingServiceConnection.kt | 17 ++++++++++++++--- .../live/map/LocationLiveMapViewModel.kt | 2 +- 4 files changed, 24 insertions(+), 6 deletions(-) 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 1d2b778764..8075ba5b7a 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 @@ -1294,8 +1294,8 @@ class TimelineViewModel @AssistedInject constructor( _viewEvents.post(RoomDetailViewEvents.OnNewTimelineEvents(eventIds)) } - override fun onLocationServiceRunning() { - setState { copy(isSharingLiveLocation = true) } + override fun onLocationServiceRunning(roomIds: Set) { + setState { copy(isSharingLiveLocation = roomId in roomIds) } } override fun onLocationServiceStopped() { diff --git a/vector/src/main/java/im/vector/app/features/location/LocationSharingAndroidService.kt b/vector/src/main/java/im/vector/app/features/location/LocationSharingAndroidService.kt index 69ffc0e89e..6fd7f27ece 100644 --- a/vector/src/main/java/im/vector/app/features/location/LocationSharingAndroidService.kt +++ b/vector/src/main/java/im/vector/app/features/location/LocationSharingAndroidService.kt @@ -193,11 +193,13 @@ class LocationSharingAndroidService : VectorAndroidService(), LocationTracker.Ca private fun addRoomArgs(beaconEventId: String, roomArgs: RoomArgs) { Timber.i("adding roomArgs for beaconEventId: $beaconEventId") roomArgsMap[beaconEventId] = roomArgs + callback?.onRoomIdsUpdate(getRoomIdsOfActiveLives()) } private fun removeRoomArgs(beaconEventId: String) { Timber.i("removing roomArgs for beaconEventId: $beaconEventId") roomArgsMap.remove(beaconEventId) + callback?.onRoomIdsUpdate(getRoomIdsOfActiveLives()) } private fun listenForLiveSummaryChanges(roomId: String, beaconEventId: String) { @@ -220,6 +222,10 @@ class LocationSharingAndroidService : VectorAndroidService(), LocationTracker.Ca ) } + fun getRoomIdsOfActiveLives(): Set { + return roomArgsMap.map { it.value.roomId }.toSet() + } + override fun onBind(intent: Intent?): IBinder { return binder } @@ -229,6 +235,7 @@ class LocationSharingAndroidService : VectorAndroidService(), LocationTracker.Ca } interface Callback { + fun onRoomIdsUpdate(roomIds: Set) fun onServiceError(error: Throwable) } diff --git a/vector/src/main/java/im/vector/app/features/location/LocationSharingServiceConnection.kt b/vector/src/main/java/im/vector/app/features/location/LocationSharingServiceConnection.kt index 495b780188..9feffb7554 100644 --- a/vector/src/main/java/im/vector/app/features/location/LocationSharingServiceConnection.kt +++ b/vector/src/main/java/im/vector/app/features/location/LocationSharingServiceConnection.kt @@ -31,7 +31,7 @@ class LocationSharingServiceConnection @Inject constructor( LocationSharingAndroidService.Callback { interface Callback { - fun onLocationServiceRunning() + fun onLocationServiceRunning(roomIds: Set) fun onLocationServiceStopped() fun onLocationServiceError(error: Throwable) } @@ -44,7 +44,7 @@ class LocationSharingServiceConnection @Inject constructor( addCallback(callback) if (isBound) { - callback.onLocationServiceRunning() + callback.onLocationServiceRunning(getRoomIdsOfActiveLives()) } else { Intent(context, LocationSharingAndroidService::class.java).also { intent -> context.bindService(intent, this, 0) @@ -56,12 +56,15 @@ class LocationSharingServiceConnection @Inject constructor( removeCallback(callback) } + private fun getRoomIdsOfActiveLives(): Set { + return locationSharingAndroidService?.getRoomIdsOfActiveLives() ?: emptySet() + } + override fun onServiceConnected(className: ComponentName, binder: IBinder) { locationSharingAndroidService = (binder as LocationSharingAndroidService.LocalBinder).getService().also { it.callback = this } isBound = true - onCallbackActionNoArg(Callback::onLocationServiceRunning) } override fun onServiceDisconnected(className: ComponentName) { @@ -71,6 +74,10 @@ class LocationSharingServiceConnection @Inject constructor( onCallbackActionNoArg(Callback::onLocationServiceStopped) } + override fun onRoomIdsUpdate(roomIds: Set) { + forwardRoomIdsToCallbacks(roomIds) + } + override fun onServiceError(error: Throwable) { forwardErrorToCallbacks(error) } @@ -87,6 +94,10 @@ class LocationSharingServiceConnection @Inject constructor( callbacks.toList().forEach(action) } + private fun forwardRoomIdsToCallbacks(roomIds: Set) { + callbacks.toList().forEach { it.onLocationServiceRunning(roomIds) } + } + private fun forwardErrorToCallbacks(error: Throwable) { callbacks.toList().forEach { it.onLocationServiceError(error) } } diff --git a/vector/src/main/java/im/vector/app/features/location/live/map/LocationLiveMapViewModel.kt b/vector/src/main/java/im/vector/app/features/location/live/map/LocationLiveMapViewModel.kt index 15c76b083e..44d39862f9 100644 --- a/vector/src/main/java/im/vector/app/features/location/live/map/LocationLiveMapViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/location/live/map/LocationLiveMapViewModel.kt @@ -87,7 +87,7 @@ class LocationLiveMapViewModel @AssistedInject constructor( } } - override fun onLocationServiceRunning() { + override fun onLocationServiceRunning(roomIds: Set) { // NOOP }