Skip to content

Commit 7062266

Browse files
author
Pablo Guardiola
authored
add copilot options to navigation options (#6387)
1 parent 7d0f0c1 commit 7062266

6 files changed

Lines changed: 121 additions & 3 deletions

File tree

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package com.mapbox.navigation.base.internal
2+
3+
/**
4+
* Defines options for Copilot.
5+
*
6+
* @param shouldSendHistoryOnlyWithFeedback true if Copilot History files should be sent only when they include Feedback events. Default is false
7+
*/
8+
class CopilotOptions private constructor(
9+
val shouldSendHistoryOnlyWithFeedback: Boolean
10+
) {
11+
/**
12+
* @return the builder that created the [CopilotOptions]
13+
*/
14+
fun toBuilder(): Builder = Builder().apply {
15+
shouldSendHistoryOnlyWithFeedback(shouldSendHistoryOnlyWithFeedback)
16+
}
17+
18+
/**
19+
* Regenerate whenever a change is made
20+
*/
21+
override fun equals(other: Any?): Boolean {
22+
if (this === other) return true
23+
if (javaClass != other?.javaClass) return false
24+
25+
other as CopilotOptions
26+
27+
if (shouldSendHistoryOnlyWithFeedback != other.shouldSendHistoryOnlyWithFeedback) {
28+
return false
29+
}
30+
31+
return true
32+
}
33+
34+
/**
35+
* Regenerate whenever a change is made
36+
*/
37+
override fun hashCode(): Int {
38+
return shouldSendHistoryOnlyWithFeedback.hashCode()
39+
}
40+
41+
/**
42+
* Returns a string representation of the object.
43+
*/
44+
override fun toString(): String {
45+
return "CopilotOptions(" +
46+
"shouldSendHistoryOnlyWithFeedback=$shouldSendHistoryOnlyWithFeedback" +
47+
")"
48+
}
49+
50+
/**
51+
* Builder for [CopilotOptions].
52+
*/
53+
class Builder {
54+
55+
private var shouldSendHistoryOnlyWithFeedback: Boolean = false
56+
57+
/**
58+
* Defines if Copilot History files should be sent only when they include Feedback events. Default is false
59+
*/
60+
fun shouldSendHistoryOnlyWithFeedback(flag: Boolean): Builder =
61+
apply { this.shouldSendHistoryOnlyWithFeedback = flag }
62+
63+
/**
64+
* Build the [CopilotOptions]
65+
*/
66+
fun build(): CopilotOptions {
67+
return CopilotOptions(
68+
shouldSendHistoryOnlyWithFeedback = shouldSendHistoryOnlyWithFeedback
69+
)
70+
}
71+
}
72+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@file:JvmName("NavigationOptionsExtensions")
2+
3+
package com.mapbox.navigation.base.internal.extensions
4+
5+
import com.mapbox.navigation.base.internal.CopilotOptions
6+
import com.mapbox.navigation.base.options.NavigationOptions
7+
8+
fun NavigationOptions.Builder.copilotOptions(copilotOptions: CopilotOptions):
9+
NavigationOptions.Builder = this.copilotOptions(copilotOptions)
10+
11+
fun NavigationOptions.copilotOptions(): CopilotOptions = this.copilotOptions

libnavigation-base/src/main/java/com/mapbox/navigation/base/options/NavigationOptions.kt

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import com.mapbox.android.core.location.LocationEngineProvider
66
import com.mapbox.android.core.location.LocationEngineRequest
77
import com.mapbox.navigation.base.TimeFormat
88
import com.mapbox.navigation.base.formatter.DistanceFormatterOptions
9+
import com.mapbox.navigation.base.internal.CopilotOptions
910
import com.mapbox.navigation.base.route.RouteAlternativesOptions
1011
import com.mapbox.navigation.base.route.RouteRefreshOptions
1112

@@ -61,6 +62,7 @@ class NavigationOptions private constructor(
6162
val historyRecorderOptions: HistoryRecorderOptions,
6263
val eventsAppMetadata: EventsAppMetadata?,
6364
val enableSensors: Boolean,
65+
internal val copilotOptions: CopilotOptions,
6466
) {
6567

6668
/**
@@ -84,6 +86,7 @@ class NavigationOptions private constructor(
8486
historyRecorderOptions(historyRecorderOptions)
8587
eventsAppMetadata(eventsAppMetadata)
8688
enableSensors(enableSensors)
89+
copilotOptions(copilotOptions)
8790
}
8891

8992
/**
@@ -113,6 +116,7 @@ class NavigationOptions private constructor(
113116
if (historyRecorderOptions != other.historyRecorderOptions) return false
114117
if (eventsAppMetadata != other.eventsAppMetadata) return false
115118
if (enableSensors != other.enableSensors) return false
119+
if (copilotOptions != other.copilotOptions) return false
116120

117121
return true
118122
}
@@ -139,6 +143,7 @@ class NavigationOptions private constructor(
139143
result = 31 * result + historyRecorderOptions.hashCode()
140144
result = 31 * result + eventsAppMetadata.hashCode()
141145
result = 31 * result + enableSensors.hashCode()
146+
result = 31 * result + copilotOptions.hashCode()
142147
return result
143148
}
144149

@@ -164,7 +169,8 @@ class NavigationOptions private constructor(
164169
"incidentsOptions=$incidentsOptions, " +
165170
"historyRecorderOptions=$historyRecorderOptions, " +
166171
"eventsAppMetadata=$eventsAppMetadata, " +
167-
"enableSensors=$enableSensors" +
172+
"enableSensors=$enableSensors, " +
173+
"copilotOptions=$copilotOptions" +
168174
")"
169175
}
170176

@@ -199,6 +205,7 @@ class NavigationOptions private constructor(
199205
HistoryRecorderOptions.Builder().build()
200206
private var eventsAppMetadata: EventsAppMetadata? = null
201207
private var enableSensors: Boolean = false
208+
private var copilotOptions: CopilotOptions = CopilotOptions.Builder().build()
202209

203210
/**
204211
* Defines [Mapbox Access Token](https://docs.mapbox.com/help/glossary/access-token/)
@@ -305,6 +312,12 @@ class NavigationOptions private constructor(
305312
fun enableSensors(value: Boolean): Builder =
306313
apply { this.enableSensors = value }
307314

315+
/**
316+
* Defines configuration for Copilot
317+
*/
318+
internal fun copilotOptions(copilotOptions: CopilotOptions): Builder =
319+
apply { this.copilotOptions = copilotOptions }
320+
308321
/**
309322
* Build a new instance of [NavigationOptions]
310323
* @return NavigationOptions
@@ -329,7 +342,8 @@ class NavigationOptions private constructor(
329342
incidentsOptions = incidentsOptions,
330343
historyRecorderOptions = historyRecorderOptions,
331344
eventsAppMetadata = eventsAppMetadata,
332-
enableSensors = enableSensors
345+
enableSensors = enableSensors,
346+
copilotOptions = copilotOptions,
333347
)
334348
}
335349
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.mapbox.navigation.base.internal
2+
3+
import com.mapbox.navigation.testing.BuilderTest
4+
import org.junit.Test
5+
6+
class CopilotOptionsTest : BuilderTest<CopilotOptions, CopilotOptions.Builder>() {
7+
override fun getImplementationClass() = CopilotOptions::class
8+
9+
override fun getFilledUpBuilder() = CopilotOptions.Builder()
10+
.shouldSendHistoryOnlyWithFeedback(true)
11+
12+
@Test
13+
override fun trigger() {
14+
// trigger, see KDoc
15+
}
16+
}

libnavigation-base/src/test/java/com/mapbox/navigation/base/options/NavigationOptionsTest.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import com.mapbox.android.core.location.LocationEngineRequest
77
import com.mapbox.navigation.base.TimeFormat.NONE_SPECIFIED
88
import com.mapbox.navigation.base.TimeFormat.TWELVE_HOURS
99
import com.mapbox.navigation.base.TimeFormat.TWENTY_FOUR_HOURS
10+
import com.mapbox.navigation.base.internal.CopilotOptions
1011
import com.mapbox.navigation.testing.BuilderTest
1112
import io.mockk.every
1213
import io.mockk.mockk
@@ -79,6 +80,9 @@ class NavigationOptionsTest : BuilderTest<NavigationOptions, NavigationOptions.B
7980
.build()
8081
)
8182
.enableSensors(true)
83+
.copilotOptions(
84+
CopilotOptions.Builder().shouldSendHistoryOnlyWithFeedback(true).build()
85+
)
8286
}
8387

8488
@Test

libnavigation-core/api/current.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,12 +760,13 @@ package com.mapbox.navigation.core.routerefresh {
760760

761761
@com.mapbox.navigation.base.ExperimentalPreviewMapboxNavigationAPI public final class RouteRefreshExtra {
762762
field public static final com.mapbox.navigation.core.routerefresh.RouteRefreshExtra INSTANCE;
763+
field public static final String REFRESH_STATE_CANCELED = "CANCELED";
763764
field public static final String REFRESH_STATE_FINISHED_FAILED = "FINISHED_FAILED";
764765
field public static final String REFRESH_STATE_FINISHED_SUCCESS = "FINISHED_SUCCESS";
765766
field public static final String REFRESH_STATE_STARTED = "STARTED";
766767
}
767768

768-
@StringDef({com.mapbox.navigation.core.routerefresh.RouteRefreshExtra.REFRESH_STATE_STARTED, com.mapbox.navigation.core.routerefresh.RouteRefreshExtra.REFRESH_STATE_FINISHED_SUCCESS, com.mapbox.navigation.core.routerefresh.RouteRefreshExtra.REFRESH_STATE_FINISHED_FAILED}) @kotlin.annotation.Retention(kotlin.annotation.AnnotationRetention.BINARY) public static @interface RouteRefreshExtra.RouteRefreshState {
769+
@StringDef({com.mapbox.navigation.core.routerefresh.RouteRefreshExtra.REFRESH_STATE_STARTED, com.mapbox.navigation.core.routerefresh.RouteRefreshExtra.REFRESH_STATE_FINISHED_SUCCESS, com.mapbox.navigation.core.routerefresh.RouteRefreshExtra.REFRESH_STATE_FINISHED_FAILED, com.mapbox.navigation.core.routerefresh.RouteRefreshExtra.REFRESH_STATE_CANCELED}) @kotlin.annotation.Retention(kotlin.annotation.AnnotationRetention.BINARY) public static @interface RouteRefreshExtra.RouteRefreshState {
769770
}
770771

771772
@com.mapbox.navigation.base.ExperimentalPreviewMapboxNavigationAPI public final class RouteRefreshStateResult {

0 commit comments

Comments
 (0)