Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send turnstiles for Snapshotter usage #920

Merged
merged 1 commit into from
Dec 16, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions sdk/src/main/java/com/mapbox/maps/Snapshotter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import android.view.ViewGroup
import android.widget.TextView
import androidx.annotation.VisibleForTesting
import androidx.core.content.res.ResourcesCompat
import com.mapbox.annotation.module.MapboxModuleType
import com.mapbox.common.Logger
import com.mapbox.common.module.provider.MapboxModuleProvider
import com.mapbox.common.module.provider.ModuleProviderArgument
import com.mapbox.geojson.Point
import com.mapbox.maps.attribution.AttributionLayout
import com.mapbox.maps.attribution.AttributionMeasure
Expand All @@ -18,6 +21,7 @@ import com.mapbox.maps.extension.observable.getMapLoadingErrorEventData
import com.mapbox.maps.extension.observable.getStyleDataLoadedEventData
import com.mapbox.maps.extension.observable.getStyleImageMissingEventData
import com.mapbox.maps.extension.observable.model.StyleDataType
import com.mapbox.maps.module.MapTelemetry
import java.lang.ref.WeakReference
import kotlin.math.min

Expand Down Expand Up @@ -48,6 +52,7 @@ open class Snapshotter {
snapshotOverlayOptions = overlayOptions
pixelRatio = context.resources.displayMetrics.density
coreSnapshotter = MapSnapshotter(options)
dispatchTelemetryTurnstileEvent(context, options)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so new turnstile event is triggered each time when Snapshotter is created? I'm not sure it's what we want...
@tobrun shouldn't it be some other telemetry event?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same with V9.

val weakSelf = WeakReference(this)
observer = Observer { event ->
weakSelf.get()?.apply {
Expand Down Expand Up @@ -83,6 +88,21 @@ open class Snapshotter {
subscribe(observer, STYLE_LOAD_EVENTS_LIST)
}

private fun dispatchTelemetryTurnstileEvent(
context: Context,
options: MapSnapshotOptions
) {
MapboxModuleProvider.createModule<MapTelemetry>(MapboxModuleType.MapTelemetry) {
arrayOf(
ModuleProviderArgument(
Context::class.java,
context.applicationContext
),
ModuleProviderArgument(String::class.java, options.resourceOptions.accessToken)
)
}.onAppUserTurnstileEvent()
}

@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
internal constructor(
context: WeakReference<Context>,
Expand Down