From 430e317433a3256d5779ca7f24af2a360a65d7c4 Mon Sep 17 00:00:00 2001 From: GaidamakUA Date: Fri, 9 Oct 2015 12:43:48 +0300 Subject: [PATCH] Colors for downloaded maps --- OsmAnd/src/net/osmand/plus/WorldRegion.java | 30 ++++++++- .../plus/download/DownloadIndexesThread.java | 67 +++---------------- .../plus/download/items/ItemViewHolder.java | 19 ++++-- .../download/items/VoiceItemsFragment.java | 4 +- 4 files changed, 57 insertions(+), 63 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/WorldRegion.java b/OsmAnd/src/net/osmand/plus/WorldRegion.java index 0238be30c7..cb228cb831 100644 --- a/OsmAnd/src/net/osmand/plus/WorldRegion.java +++ b/OsmAnd/src/net/osmand/plus/WorldRegion.java @@ -42,6 +42,8 @@ public class WorldRegion { private boolean purchased; private boolean isInPurchasedArea; + private MapState mapState = MapState.NOT_DOWNLOADED; + public String getRegionId() { return regionId; } @@ -82,6 +84,26 @@ public class WorldRegion { return isInPurchasedArea; } + public MapState getMapState() { + return mapState; + } + + public void processNewMapState(MapState mapState) { + LOG.debug("old state=" + this.mapState); + switch (this.mapState) { + case NOT_DOWNLOADED: + this.mapState = mapState; + break; + case DOWNLOADED: + if (mapState == MapState.OUTDATED) + this.mapState = mapState; + break; + case OUTDATED: + break; + } + LOG.debug("new state=" + this.mapState); + } + @Override public boolean equals(Object o) { if (this == o) return true; @@ -218,7 +240,7 @@ public class WorldRegion { regionsLookupTable.put(southAmericaRegion.regionId, southAmericaRegion); // Process remaining regions - for (;;) { + for (; ; ) { int processedRegions = 0; Iterator> iterator = loadedItems.entrySet().iterator(); @@ -294,4 +316,10 @@ public class WorldRegion { } return null; } + + public enum MapState { + NOT_DOWNLOADED, + DOWNLOADED, + OUTDATED + } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java index 69adf76ad4..0a4729fc10 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java @@ -238,6 +238,15 @@ public class DownloadIndexesThread { continue; } + if (resource.type == DownloadActivityType.NORMAL_FILE + || resource.type == DownloadActivityType.ROADS_FILE) { + if (resource.isAlreadyDownloaded(indexFileNames)) { + region.processNewMapState(checkIfItemOutdated(resource) + ? WorldRegion.MapState.OUTDATED : WorldRegion.MapState.DOWNLOADED); + } else { + region.processNewMapState(WorldRegion.MapState.NOT_DOWNLOADED); + } + } typesSet.add(resource.getType()); regionResources.put(resource.getSimplifiedFileName(), resource); } @@ -529,6 +538,8 @@ public class DownloadIndexesThread { protected IndexFileList doInBackground(Void... params) { IndexFileList indexFileList = DownloadOsmandIndexesHelper.getIndexesList(ctx); if (indexFileList != null) { + updateLoadedFiles(); + prepareFilesToUpdate(); prepareData(indexFileList.getIndexFiles()); } return indexFileList; @@ -538,7 +549,6 @@ public class DownloadIndexesThread { indexFiles = result; if (indexFiles != null && uiActivity != null) { dataPrepared = resourcesByRegions.size() > 0; - prepareFilesToUpdate(); boolean basemapExists = uiActivity.getMyApplication().getResourceManager().containsBasemap(); IndexItem basemap = indexFiles.getBasemap(); if (basemap != null) { @@ -565,7 +575,6 @@ public class DownloadIndexesThread { if (uiActivity != null) { uiActivity.updateProgress(false); runCategorization(uiActivity.getDownloadType()); - runCategorization(); // for new implementation uiActivity.onCategorizationFinished(); } } @@ -647,8 +656,6 @@ public class DownloadIndexesThread { return filtered; } - ; - public List getFilteredByType() { final List filtered = new ArrayList(); List cachedIndexFiles = getCachedIndexFiles(); @@ -685,58 +692,6 @@ public class DownloadIndexesThread { execute(inst); } - public void runCategorization() { - final BasicProgressAsyncTask> inst - = new BasicProgressAsyncTask>(ctx) { - - @Override - protected void onPreExecute() { - super.onPreExecute(); - currentRunningTask.add(this); - this.message = ctx.getString(R.string.downloading_list_indexes); - if (uiActivity != null) { - uiActivity.updateProgress(false); - } - } - - @Override - protected List doInBackground(Void... params) { - final List filtered = getFilteredByType(); - updateLoadedFiles(); - return filtered; - } - - public List getFilteredByType() { - final List filtered = new ArrayList(); - List cachedIndexFiles = getCachedIndexFiles(); - if (cachedIndexFiles != null) { - for (IndexItem file : cachedIndexFiles) { - filtered.add(file); - } - } - return filtered; - } - - @Override - protected void onPostExecute(List filtered) { - prepareFilesToUpdate(); - currentRunningTask.remove(this); - if (uiActivity != null) { - uiActivity.updateProgress(false); - } - } - - @Override - protected void updateProgress(boolean updateOnlyProgress) { - if (uiActivity != null) { - uiActivity.updateProgress(updateOnlyProgress); - } - - } - }; - execute(inst); - } - private void prepareFilesToUpdate() { List filtered = getCachedIndexFiles(); if (filtered != null) { diff --git a/OsmAnd/src/net/osmand/plus/download/items/ItemViewHolder.java b/OsmAnd/src/net/osmand/plus/download/items/ItemViewHolder.java index 86a927fc25..e33f8af40f 100644 --- a/OsmAnd/src/net/osmand/plus/download/items/ItemViewHolder.java +++ b/OsmAnd/src/net/osmand/plus/download/items/ItemViewHolder.java @@ -12,7 +12,6 @@ import android.widget.ProgressBar; import android.widget.TextView; import android.widget.Toast; -import net.osmand.PlatformUtil; import net.osmand.access.AccessibleToast; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; @@ -27,8 +26,6 @@ import java.text.DateFormat; import java.util.Map; public class ItemViewHolder { - private static final org.apache.commons.logging.Log LOG = PlatformUtil.getLog(WorldItemsFragment.class); - private final TextView nameTextView; private final TextView descrTextView; private final ImageView leftImageView; @@ -222,7 +219,21 @@ public class ItemViewHolder { descrTextView.setVisibility(View.GONE); mapDateTextView.setVisibility(View.GONE); - leftImageView.setImageDrawable(getContextIcon(context, R.drawable.ic_map)); + Drawable leftImageDrawable = null; + switch (region.getMapState()) { + case NOT_DOWNLOADED: + leftImageDrawable = getContextIcon(context, R.drawable.ic_map); + break; + case DOWNLOADED: + leftImageDrawable = getContextIcon(context, R.drawable.ic_map, + context.getResources().getColor(R.color.color_ok)); + break; + case OUTDATED: + leftImageDrawable = getContextIcon(context, R.drawable.ic_map, + context.getResources().getColor(R.color.color_distance)); + break; + } + leftImageView.setImageDrawable(leftImageDrawable); rightImageButton.setVisibility(View.GONE); progressBar.setVisibility(View.GONE); } diff --git a/OsmAnd/src/net/osmand/plus/download/items/VoiceItemsFragment.java b/OsmAnd/src/net/osmand/plus/download/items/VoiceItemsFragment.java index e3214625a1..b0beddc599 100644 --- a/OsmAnd/src/net/osmand/plus/download/items/VoiceItemsFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/items/VoiceItemsFragment.java @@ -186,8 +186,8 @@ public class VoiceItemsFragment extends OsmandExpandableListFragment { .inflate(R.layout.two_line_with_images_list_item, parent, false); viewHolder = new ItemViewHolder(convertView, getMyApplication().getResourceManager().getDateFormat(), - getMyActivity().getIndexActivatedFileNames(), - getMyActivity().getIndexFileNames()); + getMyActivity().getIndexFileNames(), + getMyActivity().getIndexActivatedFileNames()); convertView.setTag(viewHolder); } else { viewHolder = (ItemViewHolder) convertView.getTag();