From bddcfd58b8735ac6a7f6aaa84ef533aff01ebe67 Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Sun, 17 Jan 2016 14:29:53 +0300 Subject: [PATCH] Fix https://github.com/osmandapp/Osmand/issues/2001 --- .../plus/download/DownloadActivity.java | 24 +++++++++++++------ .../plus/download/ui/ItemViewHolder.java | 2 +- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java b/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java index 433cba7cee..417c2b4698 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java @@ -59,6 +59,7 @@ import net.osmand.plus.download.ui.UpdatesIndexFragment; import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin; import net.osmand.plus.srtmplugin.SRTMPlugin; import net.osmand.plus.views.controls.PagerSlidingTabStrip; +import net.osmand.util.Algorithms; import org.apache.commons.logging.Log; @@ -74,7 +75,7 @@ import java.util.Timer; import java.util.TimerTask; public class DownloadActivity extends AbstractDownloadActivity implements DownloadEvents, - ActivityCompat.OnRequestPermissionsResultCallback{ + ActivityCompat.OnRequestPermissionsResultCallback { private static final Log LOG = PlatformUtil.getLog(DownloadActivity.class); public static final int UPDATES_TAB_NUMBER = 2; @@ -106,6 +107,7 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo protected Set> fragSet = new HashSet<>(); private DownloadIndexesThread downloadThread; protected WorldRegion downloadItem; + protected String downloadTargetFileName; private boolean srtmDisabled; private boolean srtmNeedsInstallation; @@ -219,12 +221,18 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo if (downloadItem != null && downloadItem != getMyApplication().getRegions().getWorldRegion() && !WorldRegion.WORLD_BASEMAP.equals(downloadItem.getRegionDownloadNameLC())) { - boolean firstMap = !getMyApplication().getSettings().FIRST_MAP_IS_DOWNLOADED.get(); - if (firstMap) { - initSettingsFirstMap(downloadItem); + if (!Algorithms.isEmpty(downloadTargetFileName)) { + File f = new File(downloadTargetFileName); + if (f.exists() && f.lastModified() > System.currentTimeMillis() - 10000) { + boolean firstMap = !getMyApplication().getSettings().FIRST_MAP_IS_DOWNLOADED.get(); + if (firstMap) { + initSettingsFirstMap(downloadItem); + } + showGoToMap(downloadItem); + } } - showGoToMap(downloadItem); downloadItem = null; + downloadTargetFileName = null; } for (WeakReference ref : fragSet) { Fragment f = ref.get(); @@ -558,11 +566,13 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo } } - public void setDownloadItem(WorldRegion region) { + public void setDownloadItem(WorldRegion region, String targetFileName) { if (downloadItem == null) { downloadItem = region; + downloadTargetFileName = targetFileName; } else if (region == null) { downloadItem = null; + downloadTargetFileName = null; } } @@ -817,7 +827,7 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo @Override public void onClick(View v) { if (getActivity() instanceof DownloadActivity) { - ((DownloadActivity) getActivity()).setDownloadItem(null); + ((DownloadActivity) getActivity()).setDownloadItem(null, null); } dismiss(); } diff --git a/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java b/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java index bbe9decb11..8f354239ad 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java @@ -211,7 +211,7 @@ public class ItemViewHolder { boolean handled = false; if(parentOptional != null) { WorldRegion region = DownloadResourceGroup.getRegion(parentOptional); - context.setDownloadItem(region); + context.setDownloadItem(region, indexItem.getTargetFile(context.getMyApplication()).getAbsolutePath()); } if (indexItem.getType() == DownloadActivityType.ROADS_FILE && parentOptional != null) { for (IndexItem ii : parentOptional.getIndividualResources()) {