This commit is contained in:
Alex Sytnyk 2018-09-12 15:17:33 +03:00
parent 5ed6fa2277
commit 38b251f58c
2 changed files with 27 additions and 8 deletions

View file

@ -3,6 +3,7 @@ package net.osmand.plus.activities;
import android.content.DialogInterface;
import android.graphics.drawable.Drawable;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
import android.view.View;
import android.widget.AdapterView;
@ -434,7 +435,7 @@ public class MapActivityLayers {
adapter.addItem(builder.createItem());
}
public void selectMapLayer(final OsmandMapTileView mapView, final ContextMenuItem it, final ArrayAdapter<ContextMenuItem> adapter) {
public void selectMapLayer(final OsmandMapTileView mapView, @Nullable final ContextMenuItem it, @Nullable final ArrayAdapter<ContextMenuItem> adapter) {
if (OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class) == null) {
Toast.makeText(activity, R.string.map_online_plugin_is_not_installed, Toast.LENGTH_LONG).show();
return;
@ -492,8 +493,7 @@ public class MapActivityLayers {
case layerOsmVector:
settings.MAP_ONLINE_DATA.set(false);
updateMapSource(mapView, null);
it.setDescription(null);
adapter.notifyDataSetChanged();
updateItem(it, adapter, null);
break;
case layerEditInstall:
OsmandRasterMapsPlugin.defineNewEditLayer(activity, new ResultMatcher<TileSourceTemplate>() {
@ -527,8 +527,7 @@ public class MapActivityLayers {
if (count == 1) {
settings.MAP_TILE_SOURCES.set(template.getName());
settings.MAP_ONLINE_DATA.set(true);
it.setDescription(template.getName());
adapter.notifyDataSetChanged();
updateItem(it, adapter, template.getName());
updateMapSource(mapView, settings.MAP_TILE_SOURCES);
} else {
selectMapLayer(mapView, it, adapter);
@ -549,8 +548,7 @@ public class MapActivityLayers {
default:
settings.MAP_TILE_SOURCES.set(layerKey);
settings.MAP_ONLINE_DATA.set(true);
it.setDescription(layerKey);
adapter.notifyDataSetChanged();
updateItem(it, adapter, layerKey);
updateMapSource(mapView, settings.MAP_TILE_SOURCES);
break;
}
@ -563,6 +561,17 @@ public class MapActivityLayers {
builder.show();
}
private void updateItem(@Nullable ContextMenuItem item,
@Nullable ArrayAdapter<ContextMenuItem> adapter,
@Nullable String description) {
if (item != null) {
item.setDescription(description);
}
if (adapter != null) {
adapter.notifyDataSetChanged();
}
}
private String getString(int resId) {
return activity.getString(resId);

View file

@ -30,15 +30,17 @@ import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.GPXUtilities;
import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.ShortDescriptionItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerHalfItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.ShortDescriptionItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
import net.osmand.plus.myplaces.FavoritesActivity;
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.util.Algorithms;
@ -493,6 +495,14 @@ public class ImportHelper {
progress.dismiss();
}
if (error == null) {
OsmandRasterMapsPlugin plugin = OsmandPlugin.getPlugin(OsmandRasterMapsPlugin.class);
if (plugin != null && !plugin.isActive() && !plugin.needsInstallation()) {
OsmandPlugin.enablePlugin(getMapActivity(), app, plugin, true);
}
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
mapActivity.getMapLayers().selectMapLayer(mapActivity.getMapView(), null, null);
}
Toast.makeText(app, app.getString(R.string.map_imported_successfully), Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(app, app.getString(R.string.map_import_error) + ": " + error, Toast.LENGTH_SHORT).show();