From 690a2b4d05e331a2e7b086d9b6b78f248b356a1d Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Fri, 19 Aug 2016 09:49:32 +0300 Subject: [PATCH] Fix simultaneous map downloading in the first screen --- .../firstusage/FirstUsageWizardFragment.java | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/firstusage/FirstUsageWizardFragment.java b/OsmAnd/src/net/osmand/plus/firstusage/FirstUsageWizardFragment.java index d4d10d87af..eb1c9d5170 100644 --- a/OsmAnd/src/net/osmand/plus/firstusage/FirstUsageWizardFragment.java +++ b/OsmAnd/src/net/osmand/plus/firstusage/FirstUsageWizardFragment.java @@ -405,13 +405,8 @@ public class FirstUsageWizardFragment extends Fragment implements OsmAndLocation case MAP_FOUND: break; case MAP_DOWNLOAD: - int i = 0; - for (IndexItem indexItem : indexItems) { - if (!downloadThread.isDownloading(indexItem) && !indexItem.isDownloaded() - && (i == 0 && !firstMapDownloadCancelled) || (i == 1 && !secondMapDownloadCancelled)) { - validationManager.startDownload(getActivity(), indexItem); - } - i++; + if (!startDownload(0)) { + startDownload(1); } if (localDownloadRegion != null) { downloadThread.initSettingsFirstMap(localDownloadRegion); @@ -505,6 +500,29 @@ public class FirstUsageWizardFragment extends Fragment implements OsmAndLocation @Override public void downloadHasFinished() { updateDownloadedItems(); + startDownload(1); + } + + private boolean startDownload(int itemIndex) { + boolean downloadStarted = false; + if (itemIndex == 0 && indexItems.size() > 0) { + IndexItem indexItem = indexItems.get(0); + if (!downloadThread.isDownloading(indexItem) + && !indexItem.isDownloaded() + && !firstMapDownloadCancelled) { + validationManager.startDownload(getActivity(), indexItem); + downloadStarted = true; + } + } else if (itemIndex == 1 && indexItems.size() > 1) { + IndexItem indexItem = indexItems.get(1); + if (!downloadThread.isDownloading(indexItem) + && !indexItem.isDownloaded() + && !secondMapDownloadCancelled) { + validationManager.startDownload(getActivity(), indexItem); + downloadStarted = true; + } + } + return downloadStarted; } private void updateDownloadedItems() {