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

Drop proxy binary messenger #715

Merged
merged 23 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from 19 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
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ import java.util.Date
class MapboxEventHandler(
private val eventProvider: Observable,
binaryMessenger: BinaryMessenger,
eventTypes: List<Long>
eventTypes: List<Long>,
channelSuffix: String,
) : MethodChannel.MethodCallHandler {
private val channel: MethodChannel
private val cancellables = HashSet<Cancelable>()
Expand All @@ -47,7 +48,8 @@ class MapboxEventHandler(
.create()

init {
channel = MethodChannel(binaryMessenger, "com.mapbox.maps.flutter.map_events")
val pigeon_channelSuffix = if (channelSuffix.isNotEmpty()) ".$channelSuffix" else ""
channel = MethodChannel(binaryMessenger, "com.mapbox.maps.flutter.map_events$pigeon_channelSuffix")
channel.setMethodCallHandler(this)

eventTypes.mapNotNull { _MapEvent.ofRaw(it.toInt()) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class GestureController(private val mapView: MapView, private val context: Conte
private var onLongClickListener: OnMapLongClickListener? = null
private var onMoveListener: OnMoveListener? = null

fun addListeners(messenger: BinaryMessenger) {
fltGestureListener = GestureListener(messenger)
fun addListeners(messenger: BinaryMessenger, channelSuffix: String) {
fltGestureListener = GestureListener(messenger, channelSuffix)

removeListeners()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ class MapboxMapController(

private var mapView: MapView? = null
private var mapboxMap: MapboxMap? = null

private val methodChannel: MethodChannel
private val messenger: BinaryMessenger
private val channelSuffix: String

private val styleController: StyleController
private val cameraController: CameraController
private val projectionController: MapProjectionController
Expand All @@ -61,7 +65,6 @@ class MapboxMapController(
private val scaleBarController: ScaleBarController
private val compassController: CompassController

private val proxyBinaryMessenger = ProxyBinaryMessenger(messenger, "$channelSuffix")
private val eventHandler: MapboxEventHandler

/*
Expand Down Expand Up @@ -122,11 +125,14 @@ class MapboxMapController(
private var lifecycleHelper: LifecycleHelper? = null

init {
this.messenger = messenger
this.channelSuffix = channelSuffix.toString()

val mapView = MapView(context, mapInitOptions)
val mapboxMap = mapView.mapboxMap
this.mapView = mapView
this.mapboxMap = mapboxMap
eventHandler = MapboxEventHandler(mapboxMap.styleManager, proxyBinaryMessenger, eventTypes)
eventHandler = MapboxEventHandler(mapboxMap.styleManager, messenger, eventTypes, this.channelSuffix)
styleController = StyleController(context, mapboxMap)
cameraController = CameraController(mapboxMap, context)
projectionController = MapProjectionController(mapboxMap)
Expand All @@ -142,20 +148,20 @@ class MapboxMapController(

changeUserAgent(pluginVersion)

StyleManager.setUp(proxyBinaryMessenger, styleController)
_CameraManager.setUp(proxyBinaryMessenger, cameraController)
Projection.setUp(proxyBinaryMessenger, projectionController)
_MapInterface.setUp(proxyBinaryMessenger, mapInterfaceController)
_AnimationManager.setUp(proxyBinaryMessenger, animationController)
annotationController.setup(proxyBinaryMessenger)
_LocationComponentSettingsInterface.setUp(proxyBinaryMessenger, locationComponentController)
LogoSettingsInterface.setUp(proxyBinaryMessenger, logoController)
GesturesSettingsInterface.setUp(proxyBinaryMessenger, gestureController)
AttributionSettingsInterface.setUp(proxyBinaryMessenger, attributionController)
ScaleBarSettingsInterface.setUp(proxyBinaryMessenger, scaleBarController)
CompassSettingsInterface.setUp(proxyBinaryMessenger, compassController)

methodChannel = MethodChannel(proxyBinaryMessenger, "plugins.flutter.io")
StyleManager.setUp(messenger, styleController, this.channelSuffix)
_CameraManager.setUp(messenger, cameraController, this.channelSuffix)
Projection.setUp(messenger, projectionController, this.channelSuffix)
_MapInterface.setUp(messenger, mapInterfaceController, this.channelSuffix)
_AnimationManager.setUp(messenger, animationController, this.channelSuffix)
annotationController.setup(messenger, this.channelSuffix)
_LocationComponentSettingsInterface.setUp(messenger, locationComponentController, this.channelSuffix)
LogoSettingsInterface.setUp(messenger, logoController, this.channelSuffix)
GesturesSettingsInterface.setUp(messenger, gestureController, this.channelSuffix)
AttributionSettingsInterface.setUp(messenger, attributionController, this.channelSuffix)
ScaleBarSettingsInterface.setUp(messenger, scaleBarController, this.channelSuffix)
CompassSettingsInterface.setUp(messenger, compassController, this.channelSuffix)

methodChannel = MethodChannel(messenger, "plugins.flutter.io")
methodChannel.setMethodCallHandler(this)
}

Expand Down Expand Up @@ -191,18 +197,18 @@ class MapboxMapController(
mapView = null
mapboxMap = null
methodChannel.setMethodCallHandler(null)
StyleManager.setUp(proxyBinaryMessenger, null)
_CameraManager.setUp(proxyBinaryMessenger, null)
Projection.setUp(proxyBinaryMessenger, null)
_MapInterface.setUp(proxyBinaryMessenger, null)
_AnimationManager.setUp(proxyBinaryMessenger, null)
annotationController.dispose(proxyBinaryMessenger)
_LocationComponentSettingsInterface.setUp(proxyBinaryMessenger, null)
LogoSettingsInterface.setUp(proxyBinaryMessenger, null)
GesturesSettingsInterface.setUp(proxyBinaryMessenger, null)
CompassSettingsInterface.setUp(proxyBinaryMessenger, null)
ScaleBarSettingsInterface.setUp(proxyBinaryMessenger, null)
AttributionSettingsInterface.setUp(proxyBinaryMessenger, null)
StyleManager.setUp(messenger, null, channelSuffix)
_CameraManager.setUp(messenger, null, channelSuffix)
Projection.setUp(messenger, null, channelSuffix)
_MapInterface.setUp(messenger, null, channelSuffix)
_AnimationManager.setUp(messenger, null, channelSuffix)
annotationController.dispose(messenger, channelSuffix)
_LocationComponentSettingsInterface.setUp(messenger, null, channelSuffix)
LogoSettingsInterface.setUp(messenger, null, channelSuffix)
GesturesSettingsInterface.setUp(messenger, null, channelSuffix)
CompassSettingsInterface.setUp(messenger, null, channelSuffix)
ScaleBarSettingsInterface.setUp(messenger, null, channelSuffix)
AttributionSettingsInterface.setUp(messenger, null, channelSuffix)
}

override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
Expand All @@ -214,7 +220,7 @@ class MapboxMapController(
annotationController.handleRemoveManager(call, result)
}
"gesture#add_listeners" -> {
gestureController.addListeners(proxyBinaryMessenger)
gestureController.addListeners(messenger, channelSuffix)
result.success(null)
}
"gesture#remove_listeners" -> {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ class AnnotationController(private val mapView: MapView) :
private val circleAnnotationController = CircleAnnotationController(this)
private val polygonAnnotationController = PolygonAnnotationController(this)
private val polylineAnnotationController = PolylineAnnotationController(this)
private lateinit var onPointAnnotationClickListener: OnPointAnnotationClickListener
private lateinit var onPolygonAnnotationClickListener: OnPolygonAnnotationClickListener
private lateinit var onPolylineAnnotationController: OnPolylineAnnotationClickListener
private lateinit var onCircleAnnotationClickListener: OnCircleAnnotationClickListener
private var onPointAnnotationClickListener: OnPointAnnotationClickListener? = null
private var onPolygonAnnotationClickListener: OnPolygonAnnotationClickListener? = null
private var onPolylineAnnotationClickListener: OnPolylineAnnotationClickListener? = null
private var onCircleAnnotationClickListener: OnCircleAnnotationClickListener? = null
private var index = 0
fun handleCreateManager(call: MethodCall, result: MethodChannel.Result) {
val id = call.argument<String>("id") ?: (index++).toString()
Expand All @@ -41,7 +41,7 @@ class AnnotationController(private val mapView: MapView) :
mapView.annotations.createCircleAnnotationManager(AnnotationConfig(belowLayerId, id, id)).apply {
this.addClickListener(
com.mapbox.maps.plugin.annotation.generated.OnCircleAnnotationClickListener { annotation ->
onCircleAnnotationClickListener.onCircleAnnotationClick(annotation.toFLTCircleAnnotation()) {}
onCircleAnnotationClickListener?.onCircleAnnotationClick(annotation.toFLTCircleAnnotation()) {}
true
}
)
Expand All @@ -51,7 +51,7 @@ class AnnotationController(private val mapView: MapView) :
mapView.annotations.createPointAnnotationManager(AnnotationConfig(belowLayerId, id, id)).apply {
this.addClickListener(
com.mapbox.maps.plugin.annotation.generated.OnPointAnnotationClickListener { annotation ->
onPointAnnotationClickListener.onPointAnnotationClick(annotation.toFLTPointAnnotation()) {}
onPointAnnotationClickListener?.onPointAnnotationClick(annotation.toFLTPointAnnotation()) {}
true
}
)
Expand All @@ -61,7 +61,7 @@ class AnnotationController(private val mapView: MapView) :
mapView.annotations.createPolygonAnnotationManager(AnnotationConfig(belowLayerId, id, id)).apply {
this.addClickListener(
com.mapbox.maps.plugin.annotation.generated.OnPolygonAnnotationClickListener { annotation ->
onPolygonAnnotationClickListener.onPolygonAnnotationClick(annotation.toFLTPolygonAnnotation()) {}
onPolygonAnnotationClickListener?.onPolygonAnnotationClick(annotation.toFLTPolygonAnnotation()) {}
true
}
)
Expand All @@ -71,7 +71,7 @@ class AnnotationController(private val mapView: MapView) :
mapView.annotations.createPolylineAnnotationManager(AnnotationConfig(belowLayerId, id, id)).apply {
this.addClickListener(
com.mapbox.maps.plugin.annotation.generated.OnPolylineAnnotationClickListener { annotation ->
onPolylineAnnotationController.onPolylineAnnotationClick(annotation.toFLTPolylineAnnotation()) {}
onPolylineAnnotationClickListener?.onPolylineAnnotationClick(annotation.toFLTPolylineAnnotation()) {}
true
}
)
Expand All @@ -94,31 +94,35 @@ class AnnotationController(private val mapView: MapView) :
result.success(null)
}

fun setup(messenger: BinaryMessenger) {
onPointAnnotationClickListener = OnPointAnnotationClickListener(messenger)
onCircleAnnotationClickListener = OnCircleAnnotationClickListener(messenger)
onPolygonAnnotationClickListener = OnPolygonAnnotationClickListener(messenger)
onPolylineAnnotationController = OnPolylineAnnotationClickListener(messenger)
_PointAnnotationMessenger.setUp(messenger, pointAnnotationController)
fun setup(messenger: BinaryMessenger, channelSuffix: String) {
onPointAnnotationClickListener = OnPointAnnotationClickListener(messenger, channelSuffix)
onCircleAnnotationClickListener = OnCircleAnnotationClickListener(messenger, channelSuffix)
onPolygonAnnotationClickListener = OnPolygonAnnotationClickListener(messenger, channelSuffix)
onPolylineAnnotationClickListener = OnPolylineAnnotationClickListener(messenger, channelSuffix)
_PointAnnotationMessenger.setUp(messenger, pointAnnotationController, channelSuffix)
_CircleAnnotationMessenger.setUp(
messenger,
circleAnnotationController
circleAnnotationController, channelSuffix
)
_PolylineAnnotationMessenger.setUp(
messenger,
polylineAnnotationController
polylineAnnotationController, channelSuffix
)
_PolygonAnnotationMessenger.setUp(
messenger,
polygonAnnotationController
polygonAnnotationController, channelSuffix
)
}

fun dispose(messenger: BinaryMessenger) {
_PointAnnotationMessenger.setUp(messenger, null)
_CircleAnnotationMessenger.setUp(messenger, null)
_PolylineAnnotationMessenger.setUp(messenger, null)
_PolygonAnnotationMessenger.setUp(messenger, null)
fun dispose(messenger: BinaryMessenger, channelSuffix: String) {
_PointAnnotationMessenger.setUp(messenger, null, channelSuffix)
_CircleAnnotationMessenger.setUp(messenger, null, channelSuffix)
_PolylineAnnotationMessenger.setUp(messenger, null, channelSuffix)
_PolygonAnnotationMessenger.setUp(messenger, null, channelSuffix)
onPointAnnotationClickListener = null
onCircleAnnotationClickListener = null
onPolygonAnnotationClickListener = null
onPolylineAnnotationClickListener = null
}

override fun getManager(managerId: String): AnnotationManager<*, *, *, *, *, *, *> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@ import io.flutter.plugin.common.BinaryMessenger
import io.flutter.plugin.common.EventChannel
import io.flutter.plugin.common.EventChannel.StreamHandler

private const val EVENT_CHANNEL_PREFIX = "com.mapbox.maps.flutter/offline"

class OfflineController(
private val context: Context,
private val messenger: BinaryMessenger
private val messenger: BinaryMessenger,
private val channelSuffix: String,
) : _OfflineManager {

private val offlineManager = OfflineManager()
private var progressHandlers = HashMap<String, EventChannel.EventSink>()
private val mainHandler = Handler(context.mainLooper)

private val messageChannel = "offline-manager/$channelSuffix"

override fun loadStylePack(
styleURI: String,
loadOptions: StylePackLoadOptions,
Expand Down Expand Up @@ -57,7 +58,7 @@ class OfflineController(
}

override fun addStylePackLoadProgressListener(styleURI: String) {
val eventChannel = EventChannel(messenger, "com.mapbox.maps.flutter/offline/$styleURI")
val eventChannel = EventChannel(messenger, "com.mapbox.maps.flutter/$messageChannel/$styleURI")
eventChannel.setStreamHandler(
object : StreamHandler {
override fun onListen(arguments: Any?, events: EventChannel.EventSink?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.mapbox.maps.mapbox_maps.offline
import android.content.Context
import com.mapbox.common.TileStore
import com.mapbox.maps.MapboxMapsOptions
import com.mapbox.maps.mapbox_maps.ProxyBinaryMessenger
import com.mapbox.maps.mapbox_maps.pigeons.*
import io.flutter.plugin.common.BinaryMessenger

Expand All @@ -12,31 +11,24 @@ class OfflineMapInstanceManager(
private val messenger: BinaryMessenger,
) : _OfflineMapInstanceManager, _TileStoreInstanceManager {

private var proxies = HashMap<String, ProxyBinaryMessenger>()
override fun setupOfflineManager(channelSuffix: String) {
val proxy = ProxyBinaryMessenger(messenger, channelSuffix)
val offlineControler = OfflineController(context, messenger)
_OfflineManager.setUp(proxy, offlineControler)
proxies["offline-manager/$channelSuffix"] = proxy
val offlineControler = OfflineController(context, messenger, channelSuffix)
_OfflineManager.setUp(messenger, offlineControler, channelSuffix)
}

override fun tearDownOfflineManager(channelSuffix: String) {
val proxy = proxies["offline-manager/$channelSuffix"] ?: return
_OfflineManager.setUp(proxy, null)
_OfflineManager.setUp(messenger, null, channelSuffix)
}

override fun setupTileStore(channelSuffix: String, filePath: String?) {
val proxy = ProxyBinaryMessenger(messenger, channelSuffix)
val tileStore = filePath?.let { TileStore.create(it) } ?: TileStore.create()
MapboxMapsOptions.tileStore = tileStore
val tileStoreController = TileStoreController(context, messenger, tileStore)
_TileStore.setUp(proxy, tileStoreController)
proxies["tilestore/$channelSuffix"] = proxy
val tileStoreController = TileStoreController(context, messenger, channelSuffix, tileStore)
_TileStore.setUp(messenger, tileStoreController, channelSuffix)
}

override fun tearDownTileStore(channelSuffix: String) {
val proxy = proxies["tilestore/$channelSuffix"] ?: return
_TileStore.setUp(proxy, null)
_TileStore.setUp(messenger, null, channelSuffix)
MapboxMapsOptions.tileStore = null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ private const val EVENT_CHANNEL_PREFIX = "com.mapbox.maps.flutter/tilestore"
class TileStoreController(
private val context: Context,
private val binaryMessenger: BinaryMessenger,
private val channelSuffix: String,
private val tileStore: TileStore
) : _TileStore {

Expand All @@ -34,6 +35,8 @@ class TileStoreController(
private var tileRegionEstimateProgressHandlers = HashMap<String, EventChannel.EventSink>()
private val mainHandler = Handler(context.mainLooper)

private val messageChannel = "tilestore/$channelSuffix"

override fun loadTileRegion(
id: String,
loadOptions: TileRegionLoadOptions,
Expand All @@ -56,7 +59,7 @@ class TileStoreController(
}

override fun addTileRegionLoadProgressListener(id: String) {
val eventChannel = EventChannel(binaryMessenger, "com.mapbox.maps.flutter/tilestore/tile-region-$id")
val eventChannel = EventChannel(binaryMessenger, "com.mapbox.maps.flutter/$messageChannel/tile-region-$id")
eventChannel.setStreamHandler(
object : EventChannel.StreamHandler {
override fun onListen(arguments: Any?, events: EventChannel.EventSink?) {
Expand Down Expand Up @@ -96,7 +99,7 @@ class TileStoreController(
}

override fun addTileRegionEstimateProgressListener(id: String) {
val eventChannel = EventChannel(binaryMessenger, "com.mapbox.maps.flutter/tilestore/tile-region-estimate$id")
val eventChannel = EventChannel(binaryMessenger, "com.mapbox.maps.flutter/$messageChannel/tile-region-estimate$id")
eventChannel.setStreamHandler(
object : EventChannel.StreamHandler {
override fun onListen(arguments: Any?, events: EventChannel.EventSink?) {
Expand Down
Loading