Skip to content

Commit 448b6e1

Browse files
authored
Merge pull request #6539 from vector-im/bugfix/mna/lls-status-bar-disappearing
[Location Share] - Wrong room live location status bar visibility in timeline (PSG-625)
2 parents c3105c8 + ecbd2d4 commit 448b6e1

File tree

8 files changed

+58
-22
lines changed

8 files changed

+58
-22
lines changed

changelog.d/6537.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[Location Share] - Wrong room live location status bar visibility in timeline

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,4 @@ sealed class RoomDetailViewEvents : VectorViewEvents {
8484
data class StartChatEffect(val type: ChatEffect) : RoomDetailViewEvents()
8585
object StopChatEffects : RoomDetailViewEvents()
8686
object RoomReplacementStarted : RoomDetailViewEvents()
87-
88-
data class ChangeLocationIndicator(val isVisible: Boolean) : RoomDetailViewEvents()
8987
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ data class RoomDetailViewState(
7575
val switchToParentSpace: Boolean = false,
7676
val rootThreadEventId: String? = null,
7777
val threadNotificationBadgeState: ThreadNotificationBadgeState = ThreadNotificationBadgeState(),
78-
val typingUsers: List<SenderInfo>? = null
78+
val typingUsers: List<SenderInfo>? = null,
79+
val isSharingLiveLocation: Boolean = false,
7980
) : MavericksState {
8081

8182
constructor(args: TimelineArgs) : this(

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,6 @@ class TimelineFragment @Inject constructor(
498498
RoomDetailViewEvents.StopChatEffects -> handleStopChatEffects()
499499
is RoomDetailViewEvents.DisplayAndAcceptCall -> acceptIncomingCall(it)
500500
RoomDetailViewEvents.RoomReplacementStarted -> handleRoomReplacement()
501-
is RoomDetailViewEvents.ChangeLocationIndicator -> handleChangeLocationIndicator(it)
502501
}
503502
}
504503

@@ -663,10 +662,6 @@ class TimelineFragment @Inject constructor(
663662
)
664663
}
665664

666-
private fun handleChangeLocationIndicator(event: RoomDetailViewEvents.ChangeLocationIndicator) {
667-
views.locationLiveStatusIndicator.isVisible = event.isVisible
668-
}
669-
670665
private fun displayErrorMessage(error: RoomDetailViewEvents.Failure) {
671666
if (error.showInDialog) displayErrorDialog(error.throwable) else showErrorInSnackbar(error.throwable)
672667
}
@@ -1686,6 +1681,11 @@ class TimelineFragment @Inject constructor(
16861681
} else if (mainState.asyncInviter.complete) {
16871682
vectorBaseActivity.finish()
16881683
}
1684+
updateLiveLocationIndicator(mainState.isSharingLiveLocation)
1685+
}
1686+
1687+
private fun updateLiveLocationIndicator(isSharingLiveLocation: Boolean) {
1688+
views.locationLiveStatusIndicator.isVisible = isSharingLiveLocation
16891689
}
16901690

16911691
private fun FragmentTimelineBinding.hideComposerViews() {
@@ -1706,7 +1706,7 @@ class TimelineFragment @Inject constructor(
17061706

17071707
private fun renderToolbar(roomSummary: RoomSummary?) {
17081708
when {
1709-
isLocalRoom() -> {
1709+
isLocalRoom() -> {
17101710
views.includeRoomToolbar.roomToolbarContentView.isVisible = false
17111711
views.includeThreadToolbar.roomToolbarThreadConstraintLayout.isVisible = false
17121712
setupToolbar(views.roomToolbar)
@@ -1724,7 +1724,7 @@ class TimelineFragment @Inject constructor(
17241724
}
17251725
views.includeThreadToolbar.roomToolbarThreadTitleTextView.text = resources.getText(R.string.thread_timeline_title)
17261726
}
1727-
else -> {
1727+
else -> {
17281728
views.includeRoomToolbar.roomToolbarContentView.isVisible = true
17291729
views.includeThreadToolbar.roomToolbarThreadConstraintLayout.isVisible = false
17301730
if (roomSummary == null) {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,12 +1303,12 @@ class TimelineViewModel @AssistedInject constructor(
13031303
_viewEvents.post(RoomDetailViewEvents.OnNewTimelineEvents(eventIds))
13041304
}
13051305

1306-
override fun onLocationServiceRunning() {
1307-
_viewEvents.post(RoomDetailViewEvents.ChangeLocationIndicator(isVisible = true))
1306+
override fun onLocationServiceRunning(roomIds: Set<String>) {
1307+
setState { copy(isSharingLiveLocation = roomId in roomIds) }
13081308
}
13091309

13101310
override fun onLocationServiceStopped() {
1311-
_viewEvents.post(RoomDetailViewEvents.ChangeLocationIndicator(isVisible = false))
1311+
setState { copy(isSharingLiveLocation = false) }
13121312
// Bind again in case user decides to share live location without leaving the room
13131313
locationSharingServiceConnection.bind(this)
13141314
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import im.vector.app.features.redaction.CheckIfEventIsRedactedUseCase
3030
import im.vector.app.features.session.coroutineScope
3131
import kotlinx.coroutines.CoroutineScope
3232
import kotlinx.coroutines.Job
33+
import kotlinx.coroutines.flow.MutableSharedFlow
34+
import kotlinx.coroutines.flow.asSharedFlow
3335
import kotlinx.coroutines.flow.distinctUntilChangedBy
3436
import kotlinx.coroutines.flow.filter
3537
import kotlinx.coroutines.flow.launchIn
@@ -68,6 +70,9 @@ class LocationSharingAndroidService : VectorAndroidService(), LocationTracker.Ca
6870
private val jobs = mutableListOf<Job>()
6971
private var startInProgress = false
7072

73+
private val _roomIdsOfActiveLives = MutableSharedFlow<Set<String>>(replay = 1)
74+
val roomIdsOfActiveLives = _roomIdsOfActiveLives.asSharedFlow()
75+
7176
override fun onCreate() {
7277
super.onCreate()
7378
Timber.i("onCreate")
@@ -195,11 +200,13 @@ class LocationSharingAndroidService : VectorAndroidService(), LocationTracker.Ca
195200
private fun addRoomArgs(beaconEventId: String, roomArgs: RoomArgs) {
196201
Timber.i("adding roomArgs for beaconEventId: $beaconEventId")
197202
roomArgsMap[beaconEventId] = roomArgs
203+
launchWithActiveSession { _roomIdsOfActiveLives.emit(getRoomIdsOfActiveLives()) }
198204
}
199205

200206
private fun removeRoomArgs(beaconEventId: String) {
201207
Timber.i("removing roomArgs for beaconEventId: $beaconEventId")
202208
roomArgsMap.remove(beaconEventId)
209+
launchWithActiveSession { _roomIdsOfActiveLives.emit(getRoomIdsOfActiveLives()) }
203210
}
204211

205212
private fun listenForLiveSummaryChanges(roomId: String, beaconEventId: String) {
@@ -226,6 +233,10 @@ class LocationSharingAndroidService : VectorAndroidService(), LocationTracker.Ca
226233
)
227234
}
228235

236+
fun getRoomIdsOfActiveLives(): Set<String> {
237+
return roomArgsMap.map { it.value.roomId }.toSet()
238+
}
239+
229240
override fun onBind(intent: Intent?): IBinder {
230241
return binder
231242
}

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

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,22 @@ import android.content.Context
2121
import android.content.Intent
2222
import android.content.ServiceConnection
2323
import android.os.IBinder
24+
import im.vector.app.core.di.ActiveSessionHolder
25+
import im.vector.app.features.session.coroutineScope
26+
import kotlinx.coroutines.CoroutineScope
27+
import kotlinx.coroutines.flow.launchIn
28+
import kotlinx.coroutines.flow.onEach
2429
import javax.inject.Inject
2530
import javax.inject.Singleton
2631

2732
@Singleton
2833
class LocationSharingServiceConnection @Inject constructor(
29-
private val context: Context
30-
) : ServiceConnection,
31-
LocationSharingAndroidService.Callback {
34+
private val context: Context,
35+
private val activeSessionHolder: ActiveSessionHolder
36+
) : ServiceConnection, LocationSharingAndroidService.Callback {
3237

3338
interface Callback {
34-
fun onLocationServiceRunning()
39+
fun onLocationServiceRunning(roomIds: Set<String>)
3540
fun onLocationServiceStopped()
3641
fun onLocationServiceError(error: Throwable)
3742
}
@@ -44,7 +49,7 @@ class LocationSharingServiceConnection @Inject constructor(
4449
addCallback(callback)
4550

4651
if (isBound) {
47-
callback.onLocationServiceRunning()
52+
callback.onLocationServiceRunning(getRoomIdsOfActiveLives())
4853
} else {
4954
Intent(context, LocationSharingAndroidService::class.java).also { intent ->
5055
context.bindService(intent, this, 0)
@@ -56,12 +61,24 @@ class LocationSharingServiceConnection @Inject constructor(
5661
removeCallback(callback)
5762
}
5863

64+
private fun getRoomIdsOfActiveLives(): Set<String> {
65+
return locationSharingAndroidService?.getRoomIdsOfActiveLives() ?: emptySet()
66+
}
67+
5968
override fun onServiceConnected(className: ComponentName, binder: IBinder) {
60-
locationSharingAndroidService = (binder as LocationSharingAndroidService.LocalBinder).getService().also {
61-
it.callback = this
69+
locationSharingAndroidService = (binder as LocationSharingAndroidService.LocalBinder).getService().also { service ->
70+
service.callback = this
71+
getActiveSessionCoroutineScope()?.let { scope ->
72+
service.roomIdsOfActiveLives
73+
.onEach(::onRoomIdsUpdate)
74+
.launchIn(scope)
75+
}
6276
}
6377
isBound = true
64-
onCallbackActionNoArg(Callback::onLocationServiceRunning)
78+
}
79+
80+
private fun getActiveSessionCoroutineScope(): CoroutineScope? {
81+
return activeSessionHolder.getSafeActiveSession()?.coroutineScope
6582
}
6683

6784
override fun onServiceDisconnected(className: ComponentName) {
@@ -71,6 +88,10 @@ class LocationSharingServiceConnection @Inject constructor(
7188
onCallbackActionNoArg(Callback::onLocationServiceStopped)
7289
}
7390

91+
private fun onRoomIdsUpdate(roomIds: Set<String>) {
92+
forwardRoomIdsToCallbacks(roomIds)
93+
}
94+
7495
override fun onServiceError(error: Throwable) {
7596
forwardErrorToCallbacks(error)
7697
}
@@ -87,6 +108,10 @@ class LocationSharingServiceConnection @Inject constructor(
87108
callbacks.toList().forEach(action)
88109
}
89110

111+
private fun forwardRoomIdsToCallbacks(roomIds: Set<String>) {
112+
callbacks.toList().forEach { it.onLocationServiceRunning(roomIds) }
113+
}
114+
90115
private fun forwardErrorToCallbacks(error: Throwable) {
91116
callbacks.toList().forEach { it.onLocationServiceError(error) }
92117
}

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)