-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
82 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
libnavigation-metrics/src/main/java/com/mapbox/navigation/metrics/events/EventsObserver.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.mapbox.navigation.metrics.events | ||
|
||
import com.mapbox.bindgen.Value | ||
|
||
fun interface EventsObserver { | ||
fun onEvents(events: Value) | ||
} |
52 changes: 52 additions & 0 deletions
52
...rics/src/main/java/com/mapbox/navigation/metrics/events/EventsServiceInterfacesManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.mapbox.navigation.metrics.events | ||
|
||
import com.mapbox.bindgen.Value | ||
import com.mapbox.common.EventsServiceError | ||
import com.mapbox.common.EventsServiceInterface | ||
import com.mapbox.common.EventsServiceObserver | ||
|
||
class EventsServiceInterfacesManager( | ||
// platformEventsServiceInterface: EventsServiceInterface, | ||
internal val nativeEventsServiceInterface: EventsServiceInterface, | ||
) { | ||
private val eventServices = listOf( | ||
// platformEventsServiceInterface, | ||
nativeEventsServiceInterface, | ||
) | ||
|
||
private val observers = mutableListOf<EventsObserver>() | ||
|
||
private val eventsServiceObserver = object : EventsServiceObserver { | ||
override fun didEncounterError(error: EventsServiceError, events: Value) { | ||
// do nothing | ||
} | ||
|
||
override fun didSendEvents(events: Value) { | ||
observers.forEach { it.onEvents(events) } | ||
} | ||
|
||
} | ||
|
||
fun registerEventsObserver(eventsObserver: EventsObserver) { | ||
checkAndRegisterInternal() | ||
observers.add(eventsObserver) | ||
} | ||
|
||
fun unregisterEventsObserver(eventsObserver: EventsObserver) { | ||
observers.remove(eventsObserver) | ||
checkAndUnregisterInternal() | ||
} | ||
|
||
private fun checkAndRegisterInternal() { | ||
if (observers.isEmpty()) { | ||
eventServices.forEach { it.registerObserver(eventsServiceObserver) } | ||
} | ||
} | ||
|
||
private fun checkAndUnregisterInternal() { | ||
if (observers.isEmpty()) { | ||
eventServices.forEach { it.unregisterObserver(eventsServiceObserver) } | ||
} | ||
} | ||
} | ||
|
13 changes: 13 additions & 0 deletions
13
...ion-metrics/src/main/java/com/mapbox/navigation/metrics/events/TelemetryEventsProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.mapbox.navigation.metrics.events | ||
|
||
import com.mapbox.common.EventsServerOptions | ||
import com.mapbox.common.EventsService | ||
|
||
object TelemetryEventsProvider { | ||
fun getOrCreateTelemetryEventsManager(accessToken: String): EventsServiceInterfacesManager = | ||
EventsServiceInterfacesManager( | ||
EventsService.getOrCreate( | ||
EventsServerOptions(accessToken, "MapboxNavigationNative", null) | ||
) | ||
) | ||
} |