Make impassable road locations static

This commit is contained in:
Vitaliy 2020-02-14 12:23:11 +02:00
parent 5a62f55a5b
commit 3d992b56e3
9 changed files with 33 additions and 27 deletions

View file

@ -55,7 +55,7 @@ public class RoutingConfiguration {
private String defaultRouter = "";
private Map<String, GeneralRouter> routers = new LinkedHashMap<>();
private Map<String, String> attributes = new LinkedHashMap<>();
private HashMap<Long, Location> impassableRoadLocations = new HashMap<>();
private static HashMap<Long, Location> impassableRoadLocations = new HashMap<>();
// Example
// {
@ -103,11 +103,11 @@ public class RoutingConfiguration {
return i;
}
public Map<Long, Location> getImpassableRoadLocations() {
public static Map<Long, Location> getImpassableRoadLocations() {
return impassableRoadLocations;
}
public boolean addImpassableRoad(RouteDataObject route, Location location) {
public static boolean addImpassableRoad(RouteDataObject route, Location location) {
if (!impassableRoadLocations.containsKey(route.id)){
impassableRoadLocations.put(route.id, location);
return true;
@ -148,7 +148,7 @@ public class RoutingConfiguration {
return routers;
}
public void removeImpassableRoad(RouteDataObject obj) {
public static void removeImpassableRoad(RouteDataObject obj) {
impassableRoadLocations.remove(obj.id);
}
}

View file

@ -599,9 +599,9 @@ public class AppInitializer implements IProgress {
@Override
protected Map<String, RoutingConfiguration.Builder> doInBackground(Void... voids) {
RoutingConfiguration.getDefault(); // load default builder
Map<String, RoutingConfiguration.Builder> customConfigs = new HashMap<>();
File routingFolder = app.getAppPath(IndexConstants.ROUTING_PROFILES_DIR);
RoutingConfiguration.Builder defaultBuilder = RoutingConfiguration.getDefault();
if (routingFolder.isDirectory()) {
File[] fl = routingFolder.listFiles();
if (fl != null && fl.length > 0) {
@ -611,6 +611,7 @@ public class AppInitializer implements IProgress {
String fileName = f.getName();
RoutingConfiguration.Builder builder = new RoutingConfiguration.Builder();
RoutingConfiguration.parseFromInputStream(new FileInputStream(f), fileName, builder);
customConfigs.put(fileName, builder);
} catch (XmlPullParserException | IOException e) {
throw new IllegalStateException(e);

View file

@ -811,7 +811,7 @@ public class OsmandApplication extends MultiDexApplication {
return localizedResources != null ? localizedResources : super.getResources();
}
public RoutingConfiguration.Builder getDefaultRoutingConfig() {
public synchronized RoutingConfiguration.Builder getDefaultRoutingConfig() {
return RoutingConfiguration.getDefault();
}
@ -823,7 +823,7 @@ public class OsmandApplication extends MultiDexApplication {
return customRoutingConfigs.get(key);
}
public synchronized RoutingConfiguration.Builder getRoutingConfigForMode(ApplicationMode mode) {
public RoutingConfiguration.Builder getRoutingConfigForMode(ApplicationMode mode) {
RoutingConfiguration.Builder builder = null;
String routingProfileKey = mode.getRoutingProfile();
if (!Algorithms.isEmpty(routingProfileKey)) {

View file

@ -52,6 +52,7 @@ import net.osmand.router.GeneralRouter;
import net.osmand.router.GeneralRouter.GeneralRouterProfile;
import net.osmand.router.GeneralRouter.RoutingParameter;
import net.osmand.router.GeneralRouter.RoutingParameterType;
import net.osmand.router.RoutingConfiguration;
import net.osmand.util.Algorithms;
import java.util.ArrayList;
@ -314,7 +315,7 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
cat.addPreference(fastRoute);
} else {
ApplicationMode am = settings.getApplicationMode();
GeneralRouter router = getRouter(getMyApplication().getRoutingConfigForMode(am), am);
GeneralRouter router = getRouter(getMyApplication(), am);
clearParameters();
if (router != null) {
GeneralRouterProfile routerProfile = router.getProfile();
@ -430,10 +431,14 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
reliefFactorParameters.clear();
}
public static GeneralRouter getRouter(OsmandApplication app, ApplicationMode mode) {
RoutingConfiguration.Builder builder = app.getRoutingConfigForMode(mode);
return getRouter(builder, mode);
}
public static GeneralRouter getRouter(net.osmand.router.RoutingConfiguration.Builder builder, ApplicationMode am) {
GeneralRouter router = builder.getRouter(am.getRoutingProfile());
if(router == null && am.getParent() != null) {
if (router == null && am.getParent() != null) {
router = builder.getRouter(am.getParent().getStringKey());
}
return router;
@ -728,7 +733,7 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
final OsmandApplication app = (OsmandApplication) activity.getApplication();
final OsmandSettings settings = app.getSettings();
GeneralRouter router = getRouter(app.getRoutingConfigForMode(mode), mode);
GeneralRouter router = getRouter(app, mode);
SpeedConstants units = settings.SPEED_SYSTEM.getModeValue(mode);
String speedUnits = units.toShortString(activity);
final float[] ratio = new float[1];

View file

@ -36,6 +36,7 @@ import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.routing.RoutingHelper.RouteSegmentSearchResult;
import net.osmand.plus.views.ContextMenuLayer;
import net.osmand.router.RouteSegmentResult;
import net.osmand.router.RoutingConfiguration;
import net.osmand.util.MapUtils;
import java.util.ArrayList;
@ -162,7 +163,7 @@ public class AvoidSpecificRoads {
app.getSettings().removeImpassableRoad(latLon);
RouteDataObject obj = impassableRoads.remove(latLon);
if (obj != null) {
app.getDefaultRoutingConfig().removeImpassableRoad(obj);
RoutingConfiguration.Builder.removeImpassableRoad(obj);
}
}
@ -288,7 +289,7 @@ public class AvoidSpecificRoads {
final LatLon oldLoc = getLocation(currentObject);
app.getSettings().moveImpassableRoad(oldLoc, newLoc);
impassableRoads.remove(oldLoc);
app.getDefaultRoutingConfig().removeImpassableRoad(currentObject);
RoutingConfiguration.Builder.removeImpassableRoad(currentObject);
addImpassableRoadInternal(object, ll, showDialog, activity, newLoc);
if (callback != null) {
@ -310,7 +311,7 @@ public class AvoidSpecificRoads {
boolean showDialog,
@Nullable MapActivity activity,
@NonNull LatLon loc) {
if (app.getDefaultRoutingConfig().addImpassableRoad(object, ll)) {
if (RoutingConfiguration.Builder.addImpassableRoad(object, ll)) {
impassableRoads.put(loc, object);
} else {
LatLon location = getLocation(object);
@ -339,7 +340,7 @@ public class AvoidSpecificRoads {
}
public LatLon getLocation(RouteDataObject object) {
Location location = app.getDefaultRoutingConfig().getImpassableRoadLocations().get(object.getId());
Location location = RoutingConfiguration.Builder.getImpassableRoadLocations().get(object.getId());
return location == null ? null : new LatLon(location.getLatitude(), location.getLongitude());
}

View file

@ -55,7 +55,6 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import static net.osmand.plus.activities.SettingsNavigationActivity.getRouter;
public class RoutingOptionsHelper {
@ -409,7 +408,7 @@ public class RoutingOptionsHelper {
public LocalRoutingParameter getRoutingParameterInnerById(ApplicationMode am, String parameterId) {
RouteProvider.GPXRouteParamsBuilder rparams = app.getRoutingHelper().getCurrentGPXRoute();
GeneralRouter rm = getRouter(app.getRoutingConfigForMode(am), am);
GeneralRouter rm = SettingsNavigationActivity.getRouter(app, am);
if (rm == null || (rparams != null && !rparams.isCalculateOsmAndRoute()) && !rparams.getFile().hasRtePt()) {
return null;
}
@ -493,7 +492,7 @@ public class RoutingOptionsHelper {
RouteProvider.GPXRouteParamsBuilder rparams = app.getRoutingHelper().getCurrentGPXRoute();
List<LocalRoutingParameter> list = new ArrayList<LocalRoutingParameter>(getGpxRouterParameters(am));
GeneralRouter rm = SettingsNavigationActivity.getRouter(app.getRoutingConfigForMode(am), am);
GeneralRouter rm = SettingsNavigationActivity.getRouter(app, am);
if (rm == null || (rparams != null && !rparams.isCalculateOsmAndRoute()) && !rparams.getFile().hasRtePt()) {
return list;
}
@ -583,7 +582,7 @@ public class RoutingOptionsHelper {
public List<GeneralRouter.RoutingParameter> getAvoidRoutingPrefsForAppMode(ApplicationMode applicationMode) {
List<GeneralRouter.RoutingParameter> avoidParameters = new ArrayList<GeneralRouter.RoutingParameter>();
GeneralRouter router = getRouter(app.getRoutingConfigForMode(applicationMode), applicationMode);
GeneralRouter router = SettingsNavigationActivity.getRouter(app, applicationMode);
if (router != null) {
for (Map.Entry<String, GeneralRouter.RoutingParameter> e : router.getParameters().entrySet()) {
String param = e.getKey();
@ -597,7 +596,7 @@ public class RoutingOptionsHelper {
}
public GeneralRouter.RoutingParameter getRoutingPrefsForAppModeById(ApplicationMode applicationMode, String parameterId) {
GeneralRouter router = getRouter(app.getRoutingConfigForMode(applicationMode), applicationMode);
GeneralRouter router = SettingsNavigationActivity.getRouter(app, applicationMode);
GeneralRouter.RoutingParameter parameter = null;
if (router != null) {

View file

@ -243,14 +243,15 @@ public class NavigationFragment extends BaseSettingsFragment {
int iconRes = R.drawable.ic_action_gdirections_dark;
String name = router.getProfileName();
String description = app.getString(R.string.osmand_default_routing);
if (!Algorithms.isEmpty(router.getFilename())) {
description = router.getFilename();
String fileName = router.getFilename();
if (!Algorithms.isEmpty(fileName)) {
description = fileName;
} else if (RoutingProfilesResources.isRpValue(name.toUpperCase())) {
iconRes = RoutingProfilesResources.valueOf(name.toUpperCase()).getIconRes();
name = app.getString(RoutingProfilesResources.valueOf(name.toUpperCase()).getStringRes());
}
profilesObjects.put(routerKey, new RoutingProfileDataObject(routerKey, name, description,
iconRes, false, router.getFilename()));
iconRes, false, fileName));
}
}
}

View file

@ -33,7 +33,6 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import static net.osmand.plus.activities.SettingsNavigationActivity.getRouter;
import static net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.DRIVING_STYLE;
public class RouteParametersFragment extends BaseSettingsFragment implements OnPreferenceChanged {
@ -140,7 +139,7 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
if (am.getRouteService() != RouteProvider.RouteService.OSMAND) {
screen.addPreference(fastRoute);
} else {
GeneralRouter router = getRouter(app.getRoutingConfigForMode(am), am);
GeneralRouter router = SettingsNavigationActivity.getRouter(app, am);
clearParameters();
if (router != null) {
Map<String, RoutingParameter> parameters = router.getParameters();

View file

@ -34,15 +34,15 @@ public class VehicleParametersFragment extends BaseSettingsFragment implements O
if (app == null) {
return;
}
ApplicationMode mode = getSelectedAppMode();
Preference vehicleParametersInfo = findPreference("vehicle_parameters_info");
vehicleParametersInfo.setIcon(getContentIcon(R.drawable.ic_action_info_dark));
vehicleParametersInfo.setTitle(getString(R.string.route_parameters_info, getSelectedAppMode().toHumanString()));
vehicleParametersInfo.setTitle(getString(R.string.route_parameters_info, mode.toHumanString()));
ApplicationMode mode = getSelectedAppMode();
RouteService routeService = mode.getRouteService();
if (routeService == RouteService.OSMAND) {
GeneralRouter router = getRouter(app.getRoutingConfigForMode(mode), mode);
GeneralRouter router = getRouter(app, mode);
if (router != null) {
Map<String, GeneralRouter.RoutingParameter> parameters = router.getParameters();