diff --git a/OsmAnd/res/layout/download_index_fragment.xml b/OsmAnd/res/layout/download_index_fragment.xml new file mode 100644 index 0000000000..673114158f --- /dev/null +++ b/OsmAnd/res/layout/download_index_fragment.xml @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/WorldRegion.java b/OsmAnd/src/net/osmand/plus/WorldRegion.java index 5eeceb5077..8e204ab095 100644 --- a/OsmAnd/src/net/osmand/plus/WorldRegion.java +++ b/OsmAnd/src/net/osmand/plus/WorldRegion.java @@ -10,6 +10,7 @@ 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; @@ -34,12 +35,12 @@ public class WorldRegion { private LatLon bboxTopLeft; private LatLon bboxBottomRight; - private LinkedList resourceTypes; + private List resourceTypes; // Hierarchy private WorldRegion superregion; - private LinkedList subregions; - private LinkedList flattenedSubregions; + private List subregions; + private List flattenedSubregions; private boolean purchased; private boolean isInPurchasedArea; @@ -64,19 +65,23 @@ public class WorldRegion { return bboxBottomRight; } - public LinkedList getResourceTypes() { + public List getResourceTypes() { return resourceTypes; } + public void setResourceTypes(List resourceTypes) { + this.resourceTypes = resourceTypes; + } + public WorldRegion getSuperregion() { return superregion; } - public LinkedList getSubregions() { + public List getSubregions() { return subregions; } - public LinkedList getFlattenedSubregions() { + public List getFlattenedSubregions() { return flattenedSubregions; } diff --git a/OsmAnd/src/net/osmand/plus/download/BaseDownloadActivity.java b/OsmAnd/src/net/osmand/plus/download/BaseDownloadActivity.java index 10339c58c7..07621481b5 100644 --- a/OsmAnd/src/net/osmand/plus/download/BaseDownloadActivity.java +++ b/OsmAnd/src/net/osmand/plus/download/BaseDownloadActivity.java @@ -119,6 +119,10 @@ public class BaseDownloadActivity extends ActionBarProgressActivity { } + public void onCategorizationFinished() { + + } + public boolean startDownload(IndexItem item) { if (downloadListIndexThread.getCurrentRunningTask() != null && getEntriesToDownload().get(item) == null) { downloadQueue.add(item); diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java b/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java index b1f6285b32..38458d5214 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java @@ -32,6 +32,7 @@ import net.osmand.plus.activities.OsmandBaseExpandableListAdapter; import net.osmand.plus.activities.OsmandExpandableListFragment; import net.osmand.plus.activities.TabActivity; import net.osmand.plus.base.BasicProgressAsyncTask; +import net.osmand.plus.download.items.DownloadItemsFragment; import net.osmand.plus.download.newimplementation.IndexItemCategoryWithSubcat; import net.osmand.plus.download.newimplementation.NewLocalIndexesFragment; import net.osmand.plus.srtmplugin.SRTMPlugin; @@ -117,8 +118,10 @@ public class DownloadActivity extends BaseDownloadActivity { mTabs.add(new TabActivity.TabItem(R.string.download_tab_updates, getString(R.string.download_tab_updates), UpdatesIndexFragment.class)); +// mTabs.add(new TabActivity.TabItem(R.string.download_tab_local, +// getString(R.string.download_tab_local), NewLocalIndexesFragment.class)); mTabs.add(new TabActivity.TabItem(R.string.download_tab_local, - getString(R.string.download_tab_local), NewLocalIndexesFragment.class)); + getString(R.string.download_tab_local), DownloadItemsFragment.class)); viewPager.setAdapter(new TabActivity.OsmandFragmentPagerAdapter(getSupportFragmentManager(), mTabs)); mSlidingTabLayout.setViewPager(viewPager); @@ -324,6 +327,18 @@ public class DownloadActivity extends BaseDownloadActivity { } } + @Override + public void onCategorizationFinished() { + for (WeakReference ref : fragSet) { + Fragment f = ref.get(); + if (f instanceof DownloadItemsFragment) { + if (f.isAdded()) { + ((DownloadItemsFragment) f).onCategorizationFinished(); + } + } + } + } + public void downloadListUpdated() { for (WeakReference ref : fragSet) { Fragment f = ref.get(); diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java index b9bf648950..8eb4f09fc4 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java @@ -25,6 +25,7 @@ import net.osmand.plus.Version; import net.osmand.plus.base.BasicProgressAsyncTask; import net.osmand.plus.download.DownloadFileHelper.DownloadFileShowWarning; import net.osmand.plus.download.DownloadOsmandIndexesHelper.AssetIndexItem; +import net.osmand.plus.download.items.ItemsListBuilder; import net.osmand.plus.download.newimplementation.IndexItemCategoryWithSubcat; import net.osmand.plus.helpers.DatabaseHelper; import net.osmand.plus.resources.ResourceManager; @@ -411,11 +412,17 @@ public class DownloadIndexesThread { @Override protected IndexFileList doInBackground(Void... params) { - return DownloadOsmandIndexesHelper.getIndexesList(ctx); + IndexFileList indexFileList = DownloadOsmandIndexesHelper.getIndexesList(ctx); + indexFiles = indexFileList; + if (indexFileList != null) { + ItemsListBuilder builder = new ItemsListBuilder(app, app.getWorldRegion()); + builder.invalidate(); + builder.build(); + } + return indexFileList; } protected void onPostExecute(IndexFileList result) { - indexFiles = result; if (indexFiles != null && uiActivity != null) { prepareFilesToUpdate(); boolean basemapExists = uiActivity.getMyApplication().getResourceManager().containsBasemap(); @@ -445,6 +452,7 @@ public class DownloadIndexesThread { uiActivity.updateProgress(false); runCategorization(uiActivity.getDownloadType()); runCategorization(); // for new implementation + uiActivity.onCategorizationFinished(); } } diff --git a/OsmAnd/src/net/osmand/plus/download/items/DownloadItemsFragment.java b/OsmAnd/src/net/osmand/plus/download/items/DownloadItemsFragment.java new file mode 100644 index 0000000000..18734af9b2 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/download/items/DownloadItemsFragment.java @@ -0,0 +1,250 @@ +package net.osmand.plus.download.items; + +import android.content.Context; +import android.graphics.drawable.Drawable; +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.support.v4.view.MenuItemCompat; +import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.ListAdapter; +import android.widget.ListView; +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.DownloadActivity; + +import org.apache.commons.logging.Log; + +import java.text.MessageFormat; +import java.util.Locale; + +public class DownloadItemsFragment extends Fragment { + private static final Log LOG = PlatformUtil.getLog(DownloadItemsFragment.class); + private static final MessageFormat formatGb = new MessageFormat("{0, number,#.##} GB", Locale.US); + + public static final int RELOAD_ID = 0; + + private ItemsListBuilder builder; + private WorldRegionsAdapter worldRegionsAdapter; + private WorldMapAdapter worldMapAdapter; + private VoicePromtsAdapter voicePromtsAdapter; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setHasOptionsMenu(true); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.download_index_fragment, container, false); + + builder = new ItemsListBuilder(getMyApplication(), getMyApplication().getWorldRegion()); + boolean hasBuilt = builder.build(); + + ListView worldRegionsListView = (ListView) view.findViewById(R.id.list_world_regions); + worldRegionsAdapter = new WorldRegionsAdapter(getActivity(), getMyApplication()); + worldRegionsListView.setAdapter(worldRegionsAdapter); + if (hasBuilt) { + fillWorldRegionsAdapter(); + } + + ListView worldMapListView = (ListView) view.findViewById(R.id.list_world_map); + worldMapAdapter = new WorldMapAdapter(getActivity(), getMyApplication()); + worldMapListView.setAdapter(worldMapAdapter); + if (hasBuilt) { + fillWorldMapAdapter(); + } + + ListView voicePromtsListView = (ListView) view.findViewById(R.id.list_voice_promts); + voicePromtsAdapter = new VoicePromtsAdapter(getActivity(), getMyApplication()); + voicePromtsListView.setAdapter(voicePromtsAdapter); + if (hasBuilt) { + fillVoicePromtsAdapter(); + } + + return view; + } + + public static void setListViewHeightBasedOnChildren(ListView listView) { + ListAdapter listAdapter = listView.getAdapter(); + if (listAdapter == null) { + // pre-condition + return; + } + + int totalHeight = 0; + for (int i = 0; i < listAdapter.getCount(); i++) { + View listItem = listAdapter.getView(i, null, listView); + listItem.measure(0, 0); + totalHeight += listItem.getMeasuredHeight(); + } + + ViewGroup.LayoutParams params = listView.getLayoutParams(); + params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1)); + listView.setLayoutParams(params); + listView.requestLayout(); + } + + public OsmandApplication getMyApplication() { + return (OsmandApplication)getActivity().getApplication(); + } + + private void fillWorldRegionsAdapter() { + if (worldRegionsAdapter != null) { + worldRegionsAdapter.clear(); + worldRegionsAdapter.addAll(builder.getRegionsFromAllItems()); + setListViewHeightBasedOnChildren((ListView) getView().findViewById(R.id.list_world_regions)); + } + } + + private void fillWorldMapAdapter() { + if (worldMapAdapter != null) { + worldMapAdapter.clear(); + worldMapAdapter.addAll(builder.getRegionMapItems()); + setListViewHeightBasedOnChildren((ListView) getView().findViewById(R.id.list_world_map)); + } + } + + private void fillVoicePromtsAdapter() { + if (voicePromtsAdapter != null) { + voicePromtsAdapter.clear(); + //voicePromtsAdapter.addAll(cats); + } + } + + @Override + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + MenuItem item = menu.add(0, RELOAD_ID, 0, R.string.shared_string_refresh); + item.setIcon(R.drawable.ic_action_refresh_dark); + MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + if (item.getItemId() == RELOAD_ID) { + // re-create the thread + DownloadActivity.downloadListIndexThread.runReloadIndexFiles(); + return true; + } + return super.onOptionsItemSelected(item); + } + + private DownloadActivity getDownloadActivity() { + return (DownloadActivity) getActivity(); + } + + public void onCategorizationFinished() { + if (builder.build()) { + fillWorldRegionsAdapter(); + fillWorldMapAdapter(); + fillVoicePromtsAdapter(); + } + } + + private static class WorldRegionsAdapter extends ArrayAdapter { + private final OsmandApplication osmandApplication; + + public WorldRegionsAdapter(Context context, OsmandApplication osmandApplication) { + super(context, R.layout.simple_list_menu_item); + this.osmandApplication = osmandApplication; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + ViewHolder viewHolder; + if (convertView == null) { + convertView = LayoutInflater.from(parent.getContext()) + .inflate(R.layout.simple_list_menu_item, parent, false); + viewHolder = new ViewHolder(); + viewHolder.textView = (TextView) convertView.findViewById(R.id.title); + convertView.setTag(viewHolder); + } else { + viewHolder = (ViewHolder) convertView.getTag(); + } + Drawable iconLeft = osmandApplication.getIconsCache() + .getContentIcon(R.drawable.ic_world_globe_dark); + viewHolder.textView.setCompoundDrawablesWithIntrinsicBounds(iconLeft, null, null, null); + viewHolder.textView.setText(getItem(position).getName()); + return convertView; + } + + private static class ViewHolder { + TextView textView; + } + } + + private static class WorldMapAdapter extends ArrayAdapter { + private final OsmandApplication osmandApplication; + + public WorldMapAdapter(Context context, OsmandApplication osmandApplication) { + super(context, R.layout.simple_list_menu_item); + this.osmandApplication = osmandApplication; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + ViewHolder viewHolder; + if (convertView == null) { + convertView = LayoutInflater.from(parent.getContext()) + .inflate(R.layout.simple_list_menu_item, parent, false); + viewHolder = new ViewHolder(); + viewHolder.textView = (TextView) convertView.findViewById(R.id.title); + convertView.setTag(viewHolder); + } else { + viewHolder = (ViewHolder) convertView.getTag(); + } + Drawable iconLeft = osmandApplication.getIconsCache() + .getContentIcon(R.drawable.ic_world_globe_dark); + viewHolder.textView.setCompoundDrawablesWithIntrinsicBounds(iconLeft, null, null, null); + viewHolder.textView.setText(getItem(position).getTitle()); + return convertView; + } + + private static class ViewHolder { + TextView textView; + } + } + + private static class VoicePromtsAdapter extends ArrayAdapter { + private final OsmandApplication osmandApplication; + + public VoicePromtsAdapter(Context context, OsmandApplication osmandApplication) { + super(context, R.layout.simple_list_menu_item); + this.osmandApplication = osmandApplication; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + ViewHolder viewHolder; + if (convertView == null) { + convertView = LayoutInflater.from(parent.getContext()) + .inflate(R.layout.simple_list_menu_item, parent, false); + viewHolder = new ViewHolder(); + viewHolder.textView = (TextView) convertView.findViewById(R.id.title); + convertView.setTag(viewHolder); + } else { + viewHolder = (ViewHolder) convertView.getTag(); + } + Drawable iconLeft = osmandApplication.getIconsCache() + .getContentIcon(R.drawable.ic_world_globe_dark); + viewHolder.textView.setCompoundDrawablesWithIntrinsicBounds(iconLeft, null, null, null); + viewHolder.textView.setText(getItem(position).toString()); + return convertView; + } + + private static class ViewHolder { + TextView textView; + } + } + +} diff --git a/OsmAnd/src/net/osmand/plus/download/items/ItemsListBuilder.java b/OsmAnd/src/net/osmand/plus/download/items/ItemsListBuilder.java new file mode 100644 index 0000000000..a1c653853e --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/download/items/ItemsListBuilder.java @@ -0,0 +1,377 @@ +package net.osmand.plus.download.items; + +import android.content.Context; + +import net.osmand.PlatformUtil; +import net.osmand.map.OsmandRegions; +import net.osmand.plus.OsmandApplication; +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.util.Algorithms; + +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +public class ItemsListBuilder { + + public class ResourceItem { + + private String resourceId; + private String title; + private long contentSize; + private long containerSize; + private boolean disabled; + + private IndexItem indexItem; + private WorldRegion worldRegion; + + public IndexItem getIndexItem() { + return indexItem; + } + + public WorldRegion getWorldRegion() { + return worldRegion; + } + + public String getResourceId() { + return resourceId; + } + + public void setResourceId(String resourceId) { + this.resourceId = resourceId; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public long getContentSize() { + return contentSize; + } + + public void setContentSize(long contentSize) { + this.contentSize = contentSize; + } + + public long getContainerSize() { + return containerSize; + } + + public void setContainerSize(long containerSize) { + this.containerSize = containerSize; + } + + public boolean isDisabled() { + return disabled; + } + + public void setDisabled(boolean disabled) { + this.disabled = disabled; + } + + public ResourceItem(IndexItem indexItem, WorldRegion worldRegion) { + this.indexItem = indexItem; + this.worldRegion = worldRegion; + } + } + + class ResourceItemComparator implements Comparator { + @Override + public int compare(Object obj1, Object obj2) { + String str1; + String str2; + + if (obj1 instanceof WorldRegion) { + str1 = ((WorldRegion)obj1).getName(); + } else { + ResourceItem item = (ResourceItem)obj1; + str1 = item.title + item.getIndexItem().getType().getTag(); + } + + if (obj2 instanceof WorldRegion) { + str2 = ((WorldRegion)obj2).getName(); + } else { + ResourceItem item = (ResourceItem)obj2; + str2 = item.title + item.getIndexItem().getType().getTag(); + } + + return str1.compareTo(str2); + } + } + + private static final org.apache.commons.logging.Log LOG = PlatformUtil.getLog(ItemsListBuilder.class); + + private static Map> resourcesByRegions = + new HashMap<>(); + private static List searchableWorldwideRegionItems = new LinkedList<>(); + + private List regionMapItems; + private List allResourceItems; + private List allSubregionItems; + + private OsmandApplication app; + private WorldRegion region; + + private boolean invalidated; + private boolean srtmDisabled; + private boolean hasSrtm; + + 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 ItemsListBuilder(OsmandApplication app) { + this.app = app; + regionMapItems = new LinkedList(); + allResourceItems = new LinkedList(); + allSubregionItems = new LinkedList<>(); + } + + public ItemsListBuilder(OsmandApplication app, WorldRegion region) { + this(app); + this.region = region; + } + + public boolean build() { + return obtainDataAndItems(); + } + + private boolean obtainDataAndItems() { + if (invalidated) { + resourcesByRegions.clear(); + } + + if (resourcesByRegions.isEmpty()) { + if (!prepareData()) { + return false; + } + } + + collectSubregionsDataAndItems(); + collectResourcesDataAndItems(); + + LOG.warn("getRegionMapItems"); + for (ResourceItem resourceItem : getRegionMapItems()) { + LOG.warn("resId=" + resourceItem.getIndexItem().getFileName() + " title=" + resourceItem.getTitle()); + } + + LOG.warn("getAllResourceItems"); + for (Object obj : getAllResourceItems()) { + if (obj instanceof WorldRegion) { + WorldRegion item = (WorldRegion)obj; + LOG.warn("W resId=" + item.getRegionId() + " title=" + item.getName()); + } else if (obj instanceof ResourceItem) { + ResourceItem resourceItem = (ResourceItem)obj; + LOG.warn("R resId=" + resourceItem.getIndexItem().getFileName() + " title=" + resourceItem.getTitle()); + } + } + + invalidated = false; + + return true; + } + + public void invalidate() { + invalidated = true; + } + + private boolean prepareData() { + List resourcesInRepository = DownloadActivity.downloadListIndexThread.getCachedIndexFiles(); + if (resourcesInRepository == null) { + return false; + } + + boolean doInit = resourcesByRegions.isEmpty(); + boolean initSearchableRegions = searchableWorldwideRegionItems.isEmpty() || doInit; + + if (initSearchableRegions) { + searchableWorldwideRegionItems.clear(); + } + + List mergedRegions = app.getWorldRegion().getFlattenedSubregions(); + mergedRegions.add(app.getWorldRegion()); + for(WorldRegion region : mergedRegions) + { + if (initSearchableRegions) { + searchableWorldwideRegionItems.add(region); + } + + String downloadsIdPrefix = region.getDownloadsIdPrefix().toLowerCase(); + + Map regionResources = new HashMap<>(); + + if (!doInit) + { + regionResources.putAll(resourcesByRegions.get(region)); + } + + if (doInit) + { + List typesArray = new LinkedList<>(); + boolean hasSrtm = false; + for (IndexItem resource : resourcesInRepository) + { + if (!resource.getFileName().startsWith(downloadsIdPrefix)) + continue; + + if (resource.getType() == DownloadActivityType.SRTM_COUNTRY_FILE) { + hasSrtm = true; + } + + typesArray.add(resource.getType()); + + regionResources.put(resource.getFileName(), 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()); + } + }); + } + } + + Collections.sort(typesArray, new Comparator() { + @Override + public int compare(DownloadActivityType dat1, DownloadActivityType dat2) { + return dat1.getTag().compareTo(dat2.getTag()); + } + }); + region.setResourceTypes(typesArray); + } + + resourcesByRegions.put(region, regionResources); + } + return true; + } + + private void collectSubregionsDataAndItems() { + srtmDisabled = false; //todo: check if srtm plugin disabled + hasSrtm = 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 = resourcesByRegions.get(region); + + 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); + if (Algorithms.isEmpty(name)) { + continue; + } + + ResourceItem resItem = new ResourceItem(indexItem, region); + resItem.setResourceId(indexItem.getFileName()); + resItem.setTitle(name); + resItem.setContentSize(indexItem.getContentSize()); + resItem.setContainerSize(indexItem.getSize()); + + if (region != this.region && srtmDisabled) + { + if (hasSrtm && indexItem.getType() == DownloadActivityType.SRTM_COUNTRY_FILE) + continue; + + if (indexItem.getType() == DownloadActivityType.SRTM_COUNTRY_FILE) + { + resItem.setTitle("srtm_disabled"); // todo: constant + resItem.setContentSize(0); + resItem.setContainerSize(0); + } + + if (!hasSrtm && indexItem.getType() == DownloadActivityType.SRTM_COUNTRY_FILE) + hasSrtm = 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()); + + /* + * todo: remove seamarks if plugin is off + if (![[OAIAPHelper sharedInstance] productPurchased:kInAppId_Addon_Nautical]) { + for (ResourceItem *item in _regionMapItems) + if (item.resourceId.compare(QString(kWorldSeamarksKey)) == 0) { + [_regionMapItems removeObject:item]; + break; + } + } + */ + } +}