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 #127

Merged
merged 53 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
8904370
Convert milestone logic to Kotlin
Fabi755 Nov 10, 2024
8bc4fe0
Convert route progress models
Fabi755 Nov 11, 2024
b9aea76
Convert tests to dirty Kotlin
Fabi755 Nov 12, 2024
aa7c687
Make milestone logic work against tests
Fabi755 Nov 12, 2024
c414bd4
Fix converted tests
Fabi755 Nov 12, 2024
1751b60
Convert models
Fabi755 Nov 13, 2024
7c8e514
Use Kotlin serialization for JSON parsing
Fabi755 Nov 13, 2024
810e4f4
Remove abbreviation utils
Fabi755 Nov 13, 2024
67429eb
Remove unused text utils
Fabi755 Nov 13, 2024
0d1dea8
Convert utils
Fabi755 Nov 13, 2024
330f931
Convert route snapping logic
Fabi755 Nov 13, 2024
adcaa25
Convert most of the navigation logic
Fabi755 Nov 15, 2024
0ddc212
Convert route logic
Fabi755 Nov 15, 2024
870874d
Convert exception and instruction
Fabi755 Nov 15, 2024
2bd5de7
Convert off route logic
Fabi755 Nov 15, 2024
7f4b220
Replace Mockito by mockk
Fabi755 Nov 16, 2024
94fa153
Convert location logic
Fabi755 Nov 16, 2024
d91e014
Convert notification classes
Fabi755 Nov 17, 2024
abafb63
Remove core package
Fabi755 Nov 17, 2024
cc486b8
Convert route utils
Fabi755 Nov 17, 2024
4212b30
Convert camera logic
Fabi755 Nov 18, 2024
ae011c8
Remove unused and outdated classes
Fabi755 Nov 18, 2024
1028d0b
Lint clean up
Fabi755 Nov 18, 2024
72db91f
Adjust UI module to new changes
Fabi755 Nov 19, 2024
edf07ad
Adjust example app to new changes
Fabi755 Nov 19, 2024
56cc90b
Solve open todos
Fabi755 Nov 20, 2024
1cec87e
Clean test code
Fabi755 Nov 20, 2024
b71ad54
Solve open todos
Fabi755 Nov 21, 2024
8b45098
Initialize NavigationMapRoute after style has applied
Fabi755 Nov 21, 2024
1b8cb83
Fix crashes
Fabi755 Nov 21, 2024
89ade36
Solve issues
Fabi755 Nov 21, 2024
99e1f7e
Add changelog entry
Fabi755 Nov 21, 2024
e558075
Fix missing tests
Fabi755 Nov 21, 2024
4b102b8
Clean up
Fabi755 Nov 22, 2024
fc7e838
Remove auto values dependency, Add new libraries to centeral file
Fabi755 Nov 22, 2024
0dd9561
Handle possible NULL values on instruction list
Fabi755 Nov 22, 2024
57d2180
Fix Kotlin JSON serialization notation
Fabi755 Nov 27, 2024
ea2c012
Enable lenient option for JSON
Fabi755 Nov 27, 2024
5966952
Change off route interface to SAM interface
Fabi755 Nov 28, 2024
3161668
Make list items non-null
Fabi755 Nov 28, 2024
538f01b
Make default implementations open to inheritances
Fabi755 Nov 28, 2024
2d56e3f
Split `minimumDistanceBeforeRerouting` to two options
Fabi755 Nov 28, 2024
f298dca
Replace string enum by native enum
Fabi755 Nov 28, 2024
94b9f50
Fix protected companion constants
Fabi755 Nov 28, 2024
42a458f
Remove my notes
Fabi755 Nov 28, 2024
c63f5d4
Reduce singleton usage, to allow extend and inject these classes
Fabi755 Nov 28, 2024
4a74f7c
Set more classes to public
Fabi755 Nov 28, 2024
ac57fee
Add `findCurrentBannerText` again
Fabi755 Nov 28, 2024
e33ff84
Add camera target function again
Fabi755 Nov 28, 2024
137fea2
Add possible SAM interfaces
Fabi755 Nov 29, 2024
a664a04
Add PR link to changelog
Fabi755 Dec 3, 2024
0d1b908
Fix maxspeed JSON key
Fabi755 Dec 3, 2024
d8c2dce
Add missing JvmField annotation
Fabi755 Dec 3, 2024
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Maplibre welcomes participation and contributions from everyone.

### unreleased

**BREAKING CHANGES:**
- Convert module `libandroid-navigation` to Kotlin. See description of PR [#xxx] to get informed about all breaking changes
Copy link
Collaborator

Choose a reason for hiding this comment

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

We need to fix the Changelog here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You mean the xxx right?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

PR link added ✅


- Updated startNavigation() in NavigationLauncher to just use a context instead of an activity [#126](https://github.com/maplibre/maplibre-navigation-android/pull/126)

### v4.0.0 - November 9, 2024
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ 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.instruction.Instruction
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
Expand All @@ -35,6 +34,8 @@ 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
Fabi755 marked this conversation as resolved.
Show resolved Hide resolved
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
Expand All @@ -43,7 +44,6 @@ 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.android.navigation.v5.navigation.NavigationMapRoute
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
Expand Down Expand Up @@ -91,9 +91,7 @@ class MockNavigationActivity :
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
customNotification.createNotificationChannel(this)
}
val options = MapLibreNavigationOptions.builder()
.navigationNotification(customNotification)
.build()
val options = MapLibreNavigationOptions(navigationNotification = customNotification)

navigation =
MapLibreNavigation(
Expand All @@ -102,19 +100,21 @@ class MockNavigationActivity :
)

navigation.addMilestone(
RouteMilestone.Builder()
.setIdentifier(BEGIN_ROUTE_MILESTONE)
.setInstruction(BeginRouteInstruction())
.setTrigger(
Trigger.all(
Trigger.lt(
TriggerProperty.STEP_INDEX, 3),
Trigger.gt(
TriggerProperty.STEP_DISTANCE_TOTAL_METERS, 200),
Trigger.gte(
TriggerProperty.STEP_DISTANCE_TRAVELED_METERS, 75),
RouteMilestone(
identifier = BEGIN_ROUTE_MILESTONE,
instruction = BeginRouteInstruction(),
trigger = Trigger.all(
Trigger.lt(
TriggerProperty.STEP_INDEX, 3
),
Trigger.gt(
TriggerProperty.STEP_DISTANCE_TOTAL_METERS, 200
),
).build(),
Trigger.gte(
TriggerProperty.STEP_DISTANCE_TRAVELED_METERS, 75
),
),
)
)
customNotification.register(MyBroadcastReceiver(navigation), context)

Expand Down Expand Up @@ -161,25 +161,21 @@ class MockNavigationActivity :

override fun onMapReady(mapLibreMap: MapLibreMap) {
this.mapLibreMap = mapLibreMap
mapLibreMap.setStyle(Style.Builder().fromUri(getString(R.string.map_style_light))) { style ->
mapLibreMap.setStyle(
Style.Builder().fromUri(getString(R.string.map_style_light))
) { style ->
enableLocationComponent(style)
}

navigationMapRoute =
NavigationMapRoute(
navigation,
binding.mapView,
mapLibreMap
)
navigationMapRoute = NavigationMapRoute(navigation, binding.mapView, mapLibreMap)

mapLibreMap.addOnMapClickListener(this)
Snackbar.make(
findViewById(R.id.container),
"Tap map to place waypoint",
Snackbar.LENGTH_LONG,
).show()
mapLibreMap.addOnMapClickListener(this)
Snackbar.make(
findViewById(R.id.container),
"Tap map to place waypoint",
Snackbar.LENGTH_LONG,
).show()

newOrigin()
newOrigin()
}
}

@SuppressWarnings("MissingPermission")
Expand Down Expand Up @@ -261,11 +257,11 @@ class MockNavigationActivity :
) {
Timber.d("Url: %s", (call.request() as Request).url.toString())
response.body()?.let { response ->
if (response.routes().isNotEmpty()) {
if (response.routes.isNotEmpty()) {
val maplibreResponse = DirectionsResponse.fromJson(response.toJson());
val directionsRoute = maplibreResponse.routes().first()
val directionsRoute = maplibreResponse.routes.first()
[email protected] = directionsRoute
navigationMapRoute?.addRoutes(maplibreResponse.routes())
navigationMapRoute?.addRoutes(maplibreResponse.routes)
}
}
}
Expand All @@ -276,23 +272,23 @@ class MockNavigationActivity :
})
}

override fun onProgressChange(location: Location?, routeProgress: RouteProgress?) {
override fun onProgressChange(location: Location, routeProgress: RouteProgress) {
}

override fun onRunning(running: Boolean) {
}

override fun onMilestoneEvent(
routeProgress: RouteProgress?,
routeProgress: RouteProgress,
instruction: String?,
milestone: Milestone?,
milestone: Milestone,
) {
}

override fun userOffRoute(location: Location?) {
override fun userOffRoute(location: Location) {
}

private class BeginRouteInstruction : Instruction() {
private class BeginRouteInstruction : Instruction {

override fun buildInstruction(routeProgress: RouteProgress): String {
return "Have a safe trip!"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ 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.v5.navigation.NavigationMapRoute
import org.maplibre.navigation.android.navigation.ui.v5.route.NavigationMapRoute
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
Expand Down Expand Up @@ -72,7 +72,10 @@ class NavigationUIActivity :
val options = NavigationLauncherOptions.builder()
.directionsRoute(route)
.shouldSimulateRoute(simulateRoute)
.initialMapCameraPosition(CameraPosition.Builder().target(LatLng(userLocation.latitude, userLocation.longitude)).build())
.initialMapCameraPosition(
CameraPosition.Builder()
.target(LatLng(userLocation.latitude, userLocation.longitude)).build()
)
.lightThemeResId(R.style.TestNavigationViewLight)
.darkThemeResId(R.style.TestNavigationViewDark)
.build()
Expand Down Expand Up @@ -102,22 +105,20 @@ class NavigationUIActivity :

override fun onMapReady(mapLibreMap: MapLibreMap) {
this.mapLibreMap = mapLibreMap
mapLibreMap.setStyle(Style.Builder().fromUri(getString(R.string.map_style_light))) { style ->
mapLibreMap.setStyle(
Style.Builder().fromUri(getString(R.string.map_style_light))
) { style ->
enableLocationComponent(style)
}
navigationMapRoute = NavigationMapRoute(binding.mapView, mapLibreMap)

navigationMapRoute =
NavigationMapRoute(
binding.mapView,
mapLibreMap
)
mapLibreMap.addOnMapClickListener(this)

mapLibreMap.addOnMapClickListener(this)
Snackbar.make(
findViewById(R.id.container),
"Tap map to place waypoint",
Snackbar.LENGTH_LONG,
).show()
Snackbar.make(
findViewById(R.id.container),
"Tap map to place waypoint",
Snackbar.LENGTH_LONG,
).show()
}
}

@SuppressWarnings("MissingPermission")
Expand Down Expand Up @@ -199,10 +200,10 @@ class NavigationUIActivity :
) {
Timber.d("Url: %s", (call.request() as Request).url.toString())
response.body()?.let { response ->
if (response.routes().isNotEmpty()) {
if (response.routes.isNotEmpty()) {
val maplibreResponse = DirectionsResponse.fromJson(response.toJson());
[email protected] = maplibreResponse.routes().first()
navigationMapRoute?.addRoutes(maplibreResponse.routes())
[email protected] = maplibreResponse.routes.first()
navigationMapRoute?.addRoutes(maplibreResponse.routes)
binding.startRouteLayout.visibility = View.VISIBLE
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import org.maplibre.navigation.android.navigation.v5.routeprogress.RouteProgress
import org.maplibre.navigation.android.navigation.v5.snap.SnapToRoute
import okhttp3.Request
import org.maplibre.navigation.android.example.databinding.ActivitySnapToRouteNavigationBinding
import org.maplibre.navigation.android.navigation.ui.v5.route.NavigationMapRoute
import org.maplibre.navigation.android.navigation.v5.models.DirectionsCriteria
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.NavigationMapRoute
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
Expand Down Expand Up @@ -59,9 +59,7 @@ class SnapToRouteNavigationActivity : AppCompatActivity(), OnMapReadyCallback,

navigation = MapLibreNavigation(
this,
MapLibreNavigationOptions.builder()
.snapToRoute(true)
.build()
MapLibreNavigationOptions(snapToRoute = true)
).apply {
snapEngine
addProgressChangeListener(this@SnapToRouteNavigationActivity)
Expand All @@ -83,15 +81,9 @@ class SnapToRouteNavigationActivity : AppCompatActivity(), OnMapReadyCallback,
this.mapLibreMap = mapLibreMap
mapLibreMap.setStyle(Style.Builder().fromUri(getString(R.string.map_style_light))) { style ->
enableLocationComponent(style)
navigationMapRoute = NavigationMapRoute(navigation, binding.mapView, mapLibreMap)
calculateRouteAndStartNavigation()
}

navigationMapRoute =
NavigationMapRoute(
navigation,
binding.mapView,
mapLibreMap
)
calculateRouteAndStartNavigation()
}

@SuppressWarnings("MissingPermission")
Expand Down Expand Up @@ -149,11 +141,11 @@ class SnapToRouteNavigationActivity : AppCompatActivity(), OnMapReadyCallback,
) {
Timber.d("Url: %s", (call.request() as Request).url.toString())
response.body()?.let { responseBody ->
if (responseBody.routes().isNotEmpty()) {
if (responseBody.routes.isNotEmpty()) {
val maplibreResponse = DirectionsResponse.fromJson(responseBody.toJson());
val directionsRoute = maplibreResponse.routes().first()
val directionsRoute = maplibreResponse.routes.first()
[email protected] = directionsRoute
navigationMapRoute?.addRoutes(maplibreResponse.routes())
navigationMapRoute?.addRoutes(maplibreResponse.routes)

startNavigation()
}
Expand Down
Loading
Loading