Make the status bar only visible in rooms where there is an active live

This commit is contained in:
Maxime NATUREL 2022-07-13 14:42:48 +02:00
parent d2d24cbcbe
commit 33714b850f
4 changed files with 24 additions and 6 deletions

View File

@ -1294,8 +1294,8 @@ class TimelineViewModel @AssistedInject constructor(
_viewEvents.post(RoomDetailViewEvents.OnNewTimelineEvents(eventIds)) _viewEvents.post(RoomDetailViewEvents.OnNewTimelineEvents(eventIds))
} }
override fun onLocationServiceRunning() { override fun onLocationServiceRunning(roomIds: Set<String>) {
setState { copy(isSharingLiveLocation = true) } setState { copy(isSharingLiveLocation = roomId in roomIds) }
} }
override fun onLocationServiceStopped() { override fun onLocationServiceStopped() {

View File

@ -193,11 +193,13 @@ class LocationSharingAndroidService : VectorAndroidService(), LocationTracker.Ca
private fun addRoomArgs(beaconEventId: String, roomArgs: RoomArgs) { private fun addRoomArgs(beaconEventId: String, roomArgs: RoomArgs) {
Timber.i("adding roomArgs for beaconEventId: $beaconEventId") Timber.i("adding roomArgs for beaconEventId: $beaconEventId")
roomArgsMap[beaconEventId] = roomArgs roomArgsMap[beaconEventId] = roomArgs
callback?.onRoomIdsUpdate(getRoomIdsOfActiveLives())
} }
private fun removeRoomArgs(beaconEventId: String) { private fun removeRoomArgs(beaconEventId: String) {
Timber.i("removing roomArgs for beaconEventId: $beaconEventId") Timber.i("removing roomArgs for beaconEventId: $beaconEventId")
roomArgsMap.remove(beaconEventId) roomArgsMap.remove(beaconEventId)
callback?.onRoomIdsUpdate(getRoomIdsOfActiveLives())
} }
private fun listenForLiveSummaryChanges(roomId: String, beaconEventId: String) { private fun listenForLiveSummaryChanges(roomId: String, beaconEventId: String) {
@ -220,6 +222,10 @@ class LocationSharingAndroidService : VectorAndroidService(), LocationTracker.Ca
) )
} }
fun getRoomIdsOfActiveLives(): Set<String> {
return roomArgsMap.map { it.value.roomId }.toSet()
}
override fun onBind(intent: Intent?): IBinder { override fun onBind(intent: Intent?): IBinder {
return binder return binder
} }
@ -229,6 +235,7 @@ class LocationSharingAndroidService : VectorAndroidService(), LocationTracker.Ca
} }
interface Callback { interface Callback {
fun onRoomIdsUpdate(roomIds: Set<String>)
fun onServiceError(error: Throwable) fun onServiceError(error: Throwable)
} }

View File

@ -31,7 +31,7 @@ class LocationSharingServiceConnection @Inject constructor(
LocationSharingAndroidService.Callback { LocationSharingAndroidService.Callback {
interface Callback { interface Callback {
fun onLocationServiceRunning() fun onLocationServiceRunning(roomIds: Set<String>)
fun onLocationServiceStopped() fun onLocationServiceStopped()
fun onLocationServiceError(error: Throwable) fun onLocationServiceError(error: Throwable)
} }
@ -44,7 +44,7 @@ class LocationSharingServiceConnection @Inject constructor(
addCallback(callback) addCallback(callback)
if (isBound) { if (isBound) {
callback.onLocationServiceRunning() callback.onLocationServiceRunning(getRoomIdsOfActiveLives())
} else { } else {
Intent(context, LocationSharingAndroidService::class.java).also { intent -> Intent(context, LocationSharingAndroidService::class.java).also { intent ->
context.bindService(intent, this, 0) context.bindService(intent, this, 0)
@ -56,12 +56,15 @@ class LocationSharingServiceConnection @Inject constructor(
removeCallback(callback) removeCallback(callback)
} }
private fun getRoomIdsOfActiveLives(): Set<String> {
return locationSharingAndroidService?.getRoomIdsOfActiveLives() ?: emptySet()
}
override fun onServiceConnected(className: ComponentName, binder: IBinder) { override fun onServiceConnected(className: ComponentName, binder: IBinder) {
locationSharingAndroidService = (binder as LocationSharingAndroidService.LocalBinder).getService().also { locationSharingAndroidService = (binder as LocationSharingAndroidService.LocalBinder).getService().also {
it.callback = this it.callback = this
} }
isBound = true isBound = true
onCallbackActionNoArg(Callback::onLocationServiceRunning)
} }
override fun onServiceDisconnected(className: ComponentName) { override fun onServiceDisconnected(className: ComponentName) {
@ -71,6 +74,10 @@ class LocationSharingServiceConnection @Inject constructor(
onCallbackActionNoArg(Callback::onLocationServiceStopped) onCallbackActionNoArg(Callback::onLocationServiceStopped)
} }
override fun onRoomIdsUpdate(roomIds: Set<String>) {
forwardRoomIdsToCallbacks(roomIds)
}
override fun onServiceError(error: Throwable) { override fun onServiceError(error: Throwable) {
forwardErrorToCallbacks(error) forwardErrorToCallbacks(error)
} }
@ -87,6 +94,10 @@ class LocationSharingServiceConnection @Inject constructor(
callbacks.toList().forEach(action) callbacks.toList().forEach(action)
} }
private fun forwardRoomIdsToCallbacks(roomIds: Set<String>) {
callbacks.toList().forEach { it.onLocationServiceRunning(roomIds) }
}
private fun forwardErrorToCallbacks(error: Throwable) { private fun forwardErrorToCallbacks(error: Throwable) {
callbacks.toList().forEach { it.onLocationServiceError(error) } callbacks.toList().forEach { it.onLocationServiceError(error) }
} }

View File

@ -87,7 +87,7 @@ class LocationLiveMapViewModel @AssistedInject constructor(
} }
} }
override fun onLocationServiceRunning() { override fun onLocationServiceRunning(roomIds: Set<String>) {
// NOOP // NOOP
} }