Skip to content

Commit

Permalink
Convert finally to generic Kotlin module
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabi755 committed Dec 17, 2024
1 parent d74b4ed commit 6ddcf15
Show file tree
Hide file tree
Showing 92 changed files with 192 additions and 3,837 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import org.maplibre.navigation.android.navigation.ui.v5.utils.LocaleUtils
import org.maplibre.navigation.android.navigation.ui.v5.utils.time.TimeFormatter
import org.maplibre.navigation.core.models.UnitType
import org.maplibre.navigation.core.navigation.MapLibreNavigation
import org.maplibre.navigation.core.utils.ManeuverUtils
import org.maplibre.navigation.android.navigation.ui.v5.utils.ManeuverUtils
import java.util.Calendar

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
package org.maplibre.navigation.android.navigation.ui.v5.utils

import org.maplibre.navigation.android.navigation.ui.v5.R
import org.maplibre.navigation.core.models.LegStep
import org.maplibre.navigation.core.navigation.NavigationConstants

open class ManeuverUtils {

private val maneuverResources = mutableMapOf(
NavigationConstants.STEP_MANEUVER_TYPE_TURN + NavigationConstants.STEP_MANEUVER_MODIFIER_UTURN to R.drawable.ic_maneuver_turn_180,
NavigationConstants.STEP_MANEUVER_TYPE_CONTINUE + NavigationConstants.STEP_MANEUVER_MODIFIER_UTURN to R.drawable.ic_maneuver_turn_180,
NavigationConstants.STEP_MANEUVER_TYPE_CONTINUE + NavigationConstants.STEP_MANEUVER_MODIFIER_STRAIGHT to R.drawable.ic_maneuver_turn_0,

NavigationConstants.STEP_MANEUVER_TYPE_ARRIVE + NavigationConstants.STEP_MANEUVER_MODIFIER_LEFT to R.drawable.ic_maneuver_arrive_left,
NavigationConstants.STEP_MANEUVER_TYPE_ARRIVE + NavigationConstants.STEP_MANEUVER_MODIFIER_RIGHT to
R.drawable.ic_maneuver_arrive_right,
NavigationConstants.STEP_MANEUVER_TYPE_ARRIVE to
R.drawable.ic_maneuver_arrive,

NavigationConstants.STEP_MANEUVER_TYPE_DEPART + NavigationConstants.STEP_MANEUVER_MODIFIER_LEFT to
R.drawable.ic_maneuver_depart_left,
NavigationConstants.STEP_MANEUVER_TYPE_DEPART + NavigationConstants.STEP_MANEUVER_MODIFIER_RIGHT to
R.drawable.ic_maneuver_depart_right,
NavigationConstants.STEP_MANEUVER_TYPE_DEPART to
R.drawable.ic_maneuver_depart,

NavigationConstants.STEP_MANEUVER_TYPE_TURN + NavigationConstants.STEP_MANEUVER_MODIFIER_SHARP_RIGHT to
R.drawable.ic_maneuver_turn_75,
NavigationConstants.STEP_MANEUVER_TYPE_TURN + NavigationConstants.STEP_MANEUVER_MODIFIER_RIGHT to
R.drawable.ic_maneuver_turn_45,
NavigationConstants.STEP_MANEUVER_TYPE_TURN + NavigationConstants.STEP_MANEUVER_MODIFIER_SLIGHT_RIGHT to
R.drawable.ic_maneuver_turn_30,

NavigationConstants.STEP_MANEUVER_TYPE_TURN + NavigationConstants.STEP_MANEUVER_MODIFIER_SHARP_LEFT to
R.drawable.ic_maneuver_turn_75_left,
NavigationConstants.STEP_MANEUVER_TYPE_TURN + NavigationConstants.STEP_MANEUVER_MODIFIER_LEFT to
R.drawable.ic_maneuver_turn_45_left,
NavigationConstants.STEP_MANEUVER_TYPE_TURN + NavigationConstants.STEP_MANEUVER_MODIFIER_SLIGHT_LEFT to
R.drawable.ic_maneuver_turn_30_left,

NavigationConstants.STEP_MANEUVER_TYPE_MERGE + NavigationConstants.STEP_MANEUVER_MODIFIER_LEFT to
R.drawable.ic_maneuver_merge_left,
NavigationConstants.STEP_MANEUVER_TYPE_MERGE + NavigationConstants.STEP_MANEUVER_MODIFIER_SLIGHT_LEFT to
R.drawable.ic_maneuver_merge_left,
NavigationConstants.STEP_MANEUVER_TYPE_MERGE + NavigationConstants.STEP_MANEUVER_MODIFIER_RIGHT to
R.drawable.ic_maneuver_merge_right,
NavigationConstants.STEP_MANEUVER_TYPE_MERGE + NavigationConstants.STEP_MANEUVER_MODIFIER_SLIGHT_RIGHT to
R.drawable.ic_maneuver_merge_right,
NavigationConstants.STEP_MANEUVER_TYPE_MERGE + NavigationConstants.STEP_MANEUVER_MODIFIER_STRAIGHT to
R.drawable.ic_maneuver_turn_0,

NavigationConstants.STEP_MANEUVER_TYPE_ON_RAMP + NavigationConstants.STEP_MANEUVER_MODIFIER_SHARP_LEFT to
R.drawable.ic_maneuver_turn_75_left,
NavigationConstants.STEP_MANEUVER_TYPE_ON_RAMP + NavigationConstants.STEP_MANEUVER_MODIFIER_LEFT to
R.drawable.ic_maneuver_turn_45_left,
NavigationConstants.STEP_MANEUVER_TYPE_ON_RAMP + NavigationConstants.STEP_MANEUVER_MODIFIER_SLIGHT_LEFT to
R.drawable.ic_maneuver_turn_30_left,

NavigationConstants.STEP_MANEUVER_TYPE_ON_RAMP + NavigationConstants.STEP_MANEUVER_MODIFIER_SHARP_RIGHT to
R.drawable.ic_maneuver_turn_75,
NavigationConstants.STEP_MANEUVER_TYPE_ON_RAMP + NavigationConstants.STEP_MANEUVER_MODIFIER_RIGHT to
R.drawable.ic_maneuver_turn_45,
NavigationConstants.STEP_MANEUVER_TYPE_ON_RAMP + NavigationConstants.STEP_MANEUVER_MODIFIER_SLIGHT_RIGHT to
R.drawable.ic_maneuver_turn_30,

NavigationConstants.STEP_MANEUVER_TYPE_OFF_RAMP + NavigationConstants.STEP_MANEUVER_MODIFIER_LEFT to
R.drawable.ic_maneuver_off_ramp_left,
NavigationConstants.STEP_MANEUVER_TYPE_OFF_RAMP + NavigationConstants.STEP_MANEUVER_MODIFIER_SLIGHT_LEFT to
R.drawable.ic_maneuver_off_ramp_slight_left,

NavigationConstants.STEP_MANEUVER_TYPE_OFF_RAMP + NavigationConstants.STEP_MANEUVER_MODIFIER_RIGHT to
R.drawable.ic_maneuver_off_ramp_right,
NavigationConstants.STEP_MANEUVER_TYPE_OFF_RAMP + NavigationConstants.STEP_MANEUVER_MODIFIER_SLIGHT_RIGHT to
R.drawable.ic_maneuver_off_ramp_slight_right,

NavigationConstants.STEP_MANEUVER_TYPE_FORK + NavigationConstants.STEP_MANEUVER_MODIFIER_LEFT to
R.drawable.ic_maneuver_fork_left,
NavigationConstants.STEP_MANEUVER_TYPE_FORK + NavigationConstants.STEP_MANEUVER_MODIFIER_SLIGHT_LEFT to
R.drawable.ic_maneuver_fork_slight_left,
NavigationConstants.STEP_MANEUVER_TYPE_FORK + NavigationConstants.STEP_MANEUVER_MODIFIER_RIGHT to
R.drawable.ic_maneuver_fork_right,
NavigationConstants.STEP_MANEUVER_TYPE_FORK + NavigationConstants.STEP_MANEUVER_MODIFIER_SLIGHT_RIGHT to
R.drawable.ic_maneuver_fork_slight_right,
NavigationConstants.STEP_MANEUVER_TYPE_FORK + NavigationConstants.STEP_MANEUVER_MODIFIER_STRAIGHT to
R.drawable.ic_maneuver_fork_straight,
NavigationConstants.STEP_MANEUVER_TYPE_FORK to
R.drawable.ic_maneuver_fork,

NavigationConstants.STEP_MANEUVER_TYPE_END_OF_ROAD + NavigationConstants.STEP_MANEUVER_MODIFIER_LEFT to
R.drawable.ic_maneuver_end_of_road_left,
NavigationConstants.STEP_MANEUVER_TYPE_END_OF_ROAD + NavigationConstants.STEP_MANEUVER_MODIFIER_RIGHT to
R.drawable.ic_maneuver_end_of_road_right,

NavigationConstants.STEP_MANEUVER_TYPE_ROUNDABOUT + NavigationConstants.STEP_MANEUVER_MODIFIER_LEFT to
R.drawable.ic_maneuver_roundabout_left,
NavigationConstants.STEP_MANEUVER_TYPE_ROUNDABOUT + NavigationConstants.STEP_MANEUVER_MODIFIER_SHARP_LEFT to
R.drawable.ic_maneuver_roundabout_sharp_left,
NavigationConstants.STEP_MANEUVER_TYPE_ROUNDABOUT + NavigationConstants.STEP_MANEUVER_MODIFIER_SLIGHT_LEFT to
R.drawable.ic_maneuver_roundabout_slight_left,
NavigationConstants.STEP_MANEUVER_TYPE_ROUNDABOUT + NavigationConstants.STEP_MANEUVER_MODIFIER_RIGHT to
R.drawable.ic_maneuver_roundabout_right,
NavigationConstants.STEP_MANEUVER_TYPE_ROUNDABOUT + NavigationConstants.STEP_MANEUVER_MODIFIER_SHARP_RIGHT to
R.drawable.ic_maneuver_roundabout_sharp_right,
NavigationConstants.STEP_MANEUVER_TYPE_ROUNDABOUT + NavigationConstants.STEP_MANEUVER_MODIFIER_SLIGHT_RIGHT to
R.drawable.ic_maneuver_roundabout_slight_right,
NavigationConstants.STEP_MANEUVER_TYPE_ROUNDABOUT + NavigationConstants.STEP_MANEUVER_MODIFIER_STRAIGHT to
R.drawable.ic_maneuver_roundabout_straight,
NavigationConstants.STEP_MANEUVER_TYPE_ROUNDABOUT to
R.drawable.ic_maneuver_roundabout,

NavigationConstants.STEP_MANEUVER_TYPE_ROTARY + NavigationConstants.STEP_MANEUVER_MODIFIER_LEFT to
R.drawable.ic_maneuver_roundabout_left,
NavigationConstants.STEP_MANEUVER_TYPE_ROTARY + NavigationConstants.STEP_MANEUVER_MODIFIER_SHARP_LEFT to
R.drawable.ic_maneuver_roundabout_sharp_left,
NavigationConstants.STEP_MANEUVER_TYPE_ROTARY + NavigationConstants.STEP_MANEUVER_MODIFIER_SLIGHT_LEFT to
R.drawable.ic_maneuver_roundabout_slight_left,
NavigationConstants.STEP_MANEUVER_TYPE_ROTARY + NavigationConstants.STEP_MANEUVER_MODIFIER_RIGHT to
R.drawable.ic_maneuver_roundabout_right,
NavigationConstants.STEP_MANEUVER_TYPE_ROTARY + NavigationConstants.STEP_MANEUVER_MODIFIER_SHARP_RIGHT to
R.drawable.ic_maneuver_roundabout_sharp_right,
NavigationConstants.STEP_MANEUVER_TYPE_ROTARY + NavigationConstants.STEP_MANEUVER_MODIFIER_SLIGHT_RIGHT to
R.drawable.ic_maneuver_roundabout_slight_right,
NavigationConstants.STEP_MANEUVER_TYPE_ROTARY + NavigationConstants.STEP_MANEUVER_MODIFIER_STRAIGHT to
R.drawable.ic_maneuver_roundabout_straight,
NavigationConstants.STEP_MANEUVER_TYPE_ROTARY to
R.drawable.ic_maneuver_roundabout,

NavigationConstants.STEP_MANEUVER_TYPE_ROUNDABOUT_TURN + NavigationConstants.STEP_MANEUVER_MODIFIER_LEFT to
R.drawable.ic_maneuver_turn_45_left,
NavigationConstants.STEP_MANEUVER_TYPE_ROUNDABOUT_TURN + NavigationConstants.STEP_MANEUVER_MODIFIER_RIGHT to
R.drawable.ic_maneuver_turn_45,

NavigationConstants.STEP_MANEUVER_TYPE_NOTIFICATION + NavigationConstants.STEP_MANEUVER_MODIFIER_LEFT to
R.drawable.ic_maneuver_turn_45_left,
NavigationConstants.STEP_MANEUVER_TYPE_NOTIFICATION + NavigationConstants.STEP_MANEUVER_MODIFIER_SHARP_LEFT to
R.drawable.ic_maneuver_turn_75_left,
NavigationConstants.STEP_MANEUVER_TYPE_NOTIFICATION + NavigationConstants.STEP_MANEUVER_MODIFIER_SLIGHT_LEFT to
R.drawable.ic_maneuver_turn_30_left,

NavigationConstants.STEP_MANEUVER_TYPE_NOTIFICATION + NavigationConstants.STEP_MANEUVER_MODIFIER_RIGHT to
R.drawable.ic_maneuver_turn_45,
NavigationConstants.STEP_MANEUVER_TYPE_NOTIFICATION + NavigationConstants.STEP_MANEUVER_MODIFIER_SHARP_RIGHT to
R.drawable.ic_maneuver_turn_75,
NavigationConstants.STEP_MANEUVER_TYPE_NOTIFICATION + NavigationConstants.STEP_MANEUVER_MODIFIER_SLIGHT_RIGHT to
R.drawable.ic_maneuver_turn_30,
NavigationConstants.STEP_MANEUVER_TYPE_NOTIFICATION + NavigationConstants.STEP_MANEUVER_MODIFIER_STRAIGHT to
R.drawable.ic_maneuver_turn_0,

NavigationConstants.STEP_MANEUVER_TYPE_NEW_NAME + NavigationConstants.STEP_MANEUVER_MODIFIER_STRAIGHT to
R.drawable.ic_maneuver_turn_0,
)

fun getManeuverResource(step: LegStep): Int {
val maneuver = step.maneuver

val maneuverKey = listOfNotNull(maneuver.type?.text, maneuver.modifier)
return maneuverResources[maneuverKey.joinToString("")] ?: R.drawable.ic_maneuver_turn_0
return 0
}
}
5 changes: 2 additions & 3 deletions libandroid-navigation/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget

apply plugin: 'org.jetbrains.kotlin.multiplatform'
apply plugin: 'com.android.library'
apply plugin: 'maven-publish'
Expand All @@ -25,6 +23,8 @@ kotlin {

sourceSets {
commonMain.dependencies {
api dependenciesList.mapLibreTurf

implementation dependenciesList.kotlinxSerializationJson
implementation dependenciesList.kotlinxCoroutines
api dependenciesList.kotlinxDateTime
Expand All @@ -39,7 +39,6 @@ kotlin {

androidMain.dependencies {
implementation dependenciesList.mapLibre
api dependenciesList.mapLibreTurf

// Location by Play Services
// Will only used, when added by the client app
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.maplibre.navigation.android.navigation">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import kotlin.test.Test

class ValidationUtilsTest : BaseTest() {

@Test(expected = MissingFormatArgumentException::class)
@Test(expected = IllegalStateException::class)
@Throws(Exception::class)
fun validDirectionsRoute_isInvalidWithNullRouteOptions() {
var route = buildTestDirectionsRoute(DIRECTIONS_WITHOUT_VOICE_INSTRUCTIONS)
Expand All @@ -20,23 +20,23 @@ class ValidationUtilsTest : BaseTest() {
ValidationUtils.validDirectionsRoute(route, true)
}

@Test(expected = MissingFormatArgumentException::class)
@Test(expected = IllegalStateException::class)
@Throws(Exception::class)
fun validDirectionsRoute_isInvalidWithNullInstructions() {
val routeWithNullInstructions = buildRouteWithNullInstructions()

ValidationUtils.validDirectionsRoute(routeWithNullInstructions, true)
}

@Test(expected = MissingFormatArgumentException::class)
@Test(expected = IllegalStateException::class)
@Throws(Exception::class)
fun validDirectionsRoute_isInvalidWithFalseVoiceInstructions() {
val routeWithFalseVoiceInstructions = buildRouteWithFalseVoiceInstructions()

ValidationUtils.validDirectionsRoute(routeWithFalseVoiceInstructions, true)
}

@Test(expected = MissingFormatArgumentException::class)
@Test(expected = IllegalStateException::class)
@Throws(Exception::class)
fun validDirectionsRoute_isInvalidWithFalseBannerInstructions() {
val routeWithFalseBannerInstructions = buildRouteWithFalseBannerInstructions()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.launch
import org.maplibre.android.location.engine.LocationEngineRequest
import org.maplibre.geojson.LineString
import org.maplibre.geojson.Point
import org.maplibre.navigation.core.location.Location
Expand All @@ -23,7 +22,6 @@ open class ReplayRouteLocationEngine(
private var mockedLocations: MutableList<Location> = mutableListOf()
private var dispatcher: ReplayLocationDispatcher? = null

@get:SuppressLint("MissingPermission")
var lastLocation: Location? = null
private set

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.maplibre.navigation.core.models
import kotlinx.serialization.Serializable
import kotlinx.serialization.encodeToString
import org.maplibre.navigation.core.json
import kotlin.jvm.JvmStatic

/**
* This is the root Mapbox Directions API response. Inside this class are several nested classes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.encodeToString
import org.maplibre.navigation.core.json
import kotlin.jvm.JvmStatic

/**
* Detailed information about an individual route such as the duration, distance and geometry.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import org.maplibre.navigation.core.navigation.MapLibreNavigationOptions
import org.maplibre.navigation.core.navigation.NavigationConstants
import org.maplibre.navigation.core.routeprogress.RouteProgress
import org.maplibre.navigation.core.routeprogress.RouteStepProgress
import java.util.Date
import java.util.concurrent.TimeUnit

open class FasterRouteDetector(
private val navigationOptions: MapLibreNavigationOptions
Expand Down Expand Up @@ -129,12 +127,6 @@ open class FasterRouteDetector(
} ?: -1
}

@Suppress("SameParameterValue")
private fun dateDiff(firstDate: Date, secondDate: Date, timeUnit: TimeUnit): Long {
val diffInMillis = secondDate.time - firstDate.time
return timeUnit.convert(diffInMillis, TimeUnit.MILLISECONDS)
}

companion object {
private const val VALID_ROUTE_DURATION_REMAINING = 600
}
Expand Down
Loading

0 comments on commit 6ddcf15

Please sign in to comment.