Browse Source

maplibre : remove all mapbox references and update plugin to be compatible.

pull/2838/head
ganfra 4 months ago
parent
commit
a2e88383bd
  1. 4
      features/location/impl/src/main/kotlin/io/element/android/features/location/impl/common/MapDefaults.kt
  2. 6
      features/location/impl/src/main/kotlin/io/element/android/features/location/impl/send/SendLocationView.kt
  3. 8
      features/location/impl/src/main/kotlin/io/element/android/features/location/impl/show/ShowLocationView.kt
  4. 2
      features/location/impl/src/test/kotlin/io/element/android/features/location/impl/show/ShowLocationViewTest.kt
  5. 2
      gradle/libs.versions.toml
  6. 2
      libraries/maplibre-compose/src/main/kotlin/io/element/android/libraries/maplibre/compose/CameraMode.kt
  7. 12
      libraries/maplibre-compose/src/main/kotlin/io/element/android/libraries/maplibre/compose/CameraMoveStartedReason.kt
  8. 18
      libraries/maplibre-compose/src/main/kotlin/io/element/android/libraries/maplibre/compose/CameraPositionState.kt
  9. 2
      libraries/maplibre-compose/src/main/kotlin/io/element/android/libraries/maplibre/compose/IconAnchor.kt
  10. 8
      libraries/maplibre-compose/src/main/kotlin/io/element/android/libraries/maplibre/compose/MapApplier.kt
  11. 8
      libraries/maplibre-compose/src/main/kotlin/io/element/android/libraries/maplibre/compose/MapLibreMapComposable.kt
  12. 14
      libraries/maplibre-compose/src/main/kotlin/io/element/android/libraries/maplibre/compose/MapUpdater.kt
  13. 24
      libraries/maplibre-compose/src/main/kotlin/io/element/android/libraries/maplibre/compose/MapboxMap.kt
  14. 10
      libraries/maplibre-compose/src/main/kotlin/io/element/android/libraries/maplibre/compose/Symbol.kt

4
features/location/impl/src/main/kotlin/io/element/android/features/location/impl/common/MapDefaults.kt

@ -21,12 +21,12 @@ import android.view.Gravity @@ -21,12 +21,12 @@ import android.view.Gravity
import androidx.compose.runtime.Composable
import androidx.compose.runtime.ReadOnlyComposable
import androidx.compose.ui.graphics.Color
import com.mapbox.mapboxsdk.camera.CameraPosition
import com.mapbox.mapboxsdk.geometry.LatLng
import io.element.android.compound.theme.ElementTheme
import io.element.android.libraries.maplibre.compose.MapLocationSettings
import io.element.android.libraries.maplibre.compose.MapSymbolManagerSettings
import io.element.android.libraries.maplibre.compose.MapUiSettings
import org.maplibre.android.camera.CameraPosition
import org.maplibre.android.geometry.LatLng
/**
* Common configuration values for the map.

6
features/location/impl/src/main/kotlin/io/element/android/features/location/impl/send/SendLocationView.kt

@ -37,7 +37,6 @@ import androidx.compose.ui.graphics.Color @@ -37,7 +37,6 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.unit.dp
import com.mapbox.mapboxsdk.camera.CameraPosition
import io.element.android.compound.theme.ElementTheme
import io.element.android.compound.tokens.generated.CompoundIcons
import io.element.android.features.location.api.Location
@ -61,9 +60,10 @@ import io.element.android.libraries.designsystem.theme.components.bottomsheet.re @@ -61,9 +60,10 @@ import io.element.android.libraries.designsystem.theme.components.bottomsheet.re
import io.element.android.libraries.designsystem.utils.CommonDrawables
import io.element.android.libraries.maplibre.compose.CameraMode
import io.element.android.libraries.maplibre.compose.CameraMoveStartedReason
import io.element.android.libraries.maplibre.compose.MapboxMap
import io.element.android.libraries.maplibre.compose.MapLibreMap
import io.element.android.libraries.maplibre.compose.rememberCameraPositionState
import io.element.android.libraries.ui.strings.CommonStrings
import org.maplibre.android.camera.CameraPosition
@OptIn(ExperimentalMaterial3Api::class)
@Composable
@ -189,7 +189,7 @@ fun SendLocationView( @@ -189,7 +189,7 @@ fun SendLocationView(
.consumeWindowInsets(it),
contentAlignment = Alignment.Center
) {
MapboxMap(
MapLibreMap(
styleUri = rememberTileStyleUrl(),
modifier = Modifier.fillMaxSize(),
cameraPositionState = cameraPositionState,

8
features/location/impl/src/main/kotlin/io/element/android/features/location/impl/show/ShowLocationView.kt

@ -33,8 +33,6 @@ import androidx.compose.ui.text.style.TextAlign @@ -33,8 +33,6 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.unit.dp
import com.mapbox.mapboxsdk.camera.CameraPosition
import com.mapbox.mapboxsdk.geometry.LatLng
import io.element.android.compound.theme.ElementTheme
import io.element.android.compound.tokens.generated.CompoundIcons
import io.element.android.compound.tokens.generated.TypographyTokens
@ -56,12 +54,14 @@ import io.element.android.libraries.designsystem.utils.CommonDrawables @@ -56,12 +54,14 @@ import io.element.android.libraries.designsystem.utils.CommonDrawables
import io.element.android.libraries.maplibre.compose.CameraMode
import io.element.android.libraries.maplibre.compose.CameraMoveStartedReason
import io.element.android.libraries.maplibre.compose.IconAnchor
import io.element.android.libraries.maplibre.compose.MapboxMap
import io.element.android.libraries.maplibre.compose.MapLibreMap
import io.element.android.libraries.maplibre.compose.Symbol
import io.element.android.libraries.maplibre.compose.rememberCameraPositionState
import io.element.android.libraries.maplibre.compose.rememberSymbolState
import io.element.android.libraries.ui.strings.CommonStrings
import kotlinx.collections.immutable.toImmutableMap
import org.maplibre.android.camera.CameraPosition
import org.maplibre.android.geometry.LatLng
@OptIn(ExperimentalMaterial3Api::class)
@Composable
@ -166,7 +166,7 @@ fun ShowLocationView( @@ -166,7 +166,7 @@ fun ShowLocationView(
)
}
MapboxMap(
MapLibreMap(
styleUri = rememberTileStyleUrl(),
modifier = Modifier.fillMaxSize(),
images = mapOf(PIN_ID to CommonDrawables.pin).toImmutableMap(),

2
features/location/impl/src/test/kotlin/io/element/android/features/location/impl/show/ShowLocationViewTest.kt

@ -144,7 +144,7 @@ private fun <R : TestRule> AndroidComposeTestRule<R, ComponentActivity>.setShowL @@ -144,7 +144,7 @@ private fun <R : TestRule> AndroidComposeTestRule<R, ComponentActivity>.setShowL
onBackPressed: () -> Unit = EnsureNeverCalled(),
) {
setContent {
// Simulate a LocalInspectionMode for MapboxMap
// Simulate a LocalInspectionMode for MapLibreMap
CompositionLocalProvider(LocalInspectionMode provides true) {
ShowLocationView(
state = state,

2
gradle/libs.versions.toml

@ -175,7 +175,7 @@ telephoto_flick = { module = "me.saket.telephoto:flick-android", version.ref = " @@ -175,7 +175,7 @@ telephoto_flick = { module = "me.saket.telephoto:flick-android", version.ref = "
statemachine = "com.freeletics.flowredux:compose:1.2.1"
maplibre = "org.maplibre.gl:android-sdk:11.0.0"
maplibre_ktx = "org.maplibre.gl:android-sdk-ktx-v7:2.0.2"
maplibre_annotation = "org.maplibre.gl:android-plugin-annotation-v9:2.0.2"
maplibre_annotation = "org.maplibre.gl:android-plugin-annotation-v9:3.0.0"
opusencoder = "io.element.android:opusencoder:1.1.0"
kotlinpoet = "com.squareup:kotlinpoet:1.16.0"

2
libraries/maplibre-compose/src/main/kotlin/io/element/android/libraries/maplibre/compose/CameraMode.kt

@ -19,7 +19,7 @@ @@ -19,7 +19,7 @@
package io.element.android.libraries.maplibre.compose
import androidx.compose.runtime.Immutable
import com.mapbox.mapboxsdk.location.modes.CameraMode as InternalCameraMode
import org.maplibre.android.location.modes.CameraMode as InternalCameraMode
@Immutable
public enum class CameraMode {

12
libraries/maplibre-compose/src/main/kotlin/io/element/android/libraries/maplibre/compose/CameraMoveStartedReason.kt

@ -19,14 +19,14 @@ @@ -19,14 +19,14 @@
package io.element.android.libraries.maplibre.compose
import androidx.compose.runtime.Immutable
import com.mapbox.mapboxsdk.maps.MapboxMap.OnCameraMoveStartedListener.REASON_API_ANIMATION
import com.mapbox.mapboxsdk.maps.MapboxMap.OnCameraMoveStartedListener.REASON_API_GESTURE
import com.mapbox.mapboxsdk.maps.MapboxMap.OnCameraMoveStartedListener.REASON_DEVELOPER_ANIMATION
import org.maplibre.android.maps.MapLibreMap.OnCameraMoveStartedListener.REASON_API_ANIMATION
import org.maplibre.android.maps.MapLibreMap.OnCameraMoveStartedListener.REASON_API_GESTURE
import org.maplibre.android.maps.MapLibreMap.OnCameraMoveStartedListener.REASON_DEVELOPER_ANIMATION
/**
* Enumerates the different reasons why the map camera started to move.
*
* Based on enum values from https://docs.maptiler.com/maplibre-gl-native-android/com.mapbox.mapboxsdk.maps/#oncameramovestartedlistener.
* Based on enum values from https://docs.maptiler.com/maplibre-gl-native-android/org.maplibre.android.maps/#oncameramovestartedlistener.
*
* [NO_MOVEMENT_YET] is used as the initial state before any map movement has been observed.
*
@ -44,11 +44,11 @@ public enum class CameraMoveStartedReason(public val value: Int) { @@ -44,11 +44,11 @@ public enum class CameraMoveStartedReason(public val value: Int) {
public companion object {
/**
* Converts from the Maps SDK [com.mapbox.mapboxsdk.maps.MapboxMap.OnCameraMoveStartedListener]
* Converts from the Maps SDK [org.maplibre.android.maps.MapLibreMap.OnCameraMoveStartedListener]
* constants to [CameraMoveStartedReason], or returns [UNKNOWN] if there is no such
* [CameraMoveStartedReason] for the given [value].
*
* See https://docs.maptiler.com/maplibre-gl-native-android/com.mapbox.mapboxsdk.maps/#oncameramovestartedlistener.
* See https://docs.maptiler.com/maplibre-gl-native-android/org.maplibre.android.maps/#oncameramovestartedlistener.
*/
public fun fromInt(value: Int): CameraMoveStartedReason {
return values().firstOrNull { it.value == value } ?: return UNKNOWN

18
libraries/maplibre-compose/src/main/kotlin/io/element/android/libraries/maplibre/compose/CameraPositionState.kt

@ -28,11 +28,11 @@ import androidx.compose.runtime.saveable.Saver @@ -28,11 +28,11 @@ import androidx.compose.runtime.saveable.Saver
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.runtime.staticCompositionLocalOf
import com.mapbox.mapboxsdk.camera.CameraPosition
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory
import com.mapbox.mapboxsdk.maps.MapboxMap
import com.mapbox.mapboxsdk.maps.Projection
import kotlinx.parcelize.Parcelize
import org.maplibre.android.camera.CameraPosition
import org.maplibre.android.camera.CameraUpdateFactory
import org.maplibre.android.maps.MapLibreMap
import org.maplibre.android.maps.Projection
/**
* Create and [rememberSaveable] a [CameraPositionState] using [CameraPositionState.Saver].
@ -49,7 +49,7 @@ public inline fun rememberCameraPositionState( @@ -49,7 +49,7 @@ public inline fun rememberCameraPositionState(
/**
* A state object that can be hoisted to control and observe the map's camera state.
* A [CameraPositionState] may only be used by a single [MapboxMap] composable at a time
* A [CameraPositionState] may only be used by a single [MapLibreMap] composable at a time
* as it reflects instance state for a single view of a map.
*
* @param position the initial camera position
@ -143,15 +143,15 @@ public class CameraPositionState( @@ -143,15 +143,15 @@ public class CameraPositionState(
// The map currently associated with this CameraPositionState.
// Guarded by `lock`.
private var map: MapboxMap? by mutableStateOf(null)
private var map: MapLibreMap? by mutableStateOf(null)
// The current map is set and cleared by side effect.
// There can be only one associated at a time.
internal fun setMap(map: MapboxMap?) {
internal fun setMap(map: MapLibreMap?) {
synchronized(lock) {
if (this.map == null && map == null) return
if (this.map != null && map != null) {
error("CameraPositionState may only be associated with one MapboxMap at a time")
error("CameraPositionState may only be associated with one MapLibreMap at a time")
}
this.map = map
if (map == null) {
@ -179,7 +179,7 @@ internal val LocalCameraPositionState = staticCompositionLocalOf { CameraPositio @@ -179,7 +179,7 @@ internal val LocalCameraPositionState = staticCompositionLocalOf { CameraPositio
/** The current [CameraPositionState] used by the map. */
public val currentCameraPositionState: CameraPositionState
@[MapboxMapComposable ReadOnlyComposable Composable]
@[MapLibreMapComposable ReadOnlyComposable Composable]
get() = LocalCameraPositionState.current
@Parcelize

2
libraries/maplibre-compose/src/main/kotlin/io/element/android/libraries/maplibre/compose/IconAnchor.kt

@ -19,7 +19,7 @@ @@ -19,7 +19,7 @@
package io.element.android.libraries.maplibre.compose
import androidx.compose.runtime.Immutable
import com.mapbox.mapboxsdk.style.layers.Property
import org.maplibre.android.style.layers.Property
@Immutable
public enum class IconAnchor {

8
libraries/maplibre-compose/src/main/kotlin/io/element/android/libraries/maplibre/compose/MapApplier.kt

@ -19,9 +19,9 @@ @@ -19,9 +19,9 @@
package io.element.android.libraries.maplibre.compose
import androidx.compose.runtime.AbstractApplier
import com.mapbox.mapboxsdk.maps.MapboxMap
import com.mapbox.mapboxsdk.maps.Style
import com.mapbox.mapboxsdk.plugins.annotation.SymbolManager
import org.maplibre.android.maps.MapLibreMap
import org.maplibre.android.maps.Style
import org.maplibre.android.plugins.annotation.SymbolManager
internal interface MapNode {
fun onAttached() {}
@ -32,7 +32,7 @@ internal interface MapNode { @@ -32,7 +32,7 @@ internal interface MapNode {
private object MapNodeRoot : MapNode
internal class MapApplier(
val map: MapboxMap,
val map: MapLibreMap,
val style: Style,
val symbolManager: SymbolManager,
) : AbstractApplier<MapNode>(MapNodeRoot) {

8
libraries/maplibre-compose/src/main/kotlin/io/element/android/libraries/maplibre/compose/MapboxMapComposable.kt → libraries/maplibre-compose/src/main/kotlin/io/element/android/libraries/maplibre/compose/MapLibreMapComposable.kt

@ -22,10 +22,10 @@ import androidx.compose.runtime.ComposableTargetMarker @@ -22,10 +22,10 @@ import androidx.compose.runtime.ComposableTargetMarker
/**
* An annotation that can be used to mark a composable function as being expected to be use in a
* composable function that is also marked or inferred to be marked as a [MapboxMapComposable].
* composable function that is also marked or inferred to be marked as a [MapLibreMapComposable].
*
* This will produce build warnings when [MapboxMapComposable] composable functions are used outside
* of a [MapboxMapComposable] content lambda, and vice versa.
* This will produce build warnings when [MapLibreMapComposable] composable functions are used outside
* of a [MapLibreMapComposable] content lambda, and vice versa.
*/
@Retention(AnnotationRetention.BINARY)
@ComposableTargetMarker(description = "MapLibre Map Composable")
@ -36,4 +36,4 @@ import androidx.compose.runtime.ComposableTargetMarker @@ -36,4 +36,4 @@ import androidx.compose.runtime.ComposableTargetMarker
AnnotationTarget.TYPE,
AnnotationTarget.TYPE_PARAMETER,
)
public annotation class MapboxMapComposable
public annotation class MapLibreMapComposable

14
libraries/maplibre-compose/src/main/kotlin/io/element/android/libraries/maplibre/compose/MapUpdater.kt

@ -26,17 +26,17 @@ import androidx.compose.runtime.ComposeNode @@ -26,17 +26,17 @@ import androidx.compose.runtime.ComposeNode
import androidx.compose.runtime.currentComposer
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalContext
import com.mapbox.mapboxsdk.location.LocationComponentActivationOptions
import com.mapbox.mapboxsdk.location.LocationComponentOptions
import com.mapbox.mapboxsdk.location.OnCameraTrackingChangedListener
import com.mapbox.mapboxsdk.location.engine.LocationEngineRequest
import com.mapbox.mapboxsdk.maps.MapboxMap
import com.mapbox.mapboxsdk.maps.Style
import org.maplibre.android.location.LocationComponentActivationOptions
import org.maplibre.android.location.LocationComponentOptions
import org.maplibre.android.location.OnCameraTrackingChangedListener
import org.maplibre.android.location.engine.LocationEngineRequest
import org.maplibre.android.maps.MapLibreMap
import org.maplibre.android.maps.Style
private const val LOCATION_REQUEST_INTERVAL = 750L
internal class MapPropertiesNode(
val map: MapboxMap,
val map: MapLibreMap,
style: Style,
context: Context,
cameraPositionState: CameraPositionState,

24
libraries/maplibre-compose/src/main/kotlin/io/element/android/libraries/maplibre/compose/MapboxMap.kt

@ -46,14 +46,14 @@ import androidx.compose.ui.platform.LocalLifecycleOwner @@ -46,14 +46,14 @@ import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.compose.ui.viewinterop.AndroidView
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
import com.mapbox.mapboxsdk.Mapbox
import com.mapbox.mapboxsdk.maps.MapView
import com.mapbox.mapboxsdk.maps.MapboxMap
import com.mapbox.mapboxsdk.maps.Style
import com.mapbox.mapboxsdk.plugins.annotation.SymbolManager
import kotlinx.collections.immutable.ImmutableMap
import kotlinx.collections.immutable.persistentMapOf
import kotlinx.coroutines.awaitCancellation
import org.maplibre.android.MapLibre
import org.maplibre.android.maps.MapLibreMap
import org.maplibre.android.maps.MapView
import org.maplibre.android.maps.Style
import org.maplibre.android.plugins.annotation.SymbolManager
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine
@ -63,7 +63,7 @@ import kotlin.coroutines.suspendCoroutine @@ -63,7 +63,7 @@ import kotlin.coroutines.suspendCoroutine
* Heavily inspired by https://github.com/googlemaps/android-maps-compose
*
* @param styleUri a URI where to asynchronously fetch a style for the map
* @param modifier Modifier to be applied to the MapboxMap
* @param modifier Modifier to be applied to the MapLibreMap
* @param images images added to the map's style to be later used with [Symbol]
* @param cameraPositionState the [CameraPositionState] to be used to control or observe the map's
* camera state
@ -73,7 +73,7 @@ import kotlin.coroutines.suspendCoroutine @@ -73,7 +73,7 @@ import kotlin.coroutines.suspendCoroutine
* @param content the content of the map
*/
@Composable
public fun MapboxMap(
public fun MapLibreMap(
styleUri: String,
modifier: Modifier = Modifier,
images: ImmutableMap<String, Int> = persistentMapOf(),
@ -82,7 +82,7 @@ public fun MapboxMap( @@ -82,7 +82,7 @@ public fun MapboxMap(
symbolManagerSettings: MapSymbolManagerSettings = DefaultMapSymbolManagerSettings,
locationSettings: MapLocationSettings = DefaultMapLocationSettings,
content: (
@Composable @MapboxMapComposable
@Composable @MapLibreMapComposable
() -> Unit
)? = null,
) {
@ -99,7 +99,7 @@ public fun MapboxMap( @@ -99,7 +99,7 @@ public fun MapboxMap(
val context = LocalContext.current
val mapView = remember {
Mapbox.getInstance(context)
MapLibre.getInstance(context)
MapView(context)
}
@ -168,13 +168,13 @@ private suspend inline fun CompositionContext.newComposition( @@ -168,13 +168,13 @@ private suspend inline fun CompositionContext.newComposition(
}
}
private suspend inline fun MapView.awaitMap(): MapboxMap = suspendCoroutine { continuation ->
private suspend inline fun MapView.awaitMap(): MapLibreMap = suspendCoroutine { continuation ->
getMapAsync { map ->
continuation.resume(map)
}
}
private suspend inline fun MapboxMap.awaitStyle(
private suspend inline fun MapLibreMap.awaitStyle(
context: Context,
styleUri: String,
images: ImmutableMap<String, Int>,
@ -227,7 +227,7 @@ private fun MapView.lifecycleObserver(previousState: MutableState<Lifecycle.Even @@ -227,7 +227,7 @@ private fun MapView.lifecycleObserver(previousState: MutableState<Lifecycle.Even
when (event) {
Lifecycle.Event.ON_CREATE -> {
// Skip calling mapView.onCreate if the lifecycle did not go through onDestroy - in
// this case the MapboxMap composable also doesn't leave the composition. So,
// this case the MapLibreMap composable also doesn't leave the composition. So,
// recreating the map does not restore state properly which must be avoided.
if (previousState.value != Lifecycle.Event.ON_STOP) {
this.onCreate(Bundle())

10
libraries/maplibre-compose/src/main/kotlin/io/element/android/libraries/maplibre/compose/Symbol.kt

@ -26,10 +26,10 @@ import androidx.compose.runtime.mutableStateOf @@ -26,10 +26,10 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.Saver
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import com.mapbox.mapboxsdk.geometry.LatLng
import com.mapbox.mapboxsdk.plugins.annotation.Symbol
import com.mapbox.mapboxsdk.plugins.annotation.SymbolManager
import com.mapbox.mapboxsdk.plugins.annotation.SymbolOptions
import org.maplibre.android.geometry.LatLng
import org.maplibre.android.plugins.annotation.Symbol
import org.maplibre.android.plugins.annotation.SymbolManager
import org.maplibre.android.plugins.annotation.SymbolOptions
internal class SymbolNode(
val symbolManager: SymbolManager,
@ -85,7 +85,7 @@ public fun rememberSymbolState( @@ -85,7 +85,7 @@ public fun rememberSymbolState(
* @param iconAnchor the anchor for the symbol image
*/
@Composable
@MapboxMapComposable
@MapLibreMapComposable
public fun Symbol(
iconId: String,
state: SymbolState = rememberSymbolState(),

Loading…
Cancel
Save