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 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<Entry<String, String>> iterator = loadedItems.entrySet().iterator();
@ -294,4 +316,10 @@ public class WorldRegion {
}
return null;
}
public enum MapState {
NOT_DOWNLOADED,
DOWNLOADED,
OUTDATED
}
}

View file

@ -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<IndexItem> getFilteredByType() {
final List<IndexItem> filtered = new ArrayList<IndexItem>();
List<IndexItem> cachedIndexFiles = getCachedIndexFiles();
@ -685,58 +692,6 @@ public class DownloadIndexesThread {
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() {
List<IndexItem> filtered = getCachedIndexFiles();
if (filtered != null) {

View file

@ -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);
}

View file

@ -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();