Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabi755 committed Dec 19, 2024
1 parent 94fef6f commit 54de9aa
Show file tree
Hide file tree
Showing 15 changed files with 75 additions and 417 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,21 @@ import org.maplibre.navigation.core.routeprogress.ProgressChangeListener
import org.maplibre.navigation.core.routeprogress.RouteProgress
import java.lang.ref.WeakReference


///**
// * Internal usage only, use navigation by initializing a new instance of [MapLibreNavigation]
// * and customizing the navigation experience through that class.
// *
// *
// * This class is first created and started when [MapLibreNavigation.startNavigation]
// * get's called and runs in the background until either the navigation sessions ends implicitly or
// * the hosting activity gets destroyed. Location updates are also tracked and handled inside this
// * service. Thread creation gets created in this service and maintains the thread until the service
// * gets destroyed.
// *
// */
/**
* Foreground service that connected to [NavigationNotification]. This service is also
* a [ProgressChangeListener] that will forward progress changes to the notification.
*/
open class NavigationNotificationService : Service(), ProgressChangeListener, NavigationEventListener {
private val localBinder = LocalBinder()

// private var thread: RouteProcessorBackgroundThread? = null
// private var locationEngineUpdater: NavigationLocationEngineUpdater? = null
// private var notificationProvider: NavigationNotificationProvider? = null
//

// var navigation: MapLibreNavigation? = null
var navigationNotification: NavigationNotification? = null

override fun onBind(intent: Intent): IBinder {
return localBinder
}

override fun onRunning(running: Boolean) {
navigationNotification?.let {navigationNotification ->
navigationNotification?.let { navigationNotification ->
if (running) {
startForegroundNotification(navigationNotification)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,5 @@ open class ManeuverUtils {

val maneuverKey = listOfNotNull(maneuver.type?.text, maneuver.modifier)
return maneuverResources[maneuverKey.joinToString("")] ?: R.drawable.ic_maneuver_turn_0
return 0
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class TimeFormatterTest {
val twentyFourHoursTimeFormatType = MapLibreNavigationOptions.TimeFormat.TWENTY_FOUR_HOURS
val indifferentDeviceTwentyFourHourFormat = false

val formattedTime = org.maplibre.navigation.android.navigation.ui.v5.utils.time.TimeFormatter.formatTime(
val formattedTime = TimeFormatter.formatTime(
time, elevenMinutes, twentyFourHoursTimeFormatType,
indifferentDeviceTwentyFourHourFormat
)
Expand All @@ -67,7 +67,7 @@ class TimeFormatterTest {
val noneSpecifiedTimeFormatType = MapLibreNavigationOptions.TimeFormat.NONE_SPECIFIED
val deviceTwelveHourFormat = false

val formattedTime = org.maplibre.navigation.android.navigation.ui.v5.utils.time.TimeFormatter.formatTime(
val formattedTime = TimeFormatter.formatTime(
time, elevenMinutes, noneSpecifiedTimeFormatType,
deviceTwelveHourFormat
)
Expand All @@ -90,7 +90,7 @@ class TimeFormatterTest {
val noneSpecifiedTimeFormatType = MapLibreNavigationOptions.TimeFormat.NONE_SPECIFIED
val deviceTwentyFourHourFormat = true

val formattedTime = org.maplibre.navigation.android.navigation.ui.v5.utils.time.TimeFormatter.formatTime(
val formattedTime = TimeFormatter.formatTime(
time, elevenMinutes, noneSpecifiedTimeFormatType,
deviceTwentyFourHourFormat
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ open class GoogleLocationEngine(
/**
* Underlying [FusedLocationProviderClient] that is used to fetch location and listen to location updates.
*/
private val fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(context)
private val fusedLocationProviderClient =
LocationServices.getFusedLocationProviderClient(context)

@SuppressLint("MissingPermission")
override fun listenToLocation(request: LocationEngine.Request): Flow<Location> = callbackFlow {
Expand Down Expand Up @@ -70,9 +71,9 @@ open class GoogleLocationEngine(

private fun toGMSLocationPriority(accuracy: LocationEngine.Request.Accuracy): Int {
return when (accuracy) {
// LocationEngineRequest.PRIORITY_BALANCED_POWER_ACCURACY -> Priority.PRIORITY_BALANCED_POWER_ACCURACY
// LocationEngineRequest.PRIORITY_LOW_POWER -> Priority.PRIORITY_LOW_POWER
// LocationEngineRequest.PRIORITY_NO_POWER -> Priority.PRIORITY_PASSIVE
LocationEngine.Request.Accuracy.PASSIVE -> Priority.PRIORITY_PASSIVE
LocationEngine.Request.Accuracy.LOW -> Priority.PRIORITY_LOW_POWER
LocationEngine.Request.Accuracy.BALANCED -> Priority.PRIORITY_BALANCED_POWER_ACCURACY
LocationEngine.Request.Accuracy.HIGH -> Priority.PRIORITY_HIGH_ACCURACY
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,17 @@ open class MapLibreLocationEngine(
private fun toMapLibreLocationRequest(request: LocationEngine.Request): MapLibreLocationRequest {
return MapLibreLocationRequest.Builder(request.maxIntervalMilliseconds)
.setFastestInterval(request.minIntervalMilliseconds)
.setMaxWaitTime(request.maxUpdateDelayMilliseconds)
.setDisplacement(request.minUpdateDistanceMeters)
.setMaxWaitTime(request.maxUpdateDelayMilliseconds)
.setPriority(toMapLibrePriority(request.accuracy))
.build()
}

private fun toMapLibrePriority(accuracy: LocationEngine.Request.Accuracy): Int {
return when (accuracy) {
// LocationEngineRequest.PRIORITY_BALANCED_POWER_ACCURACY -> MapLibreLocationRequest.PRIORITY_BALANCED_POWER_ACCURACY
// LocationEngineRequest.PRIORITY_LOW_POWER -> MapLibreLocationRequest.PRIORITY_LOW_POWER
// LocationEngineRequest.PRIORITY_NO_POWER -> MapLibreLocationRequest.PRIORITY_PASSIVE
LocationEngine.Request.Accuracy.PASSIVE -> MapLibreLocationRequest.PRIORITY_NO_POWER
LocationEngine.Request.Accuracy.LOW -> MapLibreLocationRequest.PRIORITY_LOW_POWER
LocationEngine.Request.Accuracy.BALANCED -> MapLibreLocationRequest.PRIORITY_BALANCED_POWER_ACCURACY
LocationEngine.Request.Accuracy.HIGH -> MapLibreLocationRequest.PRIORITY_HIGH_ACCURACY
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,19 +181,6 @@ class OffRouteDetectorTest : BaseTest() {
verify {
callback.onShouldIncreaseIndex()
}

// RouteProgress routeProgress = buildDefaultTestRouteProgress();
// Point upcomingStepManeuverPoint = routeProgress.currentLegProgress().upComingStep().maneuver().location();
//
// Location firstUpdate = buildDefaultLocationUpdate(-77.0339782574523, 38.89993519985637);
// offRouteDetector.isUserOffRoute(firstUpdate, routeProgress, options);
//
// Point offRoutePoint = buildPointAwayFromPoint(upcomingStepManeuverPoint, 30, 180);
// Location secondUpdate = buildDefaultLocationUpdate(offRoutePoint.longitude, offRoutePoint.latitude);
//
// boolean isUserOffRoute = offRouteDetector.isUserOffRoute(secondUpdate, routeProgress, options);
// assertFalse(isUserOffRoute);
// verify(mockCallback, times(1)).onShouldIncreaseIndex();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package org.maplibre.navigation.core.location.engine
import kotlinx.coroutines.flow.Flow
import org.maplibre.navigation.core.location.Location

/**
* Location engine that is used to fetch current location and listen to location updates.
*/
interface LocationEngine {

/**
Expand All @@ -20,16 +23,64 @@ interface LocationEngine {
*/
suspend fun getLastLocation(): Location?


/**
* Request to configure location updates parameters
*/
data class Request(
/**
* Minimum interval between location updates. This is the fastest interval that will
* be used to get location updates.
*/
val minIntervalMilliseconds: Long = 1000,

/**
* Maximum interval between location updates. This is the slowest interval that will
* be used to get location updates.
*/
val maxIntervalMilliseconds: Long = 2000,

/**
* Minimum distance between location updates. All updates that are closer than
* this distance will be ignored.
*/
val minUpdateDistanceMeters: Float = 0f,

/**
* Maximum delay between location updates. If the location updates occur at shorter intervals,
* they may be sent as a batch
*/
val maxUpdateDelayMilliseconds: Long = 1000,

/**
* Accuracy type for location fetching
*/
val accuracy: Accuracy = Accuracy.HIGH,
) {

/**
* Accuracy type of location updates.
*/
enum class Accuracy {
/**
* Passive accuracy will don't enable any sensores or location fetching, it will only
* receive location updates that are fetched by other apps.
*/
PASSIVE,

/**
* Low accuracy for save battery power.
*/
LOW,

/**
* A balanced mid accuracy, that is saving battery power and give good location results
*/
BALANCED,

/**
* Highest possible accuracy. This all possible sensors and calculate the most recend location.
* Because of intensive use of sensors and GPS, it will costs more battery power.
*/
HIGH
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ data class MapLibreNavigationOptions(
*/
val isDebugLoggingEnabled: Boolean = Defaults.IS_DEBUG_LOGGING_ENABLED,

// val navigationNotification: NavigationNotification? = null,

/**
* The increment used for rounding the user's speed and the remaining duration of the route.
*/
Expand Down Expand Up @@ -137,7 +135,6 @@ data class MapLibreNavigationOptions(
.withOffRouteMinimumDistanceMetersBeforeWrongDirection(offRouteMinimumDistanceMetersBeforeWrongDirection)
.withOffRouteMinimumDistanceMetersBeforeRightDirection(offRouteMinimumDistanceMetersBeforeRightDirection)
.withIsDebugLoggingEnabled(isDebugLoggingEnabled)
// .withNavigationNotification(navigationNotification)
.withRoundingIncrement(roundingIncrement)
.withTimeFormatType(timeFormatType)
.withLocationAcceptableAccuracyInMetersThreshold(locationAcceptableAccuracyInMetersThreshold)
Expand Down Expand Up @@ -204,7 +201,6 @@ data class MapLibreNavigationOptions(
private var offRouteMinimumDistanceMetersBeforeRightDirection: Double =
Defaults.OFF_ROUTE_MINIMUM_DISTANCE_METERS_BEFORE_RIGHT_DIRECTION
private var isDebugLoggingEnabled: Boolean = Defaults.IS_DEBUG_LOGGING_ENABLED
// private var navigationNotification: NavigationNotification? = null
private var roundingIncrement: RoundingIncrement = Defaults.roundingIncrement
private var timeFormatType: TimeFormat = TimeFormat.NONE_SPECIFIED
private var locationAcceptableAccuracyInMetersThreshold: Int =
Expand All @@ -229,7 +225,6 @@ data class MapLibreNavigationOptions(
fun withOffRouteMinimumDistanceMetersBeforeWrongDirection(offRouteMinimumDistanceMetersBeforeWrongDirection: Double) = apply { this.offRouteMinimumDistanceMetersBeforeWrongDirection = offRouteMinimumDistanceMetersBeforeWrongDirection }
fun withOffRouteMinimumDistanceMetersBeforeRightDirection(offRouteMinimumDistanceMetersBeforeRightDirection: Double) = apply { this.offRouteMinimumDistanceMetersBeforeRightDirection = offRouteMinimumDistanceMetersBeforeRightDirection }
fun withIsDebugLoggingEnabled(isDebugLoggingEnabled: Boolean) = apply { this.isDebugLoggingEnabled = isDebugLoggingEnabled }
// fun withNavigationNotification(navigationNotification: NavigationNotification?) = apply { this.navigationNotification = navigationNotification }
fun withRoundingIncrement(roundingIncrement: RoundingIncrement) = apply { this.roundingIncrement = roundingIncrement }
fun withTimeFormatType(timeFormatType: TimeFormat) = apply { this.timeFormatType = timeFormatType }
fun withLocationAcceptableAccuracyInMetersThreshold(locationAcceptableAccuracyInMetersThreshold: Int) = apply { this.locationAcceptableAccuracyInMetersThreshold = locationAcceptableAccuracyInMetersThreshold }
Expand All @@ -254,7 +249,6 @@ data class MapLibreNavigationOptions(
offRouteMinimumDistanceMetersBeforeWrongDirection,
offRouteMinimumDistanceMetersBeforeRightDirection,
isDebugLoggingEnabled,
// navigationNotification,
roundingIncrement,
timeFormatType,
locationAcceptableAccuracyInMetersThreshold,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ interface NavigationEngine {
*/
fun stopNavigation()

/**+
/**
* Check if the navigation is running
*
* @return true if the navigation is running, false otherwise.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import org.maplibre.navigation.core.snap.SnapToRoute
import org.maplibre.navigation.core.utils.RouteUtils

/**
* A Android platform specific wrapper for [MapLibreNavigation].
* A iOS platform specific wrapper for [MapLibreNavigation].
*
* You can also use [MapLibreNavigation] directly, but this leads to more configuration.
*
* Currently the only difference is, that the location engine is created depending on
* your dependencies.
* Currently the only difference is, that the location engine is set to the [AppleLocationEngine]
* by default.
*/
class IOSMapLibreNavigation(
options: MapLibreNavigationOptions = MapLibreNavigationOptions(),
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ package org.maplibre.navigation.geo
import org.maplibre.geojson.Point as MapLibrePoint

fun MapLibrePoint.toPoint(): Point = Point(this.longitude(), this.latitude())

fun List<MapLibrePoint>.toPoints(): List<Point> = this.map { mp -> Point(mp.longitude(), mp.latitude()) }
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ package org.maplibre.navigation.geo
import org.maplibre.geojson.Point as MapLibrePoint

fun Point.toMapLibrePoint(): MapLibrePoint = MapLibrePoint.fromLngLat(this.longitude, this.latitude)

fun List<Point>.toMapLibrePoints(): List<MapLibrePoint> = this.map { p -> MapLibrePoint.fromLngLat(p.longitude, p.latitude) }
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,4 @@ object TurfConstants {
* @since 1.2.0
*/
const val UNIT_DEFAULT: String = UNIT_KILOMETERS

// /**
// * Retention policy for the various Turf units.
// *
// * @since 3.0.0
// */
// @Retention(AnnotationRetention.SOURCE)
// @StringDef(
// [UNIT_KILOMETRES, UNIT_METRES, UNIT_CENTIMETRES, UNIT_FEET, UNIT_CENTIMETERS, UNIT_METERS, UNIT_YARDS, UNIT_INCHES, UNIT_DEGREES, UNIT_RADIANS, UNIT_KILOMETERS, UNIT_MILES, UNIT_NAUTICAL_MILES
// ]
// )
// annotation class TurfUnitCriteria
}
Loading

0 comments on commit 54de9aa

Please sign in to comment.