diff --git a/OsmAnd/src/net/osmand/plus/openseamapsplugin/NauticalMapsPlugin.java b/OsmAnd/src/net/osmand/plus/openseamapsplugin/NauticalMapsPlugin.java index 47f4d04b8d..4962c50830 100644 --- a/OsmAnd/src/net/osmand/plus/openseamapsplugin/NauticalMapsPlugin.java +++ b/OsmAnd/src/net/osmand/plus/openseamapsplugin/NauticalMapsPlugin.java @@ -6,6 +6,7 @@ import android.content.DialogInterface.OnClickListener; import android.content.Intent; import android.support.v7.app.AlertDialog; import net.osmand.IndexConstants; +import net.osmand.plus.ApplicationMode; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; @@ -13,6 +14,9 @@ import net.osmand.plus.download.DownloadActivity; import net.osmand.plus.download.DownloadResources; import net.osmand.plus.render.RendererRegistry; +import java.util.LinkedHashSet; +import java.util.Set; + public class NauticalMapsPlugin extends OsmandPlugin { public static final String ID = "nauticalPlugin.plugin"; @@ -53,6 +57,7 @@ public class NauticalMapsPlugin extends OsmandPlugin { @Override public boolean init(final OsmandApplication app, final Activity activity) { if(activity != null) { + addBoatProfile(true); // called from UI previousRenderer = app.getSettings().RENDERER.get(); app.getSettings().RENDERER.set(RendererRegistry.NAUTICAL_RENDER); @@ -82,6 +87,17 @@ public class NauticalMapsPlugin extends OsmandPlugin { } return true; } + + public void addBoatProfile(boolean flag) { + Set selectedProfiles = new LinkedHashSet<>(ApplicationMode.values(app.getSettings())); + boolean isBoatEnabled = selectedProfiles.contains(ApplicationMode.BOAT); + if((!isBoatEnabled && flag) || (isBoatEnabled && !flag)) { + String s = app.getSettings().AVAILABLE_APP_MODES.get(); + String currModes = flag ? s + ApplicationMode.BOAT.getStringKey() + "," + : s.replace(ApplicationMode.BOAT.getStringKey() + ",", ""); + app.getSettings().AVAILABLE_APP_MODES.set(currModes); + } + } @Override public void disable(OsmandApplication app) { @@ -89,6 +105,7 @@ public class NauticalMapsPlugin extends OsmandPlugin { if(app.getSettings().RENDERER.get().equals(RendererRegistry.NAUTICAL_RENDER)) { app.getSettings().RENDERER.set(previousRenderer); } + addBoatProfile(false); } @Override