From 9eb975013451980528a93490e014a9b773e9e563 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Wed, 21 Oct 2015 16:51:28 +0200 Subject: [PATCH] Fix some issues --- .../plus/download/DownloadIndexesThread.java | 13 ++++++-- .../download/ui/LocalIndexesFragment.java | 30 +++++++++++++++++-- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java index 2846643366..44dd235928 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java @@ -390,6 +390,7 @@ public class DownloadIndexesThread { List filesToReindex = new ArrayList(); boolean forceWifi = downloadFileHelper.isWifiConnected(); Set currentDownloads = new HashSet(); + String warn = ""; try { downloadCycle: while (!indexItemDownloading.isEmpty()) { IndexItem item = indexItemDownloading.poll(); @@ -419,14 +420,22 @@ public class DownloadIndexesThread { } // trackEvent(entry); publishProgress(item); + String wn = reindexFiles(filesToReindex); + if(!Algorithms.isEmpty(wn)) { + warn += " " + wn; + } + filesToReindex.clear(); } } } finally { currentDownloadingItem = null; currentDownloadingItemProgress = 0; } - String warn = reindexFiles(filesToReindex); - return warn; + //String warn = reindexFiles(filesToReindex); + if(warn.trim().length() == 0) { + return null; + } + return warn.trim(); } catch (InterruptedException e) { LOG.info("Download Interrupted"); // do not dismiss dialog diff --git a/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java b/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java index bfa914032e..4cafaa7f65 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java @@ -34,7 +34,6 @@ import android.widget.ImageButton; import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; - import net.osmand.IProgress; import net.osmand.IndexConstants; import net.osmand.PlatformUtil; @@ -68,6 +67,8 @@ import java.text.Collator; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; @@ -79,6 +80,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement private static final Log LOG = PlatformUtil.getLog(LocalIndexesFragment.class); private LoadLocalIndexTask asyncLoader; + private Map filesToUpdate = new HashMap(); private LocalIndexesAdapter listAdapter; private AsyncTask operationTask; @@ -161,6 +163,11 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement } public void reloadData() { + List itemsToUpdate = getDownloadActivity().getDownloadThread().getIndexes().getItemsToUpdate(); + filesToUpdate.clear(); + for(IndexItem ii : itemsToUpdate) { + filesToUpdate.put(ii.getTargetFileName(), ii); + } LoadLocalIndexTask current = asyncLoader; if(current == null || current.getStatus() == AsyncTask.Status.FINISHED || current.isCancelled() || current.getResult() != null) { @@ -1032,7 +1039,8 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement if (child.isBackupedData()) { icon.setImageDrawable(backup); } else { - icon.setImageDrawable(getContentIcon(ctx, child.getType().getIconResource())); + int colorId = filesToUpdate.containsKey(child.getFileName()) ? R.color.color_distance : R.color.color_ok; + icon.setImageDrawable(getContentIcon(ctx, child.getType().getIconResource(), colorId)); } nameTextView.setText(getNameToDisplay(child)); @@ -1097,6 +1105,10 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement private Drawable getContentIcon(DownloadActivity context, int resourceId) { return context.getMyApplication().getIconsCache().getContentIcon(resourceId); } + + private Drawable getContentIcon(DownloadActivity context, int resourceId, int colorId) { + return context.getMyApplication().getIconsCache().getIcon(resourceId, colorId); + } } } @@ -1128,6 +1140,18 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement return true; } }); + final IndexItem update = filesToUpdate.get(info.getFileName()); + if (update != null) { + item = optionsMenu.getMenu().add(R.string.shared_string_download) + .setIcon(iconsCache.getContentIcon(R.drawable.ic_action_import)); + item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(MenuItem item) { + getDownloadActivity().startDownload(update); + return true; + } + }); + } item = optionsMenu.getMenu().add(R.string.shared_string_delete) .setIcon(iconsCache.getContentIcon(R.drawable.ic_action_delete_dark)); @@ -1138,7 +1162,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement return true; } }); - if (getMyApplication().getSettings().BETA_TESTING_LIVE_UPDATES.get()) { + if (info.getType() == LocalIndexType.MAP_DATA && getMyApplication().getSettings().BETA_TESTING_LIVE_UPDATES.get()) { item = optionsMenu.getMenu().add("Live updates") .setIcon(iconsCache.getContentIcon(R.drawable.ic_action_refresh_dark)); item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {