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))
}
override fun onLocationServiceRunning() {
setState { copy(isSharingLiveLocation = true) }
override fun onLocationServiceRunning(roomIds: Set<String>) {
setState { copy(isSharingLiveLocation = roomId in roomIds) }
}
override fun onLocationServiceStopped() {

View file

@ -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<String> {
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<String>)
fun onServiceError(error: Throwable)
}

View file

@ -31,7 +31,7 @@ class LocationSharingServiceConnection @Inject constructor(
LocationSharingAndroidService.Callback {
interface Callback {
fun onLocationServiceRunning()
fun onLocationServiceRunning(roomIds: Set<String>)
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<String> {
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<String>) {
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<String>) {
callbacks.toList().forEach { it.onLocationServiceRunning(roomIds) }
}
private fun forwardErrorToCallbacks(error: Throwable) {
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
}