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

Convert core module to Kotlin Mutliplatform #133

Open
wants to merge 48 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
92a8704
Add generic location model
Fabi755 Dec 5, 2024
08d7f68
Remove Android utils usage
Fabi755 Dec 5, 2024
87d6a94
Prototype implementation of generic location engine
Fabi755 Dec 6, 2024
396aa98
Move UI related utils to UI module
Fabi755 Dec 6, 2024
4901536
Remove Android stuff from replay engine
Fabi755 Dec 8, 2024
58f077b
Add KMP to build file, Move classes to KMP structure
Fabi755 Dec 8, 2024
d100e36
Move out Android specific utils, functions and classes to get KMP mod…
Fabi755 Dec 10, 2024
9427f41
Add MapLibre location engine, Clean up location stuff
Fabi755 Dec 10, 2024
ae60780
Replace Timber by Kermit
Fabi755 Dec 11, 2024
9e2ecb6
Update tests
Fabi755 Dec 12, 2024
7e24ca4
Update tests in UI module
Fabi755 Dec 12, 2024
dc3ae2f
Migrate notification stuff to UI package
Fabi755 Dec 12, 2024
7ee3040
Fix replay logic
Fabi755 Dec 12, 2024
a931337
Remove unused files
Fabi755 Dec 15, 2024
fa71720
Finalize generic handling model
Fabi755 Dec 15, 2024
3708b23
Use interface for platform specific location engine
Fabi755 Dec 16, 2024
1851a31
Validate location
Fabi755 Dec 16, 2024
ebbb364
Set correct coroutine scopes
Fabi755 Dec 16, 2024
92567a1
Remove service stuff
Fabi755 Dec 16, 2024
9c79af4
Response with error on failed location fetching
Fabi755 Dec 16, 2024
dc7ad32
Move out annotations
Fabi755 Dec 16, 2024
ad5057f
Remove Mapbox specific DirectionsCriteria
Fabi755 Dec 17, 2024
77dc478
Clean up navigation engine
Fabi755 Dec 17, 2024
1a06ade
Fix unit type inputs
Fabi755 Dec 17, 2024
daff7b1
Use generic UTC date for location
Fabi755 Dec 17, 2024
5a67e1c
Solve constructor leaking
Fabi755 Dec 17, 2024
8a415db
Rename to engine package
Fabi755 Dec 17, 2024
65bc588
Apply new location engine for running navigation
Fabi755 Dec 17, 2024
32f4d54
Clean up dependency configuration
Fabi755 Dec 17, 2024
d535b02
Finalize build configuration, Add Apple location engine
Fabi755 Dec 17, 2024
6c909de
Update changelog
Fabi755 Dec 17, 2024
9e36535
Merge branch 'main' into feature/kmp-core
Fabi755 Dec 17, 2024
e1e4104
Use extension for converting location
Fabi755 Dec 17, 2024
d74b4ed
Remove remaining Java stuff
Fabi755 Dec 17, 2024
6ddcf15
Convert finally to generic Kotlin module
Fabi755 Dec 17, 2024
e827211
Make RingBuffer compatible
Fabi755 Dec 17, 2024
c32908a
Add geo module
Fabi755 Dec 17, 2024
62efd25
Rename KMP modules
Fabi755 Dec 17, 2024
5a78b19
Use extension for convert location
Fabi755 Dec 17, 2024
47417c5
Add iOS framework export
Fabi755 Dec 17, 2024
10c1fa4
Remove kotlinx date time
Fabi755 Dec 17, 2024
b41c01e
Fix some tests
Fabi755 Dec 17, 2024
38fe8cd
Fix encode Polyline function
Fabi755 Dec 19, 2024
ce75393
Add missing test
Fabi755 Dec 19, 2024
94fef6f
Fix UI tests
Fabi755 Dec 19, 2024
54de9aa
Clean up
Fabi755 Dec 19, 2024
432d0a3
Add custom notification sample
Fabi755 Dec 19, 2024
7f2251c
Fix release configuration
Fabi755 Jan 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ build/

#MacOS
.DS_Store

# Kotlin
.kotlin
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Maplibre welcomes participation and contributions from everyone.
### unreleased

**BREAKING CHANGES:**
- Convert module `libandroid-navigation` to Kotlin Multiplatform. See description of [#133](https://github.com/maplibre/maplibre-navigation-android/issues/133) to get informed about all breaking changes
- Convert module `libandroid-navigation` to Kotlin. See description of PR [#127](https://github.com/maplibre/maplibre-navigation-android/pull/127) to get informed about all breaking changes
- Updated startNavigation() in NavigationLauncher to just use a context instead of an activity [#126](https://github.com/maplibre/maplibre-navigation-android/pull/126)

Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ android {
}

dependencies {
implementation project(':libandroid-navigation')
implementation project(':maplibre-navigation-core')
implementation project(':libandroid-navigation-ui')
implementation dependenciesList.mapLibre

Expand Down
14 changes: 14 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity
android:name=".NavigationWithForegroundNotificationActivity"
android:label="@string/title_foreground_notification">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity
android:name=".NavigationWithCustomForegroundNotificationActivity"
android:label="@string/title_custom_foreground_notification">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity
android:name=".MainActivity"
android:exported="true">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.maplibre.navigation.android.example;

import android.annotation.SuppressLint;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
Expand All @@ -14,10 +15,10 @@
import androidx.annotation.RequiresApi;
import androidx.core.app.NotificationCompat;

import org.maplibre.navigation.android.navigation.v5.navigation.notification.NavigationNotification;
import org.maplibre.navigation.android.navigation.v5.routeprogress.RouteProgress;
import org.maplibre.navigation.android.navigation.ui.v5.notification.NavigationNotification;
import org.maplibre.navigation.core.routeprogress.RouteProgress;

import static org.maplibre.navigation.android.navigation.v5.navigation.NavigationConstants.NAVIGATION_NOTIFICATION_CHANNEL;
import static org.maplibre.navigation.android.navigation.ui.v5.notification.MapLibreNavigationNotification.NAVIGATION_NOTIFICATION_CHANNEL;

public class CustomNavigationNotification implements NavigationNotification {

Expand Down Expand Up @@ -66,6 +67,7 @@ public void onNavigationStopped(Context context) {
notificationManager.cancel(CUSTOM_NOTIFICATION_ID);
}

@SuppressLint("UnspecifiedRegisterReceiverFlag")
public void register(BroadcastReceiver stopNavigationReceiver, Context applicationContext) {
this.stopNavigationReceiver = stopNavigationReceiver;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ protected void onCreate(Bundle savedInstanceState) {
getString(R.string.description_snap_to_route),
SnapToRouteNavigationActivity.class
));
list.add(new SampleItem(
getString(R.string.title_foreground_notification),
getString(R.string.description_foreground_notification),
NavigationWithForegroundNotificationActivity.class
));
list.add(new SampleItem(
getString(R.string.title_custom_foreground_notification),
getString(R.string.description_custom_foreground_notification),
NavigationWithForegroundNotificationActivity.class
));
RecyclerView.Adapter adapter = new MainAdapter(list);
recyclerView.setAdapter(adapter);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ import android.annotation.SuppressLint
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.location.Location
import android.os.Build
import android.os.Bundle
import android.view.View
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.google.android.material.snackbar.Snackbar
import org.maplibre.navigation.android.navigation.v5.models.DirectionsResponse
import org.maplibre.geojson.Point
import org.maplibre.navigation.core.models.DirectionsResponse
import org.maplibre.android.annotations.MarkerOptions
import org.maplibre.android.camera.CameraUpdateFactory
import org.maplibre.android.geometry.LatLng
Expand All @@ -24,26 +22,30 @@ import org.maplibre.android.maps.MapLibreMap
import org.maplibre.android.maps.OnMapReadyCallback
import org.maplibre.android.maps.Style
import org.maplibre.navigation.android.navigation.ui.v5.route.NavigationRoute
import org.maplibre.navigation.android.navigation.v5.location.replay.ReplayRouteLocationEngine
import org.maplibre.navigation.android.navigation.v5.models.DirectionsCriteria
import org.maplibre.navigation.android.navigation.v5.models.DirectionsRoute
import org.maplibre.navigation.android.navigation.v5.offroute.OffRouteListener
import org.maplibre.navigation.android.navigation.v5.routeprogress.ProgressChangeListener
import org.maplibre.navigation.android.navigation.v5.routeprogress.RouteProgress
import org.maplibre.navigation.core.location.replay.ReplayRouteLocationEngine
import org.maplibre.navigation.core.models.DirectionsRoute
import org.maplibre.navigation.core.offroute.OffRouteListener
import org.maplibre.navigation.core.routeprogress.ProgressChangeListener
import org.maplibre.navigation.core.routeprogress.RouteProgress
import org.maplibre.turf.TurfConstants
import org.maplibre.turf.TurfMeasurement
import okhttp3.Request
import org.maplibre.navigation.android.example.databinding.ActivityMockNavigationBinding
import org.maplibre.navigation.android.navigation.ui.v5.route.NavigationMapRoute
import org.maplibre.navigation.android.navigation.v5.instruction.Instruction
import org.maplibre.navigation.android.navigation.v5.milestone.Milestone
import org.maplibre.navigation.android.navigation.v5.milestone.MilestoneEventListener
import org.maplibre.navigation.android.navigation.v5.milestone.RouteMilestone
import org.maplibre.navigation.android.navigation.v5.milestone.Trigger
import org.maplibre.navigation.android.navigation.v5.milestone.TriggerProperty
import org.maplibre.navigation.android.navigation.v5.navigation.MapLibreNavigation
import org.maplibre.navigation.android.navigation.v5.navigation.MapLibreNavigationOptions
import org.maplibre.navigation.android.navigation.v5.navigation.NavigationEventListener
import org.maplibre.navigation.core.instruction.Instruction
import org.maplibre.navigation.core.location.Location
import org.maplibre.navigation.core.milestone.Milestone
import org.maplibre.navigation.core.milestone.MilestoneEventListener
import org.maplibre.navigation.core.milestone.RouteMilestone
import org.maplibre.navigation.core.milestone.Trigger
import org.maplibre.navigation.core.milestone.TriggerProperty
import org.maplibre.navigation.core.models.UnitType
import org.maplibre.navigation.core.navigation.AndroidMapLibreNavigation
import org.maplibre.navigation.core.navigation.MapLibreNavigation
import org.maplibre.navigation.core.navigation.MapLibreNavigationOptions
import org.maplibre.navigation.core.navigation.NavigationEventListener
import org.maplibre.navigation.geo.Point
import org.maplibre.navigation.geo.toMapLibrePoint
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
Expand Down Expand Up @@ -83,22 +85,7 @@ class MockNavigationActivity :
getMapAsync(this@MockNavigationActivity)
}

val context = applicationContext
val customNotification =
CustomNavigationNotification(
context
)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
customNotification.createNotificationChannel(this)
}
val options = MapLibreNavigationOptions(navigationNotification = customNotification)

navigation =
MapLibreNavigation(
this,
options
)

navigation = AndroidMapLibreNavigation(applicationContext)
navigation.addMilestone(
RouteMilestone(
identifier = BEGIN_ROUTE_MILESTONE,
Expand All @@ -116,7 +103,6 @@ class MockNavigationActivity :
),
)
)
customNotification.register(MyBroadcastReceiver(navigation), context)

binding.startRouteButton.setOnClickListener {
route?.let { route ->
Expand Down Expand Up @@ -198,15 +184,15 @@ class MockNavigationActivity :
// Set the component's render mode
it.renderMode = RenderMode.GPS

it.locationEngine = locationEngine
// it.locationEngine = locationEngine
}
}

override fun onMapClick(point: LatLng): Boolean {
var addMarker = true
when {
destination == null -> destination = Point.fromLngLat(point.longitude, point.latitude)
waypoint == null -> waypoint = Point.fromLngLat(point.longitude, point.latitude)
destination == null -> destination = Point(point.longitude, point.latitude)
waypoint == null -> waypoint = Point(point.longitude, point.latitude)
else -> {
Toast.makeText(this, "Only 2 waypoints supported", Toast.LENGTH_LONG).show()
addMarker = false
Expand Down Expand Up @@ -235,17 +221,17 @@ class MockNavigationActivity :
return
}

val origin = Point.fromLngLat(userLocation.longitude, userLocation.latitude)
if (TurfMeasurement.distance(origin, destination, TurfConstants.UNIT_METERS) < 50) {
val origin = Point(userLocation.longitude, userLocation.latitude)
if (TurfMeasurement.distance(origin.toMapLibrePoint(), destination.toMapLibrePoint(), TurfConstants.UNIT_METERS) < 50) {
binding.startRouteButton.visibility = View.GONE
return
}

val navigationRouteBuilder = NavigationRoute.builder(this).apply {
this.accessToken(getString(R.string.mapbox_access_token))
this.origin(origin)
this.destination(destination)
this.voiceUnits(DirectionsCriteria.METRIC)
this.origin(origin.toMapLibrePoint())
this.destination(destination.toMapLibrePoint())
this.voiceUnits(UnitType.METRIC)
this.alternatives(true)
this.baseUrl(getString(R.string.base_url))
}
Expand Down Expand Up @@ -347,7 +333,7 @@ class MockNavigationActivity :
mapLibreMap.let {
val latLng = LatLng(52.039176, 5.550339)
locationEngine.assignLastLocation(
Point.fromLngLat(latLng.longitude, latLng.latitude),
Point(latLng.longitude, latLng.latitude),
)
it.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 12.0))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import android.view.View
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.google.android.material.snackbar.Snackbar
import org.maplibre.navigation.android.navigation.v5.models.DirectionsResponse
import org.maplibre.navigation.core.models.DirectionsResponse
import org.maplibre.geojson.Point
import org.maplibre.android.annotations.MarkerOptions
import org.maplibre.android.camera.CameraPosition
Expand All @@ -21,13 +21,13 @@ import org.maplibre.android.maps.Style
import org.maplibre.navigation.android.navigation.ui.v5.NavigationLauncher
import org.maplibre.navigation.android.navigation.ui.v5.NavigationLauncherOptions
import org.maplibre.navigation.android.navigation.ui.v5.route.NavigationRoute
import org.maplibre.navigation.android.navigation.v5.models.DirectionsCriteria
import org.maplibre.navigation.android.navigation.v5.models.DirectionsRoute
import org.maplibre.navigation.core.models.DirectionsRoute
import org.maplibre.turf.TurfConstants
import org.maplibre.turf.TurfMeasurement
import okhttp3.Request
import org.maplibre.navigation.android.example.databinding.ActivityNavigationUiBinding
import org.maplibre.navigation.android.navigation.ui.v5.route.NavigationMapRoute
import org.maplibre.navigation.core.models.UnitType
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
Expand Down Expand Up @@ -185,7 +185,7 @@ class NavigationUIActivity :
this.accessToken(getString(R.string.mapbox_access_token))
this.origin(origin)
this.destination(destination)
this.voiceUnits(DirectionsCriteria.METRIC)
this.voiceUnits(UnitType.METRIC)
this.alternatives(true)
// If you are using this with the GraphHopper Directions API, you need to uncomment user and profile here.
//this.user("gh")
Expand Down
Loading
Loading