mirror of
https://github.com/element-hq/element-android
synced 2024-11-24 10:25:35 +03:00
Forward error to UI in timeline screen
This commit is contained in:
parent
9eba3034db
commit
31bb9eaac8
4 changed files with 28 additions and 7 deletions
|
@ -1293,6 +1293,10 @@ class TimelineViewModel @AssistedInject constructor(
|
|||
locationSharingServiceConnection.bind(this)
|
||||
}
|
||||
|
||||
override fun onLocationServiceError(error: Throwable) {
|
||||
_viewEvents.post(RoomDetailViewEvents.Failure(error))
|
||||
}
|
||||
|
||||
override fun onCleared() {
|
||||
timeline.dispose()
|
||||
timeline.removeAllListeners()
|
||||
|
|
|
@ -55,8 +55,9 @@ class LocationSharingService : VectorService(), LocationTracker.Callback {
|
|||
/**
|
||||
* Keep track of a map between beacon event Id starting the live and RoomArgs.
|
||||
*/
|
||||
private var roomArgsMap = mutableMapOf<String, RoomArgs>()
|
||||
private var timers = mutableListOf<Timer>()
|
||||
private val roomArgsMap = mutableMapOf<String, RoomArgs>()
|
||||
private val timers = mutableListOf<Timer>()
|
||||
var callback: Callback? = null
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
|
@ -103,6 +104,7 @@ class LocationSharingService : VectorService(), LocationTracker.Callback {
|
|||
locationTracker.requestLastKnownLocation()
|
||||
}
|
||||
is UpdateLiveLocationShareResult.Failure -> {
|
||||
callback?.onServiceError(result.error)
|
||||
tryToDestroyMe()
|
||||
}
|
||||
}
|
||||
|
@ -132,8 +134,7 @@ class LocationSharingService : VectorService(), LocationTracker.Callback {
|
|||
Timber.i("### LocationSharingService.stopSharingLocation for $roomId")
|
||||
|
||||
launchInIO { session ->
|
||||
// Send a new beacon info state by setting live field as false
|
||||
when (sendStoppedBeaconInfo(session, roomId)) {
|
||||
when (val result = sendStoppedBeaconInfo(session, roomId)) {
|
||||
is UpdateLiveLocationShareResult.Success -> {
|
||||
synchronized(roomArgsMap) {
|
||||
val beaconIds = roomArgsMap
|
||||
|
@ -144,6 +145,7 @@ class LocationSharingService : VectorService(), LocationTracker.Callback {
|
|||
tryToDestroyMe()
|
||||
}
|
||||
}
|
||||
is UpdateLiveLocationShareResult.Failure -> callback?.onServiceError(result.error)
|
||||
else -> Unit
|
||||
}
|
||||
}
|
||||
|
@ -224,6 +226,10 @@ class LocationSharingService : VectorService(), LocationTracker.Callback {
|
|||
fun getService(): LocationSharingService = this@LocationSharingService
|
||||
}
|
||||
|
||||
interface Callback {
|
||||
fun onServiceError(error: Throwable)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val EXTRA_ROOM_ARGS = "EXTRA_ROOM_ARGS"
|
||||
}
|
||||
|
|
|
@ -25,12 +25,12 @@ import javax.inject.Inject
|
|||
|
||||
class LocationSharingServiceConnection @Inject constructor(
|
||||
private val context: Context
|
||||
) : ServiceConnection {
|
||||
) : ServiceConnection, LocationSharingService.Callback {
|
||||
|
||||
interface Callback {
|
||||
// TODO add onLocationServiceError()
|
||||
fun onLocationServiceRunning()
|
||||
fun onLocationServiceStopped()
|
||||
fun onLocationServiceError(error: Throwable)
|
||||
}
|
||||
|
||||
private var callback: Callback? = null
|
||||
|
@ -58,14 +58,21 @@ class LocationSharingServiceConnection @Inject constructor(
|
|||
}
|
||||
|
||||
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
|
||||
callback?.onLocationServiceRunning()
|
||||
}
|
||||
|
||||
override fun onServiceDisconnected(className: ComponentName) {
|
||||
isBound = false
|
||||
locationSharingService?.callback = null
|
||||
locationSharingService = null
|
||||
callback?.onLocationServiceStopped()
|
||||
}
|
||||
|
||||
override fun onServiceError(error: Throwable) {
|
||||
callback?.onLocationServiceError(error)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,4 +80,8 @@ class LocationLiveMapViewModel @AssistedInject constructor(
|
|||
override fun onLocationServiceStopped() {
|
||||
// NOOP
|
||||
}
|
||||
|
||||
override fun onLocationServiceError(error: Throwable) {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue