Forward error to UI in timeline screen

This commit is contained in:
Maxime NATUREL 2022-06-15 14:34:13 +02:00
parent 9eba3034db
commit 31bb9eaac8
4 changed files with 28 additions and 7 deletions

View file

@ -1293,6 +1293,10 @@ class TimelineViewModel @AssistedInject constructor(
locationSharingServiceConnection.bind(this) locationSharingServiceConnection.bind(this)
} }
override fun onLocationServiceError(error: Throwable) {
_viewEvents.post(RoomDetailViewEvents.Failure(error))
}
override fun onCleared() { override fun onCleared() {
timeline.dispose() timeline.dispose()
timeline.removeAllListeners() timeline.removeAllListeners()

View file

@ -55,8 +55,9 @@ class LocationSharingService : VectorService(), LocationTracker.Callback {
/** /**
* Keep track of a map between beacon event Id starting the live and RoomArgs. * Keep track of a map between beacon event Id starting the live and RoomArgs.
*/ */
private var roomArgsMap = mutableMapOf<String, RoomArgs>() private val roomArgsMap = mutableMapOf<String, RoomArgs>()
private var timers = mutableListOf<Timer>() private val timers = mutableListOf<Timer>()
var callback: Callback? = null
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
@ -103,6 +104,7 @@ class LocationSharingService : VectorService(), LocationTracker.Callback {
locationTracker.requestLastKnownLocation() locationTracker.requestLastKnownLocation()
} }
is UpdateLiveLocationShareResult.Failure -> { is UpdateLiveLocationShareResult.Failure -> {
callback?.onServiceError(result.error)
tryToDestroyMe() tryToDestroyMe()
} }
} }
@ -132,8 +134,7 @@ class LocationSharingService : VectorService(), LocationTracker.Callback {
Timber.i("### LocationSharingService.stopSharingLocation for $roomId") Timber.i("### LocationSharingService.stopSharingLocation for $roomId")
launchInIO { session -> launchInIO { session ->
// Send a new beacon info state by setting live field as false when (val result = sendStoppedBeaconInfo(session, roomId)) {
when (sendStoppedBeaconInfo(session, roomId)) {
is UpdateLiveLocationShareResult.Success -> { is UpdateLiveLocationShareResult.Success -> {
synchronized(roomArgsMap) { synchronized(roomArgsMap) {
val beaconIds = roomArgsMap val beaconIds = roomArgsMap
@ -144,6 +145,7 @@ class LocationSharingService : VectorService(), LocationTracker.Callback {
tryToDestroyMe() tryToDestroyMe()
} }
} }
is UpdateLiveLocationShareResult.Failure -> callback?.onServiceError(result.error)
else -> Unit else -> Unit
} }
} }
@ -224,6 +226,10 @@ class LocationSharingService : VectorService(), LocationTracker.Callback {
fun getService(): LocationSharingService = this@LocationSharingService fun getService(): LocationSharingService = this@LocationSharingService
} }
interface Callback {
fun onServiceError(error: Throwable)
}
companion object { companion object {
const val EXTRA_ROOM_ARGS = "EXTRA_ROOM_ARGS" const val EXTRA_ROOM_ARGS = "EXTRA_ROOM_ARGS"
} }

View file

@ -25,12 +25,12 @@ import javax.inject.Inject
class LocationSharingServiceConnection @Inject constructor( class LocationSharingServiceConnection @Inject constructor(
private val context: Context private val context: Context
) : ServiceConnection { ) : ServiceConnection, LocationSharingService.Callback {
interface Callback { interface Callback {
// TODO add onLocationServiceError()
fun onLocationServiceRunning() fun onLocationServiceRunning()
fun onLocationServiceStopped() fun onLocationServiceStopped()
fun onLocationServiceError(error: Throwable)
} }
private var callback: Callback? = null private var callback: Callback? = null
@ -58,14 +58,21 @@ class LocationSharingServiceConnection @Inject constructor(
} }
override fun onServiceConnected(className: ComponentName, binder: IBinder) { override fun onServiceConnected(className: ComponentName, binder: IBinder) {
locationSharingService = (binder as LocationSharingService.LocalBinder).getService() locationSharingService = (binder as LocationSharingService.LocalBinder).getService().also {
it.callback = this
}
isBound = true isBound = true
callback?.onLocationServiceRunning() callback?.onLocationServiceRunning()
} }
override fun onServiceDisconnected(className: ComponentName) { override fun onServiceDisconnected(className: ComponentName) {
isBound = false isBound = false
locationSharingService?.callback = null
locationSharingService = null locationSharingService = null
callback?.onLocationServiceStopped() callback?.onLocationServiceStopped()
} }
override fun onServiceError(error: Throwable) {
callback?.onLocationServiceError(error)
}
} }

View file

@ -80,4 +80,8 @@ class LocationLiveMapViewModel @AssistedInject constructor(
override fun onLocationServiceStopped() { override fun onLocationServiceStopped() {
// NOOP // NOOP
} }
override fun onLocationServiceError(error: Throwable) {
// TODO
}
} }