Skip to content

Commit 33714b8

Browse files
author
Maxime NATUREL
committed
Make the status bar only visible in rooms where there is an active live
1 parent d2d24cb commit 33714b8

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

vector/src/main/java/im/vector/app/features/home/room/detail/TimelineViewModel.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,8 +1294,8 @@ class TimelineViewModel @AssistedInject constructor(
12941294
_viewEvents.post(RoomDetailViewEvents.OnNewTimelineEvents(eventIds))
12951295
}
12961296

1297-
override fun onLocationServiceRunning() {
1298-
setState { copy(isSharingLiveLocation = true) }
1297+
override fun onLocationServiceRunning(roomIds: Set<String>) {
1298+
setState { copy(isSharingLiveLocation = roomId in roomIds) }
12991299
}
13001300

13011301
override fun onLocationServiceStopped() {

vector/src/main/java/im/vector/app/features/location/LocationSharingAndroidService.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,13 @@ class LocationSharingAndroidService : VectorAndroidService(), LocationTracker.Ca
193193
private fun addRoomArgs(beaconEventId: String, roomArgs: RoomArgs) {
194194
Timber.i("adding roomArgs for beaconEventId: $beaconEventId")
195195
roomArgsMap[beaconEventId] = roomArgs
196+
callback?.onRoomIdsUpdate(getRoomIdsOfActiveLives())
196197
}
197198

198199
private fun removeRoomArgs(beaconEventId: String) {
199200
Timber.i("removing roomArgs for beaconEventId: $beaconEventId")
200201
roomArgsMap.remove(beaconEventId)
202+
callback?.onRoomIdsUpdate(getRoomIdsOfActiveLives())
201203
}
202204

203205
private fun listenForLiveSummaryChanges(roomId: String, beaconEventId: String) {
@@ -220,6 +222,10 @@ class LocationSharingAndroidService : VectorAndroidService(), LocationTracker.Ca
220222
)
221223
}
222224

225+
fun getRoomIdsOfActiveLives(): Set<String> {
226+
return roomArgsMap.map { it.value.roomId }.toSet()
227+
}
228+
223229
override fun onBind(intent: Intent?): IBinder {
224230
return binder
225231
}
@@ -229,6 +235,7 @@ class LocationSharingAndroidService : VectorAndroidService(), LocationTracker.Ca
229235
}
230236

231237
interface Callback {
238+
fun onRoomIdsUpdate(roomIds: Set<String>)
232239
fun onServiceError(error: Throwable)
233240
}
234241

vector/src/main/java/im/vector/app/features/location/LocationSharingServiceConnection.kt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class LocationSharingServiceConnection @Inject constructor(
3131
LocationSharingAndroidService.Callback {
3232

3333
interface Callback {
34-
fun onLocationServiceRunning()
34+
fun onLocationServiceRunning(roomIds: Set<String>)
3535
fun onLocationServiceStopped()
3636
fun onLocationServiceError(error: Throwable)
3737
}
@@ -44,7 +44,7 @@ class LocationSharingServiceConnection @Inject constructor(
4444
addCallback(callback)
4545

4646
if (isBound) {
47-
callback.onLocationServiceRunning()
47+
callback.onLocationServiceRunning(getRoomIdsOfActiveLives())
4848
} else {
4949
Intent(context, LocationSharingAndroidService::class.java).also { intent ->
5050
context.bindService(intent, this, 0)
@@ -56,12 +56,15 @@ class LocationSharingServiceConnection @Inject constructor(
5656
removeCallback(callback)
5757
}
5858

59+
private fun getRoomIdsOfActiveLives(): Set<String> {
60+
return locationSharingAndroidService?.getRoomIdsOfActiveLives() ?: emptySet()
61+
}
62+
5963
override fun onServiceConnected(className: ComponentName, binder: IBinder) {
6064
locationSharingAndroidService = (binder as LocationSharingAndroidService.LocalBinder).getService().also {
6165
it.callback = this
6266
}
6367
isBound = true
64-
onCallbackActionNoArg(Callback::onLocationServiceRunning)
6568
}
6669

6770
override fun onServiceDisconnected(className: ComponentName) {
@@ -71,6 +74,10 @@ class LocationSharingServiceConnection @Inject constructor(
7174
onCallbackActionNoArg(Callback::onLocationServiceStopped)
7275
}
7376

77+
override fun onRoomIdsUpdate(roomIds: Set<String>) {
78+
forwardRoomIdsToCallbacks(roomIds)
79+
}
80+
7481
override fun onServiceError(error: Throwable) {
7582
forwardErrorToCallbacks(error)
7683
}
@@ -87,6 +94,10 @@ class LocationSharingServiceConnection @Inject constructor(
8794
callbacks.toList().forEach(action)
8895
}
8996

97+
private fun forwardRoomIdsToCallbacks(roomIds: Set<String>) {
98+
callbacks.toList().forEach { it.onLocationServiceRunning(roomIds) }
99+
}
100+
90101
private fun forwardErrorToCallbacks(error: Throwable) {
91102
callbacks.toList().forEach { it.onLocationServiceError(error) }
92103
}

vector/src/main/java/im/vector/app/features/location/live/map/LocationLiveMapViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class LocationLiveMapViewModel @AssistedInject constructor(
8787
}
8888
}
8989

90-
override fun onLocationServiceRunning() {
90+
override fun onLocationServiceRunning(roomIds: Set<String>) {
9191
// NOOP
9292
}
9393

0 commit comments

Comments
 (0)