diff --git a/OsmAnd/src/net/osmand/plus/WorldRegion.java b/OsmAnd/src/net/osmand/plus/WorldRegion.java index 048c218e84..ef567fa1b1 100644 --- a/OsmAnd/src/net/osmand/plus/WorldRegion.java +++ b/OsmAnd/src/net/osmand/plus/WorldRegion.java @@ -1,5 +1,7 @@ package net.osmand.plus; +import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; @@ -85,7 +87,7 @@ public class WorldRegion { public void initWorld() { regionId = ""; - downloadsId= WORLD; + downloadsId = WORLD; name = ""; superregion = null; } @@ -109,26 +111,10 @@ public class WorldRegion { return this; } - - private WorldRegion init(String regionId, String name) { - this.regionId = regionId; - this.downloadsId = regionId.toLowerCase() ; - this.name = name; - return this; - } - - private void addSubregion(WorldRegion subregion) { + private void addSubregion(WorldRegion subregion, WorldRegion world) { subregion.superregion = this; subregions.add(subregion); - propagateSubregionToFlattenedHierarchy(subregion); - } - - private void propagateSubregionToFlattenedHierarchy(WorldRegion subregion) { - if (superregion != null) { - superregion.propagateSubregionToFlattenedHierarchy(subregion); - } else { - flattenedSubregions.add(subregion); - } + world.flattenedSubregions.add(subregion); } public void loadWorldRegions(OsmandApplication app) { @@ -143,42 +129,42 @@ public class WorldRegion { WorldRegion africaRegion = createRegionAs(AFRICA_REGION_ID, loadedItems, osmandRegions, res.getString(R.string.index_name_africa)); - addSubregion(africaRegion); + addSubregion(africaRegion, this); regionsLookupTable.put(africaRegion.regionId, africaRegion); WorldRegion asiaRegion = createRegionAs(ASIA_REGION_ID, loadedItems, osmandRegions, res.getString(R.string.index_name_asia)); - addSubregion(asiaRegion); + addSubregion(asiaRegion, this); regionsLookupTable.put(asiaRegion.regionId, asiaRegion); WorldRegion australiaAndOceaniaRegion = createRegionAs(AUSTRALIA_AND_OCEANIA_REGION_ID, loadedItems, osmandRegions, res.getString(R.string.index_name_oceania)); - addSubregion(australiaAndOceaniaRegion); + addSubregion(australiaAndOceaniaRegion, this); regionsLookupTable.put(australiaAndOceaniaRegion.regionId, australiaAndOceaniaRegion); WorldRegion centralAmericaRegion = createRegionAs(CENTRAL_AMERICA_REGION_ID, loadedItems, osmandRegions, res.getString(R.string.index_name_central_america)); - addSubregion(centralAmericaRegion); + addSubregion(centralAmericaRegion, this); regionsLookupTable.put(centralAmericaRegion.regionId, centralAmericaRegion); WorldRegion europeRegion = createRegionAs(EUROPE_REGION_ID, loadedItems, osmandRegions, res.getString(R.string.index_name_europe)); - addSubregion(europeRegion); + addSubregion(europeRegion, this); regionsLookupTable.put(europeRegion.regionId, europeRegion); WorldRegion northAmericaRegion = createRegionAs(NORTH_AMERICA_REGION_ID, loadedItems, osmandRegions, res.getString(R.string.index_name_north_america)); - addSubregion(northAmericaRegion); + addSubregion(northAmericaRegion, this); regionsLookupTable.put(northAmericaRegion.regionId, northAmericaRegion); WorldRegion russiaRegion = createRegionAs(RUSSIA_REGION_ID, loadedItems, osmandRegions, res.getString(R.string.index_name_russia)); - addSubregion(russiaRegion); + addSubregion(russiaRegion, this); regionsLookupTable.put(russiaRegion.regionId, russiaRegion); WorldRegion southAmericaRegion = createRegionAs(SOUTH_AMERICA_REGION_ID, loadedItems, osmandRegions, res.getString(R.string.index_name_south_america)); - addSubregion(southAmericaRegion); + addSubregion(southAmericaRegion, this); regionsLookupTable.put(southAmericaRegion.regionId, southAmericaRegion); // Process all regions @@ -199,7 +185,7 @@ public class WorldRegion { } WorldRegion newRegion = new WorldRegion().init(regionId, osmandRegions, null); - parentRegion.addSubregion(newRegion); + parentRegion.addSubregion(newRegion, this); regionsLookupTable.put(newRegion.regionId, newRegion); // Remove @@ -212,6 +198,14 @@ public class WorldRegion { break; } + Comparator nameComparator = new Comparator() { + @Override + public int compare(WorldRegion w1, WorldRegion w2) { + return w1.getName().compareTo(w2.getName()); + } + }; + sortSubregions(this, nameComparator); + if (loadedItems.size() > 0) { LOG.warn("Found orphaned regions: " + loadedItems.size()); for (String regionId : loadedItems.keySet()) { @@ -220,6 +214,15 @@ public class WorldRegion { } } + private void sortSubregions(WorldRegion region, Comparator comparator) { + Collections.sort(region.subregions, comparator); + for (WorldRegion r : region.subregions) { + if (r.subregions.size() > 0) { + sortSubregions(r, comparator); + } + } + } + private static WorldRegion createRegionAs(String regionId, Map loadedItems, OsmandRegions osmandRegions, String localizedName) { WorldRegion worldRegion = new WorldRegion().init(regionId, osmandRegions, localizedName); diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadResourceGroup.java b/OsmAnd/src/net/osmand/plus/download/DownloadResourceGroup.java index 9d38a70ccd..6af9371c4c 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadResourceGroup.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadResourceGroup.java @@ -1,6 +1,7 @@ package net.osmand.plus.download; import android.annotation.SuppressLint; +import android.content.Context; import java.util.ArrayList; import java.util.Collections; @@ -53,7 +54,7 @@ public class DownloadResourceGroup { } public boolean containsIndexItem() { - return isHeader() && this != SUBREGIONS; + return isHeader() && this != SUBREGIONS && this != VOICE_GROUP; } public boolean isHeader() { @@ -203,8 +204,14 @@ public class DownloadResourceGroup { return null; } - public String getName() { - return id; + public String getName(Context ctx) { + if (region != null) { + return region.getName(); + } else if (type != null && type.resId != -1) { + return ctx.getString(type.resId); + } else { + return id; + } } public String getUniqueId() { diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadResources.java b/OsmAnd/src/net/osmand/plus/download/DownloadResources.java index 64d2ba2e54..d7dfd0bd45 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadResources.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadResources.java @@ -170,10 +170,10 @@ public class DownloadResources extends DownloadResourceGroup { this.rawResources = resources; DownloadResourceGroup voiceGroup = new DownloadResourceGroup(this, DownloadResourceGroupType.VOICE_GROUP); - DownloadResourceGroup voiceScreenRec = new DownloadResourceGroup(this, DownloadResourceGroupType.VOICE_REC); - DownloadResourceGroup voiceRec = new DownloadResourceGroup(this, DownloadResourceGroupType.VOICE_HEADER_REC); - DownloadResourceGroup voiceTTS = new DownloadResourceGroup(this, DownloadResourceGroupType.VOICE_TTS); - DownloadResourceGroup voiceScreenTTS = new DownloadResourceGroup(this, DownloadResourceGroupType.VOICE_HEADER_TTS); + DownloadResourceGroup voiceScreenRec = new DownloadResourceGroup(voiceGroup, DownloadResourceGroupType.VOICE_REC); + DownloadResourceGroup voiceScreenTTS = new DownloadResourceGroup(voiceGroup, DownloadResourceGroupType.VOICE_TTS); + DownloadResourceGroup voiceRec = new DownloadResourceGroup(voiceGroup, DownloadResourceGroupType.VOICE_HEADER_REC); + DownloadResourceGroup voiceTTS = new DownloadResourceGroup(voiceGroup, DownloadResourceGroupType.VOICE_HEADER_TTS); voiceScreenTTS.addGroup(voiceTTS); voiceScreenRec.addGroup(voiceRec); voiceGroup.addGroup(voiceScreenRec); @@ -194,6 +194,7 @@ public class DownloadResources extends DownloadResourceGroup { } else { voiceRec.addItem(ii); } + continue; } String basename = ii.getBasename().toLowerCase(); WorldRegion wg = downloadIdForRegion.get(basename); @@ -219,6 +220,7 @@ public class DownloadResources extends DownloadResourceGroup { DownloadResourceGroup parentGroup = parent.pollFirst(); List subregions = reg.getSubregions(); DownloadResourceGroup mainGrp = new DownloadResourceGroup(parentGroup, DownloadResourceGroupType.REGION, reg.getRegionId()); + mainGrp.region = reg; parentGroup.addGroup(mainGrp); DownloadResourceGroup subRegions = new DownloadResourceGroup(mainGrp, DownloadResourceGroupType.SUBREGIONS); mainGrp.addGroup(subRegions); diff --git a/OsmAnd/src/net/osmand/plus/download/IndexItem.java b/OsmAnd/src/net/osmand/plus/download/IndexItem.java index e1ed4f676c..0e6cb31b4a 100644 --- a/OsmAnd/src/net/osmand/plus/download/IndexItem.java +++ b/OsmAnd/src/net/osmand/plus/download/IndexItem.java @@ -132,16 +132,19 @@ public class IndexItem implements Comparable { public boolean isOutdated() { - FIXME; + //FIXME; + return false; } public String getLocalDate() { - FIXME; + //FIXME; + return "FIXME"; } public boolean isDownloaded() { // return listAlreadyDownloaded.containsKey(getTargetFileName()); + /* Map indexFileNames = context.getIndexFileNames(); if (indexFileNames != null && indexItem.isAlreadyDownloaded(indexFileNames)) { boolean outdated = false; @@ -155,6 +158,8 @@ public class IndexItem implements Comparable { date = updatableResource ? indexActivatedFileNames.get(sfName) : indexFileNames.get(sfName); outdated = DownloadActivity.downloadListIndexThread.checkIfItemOutdated(indexItem); } + */ + return false; // FIXME } public String getVisibleName(Context ctx, OsmandRegions osmandRegions) { diff --git a/OsmAnd/src/net/osmand/plus/download/ui/DownloadResourceGroupFragment.java b/OsmAnd/src/net/osmand/plus/download/ui/DownloadResourceGroupFragment.java index e07ce9d88f..4bdad0b991 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/DownloadResourceGroupFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/DownloadResourceGroupFragment.java @@ -74,7 +74,7 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow if (savedInstanceState != null) { groupId = savedInstanceState.getString(REGION_ID_DLG_KEY); } - if (groupId == null) { + if (groupId == null && getArguments() != null) { groupId = getArguments().getString(REGION_ID_DLG_KEY); } if (groupId == null) { @@ -112,9 +112,7 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow group = indexes.getGroupById(groupId); if (group != null) { listAdapter.update(group); - if (group.getRegion() != null) { - toolbar.setTitle(group.getRegion().getName()); - } + toolbar.setTitle(group.getName(activity)); } expandAllGroups(); } @@ -212,18 +210,14 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow getDownloadActivity().getDownloadThread().runReloadIndexFiles(); return true; case SEARCH_ID: - getDownloadActivity().showDialog(getActivity(), SearchDialogFragment.createInstance("")); + // FIXME + //getDownloadActivity().showDialog(getActivity(), SearchDialogFragment.createInstance("")); return true; default: return super.onOptionsItemSelected(item); } } - public void onRegionSelected(String regionId) { - final DownloadResourceGroupFragment regionDialogFragment = createInstance(regionId); - getDownloadActivity().showDialog(getActivity(), regionDialogFragment); - } - public static DownloadResourceGroupFragment createInstance(String regionId) { Bundle bundle = new Bundle(); bundle.putString(REGION_ID_DLG_KEY, regionId); @@ -315,12 +309,8 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow public void bindItem(DownloadResourceGroup group) { Drawable iconLeft = getIconForGroup(group); textView.setCompoundDrawablesWithIntrinsicBounds(iconLeft, null, null, null); - String name = group.getName(); - WorldRegion region = group.getRegion(); - if (region != null) { - name = region.getName(); - } - textView.setText(name); + String name = group.getName(ctx); + textView.setText(name); } } diff --git a/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java b/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java index 0d49d4ea9f..2945e6af0b 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java @@ -15,7 +15,6 @@ import net.osmand.access.AccessibleToast; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; import net.osmand.plus.Version; -import net.osmand.plus.WorldRegion; import net.osmand.plus.download.DownloadActivity; import net.osmand.plus.download.DownloadActivityType; import net.osmand.plus.download.DownloadIndexesThread; @@ -24,9 +23,6 @@ import net.osmand.plus.download.IndexItem; import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin; import net.osmand.plus.srtmplugin.SRTMPlugin; -import java.text.DateFormat; -import java.util.Map; - // FIXME public class ItemViewHolder { diff --git a/OsmAnd/src/net/osmand/plus/download/ui/SearchDialogFragment.java b/OsmAnd/src/net/osmand/plus/download/ui/SearchDialogFragment.java index 8df0570dfb..01f83740d5 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/SearchDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/SearchDialogFragment.java @@ -16,12 +16,12 @@ import net.osmand.plus.R; import net.osmand.plus.download.DownloadActivity; import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents; -public class SearchDialogFragment extends DialogFragment implements DownloadEvents { +public class SearchDialogFragment { /*extends DialogFragment implements DownloadEvents { public static final String TAG = "SearchDialogFragment"; private static final String SEARCH_TEXT_DLG_KEY = "search_text_dlg_key"; private String searchText; - SearchView search; + private SearchView search; @Override public void onCreate(Bundle savedInstanceState) { @@ -139,4 +139,5 @@ public class SearchDialogFragment extends DialogFragment implements DownloadEven fragment.setArguments(bundle); return fragment; } + */ } diff --git a/OsmAnd/src/net/osmand/plus/download/ui/SearchItemsFragment.java b/OsmAnd/src/net/osmand/plus/download/ui/SearchItemsFragment.java index 648b2dd175..6ef6e9b7c3 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/SearchItemsFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/SearchItemsFragment.java @@ -29,7 +29,7 @@ import android.widget.Filter; import android.widget.Filterable; import android.widget.ListView; -public class SearchItemsFragment extends Fragment implements DownloadEvents { +public class SearchItemsFragment { /*extends Fragment implements DownloadEvents { public static final String TAG = "SearchItemsFragment"; private SearchItemsAdapter listAdapter; @@ -332,4 +332,5 @@ public class SearchItemsFragment extends Fragment implements DownloadEvents { } } } + */ }