Colors for downloaded maps

This commit is contained in:
GaidamakUA 2015-10-09 12:43:48 +03:00
parent 9a4f2788f1
commit 430e317433
4 changed files with 57 additions and 63 deletions

View file

@ -42,6 +42,8 @@ public class WorldRegion {
private boolean purchased; private boolean purchased;
private boolean isInPurchasedArea; private boolean isInPurchasedArea;
private MapState mapState = MapState.NOT_DOWNLOADED;
public String getRegionId() { public String getRegionId() {
return regionId; return regionId;
} }
@ -82,6 +84,26 @@ public class WorldRegion {
return isInPurchasedArea; 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 @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;
@ -218,7 +240,7 @@ public class WorldRegion {
regionsLookupTable.put(southAmericaRegion.regionId, southAmericaRegion); regionsLookupTable.put(southAmericaRegion.regionId, southAmericaRegion);
// Process remaining regions // Process remaining regions
for (;;) { for (; ; ) {
int processedRegions = 0; int processedRegions = 0;
Iterator<Entry<String, String>> iterator = loadedItems.entrySet().iterator(); Iterator<Entry<String, String>> iterator = loadedItems.entrySet().iterator();
@ -294,4 +316,10 @@ public class WorldRegion {
} }
return null; return null;
} }
public enum MapState {
NOT_DOWNLOADED,
DOWNLOADED,
OUTDATED
}
} }

View file

@ -238,6 +238,15 @@ public class DownloadIndexesThread {
continue; 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()); typesSet.add(resource.getType());
regionResources.put(resource.getSimplifiedFileName(), resource); regionResources.put(resource.getSimplifiedFileName(), resource);
} }
@ -529,6 +538,8 @@ public class DownloadIndexesThread {
protected IndexFileList doInBackground(Void... params) { protected IndexFileList doInBackground(Void... params) {
IndexFileList indexFileList = DownloadOsmandIndexesHelper.getIndexesList(ctx); IndexFileList indexFileList = DownloadOsmandIndexesHelper.getIndexesList(ctx);
if (indexFileList != null) { if (indexFileList != null) {
updateLoadedFiles();
prepareFilesToUpdate();
prepareData(indexFileList.getIndexFiles()); prepareData(indexFileList.getIndexFiles());
} }
return indexFileList; return indexFileList;
@ -538,7 +549,6 @@ public class DownloadIndexesThread {
indexFiles = result; indexFiles = result;
if (indexFiles != null && uiActivity != null) { if (indexFiles != null && uiActivity != null) {
dataPrepared = resourcesByRegions.size() > 0; dataPrepared = resourcesByRegions.size() > 0;
prepareFilesToUpdate();
boolean basemapExists = uiActivity.getMyApplication().getResourceManager().containsBasemap(); boolean basemapExists = uiActivity.getMyApplication().getResourceManager().containsBasemap();
IndexItem basemap = indexFiles.getBasemap(); IndexItem basemap = indexFiles.getBasemap();
if (basemap != null) { if (basemap != null) {
@ -565,7 +575,6 @@ public class DownloadIndexesThread {
if (uiActivity != null) { if (uiActivity != null) {
uiActivity.updateProgress(false); uiActivity.updateProgress(false);
runCategorization(uiActivity.getDownloadType()); runCategorization(uiActivity.getDownloadType());
runCategorization(); // for new implementation
uiActivity.onCategorizationFinished(); uiActivity.onCategorizationFinished();
} }
} }
@ -647,8 +656,6 @@ public class DownloadIndexesThread {
return filtered; return filtered;
} }
;
public List<IndexItem> getFilteredByType() { public List<IndexItem> getFilteredByType() {
final List<IndexItem> filtered = new ArrayList<IndexItem>(); final List<IndexItem> filtered = new ArrayList<IndexItem>();
List<IndexItem> cachedIndexFiles = getCachedIndexFiles(); List<IndexItem> cachedIndexFiles = getCachedIndexFiles();
@ -685,58 +692,6 @@ public class DownloadIndexesThread {
execute(inst); execute(inst);
} }
public void runCategorization() {
final BasicProgressAsyncTask<Void, Void, List<IndexItem>> inst
= new BasicProgressAsyncTask<Void, Void, List<IndexItem>>(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<IndexItem> doInBackground(Void... params) {
final List<IndexItem> filtered = getFilteredByType();
updateLoadedFiles();
return filtered;
}
public List<IndexItem> getFilteredByType() {
final List<IndexItem> filtered = new ArrayList<IndexItem>();
List<IndexItem> cachedIndexFiles = getCachedIndexFiles();
if (cachedIndexFiles != null) {
for (IndexItem file : cachedIndexFiles) {
filtered.add(file);
}
}
return filtered;
}
@Override
protected void onPostExecute(List<IndexItem> 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() { private void prepareFilesToUpdate() {
List<IndexItem> filtered = getCachedIndexFiles(); List<IndexItem> filtered = getCachedIndexFiles();
if (filtered != null) { if (filtered != null) {

View file

@ -12,7 +12,6 @@ import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import net.osmand.PlatformUtil;
import net.osmand.access.AccessibleToast; import net.osmand.access.AccessibleToast;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R; import net.osmand.plus.R;
@ -27,8 +26,6 @@ import java.text.DateFormat;
import java.util.Map; import java.util.Map;
public class ItemViewHolder { public class ItemViewHolder {
private static final org.apache.commons.logging.Log LOG = PlatformUtil.getLog(WorldItemsFragment.class);
private final TextView nameTextView; private final TextView nameTextView;
private final TextView descrTextView; private final TextView descrTextView;
private final ImageView leftImageView; private final ImageView leftImageView;
@ -222,7 +219,21 @@ public class ItemViewHolder {
descrTextView.setVisibility(View.GONE); descrTextView.setVisibility(View.GONE);
mapDateTextView.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); rightImageButton.setVisibility(View.GONE);
progressBar.setVisibility(View.GONE); progressBar.setVisibility(View.GONE);
} }

View file

@ -186,8 +186,8 @@ public class VoiceItemsFragment extends OsmandExpandableListFragment {
.inflate(R.layout.two_line_with_images_list_item, parent, false); .inflate(R.layout.two_line_with_images_list_item, parent, false);
viewHolder = new ItemViewHolder(convertView, viewHolder = new ItemViewHolder(convertView,
getMyApplication().getResourceManager().getDateFormat(), getMyApplication().getResourceManager().getDateFormat(),
getMyActivity().getIndexActivatedFileNames(), getMyActivity().getIndexFileNames(),
getMyActivity().getIndexFileNames()); getMyActivity().getIndexActivatedFileNames());
convertView.setTag(viewHolder); convertView.setTag(viewHolder);
} else { } else {
viewHolder = (ItemViewHolder) convertView.getTag(); viewHolder = (ItemViewHolder) convertView.getTag();