From 6b55a731c2e9640af0283d962c7c0fdc311668c1 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sun, 16 Apr 2017 14:15:29 +0300 Subject: [PATCH] Fix 2.6 --- .../net/osmand/plus/download/DownloadIndexesThread.java | 6 +++++- .../src/net/osmand/plus/download/DownloadResources.java | 9 ++++++--- .../plus/download/ui/DownloadResourceGroupFragment.java | 8 +++++++- .../osmand/plus/helpers/FileNameTranslationHelper.java | 5 +++-- .../plus/openseamapsplugin/NauticalMapsPlugin.java | 4 ++-- 5 files changed, 23 insertions(+), 9 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java index 5cb55eca30..3c91072ad4 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java @@ -20,7 +20,6 @@ import android.support.v7.app.NotificationCompat; import android.support.v7.app.NotificationCompat.Builder; import android.view.View; import android.widget.Toast; - import net.osmand.IndexConstants; import net.osmand.PlatformUtil; import net.osmand.map.WorldRegion; @@ -516,6 +515,11 @@ public class DownloadIndexesThread { if (DownloadActivityType.isCountedInDownloads(item)) { downloads.set(downloads.get() + 1); } + if(item.getBasename().toLowerCase().equals(DownloadResources.WORLD_SEAMARKS_KEY)) { + File oldFile = new File(app.getAppPath(IndexConstants.MAPS_PATH), DownloadResources.WORLD_SEAMARKS_OLD_NAME + + IndexConstants.BINARY_MAP_INDEX_EXT); + Algorithms.removeAllFiles(oldFile); + } File bf = item.getBackupFile(app); if (bf.exists()) { Algorithms.removeAllFiles(bf); diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadResources.java b/OsmAnd/src/net/osmand/plus/download/DownloadResources.java index 028831c952..c48ac8896c 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadResources.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadResources.java @@ -32,8 +32,10 @@ public class DownloadResources extends DownloadResourceGroup { private List rawResources; private Map > groupByRegion; private List itemsToUpdate = new ArrayList<>(); - public static final String WORLD_SEAMARKS_KEY = "world_seamarks_basemap"; - + public static final String WORLD_SEAMARKS_KEY = "world_seamarks"; + public static final String WORLD_SEAMARKS_NAME = "World_seamarks"; + public static final String WORLD_SEAMARKS_OLD_KEY = "world_seamarks_basemap"; + public static final String WORLD_SEAMARKS_OLD_NAME = "World_seamarks_basemap"; public DownloadResources(OsmandApplication app) { super(null, DownloadResourceGroupType.WORLD, ""); @@ -293,7 +295,8 @@ public class DownloadResources extends DownloadResourceGroup { groupByRegion.get(wg).add(ii); } else { if (ii.getFileName().startsWith("World_")) { - if (ii.getFileName().toLowerCase().startsWith(WORLD_SEAMARKS_KEY)) { + if (ii.getFileName().toLowerCase().startsWith(WORLD_SEAMARKS_KEY) || + ii.getFileName().toLowerCase().startsWith(WORLD_SEAMARKS_OLD_KEY)) { nauticalMaps.addItem(ii); } else { worldMaps.addItem(ii); diff --git a/OsmAnd/src/net/osmand/plus/download/ui/DownloadResourceGroupFragment.java b/OsmAnd/src/net/osmand/plus/download/ui/DownloadResourceGroupFragment.java index c4e88a3749..cf53b652b8 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/DownloadResourceGroupFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/DownloadResourceGroupFragment.java @@ -306,7 +306,13 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow if (!email.equalsIgnoreCase(responseEmail)) { app.showShortToastMessage(activity.getString(R.string.shared_string_unexpected_error)); } else { - app.getSettings().NUMBER_OF_FREE_DOWNLOADS.set(DownloadValidationManager.MAXIMUM_AVAILABLE_FREE_DOWNLOADS - 3); + int newDownloads = app.getSettings().NUMBER_OF_FREE_DOWNLOADS.get().intValue() - 3; + if(newDownloads < 0) { + newDownloads = 0; + } else if(newDownloads > DownloadValidationManager.MAXIMUM_AVAILABLE_FREE_DOWNLOADS - 3) { + newDownloads = DownloadValidationManager.MAXIMUM_AVAILABLE_FREE_DOWNLOADS - 3; + } + app.getSettings().NUMBER_OF_FREE_DOWNLOADS.set(newDownloads); app.getSettings().EMAIL_SUBSCRIBED.set(true); hideSubscribeEmailView(); activity.updateBanner(); diff --git a/OsmAnd/src/net/osmand/plus/helpers/FileNameTranslationHelper.java b/OsmAnd/src/net/osmand/plus/helpers/FileNameTranslationHelper.java index 3102ecb411..7ac6a82ed8 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/FileNameTranslationHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/FileNameTranslationHelper.java @@ -1,11 +1,11 @@ package net.osmand.plus.helpers; import android.content.Context; - import net.osmand.IndexConstants; import net.osmand.PlatformUtil; import net.osmand.map.OsmandRegions; import net.osmand.plus.R; +import net.osmand.plus.download.DownloadResources; import org.apache.commons.logging.Log; @@ -217,7 +217,8 @@ public class FileNameTranslationHelper { return ctx.getString(R.string.index_item_world_basemap); } else if (basename.equals("world_bitcoin_payments")) { return ctx.getString(R.string.index_item_world_bitcoin_payments); - } else if (basename.equals("world_seamarks_basemap")) { + } else if (basename.equals(DownloadResources.WORLD_SEAMARKS_KEY) || + basename.equals(DownloadResources.WORLD_SEAMARKS_OLD_KEY)) { return ctx.getString(R.string.index_item_world_seamarks); } else if (basename.equals("depth_contours_osmand_ext")) { return ctx.getString(R.string.index_item_depth_contours_osmand_ext); diff --git a/OsmAnd/src/net/osmand/plus/openseamapsplugin/NauticalMapsPlugin.java b/OsmAnd/src/net/osmand/plus/openseamapsplugin/NauticalMapsPlugin.java index 5a4a8c1114..47f4d04b8d 100644 --- a/OsmAnd/src/net/osmand/plus/openseamapsplugin/NauticalMapsPlugin.java +++ b/OsmAnd/src/net/osmand/plus/openseamapsplugin/NauticalMapsPlugin.java @@ -5,12 +5,12 @@ import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; import android.content.Intent; import android.support.v7.app.AlertDialog; - import net.osmand.IndexConstants; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; import net.osmand.plus.download.DownloadActivity; +import net.osmand.plus.download.DownloadResources; import net.osmand.plus.render.RendererRegistry; public class NauticalMapsPlugin extends OsmandPlugin { @@ -56,7 +56,7 @@ public class NauticalMapsPlugin extends OsmandPlugin { // called from UI previousRenderer = app.getSettings().RENDERER.get(); app.getSettings().RENDERER.set(RendererRegistry.NAUTICAL_RENDER); - if(!app.getResourceManager().getIndexFileNames().containsKey("World_seamarks"+ + if(!app.getResourceManager().getIndexFileNames().containsKey(DownloadResources.WORLD_SEAMARKS_NAME+ IndexConstants.BINARY_MAP_INDEX_EXT)){ AlertDialog.Builder dlg = new AlertDialog.Builder(activity); dlg.setMessage(net.osmand.plus.R.string.nautical_maps_missing);