New maps download tree in progress
This commit is contained in:
parent
e6d8f75583
commit
4a34765959
7 changed files with 739 additions and 9 deletions
71
OsmAnd/res/layout/download_index_fragment.xml
Normal file
71
OsmAnd/res/layout/download_index_fragment.xml
Normal file
|
@ -0,0 +1,71 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:text="World Regions"
|
||||
android:textSize="@dimen/default_list_text_size"/>
|
||||
|
||||
<ListView
|
||||
android:id="@+id/list_world_regions"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:groupIndicator="@android:color/transparent"
|
||||
android:isScrollContainer="false"
|
||||
android:scrollbars="none"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:text="World Map"
|
||||
android:textSize="@dimen/default_list_text_size"/>
|
||||
|
||||
<ListView
|
||||
android:id="@+id/list_world_map"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:groupIndicator="@android:color/transparent"
|
||||
android:isScrollContainer="false"
|
||||
android:scrollbars="none"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:text="Voice Promts"
|
||||
android:textSize="@dimen/default_list_text_size"/>
|
||||
|
||||
<ListView
|
||||
android:id="@+id/list_voice_promts"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:groupIndicator="@android:color/transparent"
|
||||
android:isScrollContainer="false"
|
||||
android:scrollbars="none"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
||||
|
||||
</LinearLayout>
|
|
@ -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<DownloadActivityType> resourceTypes;
|
||||
private List<DownloadActivityType> resourceTypes;
|
||||
|
||||
// Hierarchy
|
||||
private WorldRegion superregion;
|
||||
private LinkedList<WorldRegion> subregions;
|
||||
private LinkedList<WorldRegion> flattenedSubregions;
|
||||
private List<WorldRegion> subregions;
|
||||
private List<WorldRegion> flattenedSubregions;
|
||||
|
||||
private boolean purchased;
|
||||
private boolean isInPurchasedArea;
|
||||
|
@ -64,19 +65,23 @@ public class WorldRegion {
|
|||
return bboxBottomRight;
|
||||
}
|
||||
|
||||
public LinkedList<DownloadActivityType> getResourceTypes() {
|
||||
public List<DownloadActivityType> getResourceTypes() {
|
||||
return resourceTypes;
|
||||
}
|
||||
|
||||
public void setResourceTypes(List<DownloadActivityType> resourceTypes) {
|
||||
this.resourceTypes = resourceTypes;
|
||||
}
|
||||
|
||||
public WorldRegion getSuperregion() {
|
||||
return superregion;
|
||||
}
|
||||
|
||||
public LinkedList<WorldRegion> getSubregions() {
|
||||
public List<WorldRegion> getSubregions() {
|
||||
return subregions;
|
||||
}
|
||||
|
||||
public LinkedList<WorldRegion> getFlattenedSubregions() {
|
||||
public List<WorldRegion> getFlattenedSubregions() {
|
||||
return flattenedSubregions;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<Fragment> ref : fragSet) {
|
||||
Fragment f = ref.get();
|
||||
if (f instanceof DownloadItemsFragment) {
|
||||
if (f.isAdded()) {
|
||||
((DownloadItemsFragment) f).onCategorizationFinished();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void downloadListUpdated() {
|
||||
for (WeakReference<Fragment> ref : fragSet) {
|
||||
Fragment f = ref.get();
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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,<b>#.##</b>} 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<WorldRegion> {
|
||||
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<ItemsListBuilder.ResourceItem> {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
377
OsmAnd/src/net/osmand/plus/download/items/ItemsListBuilder.java
Normal file
377
OsmAnd/src/net/osmand/plus/download/items/ItemsListBuilder.java
Normal file
|
@ -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<WorldRegion, Map<String, IndexItem>> resourcesByRegions =
|
||||
new HashMap<>();
|
||||
private static List<WorldRegion> searchableWorldwideRegionItems = new LinkedList<>();
|
||||
|
||||
private List<ResourceItem> regionMapItems;
|
||||
private List allResourceItems;
|
||||
private List<WorldRegion> allSubregionItems;
|
||||
|
||||
private OsmandApplication app;
|
||||
private WorldRegion region;
|
||||
|
||||
private boolean invalidated;
|
||||
private boolean srtmDisabled;
|
||||
private boolean hasSrtm;
|
||||
|
||||
public List<ResourceItem> getRegionMapItems() {
|
||||
return regionMapItems;
|
||||
}
|
||||
|
||||
public List getAllResourceItems() {
|
||||
return allResourceItems;
|
||||
}
|
||||
|
||||
public List<WorldRegion> getRegionsFromAllItems() {
|
||||
List<WorldRegion> 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<IndexItem> resourcesInRepository = DownloadActivity.downloadListIndexThread.getCachedIndexFiles();
|
||||
if (resourcesInRepository == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean doInit = resourcesByRegions.isEmpty();
|
||||
boolean initSearchableRegions = searchableWorldwideRegionItems.isEmpty() || doInit;
|
||||
|
||||
if (initSearchableRegions) {
|
||||
searchableWorldwideRegionItems.clear();
|
||||
}
|
||||
|
||||
List<WorldRegion> mergedRegions = app.getWorldRegion().getFlattenedSubregions();
|
||||
mergedRegions.add(app.getWorldRegion());
|
||||
for(WorldRegion region : mergedRegions)
|
||||
{
|
||||
if (initSearchableRegions) {
|
||||
searchableWorldwideRegionItems.add(region);
|
||||
}
|
||||
|
||||
String downloadsIdPrefix = region.getDownloadsIdPrefix().toLowerCase();
|
||||
|
||||
Map<String, IndexItem> regionResources = new HashMap<>();
|
||||
|
||||
if (!doInit)
|
||||
{
|
||||
regionResources.putAll(resourcesByRegions.get(region));
|
||||
}
|
||||
|
||||
if (doInit)
|
||||
{
|
||||
List<DownloadActivityType> 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<DownloadActivityType>() {
|
||||
@Override
|
||||
public int compare(DownloadActivityType dat1, DownloadActivityType dat2) {
|
||||
return dat1.getTag().compareTo(dat2.getTag());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(typesArray, new Comparator<DownloadActivityType>() {
|
||||
@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<String, IndexItem> regionResources = resourcesByRegions.get(region);
|
||||
|
||||
List<ResourceItem> 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;
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue