Skip to content

Commit 5505624

Browse files
committed
Routes created by Start Beacon no longer auto stop when it is reached
When a beacon is created with Start Beacon, it should carry on sounding until the user stops it via the UI.
1 parent 133ac86 commit 5505624

1 file changed

Lines changed: 35 additions & 19 deletions

File tree

  • app/src/main/java/org/scottishtecharmy/soundscape/services

app/src/main/java/org/scottishtecharmy/soundscape/services/RoutePlayer.kt

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ data class RoutePlayerState(val routeData: RouteWithMarkers? = null, val current
2525
class RoutePlayer(val service: SoundscapeService, context: Context) {
2626
private var currentRouteData: RouteWithMarkers? = null
2727
private var currentMarker = -1
28+
private var autoProgressRoute = true
2829
private val coroutineScope = CoroutineScope(Job())
2930
private var localizedContext: Context
3031
init {
@@ -59,6 +60,10 @@ class RoutePlayer(val service: SoundscapeService, context: Context) {
5960
RouteEntity(0, beaconName, ""),
6061
waypoints
6162
)
63+
// We don't auto progress this route, as we want to allow setting the beacon at the current
64+
// location and keeping it active. If auto progress were set, that beacon would immediately
65+
// stop because it is nearby.
66+
autoProgressRoute = false
6267
_currentRouteFlow.update {
6368
it.copy(
6469
routeData = currentRouteData,
@@ -83,6 +88,7 @@ class RoutePlayer(val service: SoundscapeService, context: Context) {
8388
val route = routeDao.getRouteWithMarkers(routeId)
8489
currentMarker = 0
8590
currentRouteData = route
91+
autoProgressRoute = true
8692
_currentRouteFlow.update {
8793
it.copy(
8894
routeData = currentRouteData,
@@ -102,25 +108,35 @@ class RoutePlayer(val service: SoundscapeService, context: Context) {
102108
service.locationProvider.locationFlow.collect { value ->
103109
if (value != null) {
104110
currentRouteData?.let { route ->
105-
if(currentMarker < route.markers.size) {
106-
val location = route.markers[currentMarker].getLngLatAlt()
107-
if(distance(location.latitude, location.longitude, value.latitude, value.longitude) < 15.0) {
108-
if((currentMarker + 1) < route.markers.size) {
109-
// We're within 15m of the marker, move on to the next one
110-
moveToNext()
111-
} else {
112-
// We've reached the end of the route
113-
// Announce the end of the route
114-
val endOfRouteText = localizedContext.getString(
115-
R.string.route_end_completed_accessibility,
116-
route.route.name)
117-
service.audioEngine.clearTextToSpeechQueue()
118-
service.audioEngine.createTextToSpeech(
119-
endOfRouteText,
120-
AudioType.STANDARD)
121-
122-
// Stop the beacon
123-
stopRoute()
111+
if(autoProgressRoute) {
112+
if(currentMarker < route.markers.size) {
113+
val location = route.markers[currentMarker].getLngLatAlt()
114+
if (distance(
115+
location.latitude,
116+
location.longitude,
117+
value.latitude,
118+
value.longitude
119+
) < 15.0
120+
) {
121+
if ((currentMarker + 1) < route.markers.size) {
122+
// We're within 15m of the marker, move on to the next one
123+
moveToNext()
124+
} else {
125+
// We've reached the end of the route
126+
// Announce the end of the route
127+
val endOfRouteText = localizedContext.getString(
128+
R.string.route_end_completed_accessibility,
129+
route.route.name
130+
)
131+
service.audioEngine.clearTextToSpeechQueue()
132+
service.audioEngine.createTextToSpeech(
133+
endOfRouteText,
134+
AudioType.STANDARD
135+
)
136+
137+
// Stop the beacon
138+
stopRoute()
139+
}
124140
}
125141
}
126142
}

0 commit comments

Comments
 (0)