Stop live location sharing.

This commit is contained in:
Onuray Sahin 2022-04-13 17:00:37 +03:00
parent 4ee7332973
commit 33e735cbdd
5 changed files with 35 additions and 1 deletions

View file

@ -111,4 +111,7 @@ sealed class RoomDetailAction : VectorViewModelAction {
// Poll
data class EndPoll(val eventId: String) : RoomDetailAction()
// Live Location
object StopLiveLocationSharing : RoomDetailAction()
}

View file

@ -385,6 +385,7 @@ class TimelineFragment @Inject constructor(
setupEmojiButton()
setupRemoveJitsiWidgetView()
setupVoiceMessageView()
setupLiveLocationIndicator()
views.includeRoomToolbar.roomToolbarContentView.debouncedClicks {
navigator.openRoomProfile(requireActivity(), timelineArgs.roomId)
@ -810,6 +811,12 @@ class TimelineFragment @Inject constructor(
}
}
private fun setupLiveLocationIndicator() {
views.locationLiveStatusIndicator.stopButton.debouncedClicks {
timelineViewModel.handle(RoomDetailAction.StopLiveLocationSharing)
}
}
private fun joinJitsiRoom(jitsiWidget: Widget, enableVideo: Boolean) {
navigator.openRoomWidget(requireContext(), timelineArgs.roomId, jitsiWidget, mapOf(JitsiCallViewModel.ENABLE_VIDEO_OPTION to enableVideo))
}

View file

@ -444,6 +444,7 @@ class TimelineViewModel @AssistedInject constructor(
_viewEvents.post(RoomDetailViewEvents.OpenRoom(action.replacementRoomId, closeCurrentRoom = true))
}
is RoomDetailAction.EndPoll -> handleEndPoll(action.eventId)
RoomDetailAction.StopLiveLocationSharing -> handleStopLiveLocationSharing()
}
}
@ -1093,6 +1094,23 @@ class TimelineViewModel @AssistedInject constructor(
}
}
private fun handleStopLiveLocationSharing() {
viewModelScope.launch {
EventType
.STATE_ROOM_BEACON_INFO
.mapNotNull {
room.getStateEvent(it, QueryStringValue.Equals(session.myUserId))
}
.firstOrNull()
?.let { beaconInfoEvent ->
room.stopLiveLocation(beaconInfoEvent)
}
?.also {
locationSharingServiceConnection.stopLiveLocationSharing(room.roomId)
}
}
}
private fun observeRoomSummary() {
room.flow().liveRoomSummary()
.unwrap()

View file

@ -129,7 +129,7 @@ class LocationSharingService : VectorService(), LocationTracker.Callback {
}
}
private fun stopSharingLocation(roomId: String) {
fun stopSharingLocation(roomId: String) {
Timber.i("### LocationSharingService.stopSharingLocation for $roomId")
synchronized(roomArgsList) {
roomArgsList.removeAll { it.roomId == roomId }

View file

@ -34,6 +34,7 @@ class LocationSharingServiceConnection @Inject constructor(
private var callback: Callback? = null
private var isBound = false
private var locationSharingService: LocationSharingService? = null
fun bind(callback: Callback) {
this.callback = callback
@ -51,7 +52,12 @@ class LocationSharingServiceConnection @Inject constructor(
callback = null
}
fun stopLiveLocationSharing(roomId: String) {
locationSharingService?.stopSharingLocation(roomId)
}
override fun onServiceConnected(className: ComponentName, binder: IBinder) {
locationSharingService = (binder as LocationSharingService.LocalBinder).getService()
isBound = true
callback?.onLocationServiceRunning()
}