diff --git a/OsmAnd/src/net/osmand/plus/download/BaseDownloadActivity.java b/OsmAnd/src/net/osmand/plus/download/BaseDownloadActivity.java index 8cfa836b03..fe1af6e3ae 100644 --- a/OsmAnd/src/net/osmand/plus/download/BaseDownloadActivity.java +++ b/OsmAnd/src/net/osmand/plus/download/BaseDownloadActivity.java @@ -51,8 +51,9 @@ public class BaseDownloadActivity extends SherlockFragmentActivity { if (downloadListIndexThread == null) { downloadListIndexThread = new DownloadIndexesThread(this); } -//Having the next line here causes bug AND-197: The storage folder dialogue popped up upon EVERY app startup, because the map list is not indexed yet. Hence line moved to updateDownloads() now. -// prepareDownloadDirectory(); + // Having the next line here causes bug AND-197: The storage folder dialogue popped up upon EVERY app startup, because the map list is not indexed yet. + // Hence line moved to updateDownloads() now. + // prepareDownloadDirectory(); } public void updateDownloads() { diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java index 9a3151315d..01162a3622 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java @@ -542,28 +542,9 @@ public class DownloadIndexesThread { if (filtered != null) { itemsToUpdate.clear(); for (IndexItem item : filtered) { - String sfName = item.getTargetFileName(); - java.text.DateFormat format = app.getResourceManager().getDateFormat(); - String date = item.getDate(format); - String indexactivateddate = indexActivatedFileNames.get(sfName); - String indexfilesdate = indexFileNames.get(sfName); - if (date != null && - !date.equals(indexactivateddate) && - !date.equals(indexfilesdate) && - indexActivatedFileNames.containsKey(sfName)) { - if ((item.getType() == DownloadActivityType.NORMAL_FILE && !item.extra) || - item.getType() == DownloadActivityType.ROADS_FILE || - item.getType() == DownloadActivityType.SRTM_COUNTRY_FILE){ - itemsToUpdate.add(item); - } else { - long itemSize = item.getContentSize(); - File file = new File(item.getType().getDownloadFolder(app, item), sfName); - long oldItemSize = file.length(); - if (itemSize != oldItemSize){ - itemsToUpdate.add(item); - } - } - + boolean outdated = checkIfItemOutdated(item); + if(outdated) { + itemsToUpdate.add(item); } } if (uiActivity != null){ @@ -572,6 +553,33 @@ public class DownloadIndexesThread { } } + public boolean checkIfItemOutdated(IndexItem item) { + boolean outdated = false; + String sfName = item.getTargetFileName(); + java.text.DateFormat format = app.getResourceManager().getDateFormat(); + String date = item.getDate(format); + String indexactivateddate = indexActivatedFileNames.get(sfName); + String indexfilesdate = indexFileNames.get(sfName); + if (date != null && + !date.equals(indexactivateddate) && + !date.equals(indexfilesdate) && + indexActivatedFileNames.containsKey(sfName)) { + if ((item.getType() == DownloadActivityType.NORMAL_FILE && !item.extra) || + item.getType() == DownloadActivityType.ROADS_FILE || + item.getType() == DownloadActivityType.SRTM_COUNTRY_FILE){ + outdated = true; + } else { + long itemSize = item.getContentSize(); + File file = new File(item.getType().getDownloadFolder(app, item), sfName); + long oldItemSize = file.length(); + if (itemSize != oldItemSize){ + outdated = true; + } + } + } + return outdated; + } + private void updateFilesToUpdate(){ List stillUpdate = new ArrayList(); for (IndexItem item : itemsToUpdate) { diff --git a/OsmAnd/src/net/osmand/plus/download/UpdatesIndexFragment.java b/OsmAnd/src/net/osmand/plus/download/UpdatesIndexFragment.java index dc04bb34f4..bd0a07df2e 100644 --- a/OsmAnd/src/net/osmand/plus/download/UpdatesIndexFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/UpdatesIndexFragment.java @@ -239,7 +239,8 @@ public class UpdatesIndexFragment extends SherlockListFragment { if (indexActivatedFileNames != null && indexFileNames != null){ String sfName = e.getTargetFileName(); - if (e.getDate(format).equals(indexActivatedFileNames.get(sfName))) { + final boolean updatableResource = indexActivatedFileNames.containsKey(sfName); + if (updatableResource && !DownloadActivity.downloadListIndexThread.checkIfItemOutdated(e)) { name.setText(name.getText() + "\n" + getResources().getString(R.string.local_index_installed) + " : " + indexActivatedFileNames.get(sfName)); name.setTypeface(Typeface.DEFAULT, Typeface.NORMAL); @@ -247,7 +248,7 @@ public class UpdatesIndexFragment extends SherlockListFragment { name.setText(name.getText() + "\n" + getResources().getString(R.string.local_index_installed) + " : " + indexFileNames.get(sfName)); name.setTypeface(Typeface.DEFAULT, Typeface.ITALIC); - } else if (indexActivatedFileNames.containsKey(sfName)) { + } else if (updatableResource) { name.setText(name.getText() + "\n" + getResources().getString(R.string.local_index_installed) + " : " + indexActivatedFileNames.get(sfName)); name.setTextColor(updateColor); // LIGHT_BLUE