From a172c48d08fb3a01cbd431178beeadc71be18ed6 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sun, 18 Oct 2015 23:39:10 +0200 Subject: [PATCH] Finalize data package refactoring --- OsmAnd/src/net/osmand/plus/WorldRegion.java | 87 ++-- .../plus/download/DownloadActivity.java | 8 - .../download/DownloadOsmandIndexesHelper.java | 6 +- .../plus/download/DownloadResourceGroup.java | 55 ++- .../plus/download/DownloadResources.java | 376 ++++-------------- .../osmand/plus/download/DownloadTracker.java | 1 - .../net/osmand/plus/download/IndexItem.java | 5 - .../plus/download/ui/ItemViewHolder.java | 2 +- 8 files changed, 159 insertions(+), 381 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/WorldRegion.java b/OsmAnd/src/net/osmand/plus/WorldRegion.java index 888150d54b..048c218e84 100644 --- a/OsmAnd/src/net/osmand/plus/WorldRegion.java +++ b/OsmAnd/src/net/osmand/plus/WorldRegion.java @@ -1,18 +1,16 @@ package net.osmand.plus; -import android.content.res.Resources; - -import net.osmand.PlatformUtil; -import net.osmand.map.OsmandRegions; -import net.osmand.plus.download.DownloadActivityType; - import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Map.Entry; -import java.util.Set; + +import net.osmand.PlatformUtil; +import net.osmand.map.OsmandRegions; +import net.osmand.util.Algorithms; +import android.content.res.Resources; public class WorldRegion { @@ -24,16 +22,15 @@ public class WorldRegion { public static final String NORTH_AMERICA_REGION_ID = "northamerica"; public static final String RUSSIA_REGION_ID = "russia"; public static final String SOUTH_AMERICA_REGION_ID = "southamerica"; + public static final String WORLD = "world"; private static final org.apache.commons.logging.Log LOG = PlatformUtil.getLog(WorldRegion.class); // Region data private String regionId; - private String downloadsIdPrefix; + private String downloadsId; private String name; - private Set resourceTypes; - // Hierarchy private WorldRegion superregion; private List subregions; @@ -45,22 +42,14 @@ public class WorldRegion { return regionId; } - public String getDownloadsIdPrefix() { - return downloadsIdPrefix; + public String getDownloadsId() { + return downloadsId; } public String getName() { return name; } - public Set getResourceTypes() { - return resourceTypes; - } - - public void setResourceTypes(Set resourceTypes) { - this.resourceTypes = resourceTypes; - } - public WorldRegion getSuperregion() { return superregion; } @@ -96,7 +85,7 @@ public class WorldRegion { public void initWorld() { regionId = ""; - downloadsIdPrefix = "world_"; + downloadsId= WORLD; name = ""; superregion = null; } @@ -105,9 +94,9 @@ public class WorldRegion { this.regionId = regionId; String downloadName = osmandRegions.getDownloadName(regionId); if (downloadName != null) { - downloadsIdPrefix = downloadName.toLowerCase() + "."; + downloadsId = downloadName.toLowerCase(); } else { - this.downloadsIdPrefix = regionId.toLowerCase() + "."; + this.downloadsId = regionId.toLowerCase(); } if (name != null) { this.name = name; @@ -120,24 +109,10 @@ public class WorldRegion { return this; } - private WorldRegion init(String regionId, OsmandRegions osmandRegions) { - this.regionId = regionId; - String downloadName = osmandRegions.getDownloadName(regionId); - if (downloadName != null) { - downloadsIdPrefix = downloadName.toLowerCase() + "."; - } else { - this.downloadsIdPrefix = regionId.toLowerCase() + "."; - } - this.name = osmandRegions.getLocaleNameByFullName(regionId, false); - if (this.name == null) { - this.name = capitalize(regionId.replace('_', ' ')); - } - return this; - } private WorldRegion init(String regionId, String name) { this.regionId = regionId; - this.downloadsIdPrefix = regionId.toLowerCase() + "."; + this.downloadsId = regionId.toLowerCase() ; this.name = name; return this; } @@ -149,22 +124,20 @@ public class WorldRegion { } private void propagateSubregionToFlattenedHierarchy(WorldRegion subregion) { - flattenedSubregions.add(subregion); if (superregion != null) { superregion.propagateSubregionToFlattenedHierarchy(subregion); + } else { + flattenedSubregions.add(subregion); } } public void loadWorldRegions(OsmandApplication app) { OsmandRegions osmandRegions = app.getRegions(); - Map loadedItems = osmandRegions.getFullNamesToLowercaseCopy(); if (loadedItems.size() == 0) { return; } - HashMap regionsLookupTable = new HashMap<>(loadedItems.size()); - // Create main regions Resources res = app.getResources(); @@ -208,10 +181,9 @@ public class WorldRegion { addSubregion(southAmericaRegion); regionsLookupTable.put(southAmericaRegion.regionId, southAmericaRegion); - // Process remaining regions + // Process all regions for (; ; ) { int processedRegions = 0; - Iterator> iterator = loadedItems.entrySet().iterator(); while (iterator.hasNext()) { String regionId = iterator.next().getKey(); @@ -226,7 +198,7 @@ public class WorldRegion { continue; } - WorldRegion newRegion = new WorldRegion().init(regionId, osmandRegions); + WorldRegion newRegion = new WorldRegion().init(regionId, osmandRegions, null); parentRegion.addSubregion(newRegion); regionsLookupTable.put(newRegion.regionId, newRegion); @@ -240,21 +212,18 @@ public class WorldRegion { break; } - LOG.warn("Found orphaned regions: " + loadedItems.size()); - for (String regionId : loadedItems.keySet()) { - LOG.warn("FullName = " + regionId + " parent=" + osmandRegions.getParentFullName(regionId)); + if (loadedItems.size() > 0) { + LOG.warn("Found orphaned regions: " + loadedItems.size()); + for (String regionId : loadedItems.keySet()) { + LOG.warn("FullName = " + regionId + " parent=" + osmandRegions.getParentFullName(regionId)); + } } } - private static WorldRegion createRegionAs(String regionId, Map loadedItems, OsmandRegions osmandRegions, String localizedName) { - WorldRegion worldRegion; - boolean hasRegion = loadedItems.containsKey(regionId); - if (hasRegion) { - worldRegion = new WorldRegion().init(regionId, osmandRegions, localizedName); - loadedItems.remove(regionId); - } else { - worldRegion = new WorldRegion().init(regionId, localizedName); - } + private static WorldRegion createRegionAs(String regionId, Map loadedItems, + OsmandRegions osmandRegions, String localizedName) { + WorldRegion worldRegion = new WorldRegion().init(regionId, osmandRegions, localizedName); + loadedItems.remove(regionId); return worldRegion; } @@ -262,10 +231,10 @@ public class WorldRegion { String[] words = s.split(" "); if (words[0].length() > 0) { StringBuilder sb = new StringBuilder(); - sb.append(Character.toUpperCase(words[0].charAt(0))).append(words[0].subSequence(1, words[0].length()).toString().toLowerCase()); + sb.append(Algorithms.capitalizeFirstLetterAndLowercase(words[0])); for (int i = 1; i < words.length; i++) { sb.append(" "); - sb.append(Character.toUpperCase(words[i].charAt(0))).append(words[i].subSequence(1, words[i].length()).toString().toLowerCase()); + sb.append(Algorithms.capitalizeFirstLetterAndLowercase(words[i])); } return sb.toString(); } else { diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java b/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java index e1fc04662f..eb7e7b64f3 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java @@ -6,17 +6,13 @@ import java.text.MessageFormat; import java.util.ArrayList; import java.util.List; import java.util.Locale; -import java.util.Map; -import net.osmand.PlatformUtil; import net.osmand.plus.OsmandApplication; -import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.Version; import net.osmand.plus.activities.LocalIndexInfo; import net.osmand.plus.activities.OsmAndListFragment; -import net.osmand.plus.activities.OsmandBaseExpandableListAdapter; import net.osmand.plus.activities.OsmandExpandableListFragment; import net.osmand.plus.activities.TabActivity; import net.osmand.plus.base.BasicProgressAsyncTask; @@ -27,11 +23,7 @@ import net.osmand.plus.download.ui.RegionItemsFragment; import net.osmand.plus.download.ui.SearchDialogFragment; import net.osmand.plus.download.ui.UpdatesIndexFragment; import net.osmand.plus.download.ui.WorldItemsFragment; -import net.osmand.plus.srtmplugin.SRTMPlugin; import net.osmand.plus.views.controls.PagerSlidingTabStrip; - -import org.apache.commons.logging.Log; - import android.content.ActivityNotFoundException; import android.content.Intent; import android.net.Uri; diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadOsmandIndexesHelper.java b/OsmAnd/src/net/osmand/plus/download/DownloadOsmandIndexesHelper.java index 513d9da551..5f061d2283 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadOsmandIndexesHelper.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadOsmandIndexesHelper.java @@ -12,19 +12,17 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.zip.GZIPInputStream; - import net.osmand.AndroidUtils; import net.osmand.IndexConstants; import net.osmand.PlatformUtil; import net.osmand.osm.io.NetworkUtils; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; - import org.apache.commons.logging.Log; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserFactory; - +import android.annotation.SuppressLint; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; @@ -72,6 +70,7 @@ public class DownloadOsmandIndexesHelper { this.mapversion = mapversion; } + @SuppressLint("DefaultLocale") public void add(IndexItem indexItem) { indexFiles.add(indexItem); if(indexItem.getFileName().toLowerCase().startsWith("world_basemap")) { @@ -142,7 +141,6 @@ public class DownloadOsmandIndexesHelper { OsmandSettings settings) { try { String ext = DownloadActivityType.addVersionToExt(IndexConstants.TTSVOICE_INDEX_EXT_ZIP, IndexConstants.TTSVOICE_VERSION); - String extvoice = DownloadActivityType.addVersionToExt(IndexConstants.VOICE_INDEX_EXT_ZIP, IndexConstants.VOICE_VERSION); File voicePath = settings.getContext().getAppPath(IndexConstants.VOICE_INDEX_DIR); // list = amanager.list("voice"); String date = ""; diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadResourceGroup.java b/OsmAnd/src/net/osmand/plus/download/DownloadResourceGroup.java index f7bed5b604..80e829b864 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadResourceGroup.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadResourceGroup.java @@ -1,8 +1,14 @@ package net.osmand.plus.download; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.Iterator; import java.util.List; +import net.osmand.OsmAndCollator; +import net.osmand.map.OsmandRegions; +import net.osmand.plus.OsmandApplication; import net.osmand.plus.WorldRegion; public class DownloadResourceGroup { @@ -15,9 +21,12 @@ public class DownloadResourceGroup { protected final String id; protected WorldRegion region; + public static final String REGION_MAPS_ID = "maps"; public enum DownloadResourceGroupType { - WORLD, VOICE, WORLD_MAPS, REGION +// return ctx.getResources().getString(R.string.index_name_voice); +// return ctx.getResources().getString(R.string.index_name_tts_voice); + WORLD, VOICE_REC, VOICE_TTS, WORLD_MAPS, REGION, REGION_MAPS } @@ -34,6 +43,50 @@ public class DownloadResourceGroup { this.type = type; this.parentGroup = parentGroup; } + + public void trimEmptyGroups() { + if(groups != null) { + for(DownloadResourceGroup gr : groups) { + gr.trimEmptyGroups(); + } + Iterator gr = groups.iterator(); + while(gr.hasNext()) { + DownloadResourceGroup group = gr.next(); + if(group.isEmpty()) { + gr.remove(); + } + } + } + + } + + public void addGroup(DownloadResourceGroup g) { + groups.add(g); + if (g.individualResources != null) { + final net.osmand.Collator collator = OsmAndCollator.primaryCollator(); + final OsmandApplication app = getRoot().app; + final OsmandRegions osmandRegions = app.getRegions(); + Collections.sort(g.individualResources, new Comparator() { + @Override + public int compare(IndexItem lhs, IndexItem rhs) { + return collator.compare(lhs.getVisibleName(app.getApplicationContext(), osmandRegions), + rhs.getVisibleName(app.getApplicationContext(), osmandRegions)); + } + }); + } + } + + public void addItem(IndexItem i) { + individualResources.add(i); + } + + public boolean isEmpty() { + return isEmpty(individualResources) && isEmpty(groups); + } + + private boolean isEmpty(List l) { + return l == null || l.isEmpty(); + } public String getGroupId() { return id; diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadResources.java b/OsmAnd/src/net/osmand/plus/download/DownloadResources.java index 48211c10e2..a00fac3645 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadResources.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadResources.java @@ -4,35 +4,16 @@ import java.io.File; import java.io.FilenameFilter; import java.io.IOException; import java.io.InputStream; -import java.text.Collator; import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; -import java.util.Set; -import java.util.TreeSet; -import android.content.Context; import net.osmand.IndexConstants; -import net.osmand.OsmAndCollator; -import net.osmand.PlatformUtil; -import net.osmand.map.OsmandRegions; import net.osmand.plus.OsmandApplication; -import net.osmand.plus.OsmandPlugin; -import net.osmand.plus.R; import net.osmand.plus.WorldRegion; import net.osmand.plus.download.DownloadOsmandIndexesHelper.AssetIndexItem; -import net.osmand.plus.download.ui.DownloadIndexes; -import net.osmand.plus.download.ui.ItemsListBuilder; -import net.osmand.plus.download.ui.ResourceItem; -import net.osmand.plus.download.ui.ResourceItemComparator; -import net.osmand.plus.download.ui.ItemsListBuilder.VoicePromptsType; -import net.osmand.plus.srtmplugin.SRTMPlugin; -import net.osmand.util.Algorithms; public class DownloadResources extends DownloadResourceGroup { public boolean isDownloadedFromInternet = false; @@ -40,8 +21,12 @@ public class DownloadResources extends DownloadResourceGroup { public OsmandApplication app; private Map indexFileNames = new LinkedHashMap<>(); private Map indexActivatedFileNames = new LinkedHashMap<>(); + private List rawResources; private List itemsToUpdate = new ArrayList<>(); - + //public static final String WORLD_BASEMAP_KEY = "world_basemap.obf.zip"; + public static final String WORLD_SEAMARKS_KEY = "world_seamarks_basemap.obf.zip"; + + public DownloadResources(OsmandApplication app) { super(null, DownloadResourceGroupType.WORLD, "", false); this.region = app.getWorldRegion(); @@ -63,13 +48,15 @@ public class DownloadResources extends DownloadResourceGroup { prepareFilesToUpdate(); } - public boolean checkIfItemOutdated(IndexItem item) { + public boolean checkIfItemOutdated(IndexItem item, java.text.DateFormat format) { 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(indexactivateddate == null && indexfilesdate == null) { + return outdated; + } + String date = item.getDate(format); if (date != null && !date.equals(indexactivateddate) && !date.equals(indexfilesdate)) { if ((item.getType() == DownloadActivityType.NORMAL_FILE && !item.extra) || item.getType() == DownloadActivityType.ROADS_FILE @@ -160,16 +147,13 @@ public class DownloadResources extends DownloadResourceGroup { return file; } - - - ////////// FIXME //////////// - private void prepareFilesToUpdate() { - List filtered = getCachedIndexFiles(); + List filtered = rawResources; if (filtered != null) { itemsToUpdate.clear(); + java.text.DateFormat format = app.getResourceManager().getDateFormat(); for (IndexItem item : filtered) { - boolean outdated = checkIfItemOutdated(item); + boolean outdated = checkIfItemOutdated(item, format); // include only activated files here if (outdated && indexActivatedFileNames.containsKey(item.getTargetFileName())) { itemsToUpdate.add(item); @@ -178,287 +162,75 @@ public class DownloadResources extends DownloadResourceGroup { } } - private void processRegion(List resourcesInRepository, DownloadResources di, - boolean processVoiceFiles, WorldRegion region) { - String downloadsIdPrefix = region.getDownloadsIdPrefix(); - Map regionResources = new HashMap<>(); - Set typesSet = new TreeSet<>(new Comparator() { - @Override - public int compare(DownloadActivityType dat1, DownloadActivityType dat2) { - return dat1.getTag().compareTo(dat2.getTag()); - } - }); - for (IndexItem resource : resourcesInRepository) { - if (processVoiceFiles) { - if (resource.getSimplifiedFileName().endsWith(".voice.zip")) { - voiceRecItems.add(resource); - continue; - } else if (resource.getSimplifiedFileName().contains(".ttsvoice.zip")) { - voiceTTSItems.add(resource); - continue; - } - } - if (!resource.getSimplifiedFileName().startsWith(downloadsIdPrefix)) { - 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); - } - - if (region.getSuperregion() != null && region.getSuperregion().getSuperregion() != app.getWorldRegion()) { - if (region.getSuperregion().getResourceTypes() == null) { - region.getSuperregion().setResourceTypes(typesSet); - } else { - region.getSuperregion().getResourceTypes().addAll(typesSet); - } - } - - region.setResourceTypes(typesSet); - resourcesByRegions.put(region, regionResources); - } - protected boolean prepareData(List resources) { - for (WorldRegion region : app.getWorldRegion().getFlattenedSubregions()) { - processRegion(resourcesInRepository, di, false, region); + this.rawResources = resources; + DownloadResourceGroup voiceRec = new DownloadResourceGroup(this, DownloadResourceGroupType.VOICE_REC, "voice_rec", true); + DownloadResourceGroup voiceTTS = new DownloadResourceGroup(this, DownloadResourceGroupType.VOICE_TTS, "voice_tts", true); + DownloadResourceGroup worldMaps = new DownloadResourceGroup(this, DownloadResourceGroupType.WORLD_MAPS, "world", true); + Map > groupByRegion = new LinkedHashMap>(); + + Map downloadIdForRegion = new LinkedHashMap(); + for(WorldRegion wg : region.getFlattenedSubregions()) { + downloadIdForRegion.put(wg.getDownloadsId(), wg); } - processRegion(resourcesInRepository, di, true, app.getWorldRegion()); - - final net.osmand.Collator collator = OsmAndCollator.primaryCollator(); - final OsmandRegions osmandRegions = app.getRegions(); - - Collections.sort(di.voiceRecItems, new Comparator() { - @Override - public int compare(IndexItem lhs, IndexItem rhs) { - return collator.compare(lhs.getVisibleName(app.getApplicationContext(), osmandRegions), - rhs.getVisibleName(app.getApplicationContext(), osmandRegions)); + + for (IndexItem ii : resources) { + if (ii.getType() == DownloadActivityType.VOICE_FILE) { + if (ii.getFileName().endsWith(IndexConstants.TTSVOICE_INDEX_EXT_ZIP)) { + voiceTTS.addItem(ii); + } else { + voiceRec.addItem(ii); + } } - }); - - Collections.sort(di.voiceTTSItems, new Comparator() { - @Override - public int compare(IndexItem lhs, IndexItem rhs) { - return collator.compare(lhs.getVisibleName(app.getApplicationContext(), osmandRegions), - rhs.getVisibleName(app.getApplicationContext(), osmandRegions)); + String basename = ii.getBasename().toLowerCase(); + WorldRegion wg = downloadIdForRegion.get(basename); + if (wg != null) { + if (!groupByRegion.containsKey(wg)) { + groupByRegion.put(wg, new ArrayList()); + } + groupByRegion.get(wg).add(ii); + } else { + worldMaps.addItem(ii); } - }); + } + LinkedList queue = new LinkedList(); + LinkedList parent = new LinkedList(); + for(WorldRegion rg : region.getSubregions()) { + queue.add(rg); + parent.add(this); + } + while(!queue.isEmpty()) { + WorldRegion reg = queue.pollFirst(); + DownloadResourceGroup parentGroup = parent.pollFirst(); + List subregions = reg.getSubregions(); + DownloadResourceGroup mainGrp = new DownloadResourceGroup(parentGroup, DownloadResourceGroupType.REGION, reg.getRegionId(), false); + parentGroup.addGroup(mainGrp); + List list = groupByRegion.get(reg); + if(list != null) { + DownloadResourceGroup flatFiles = new DownloadResourceGroup(parentGroup, DownloadResourceGroupType.REGION_MAPS, REGION_MAPS_ID, true); + for(IndexItem ii : list) { + flatFiles.addItem(ii); + } + mainGrp.addGroup(flatFiles); + } + // add to processing queue + for(WorldRegion rg : subregions) { + queue.add(rg); + parent.add(mainGrp); + } + } + // Possible improvements + // 1. if there is no subregions no need to create resource group REGIONS_MAPS - objection raise diversity and there is no value + // 2. if there is no subregions and there only 1 index item it could be merged to the level up - objection there is no such maps + // 3. if hillshade/srtm is disabled, all maps from inner level could be combined into 1 + addGroup(worldMaps); + addGroup(voiceTTS); + addGroup(voiceRec); + trimEmptyGroups(); initAlreadyLoadedFiles(); return true; } - public class ItemsListBuilder { - - //public static final String WORLD_BASEMAP_KEY = "world_basemap.obf.zip"; - public static final String WORLD_SEAMARKS_KEY = "world_seamarks_basemap.obf.zip"; - private static final org.apache.commons.logging.Log LOG = PlatformUtil.getLog(ItemsListBuilder.class); - - private DownloadIndexes downloadIndexes; - - private List regionMapItems; - private List allResourceItems; - private List allSubregionItems; - - private OsmandApplication app; - private WorldRegion region; - - private boolean srtmDisabled; - private boolean hasSrtm; - private boolean hasHillshade; - - public List getRegionMapItems() { - return regionMapItems; - } - - public List getAllResourceItems() { - return allResourceItems; - } - - public List getRegionsFromAllItems() { - List list = new LinkedList<>(); - for (Object obj : allResourceItems) { - if (obj instanceof WorldRegion) { - list.add((WorldRegion) obj); - } - } - return list; - } - - public static String getVoicePromtName(Context ctx, VoicePromptsType type) { - switch (type) { - case RECORDED: - return ctx.getResources().getString(R.string.index_name_voice); - case TTS: - return ctx.getResources().getString(R.string.index_name_tts_voice); - default: - return ""; - } - } - - public List getVoicePromptsItems(VoicePromptsType type) { - switch (type) { - case RECORDED: - return downloadIndexes.voiceRecItems; - case TTS: - return downloadIndexes.voiceTTSItems; - default: - return new LinkedList<>(); - } - } - - public boolean isVoicePromptsItemsEmpty(VoicePromptsType type) { - switch (type) { - case RECORDED: - return downloadIndexes.voiceRecItems.isEmpty(); - case TTS: - return downloadIndexes.voiceTTSItems.isEmpty(); - default: - return true; - } - } - - // FIXME - public ItemsListBuilder(OsmandApplication app, String regionId, DownloadIndexes di) { - this.app = app; - this.downloadIndexes = di; - - regionMapItems = new LinkedList<>(); - allResourceItems = new LinkedList<>(); - allSubregionItems = new LinkedList<>(); - - region = app.getWorldRegion().getRegionById(regionId); - } - - public ItemsListBuilder build() { - if (obtainDataAndItems()) { - return this; - } else { - return null; - } - } - - private boolean obtainDataAndItems() { - if (downloadIndexes.resourcesByRegions.isEmpty() || region == null) { - return false; - } - - collectSubregionsDataAndItems(); - collectResourcesDataAndItems(); - - return true; - } - - private void collectSubregionsDataAndItems() { - srtmDisabled = OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) == null; - hasSrtm = false; - hasHillshade = false; - - // Collect all regions (and their parents) that have at least one - // resource available in repository or locally. - - allResourceItems.clear(); - allSubregionItems.clear(); - regionMapItems.clear(); - - for (WorldRegion subregion : region.getFlattenedSubregions()) { - if (subregion.getSuperregion() == region) { - if (subregion.getFlattenedSubregions().size() > 0) { - allSubregionItems.add(subregion); - } else { - collectSubregionItems(subregion); - } - } - } - } - - private void collectSubregionItems(WorldRegion region) { - Map regionResources = downloadIndexes.resourcesByRegions.get(region); - - if (regionResources == null) { - return; - } - - List regionMapArray = new LinkedList<>(); - List allResourcesArray = new LinkedList<>(); - - Context context = app.getApplicationContext(); - OsmandRegions osmandRegions = app.getRegions(); - - for (IndexItem indexItem : regionResources.values()) { - - String name = indexItem.getVisibleName(context, osmandRegions, false); - if (Algorithms.isEmpty(name)) { - continue; - } - - ResourceItem resItem = new ResourceItem(indexItem, region); - resItem.setResourceId(indexItem.getSimplifiedFileName()); - resItem.setTitle(name); - - if (region != this.region && srtmDisabled) { - if (indexItem.getType() == DownloadActivityType.SRTM_COUNTRY_FILE) { - if (hasSrtm) { - continue; - } else { - hasSrtm = true; - } - } else if (indexItem.getType() == DownloadActivityType.HILLSHADE_FILE) { - if (hasHillshade) { - continue; - } else { - hasHillshade = true; - } - } - } - - - if (region == this.region) { - regionMapArray.add(resItem); - } else { - allResourcesArray.add(resItem); - } - - } - - regionMapItems.addAll(regionMapArray); - - if (allResourcesArray.size() > 1) { - allSubregionItems.add(region); - } else { - allResourceItems.addAll(allResourcesArray); - } - } - - private void collectResourcesDataAndItems() { - collectSubregionItems(region); - - allResourceItems.addAll(allSubregionItems); - - Collections.sort(allResourceItems, new ResourceItemComparator()); - Collections.sort(regionMapItems, new ResourceItemComparator()); - } - - public enum MapState { - NOT_DOWNLOADED, - DOWNLOADED, - OUTDATED - } - - - public enum VoicePromptsType { - NONE, - RECORDED, - TTS - } - } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadTracker.java b/OsmAnd/src/net/osmand/plus/download/DownloadTracker.java index 20aa692dad..b612299ebd 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadTracker.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadTracker.java @@ -3,7 +3,6 @@ package net.osmand.plus.download; import java.io.File; import java.io.IOException; import java.net.HttpURLConnection; -import java.net.URL; import java.net.URLEncoder; import java.text.MessageFormat; import java.util.Iterator; diff --git a/OsmAnd/src/net/osmand/plus/download/IndexItem.java b/OsmAnd/src/net/osmand/plus/download/IndexItem.java index a77c35e657..e4d3a3f981 100644 --- a/OsmAnd/src/net/osmand/plus/download/IndexItem.java +++ b/OsmAnd/src/net/osmand/plus/download/IndexItem.java @@ -21,7 +21,6 @@ public class IndexItem implements Comparable/*, Parcelable*/ { String description; String fileName; - String simplifiedFileName; String size; long timestamp; long contentSize; @@ -33,7 +32,6 @@ public class IndexItem implements Comparable/*, Parcelable*/ { public IndexItem(String fileName, String description, long timestamp, String size, long contentSize, long containerSize, DownloadActivityType tp) { this.fileName = fileName; - this.simplifiedFileName = fileName.toLowerCase().replace("_2.", ".").replace("hillshade_", ""); this.description = description; this.timestamp = timestamp; this.size = size; @@ -50,9 +48,6 @@ public class IndexItem implements Comparable/*, Parcelable*/ { return fileName; } - public String getSimplifiedFileName() { - return simplifiedFileName; - } public String getDescription() { return description; diff --git a/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java b/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java index a35100c0c4..e90976d9e5 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java @@ -79,7 +79,7 @@ public class ItemViewHolder extends TwoLineWithImagesViewHolder { nameTextView.setText(indexItem.getVisibleName(context, context.getMyApplication().getRegions(), false)); } else { - if (indexItem.getSimplifiedFileName().equals(ItemsListBuilder.WORLD_SEAMARKS_KEY) + if (indexItem.getSimplifiedFileName().equals(WORLD_SEAMARKS_KEY) && nauticalPluginDisabled) { rightButtonAction = RightButtonAction.ASK_FOR_SEAMARKS_PLUGIN; disabled = true;