mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-02-17 04:20:00 +03:00
Show a banner in timeline while location sharing service is running.
This commit is contained in:
parent
3cf7765aaf
commit
7999bd7523
5 changed files with 100 additions and 3 deletions
|
@ -82,4 +82,7 @@ sealed class RoomDetailViewEvents : VectorViewEvents {
|
||||||
data class StartChatEffect(val type: ChatEffect) : RoomDetailViewEvents()
|
data class StartChatEffect(val type: ChatEffect) : RoomDetailViewEvents()
|
||||||
object StopChatEffects : RoomDetailViewEvents()
|
object StopChatEffects : RoomDetailViewEvents()
|
||||||
object RoomReplacementStarted : RoomDetailViewEvents()
|
object RoomReplacementStarted : RoomDetailViewEvents()
|
||||||
|
|
||||||
|
object ShowLocationSharingIndicator : RoomDetailViewEvents()
|
||||||
|
object HideLocationSharingIndicator : RoomDetailViewEvents()
|
||||||
}
|
}
|
||||||
|
|
|
@ -482,6 +482,8 @@ class TimelineFragment @Inject constructor(
|
||||||
RoomDetailViewEvents.StopChatEffects -> handleStopChatEffects()
|
RoomDetailViewEvents.StopChatEffects -> handleStopChatEffects()
|
||||||
is RoomDetailViewEvents.DisplayAndAcceptCall -> acceptIncomingCall(it)
|
is RoomDetailViewEvents.DisplayAndAcceptCall -> acceptIncomingCall(it)
|
||||||
RoomDetailViewEvents.RoomReplacementStarted -> handleRoomReplacement()
|
RoomDetailViewEvents.RoomReplacementStarted -> handleRoomReplacement()
|
||||||
|
RoomDetailViewEvents.ShowLocationSharingIndicator -> handleShowLocationSharingIndicator()
|
||||||
|
RoomDetailViewEvents.HideLocationSharingIndicator -> handleHideLocationSharingIndicator()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -616,6 +618,14 @@ class TimelineFragment @Inject constructor(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun handleShowLocationSharingIndicator() {
|
||||||
|
views.locationLiveStatusIndicator.isVisible = true
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun handleHideLocationSharingIndicator() {
|
||||||
|
views.locationLiveStatusIndicator.isVisible = false
|
||||||
|
}
|
||||||
|
|
||||||
private fun displayErrorMessage(error: RoomDetailViewEvents.Failure) {
|
private fun displayErrorMessage(error: RoomDetailViewEvents.Failure) {
|
||||||
if (error.showInDialog) displayErrorDialog(error.throwable) else showErrorInSnackbar(error.throwable)
|
if (error.showInDialog) displayErrorDialog(error.throwable) else showErrorInSnackbar(error.throwable)
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,7 @@ import im.vector.app.features.home.room.detail.sticker.StickerPickerActionHandle
|
||||||
import im.vector.app.features.home.room.detail.timeline.factory.TimelineFactory
|
import im.vector.app.features.home.room.detail.timeline.factory.TimelineFactory
|
||||||
import im.vector.app.features.home.room.detail.timeline.url.PreviewUrlRetriever
|
import im.vector.app.features.home.room.detail.timeline.url.PreviewUrlRetriever
|
||||||
import im.vector.app.features.home.room.typing.TypingHelper
|
import im.vector.app.features.home.room.typing.TypingHelper
|
||||||
|
import im.vector.app.features.location.LocationSharingServiceConnection
|
||||||
import im.vector.app.features.notifications.NotificationDrawerManager
|
import im.vector.app.features.notifications.NotificationDrawerManager
|
||||||
import im.vector.app.features.powerlevel.PowerLevelsFlowFactory
|
import im.vector.app.features.powerlevel.PowerLevelsFlowFactory
|
||||||
import im.vector.app.features.session.coroutineScope
|
import im.vector.app.features.session.coroutineScope
|
||||||
|
@ -124,10 +125,11 @@ class TimelineViewModel @AssistedInject constructor(
|
||||||
private val activeConferenceHolder: JitsiActiveConferenceHolder,
|
private val activeConferenceHolder: JitsiActiveConferenceHolder,
|
||||||
private val decryptionFailureTracker: DecryptionFailureTracker,
|
private val decryptionFailureTracker: DecryptionFailureTracker,
|
||||||
private val notificationDrawerManager: NotificationDrawerManager,
|
private val notificationDrawerManager: NotificationDrawerManager,
|
||||||
|
private val locationSharingServiceConnection: LocationSharingServiceConnection,
|
||||||
timelineFactory: TimelineFactory,
|
timelineFactory: TimelineFactory,
|
||||||
appStateHandler: AppStateHandler
|
appStateHandler: AppStateHandler
|
||||||
) : VectorViewModel<RoomDetailViewState, RoomDetailAction, RoomDetailViewEvents>(initialState),
|
) : VectorViewModel<RoomDetailViewState, RoomDetailAction, RoomDetailViewEvents>(initialState),
|
||||||
Timeline.Listener, ChatEffectManager.Delegate, CallProtocolsChecker.Listener {
|
Timeline.Listener, ChatEffectManager.Delegate, CallProtocolsChecker.Listener, LocationSharingServiceConnection.Callback {
|
||||||
|
|
||||||
private val room = session.getRoom(initialState.roomId)!!
|
private val room = session.getRoom(initialState.roomId)!!
|
||||||
private val eventId = initialState.eventId
|
private val eventId = initialState.eventId
|
||||||
|
@ -219,6 +221,9 @@ class TimelineViewModel @AssistedInject constructor(
|
||||||
|
|
||||||
// Threads
|
// Threads
|
||||||
initThreads()
|
initThreads()
|
||||||
|
|
||||||
|
// Observe location service lifecycle to be able to warn the user
|
||||||
|
locationSharingServiceConnection.bind(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1218,6 +1223,14 @@ class TimelineViewModel @AssistedInject constructor(
|
||||||
_viewEvents.post(RoomDetailViewEvents.OnNewTimelineEvents(eventIds))
|
_viewEvents.post(RoomDetailViewEvents.OnNewTimelineEvents(eventIds))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onLocationServiceRunning() {
|
||||||
|
_viewEvents.post(RoomDetailViewEvents.ShowLocationSharingIndicator)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onLocationServiceStopped() {
|
||||||
|
_viewEvents.post(RoomDetailViewEvents.HideLocationSharingIndicator)
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCleared() {
|
override fun onCleared() {
|
||||||
timeline.dispose()
|
timeline.dispose()
|
||||||
timeline.removeAllListeners()
|
timeline.removeAllListeners()
|
||||||
|
@ -1231,6 +1244,7 @@ class TimelineViewModel @AssistedInject constructor(
|
||||||
// we should also mark it as read here, for the scenario that the user
|
// we should also mark it as read here, for the scenario that the user
|
||||||
// is already in the thread timeline
|
// is already in the thread timeline
|
||||||
markThreadTimelineAsReadLocal()
|
markThreadTimelineAsReadLocal()
|
||||||
|
locationSharingServiceConnection.unbind()
|
||||||
super.onCleared()
|
super.onCleared()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
package im.vector.app.features.location
|
package im.vector.app.features.location
|
||||||
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.os.Binder
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import android.os.Parcelable
|
import android.os.Parcelable
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
|
@ -41,6 +42,8 @@ class LocationSharingService : VectorService(), LocationTracker.Callback {
|
||||||
@Inject lateinit var notificationUtils: NotificationUtils
|
@Inject lateinit var notificationUtils: NotificationUtils
|
||||||
@Inject lateinit var locationTracker: LocationTracker
|
@Inject lateinit var locationTracker: LocationTracker
|
||||||
|
|
||||||
|
private val binder = LocalBinder()
|
||||||
|
|
||||||
private var roomArgsList = mutableListOf<RoomArgs>()
|
private var roomArgsList = mutableListOf<RoomArgs>()
|
||||||
private var timers = mutableListOf<Timer>()
|
private var timers = mutableListOf<Timer>()
|
||||||
|
|
||||||
|
@ -120,8 +123,12 @@ class LocationSharingService : VectorService(), LocationTracker.Callback {
|
||||||
destroyMe()
|
destroyMe()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBind(intent: Intent?): IBinder? {
|
override fun onBind(intent: Intent?): IBinder {
|
||||||
return null
|
return binder
|
||||||
|
}
|
||||||
|
|
||||||
|
inner class LocalBinder : Binder() {
|
||||||
|
fun getService(): LocationSharingService = this@LocationSharingService
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022 New Vector Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package im.vector.app.features.location
|
||||||
|
|
||||||
|
import android.content.ComponentName
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.content.ServiceConnection
|
||||||
|
import android.os.IBinder
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class LocationSharingServiceConnection @Inject constructor(
|
||||||
|
private val context: Context
|
||||||
|
) : ServiceConnection {
|
||||||
|
|
||||||
|
interface Callback {
|
||||||
|
fun onLocationServiceRunning()
|
||||||
|
fun onLocationServiceStopped()
|
||||||
|
}
|
||||||
|
|
||||||
|
private var callback: Callback? = null
|
||||||
|
private var isBound = false
|
||||||
|
|
||||||
|
fun bind(callback: Callback) {
|
||||||
|
this.callback = callback
|
||||||
|
|
||||||
|
if (isBound) {
|
||||||
|
callback.onLocationServiceRunning()
|
||||||
|
} else {
|
||||||
|
Intent(context, LocationSharingService::class.java).also { intent ->
|
||||||
|
context.bindService(intent, this, 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun unbind() {
|
||||||
|
callback = null
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onServiceConnected(className: ComponentName, binder: IBinder) {
|
||||||
|
isBound = true
|
||||||
|
callback?.onLocationServiceRunning()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onServiceDisconnected(className: ComponentName) {
|
||||||
|
isBound = false
|
||||||
|
callback?.onLocationServiceStopped()
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue