From 89f73adbbff184d4f5b49efc026d5009c9cec672 Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Fri, 2 Oct 2015 11:09:23 +0300 Subject: [PATCH] Download maps fixes --- OsmAnd/src/net/osmand/plus/WorldRegion.java | 40 +++++++++++++----- .../plus/download/items/ItemsListBuilder.java | 41 +++++++------------ ...ragment.java => RegionDialogFragment.java} | 12 +++--- ...Fragment.java => RegionItemsFragment.java} | 17 +++----- .../download/items/WorldItemsFragment.java | 4 +- 5 files changed, 59 insertions(+), 55 deletions(-) rename OsmAnd/src/net/osmand/plus/download/items/{LocalDialogFragment.java => RegionDialogFragment.java} (86%) rename OsmAnd/src/net/osmand/plus/download/items/{LocalItemsFragment.java => RegionItemsFragment.java} (93%) diff --git a/OsmAnd/src/net/osmand/plus/WorldRegion.java b/OsmAnd/src/net/osmand/plus/WorldRegion.java index ed9ebda041..f461a0987e 100644 --- a/OsmAnd/src/net/osmand/plus/WorldRegion.java +++ b/OsmAnd/src/net/osmand/plus/WorldRegion.java @@ -14,6 +14,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Set; public class WorldRegion implements Serializable { @@ -36,7 +37,7 @@ public class WorldRegion implements Serializable { private LatLon bboxTopLeft; private LatLon bboxBottomRight; - private List resourceTypes; + private Set resourceTypes; // Hierarchy private WorldRegion superregion; @@ -66,11 +67,11 @@ public class WorldRegion implements Serializable { return bboxBottomRight; } - public List getResourceTypes() { + public Set getResourceTypes() { return resourceTypes; } - public void setResourceTypes(List resourceTypes) { + public void setResourceTypes(Set resourceTypes) { this.resourceTypes = resourceTypes; } @@ -129,14 +130,16 @@ public class WorldRegion implements Serializable { String downloadName = osmandRegions.getDownloadName(regionId); if (downloadName != null) { downloadsIdPrefix = downloadName.toLowerCase() + "."; - if (name != null) { - this.name = name; - } else { - this.name = osmandRegions.getLocaleName(downloadName); - } } else { this.downloadsIdPrefix = regionId.toLowerCase() + "."; + } + if (name != null) { this.name = name; + } else { + this.name = osmandRegions.getLocaleNameByFullName(regionId); + if (this.name == null) { + this.name = capitalize(regionId.replace('_', ' ')); + } } return this; } @@ -146,10 +149,12 @@ public class WorldRegion implements Serializable { String downloadName = osmandRegions.getDownloadName(regionId); if (downloadName != null) { downloadsIdPrefix = downloadName.toLowerCase() + "."; - this.name = osmandRegions.getLocaleName(downloadName); } else { this.downloadsIdPrefix = regionId.toLowerCase() + "."; - this.name = regionId; + } + this.name = osmandRegions.getLocaleNameByFullName(regionId); + if (this.name == null) { + this.name = capitalize(regionId.replace('_', ' ')); } return this; } @@ -281,4 +286,19 @@ public class WorldRegion implements Serializable { } return worldRegion; } + + private String capitalize(String s) { + 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()); + 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()); + } + return sb.toString(); + } else { + return s; + } + } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/download/items/ItemsListBuilder.java b/OsmAnd/src/net/osmand/plus/download/items/ItemsListBuilder.java index 50a7a4d272..2b847cf42f 100644 --- a/OsmAnd/src/net/osmand/plus/download/items/ItemsListBuilder.java +++ b/OsmAnd/src/net/osmand/plus/download/items/ItemsListBuilder.java @@ -9,7 +9,6 @@ import net.osmand.plus.WorldRegion; import net.osmand.plus.download.DownloadActivity; import net.osmand.plus.download.DownloadActivityType; import net.osmand.plus.download.IndexItem; -import net.osmand.plus.mapcontextmenu.editors.PointEditor; import net.osmand.util.Algorithms; import java.util.Collections; @@ -18,6 +17,8 @@ import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Set; +import java.util.TreeSet; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; @@ -235,8 +236,12 @@ public class ItemsListBuilder { } if (doInit) { - List typesArray = new LinkedList<>(); - boolean hasSrtm = false; + Set typesSet = new TreeSet<>(new Comparator() { + @Override + public int compare(DownloadActivityType dat1, DownloadActivityType dat2) { + return dat1.getTag().compareTo(dat2.getTag()); + } + }); for (IndexItem resource : resourcesInRepository) { @@ -244,36 +249,20 @@ public class ItemsListBuilder { continue; } - if (resource.getType() == DownloadActivityType.SRTM_COUNTRY_FILE) { - hasSrtm = true; - } - - typesArray.add(resource.getType()); - + typesSet.add(resource.getType()); regionResources.put(resource.getSimplifiedFileName(), resource); } - if (region.getSuperregion() != null && hasSrtm && region.getSuperregion().getSuperregion() != app.getWorldRegion()) { - if (!region.getSuperregion().getResourceTypes().contains(DownloadActivityType.SRTM_COUNTRY_FILE)) { - region.getSuperregion().getResourceTypes().add(DownloadActivityType.SRTM_COUNTRY_FILE); - Collections.sort(region.getSuperregion().getResourceTypes(), new Comparator() { - @Override - public int compare(DownloadActivityType dat1, DownloadActivityType dat2) { - return dat1.getTag().compareTo(dat2.getTag()); - } - }); + if (region.getSuperregion() != null && region.getSuperregion().getSuperregion() != app.getWorldRegion()) { + if (region.getSuperregion().getResourceTypes() == null) { + region.getSuperregion().setResourceTypes(typesSet); + } else { + region.getSuperregion().getResourceTypes().addAll(typesSet); } } - Collections.sort(typesArray, new Comparator() { - @Override - public int compare(DownloadActivityType dat1, DownloadActivityType dat2) { - return dat1.getTag().compareTo(dat2.getTag()); - } - }); - region.setResourceTypes(typesArray); + region.setResourceTypes(typesSet); } - resourcesByRegions.put(region, regionResources); } return true; diff --git a/OsmAnd/src/net/osmand/plus/download/items/LocalDialogFragment.java b/OsmAnd/src/net/osmand/plus/download/items/RegionDialogFragment.java similarity index 86% rename from OsmAnd/src/net/osmand/plus/download/items/LocalDialogFragment.java rename to OsmAnd/src/net/osmand/plus/download/items/RegionDialogFragment.java index da599cc54d..8ea22a4e03 100644 --- a/OsmAnd/src/net/osmand/plus/download/items/LocalDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/items/RegionDialogFragment.java @@ -15,9 +15,9 @@ import net.osmand.plus.WorldRegion; import org.apache.commons.logging.Log; -public class LocalDialogFragment extends DialogFragment { - private static final Log LOG = PlatformUtil.getLog(LocalDialogFragment.class); - public static final String TAG = "LocalDialogFragment"; +public class RegionDialogFragment extends DialogFragment { + private static final Log LOG = PlatformUtil.getLog(RegionDialogFragment.class); + public static final String TAG = "RegionDialogFragment"; private static final String REGION_DLG_KEY = "world_region_dialog_key"; private WorldRegion region; @@ -62,7 +62,7 @@ public class LocalDialogFragment extends DialogFragment { if (this.region != null) { getChildFragmentManager().beginTransaction().add(R.id.fragmentContainer, - LocalItemsFragment.createInstance(region)).commit(); + RegionItemsFragment.createInstance(region)).commit(); toolbar.setTitle(this.region.getName()); } @@ -83,10 +83,10 @@ public class LocalDialogFragment extends DialogFragment { createInstance(region).show(getChildFragmentManager(), TAG); } - public static LocalDialogFragment createInstance(WorldRegion region) { + public static RegionDialogFragment createInstance(WorldRegion region) { Bundle bundle = new Bundle(); bundle.putSerializable(REGION_DLG_KEY, region); - LocalDialogFragment fragment = new LocalDialogFragment(); + RegionDialogFragment fragment = new RegionDialogFragment(); fragment.setArguments(bundle); return fragment; } diff --git a/OsmAnd/src/net/osmand/plus/download/items/LocalItemsFragment.java b/OsmAnd/src/net/osmand/plus/download/items/RegionItemsFragment.java similarity index 93% rename from OsmAnd/src/net/osmand/plus/download/items/LocalItemsFragment.java rename to OsmAnd/src/net/osmand/plus/download/items/RegionItemsFragment.java index 1e78149e72..b50ac05070 100644 --- a/OsmAnd/src/net/osmand/plus/download/items/LocalItemsFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/items/RegionItemsFragment.java @@ -9,29 +9,24 @@ import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.ArrayAdapter; -import android.widget.ImageView; import android.widget.ListAdapter; import android.widget.ListView; -import android.widget.ProgressBar; import android.widget.TextView; import net.osmand.PlatformUtil; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.WorldRegion; -import net.osmand.plus.download.BaseDownloadActivity; import net.osmand.plus.download.DownloadActivity; -import net.osmand.plus.download.DownloadActivityType; -import net.osmand.plus.download.IndexItem; import org.apache.commons.logging.Log; import java.text.MessageFormat; import java.util.Locale; -public class LocalItemsFragment extends Fragment { - public static final String TAG = "LocalItemsFragment"; - private static final Log LOG = PlatformUtil.getLog(LocalItemsFragment.class); +public class RegionItemsFragment extends Fragment { + public static final String TAG = "RegionItemsFragment"; + private static final Log LOG = PlatformUtil.getLog(RegionItemsFragment.class); private static final MessageFormat formatGb = new MessageFormat("{0, number,#.##} GB", Locale.US); private ItemsListBuilder builder; @@ -95,7 +90,7 @@ public class LocalItemsFragment extends Fragment { Object obj = regionsAdapter.getItem(position); if (obj instanceof WorldRegion) { WorldRegion region = (WorldRegion) obj; - ((LocalDialogFragment) getParentFragment()) + ((RegionDialogFragment) getParentFragment()) .onRegionSelected(region); } } @@ -185,10 +180,10 @@ public class LocalItemsFragment extends Fragment { return (DownloadActivity) getActivity(); } - public static LocalItemsFragment createInstance(WorldRegion region) { + public static RegionItemsFragment createInstance(WorldRegion region) { Bundle bundle = new Bundle(); bundle.putSerializable(REGION_KEY, region); - LocalItemsFragment fragment = new LocalItemsFragment(); + RegionItemsFragment fragment = new RegionItemsFragment(); fragment.setArguments(bundle); return fragment; } diff --git a/OsmAnd/src/net/osmand/plus/download/items/WorldItemsFragment.java b/OsmAnd/src/net/osmand/plus/download/items/WorldItemsFragment.java index 9b9d94fdee..067158ed99 100644 --- a/OsmAnd/src/net/osmand/plus/download/items/WorldItemsFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/items/WorldItemsFragment.java @@ -69,8 +69,8 @@ public class WorldItemsFragment extends Fragment { FragmentTransaction fragmentTransaction = getChildFragmentManager().beginTransaction(); fragmentTransaction.addToBackStack(null); - LocalDialogFragment.createInstance(region) - .show(fragmentTransaction, LocalDialogFragment.TAG); + RegionDialogFragment.createInstance(region) + .show(fragmentTransaction, RegionDialogFragment.TAG); } });