added route singleton

This commit is contained in:
Sem van der Hoeven
2021-01-06 10:48:03 +01:00
parent abc58d3606
commit f6af7ae80b
4 changed files with 46 additions and 18 deletions

View File

@@ -0,0 +1,42 @@
package com.a1.nextlocation.data;
/**
* singleton to track the current route that is being followed
*/
public enum RouteHandler {
INSTANCE;
private boolean isFollowingRoute = false;
private Route currentRoute;
private int stepCount = 0;
public int getStepCount() {
return stepCount;
}
public void addStep() {
stepCount++;
}
public void finishRoute() {
stepCount = 0;
isFollowingRoute = false;
currentRoute = null;
}
public void followRoute(Route route) {
this.currentRoute = route;
setFollowingRoute(true);
}
public boolean isFollowingRoute(Route route) {
return isFollowingRoute && route.equals(currentRoute);
}
public void setFollowingRoute(boolean followingRoute) {
isFollowingRoute = followingRoute;
}
public boolean isFollowingRoute() {
return isFollowingRoute;
}
}

View File

@@ -11,24 +11,6 @@ public enum StaticData {
INSTANCE;
private double distanceTraveled = 0;
private int locationsVisited = 0;
private boolean isFollowingRoute = false;
private String routeName = "";
public void followRoute(Route route) {
routeName = route.getName();
setFollowingRoute(true);
}
public boolean isFollowingRoute(Route route) {
return isFollowingRoute && route.getName().equals(routeName);
}
public void setFollowingRoute(boolean followingRoute) {
isFollowingRoute = followingRoute;
}
public boolean isFollowingRoute() {
return isFollowingRoute;
}
private ArrayList<String> visitedNames = new ArrayList<>();