Merge branch 'master' of github.com:osmandapp/Osmand

This commit is contained in:
Victor Shcherb 2015-10-05 22:21:32 +03:00
commit eb2a587e5f
7 changed files with 214 additions and 204 deletions

View file

@ -282,4 +282,17 @@ public class WorldRegion implements Serializable {
return s;
}
}
public WorldRegion getRegionById(String regionId) {
if (regionId == null) {
return this;
} else {
for (WorldRegion region : flattenedSubregions) {
if (region.getRegionId().equals(regionId)) {
return region;
}
}
}
return null;
}
}

View file

@ -19,6 +19,7 @@ import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.activities.ActionBarProgressActivity;
import net.osmand.plus.base.BasicProgressAsyncTask;
import net.osmand.plus.download.items.ItemsListBuilder;
import net.osmand.plus.download.newimplementation.IndexItemCategoryWithSubcat;
import java.lang.ref.WeakReference;
@ -122,6 +123,24 @@ public class BaseDownloadActivity extends ActionBarProgressActivity {
}
public ItemsListBuilder getItemsBuilder() {
if (downloadListIndexThread.isDataPrepared()) {
return new ItemsListBuilder(getMyApplication(), null, downloadListIndexThread.getResourcesByRegions(),
downloadListIndexThread.getVoiceRecItems(), downloadListIndexThread.getVoiceTTSItems());
} else {
return null;
}
}
public ItemsListBuilder getItemsBuilder(String regionId) {
if (downloadListIndexThread.isDataPrepared()) {
return new ItemsListBuilder(getMyApplication(), regionId, downloadListIndexThread.getResourcesByRegions(),
downloadListIndexThread.getVoiceRecItems(), downloadListIndexThread.getVoiceTTSItems());
} else {
return null;
}
}
public boolean startDownload(IndexItem item) {
if (downloadListIndexThread.getCurrentRunningTask() != null && getEntriesToDownload().get(item) == null) {
downloadQueue.add(item);

View file

@ -15,13 +15,17 @@ import android.os.StatFs;
import android.view.View;
import android.widget.Toast;
import net.osmand.Collator;
import net.osmand.IndexConstants;
import net.osmand.OsmAndCollator;
import net.osmand.PlatformUtil;
import net.osmand.access.AccessibleToast;
import net.osmand.map.OsmandRegions;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings.OsmandPreference;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.WorldRegion;
import net.osmand.plus.base.BasicProgressAsyncTask;
import net.osmand.plus.download.DownloadFileHelper.DownloadFileShowWarning;
import net.osmand.plus.download.DownloadOsmandIndexesHelper.AssetIndexItem;
@ -39,13 +43,17 @@ import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
@SuppressLint("NewApi")
@ -64,6 +72,12 @@ public class DownloadIndexesThread {
private java.text.DateFormat dateFormat;
private List<IndexItem> itemsToUpdate = new ArrayList<IndexItem>();
private Map<WorldRegion, Map<String, IndexItem>> resourcesByRegions = new HashMap<>();
private List<IndexItem> voiceRecItems = new LinkedList<>();
private List<IndexItem> voiceTTSItems = new LinkedList<>();
private boolean dataPrepared;
DatabaseHelper dbHelper;
public DownloadIndexesThread(Context ctx) {
@ -141,6 +155,107 @@ public class DownloadIndexesThread {
return itemsToUpdate;
}
public boolean isDataPrepared() {
return dataPrepared;
}
public Map<WorldRegion, Map<String, IndexItem>> getResourcesByRegions() {
return resourcesByRegions;
}
public List<IndexItem> getVoiceRecItems() {
return voiceRecItems;
}
public List<IndexItem> getVoiceTTSItems() {
return voiceTTSItems;
}
private boolean prepareData(List<IndexItem> resources) {
List<IndexItem> resourcesInRepository;
if (resources != null) {
resourcesInRepository = resources;
} else {
resourcesInRepository = DownloadActivity.downloadListIndexThread.getCachedIndexFiles();
}
if (resourcesInRepository == null) {
return false;
}
resourcesByRegions.clear();
voiceRecItems.clear();
voiceTTSItems.clear();
List<WorldRegion> mergedRegions = app.getWorldRegion().getFlattenedSubregions();
mergedRegions.add(app.getWorldRegion());
boolean voiceFilesProcessed = false;
for (WorldRegion region : mergedRegions) {
String downloadsIdPrefix = region.getDownloadsIdPrefix();
Map<String, IndexItem> regionResources = new HashMap<>();
Set<DownloadActivityType> typesSet = new TreeSet<>(new Comparator<DownloadActivityType>() {
@Override
public int compare(DownloadActivityType dat1, DownloadActivityType dat2) {
return dat1.getTag().compareTo(dat2.getTag());
}
});
for (IndexItem resource : resourcesInRepository) {
if (!voiceFilesProcessed) {
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;
}
typesSet.add(resource.getType());
regionResources.put(resource.getSimplifiedFileName(), resource);
}
voiceFilesProcessed = true;
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);
}
final Collator collator = OsmAndCollator.primaryCollator();
final OsmandRegions osmandRegions = app.getRegions();
Collections.sort(voiceRecItems, new Comparator<IndexItem>() {
@Override
public int compare(IndexItem lhs, IndexItem rhs) {
return collator.compare(lhs.getVisibleName(app.getApplicationContext(), osmandRegions),
rhs.getVisibleName(app.getApplicationContext(), osmandRegions));
}
});
Collections.sort(voiceTTSItems, new Comparator<IndexItem>() {
@Override
public int compare(IndexItem lhs, IndexItem rhs) {
return collator.compare(lhs.getVisibleName(app.getApplicationContext(), osmandRegions),
rhs.getVisibleName(app.getApplicationContext(), osmandRegions));
}
});
return true;
}
public class DownloadIndexesAsyncTask extends BasicProgressAsyncTask<IndexItem, Object, String> implements DownloadFileShowWarning {
@ -408,13 +523,14 @@ public class DownloadIndexesThread {
currentRunningTask.add(this);
super.onPreExecute();
this.message = ctx.getString(R.string.downloading_list_indexes);
dataPrepared = false;
}
@Override
protected IndexFileList doInBackground(Void... params) {
IndexFileList indexFileList = DownloadOsmandIndexesHelper.getIndexesList(ctx);
if (indexFileList != null) {
ItemsListBuilder.prepareData(app, indexFileList.getIndexFiles());
prepareData(indexFileList.getIndexFiles());
}
return indexFileList;
}
@ -422,6 +538,7 @@ public class DownloadIndexesThread {
protected void onPostExecute(IndexFileList result) {
indexFiles = result;
if (indexFiles != null && uiActivity != null) {
dataPrepared = resourcesByRegions.size() > 0;
prepareFilesToUpdate();
boolean basemapExists = uiActivity.getMyApplication().getResourceManager().containsBasemap();
IndexItem basemap = indexFiles.getBasemap();

View file

@ -2,15 +2,12 @@ package net.osmand.plus.download.items;
import android.content.Context;
import net.osmand.Collator;
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.DownloadActivity;
import net.osmand.plus.download.DownloadActivityType;
import net.osmand.plus.download.IndexItem;
import net.osmand.plus.srtmplugin.SRTMPlugin;
@ -18,20 +15,19 @@ 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;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
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 Map<WorldRegion, Map<String, IndexItem>> resourcesByRegions;
private List<IndexItem> voiceRecItems;
private List<IndexItem> voiceTTSItems;
public class ResourceItem {
private String resourceId;
@ -101,15 +97,6 @@ public class ItemsListBuilder {
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 static List<IndexItem> voiceRecItems = new LinkedList<>();
private static List<IndexItem> voiceTTSItems = new LinkedList<>();
private static final Lock lock = new ReentrantLock();
private List<ResourceItem> regionMapItems;
private List<Object> allResourceItems;
private List<WorldRegion> allSubregionItems;
@ -138,18 +125,18 @@ public class ItemsListBuilder {
return list;
}
public static String getVoicePromtName(Context context, VoicePromptsType type) {
public String getVoicePromtName(VoicePromptsType type) {
switch (type) {
case RECORDED:
return context.getResources().getString(R.string.index_name_voice);
return app.getResources().getString(R.string.index_name_voice);
case TTS:
return context.getResources().getString(R.string.index_name_tts_voice);
return app.getResources().getString(R.string.index_name_tts_voice);
default:
return null;
}
}
public static List<IndexItem> getVoicePromptsItems(VoicePromptsType type) {
public List<IndexItem> getVoicePromptsItems(VoicePromptsType type) {
switch (type) {
case RECORDED:
return voiceRecItems;
@ -160,7 +147,7 @@ public class ItemsListBuilder {
}
}
public static boolean isVoicePromptsItemsEmpty(VoicePromptsType type) {
public boolean isVoicePromptsItemsEmpty(VoicePromptsType type) {
switch (type) {
case RECORDED:
return voiceRecItems.isEmpty();
@ -171,28 +158,22 @@ public class ItemsListBuilder {
}
}
public ItemsListBuilder(OsmandApplication app) {
public ItemsListBuilder(OsmandApplication app, String regionId, Map<WorldRegion, Map<String, IndexItem>> resourcesByRegions,
List<IndexItem> voiceRecItems, List<IndexItem> voiceTTSItems) {
this.app = app;
regionMapItems = new LinkedList<>();
allResourceItems = new LinkedList<Object>();
allSubregionItems = new LinkedList<>();
}
this.resourcesByRegions = resourcesByRegions;
this.voiceRecItems = voiceRecItems;
this.voiceTTSItems = voiceTTSItems;
public ItemsListBuilder(OsmandApplication app, WorldRegion region) {
this(app);
this.region = region;
regionMapItems = new LinkedList<>();
allResourceItems = new LinkedList<>();
allSubregionItems = new LinkedList<>();
region = app.getWorldRegion().getRegionById(regionId);
}
public boolean build() {
if (lock.tryLock()) {
try {
return obtainDataAndItems();
} finally {
lock.unlock();
}
} else {
return false;
}
}
private boolean obtainDataAndItems() {
@ -206,92 +187,6 @@ public class ItemsListBuilder {
return true;
}
public static boolean prepareData(final OsmandApplication app, List<IndexItem> resources) {
lock.lock();
try {
List<IndexItem> resourcesInRepository;
if (resources != null) {
resourcesInRepository = resources;
} else {
resourcesInRepository = DownloadActivity.downloadListIndexThread.getCachedIndexFiles();
}
if (resourcesInRepository == null) {
return false;
}
resourcesByRegions.clear();
searchableWorldwideRegionItems.clear();
voiceRecItems.clear();
voiceTTSItems.clear();
List<WorldRegion> mergedRegions = app.getWorldRegion().getFlattenedSubregions();
mergedRegions.add(app.getWorldRegion());
boolean voiceFilesProcessed = false;
for (WorldRegion region : mergedRegions) {
searchableWorldwideRegionItems.add(region);
String downloadsIdPrefix = region.getDownloadsIdPrefix();
Map<String, IndexItem> regionResources = new HashMap<>();
Set<DownloadActivityType> typesSet = new TreeSet<>(new Comparator<DownloadActivityType>() {
@Override
public int compare(DownloadActivityType dat1, DownloadActivityType dat2) {
return dat1.getTag().compareTo(dat2.getTag());
}
});
for (IndexItem resource : resourcesInRepository) {
if (!voiceFilesProcessed) {
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;
}
typesSet.add(resource.getType());
regionResources.put(resource.getSimplifiedFileName(), resource);
}
voiceFilesProcessed = true;
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);
}
final Collator collator = OsmAndCollator.primaryCollator();
final OsmandRegions osmandRegions = app.getRegions();
Collections.sort(voiceRecItems, new Comparator<IndexItem>() {
@Override
public int compare(IndexItem lhs, IndexItem rhs) {
return collator.compare(lhs.getVisibleName(app.getApplicationContext(), osmandRegions),
rhs.getVisibleName(app.getApplicationContext(), osmandRegions));
}
});
return true;
} finally {
lock.unlock();
}
}
private void collectSubregionsDataAndItems() {
srtmDisabled = OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) == null;
hasSrtm = false;

View file

@ -21,8 +21,8 @@ import org.apache.commons.logging.Log;
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;
private static final String REGION_ID_DLG_KEY = "world_region_dialog_key";
private String regionId;
private DownloadsUiHelper.MapDownloadListener mProgressListener;
@Override
@ -39,21 +39,12 @@ public class RegionDialogFragment extends DialogFragment {
Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.maps_in_category_fragment, container, false);
WorldRegion region = null;
if (savedInstanceState != null) {
Object regionObj = savedInstanceState.getSerializable(REGION_DLG_KEY);
if (regionObj != null) {
region = (WorldRegion)regionObj;
regionId = savedInstanceState.getString(REGION_ID_DLG_KEY);
}
if (regionId == null) {
regionId = getArguments().getString(REGION_ID_DLG_KEY);
}
if (region == null) {
Object regionObj = getArguments().getSerializable(REGION_DLG_KEY);
if (regionObj != null) {
region = (WorldRegion)regionObj;
}
}
this.region = region;
Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar);
toolbar.setNavigationIcon(getMyApplication().getIconsCache().getIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha));
@ -64,13 +55,16 @@ public class RegionDialogFragment extends DialogFragment {
}
});
if (this.region != null) {
if (regionId != null) {
Fragment fragment = getChildFragmentManager().findFragmentById(R.id.fragmentContainer);
if (fragment == null) {
getChildFragmentManager().beginTransaction().add(R.id.fragmentContainer,
RegionItemsFragment.createInstance(region)).commit();
RegionItemsFragment.createInstance(regionId)).commit();
}
WorldRegion region = getMyApplication().getWorldRegion().getRegionById(regionId);
if (region != null) {
toolbar.setTitle(region.getName());
}
toolbar.setTitle(this.region.getName());
}
DownloadsUiHelper.initFreeVersionBanner(view, getMyApplication(),
getResources());
@ -95,7 +89,6 @@ public class RegionDialogFragment extends DialogFragment {
@Override
public void onResume() {
super.onResume();
LOG.debug(region.getName() + " onResume()");
getMyActivity().setOnProgressUpdateListener(mProgressListener);
}
@ -107,7 +100,7 @@ public class RegionDialogFragment extends DialogFragment {
@Override
public void onSaveInstanceState(Bundle outState) {
outState.putSerializable(REGION_DLG_KEY, region);
outState.putString(REGION_ID_DLG_KEY, regionId);
super.onSaveInstanceState(outState);
}
@ -119,13 +112,13 @@ public class RegionDialogFragment extends DialogFragment {
return (DownloadActivity) getActivity();
}
public void onRegionSelected(WorldRegion region) {
DownloadsUiHelper.showDialog(getActivity(), createInstance(region));
public void onRegionSelected(String regionId) {
DownloadsUiHelper.showDialog(getActivity(), createInstance(regionId));
}
public static RegionDialogFragment createInstance(WorldRegion region) {
public static RegionDialogFragment createInstance(String regionId) {
Bundle bundle = new Bundle();
bundle.putSerializable(REGION_DLG_KEY, region);
bundle.putString(REGION_ID_DLG_KEY, regionId);
RegionDialogFragment fragment = new RegionDialogFragment();
fragment.setArguments(bundle);
return fragment;

View file

@ -7,7 +7,6 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ExpandableListView;
import android.widget.LinearLayout;
import android.widget.TextView;
import net.osmand.PlatformUtil;
@ -21,7 +20,6 @@ import net.osmand.plus.activities.OsmandExpandableListFragment;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin;
import net.osmand.plus.srtmplugin.SRTMPlugin;
import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
@ -38,13 +36,12 @@ public class RegionItemsFragment extends OsmandExpandableListFragment {
private static final Log LOG = PlatformUtil.getLog(RegionItemsFragment.class);
private static final MessageFormat formatGb = new MessageFormat("{0, number,<b>#.##</b>} GB", Locale.US);
private ItemsListBuilder builder;
private RegionsItemsAdapter listAdapter;
private int regionMapsGroupPos = -1;
private int additionalMapsGroupPos = -1;
private static final String REGION_KEY = "world_region_key";
private WorldRegion region;
private static final String REGION_ID_KEY = "world_region_id_key";
private String regionId;
@Override
public void onCreate(Bundle savedInstanceState) {
@ -56,41 +53,33 @@ public class RegionItemsFragment extends OsmandExpandableListFragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.download_items_fragment, container, false);
WorldRegion region = null;
if (savedInstanceState != null) {
Object regionObj = savedInstanceState.getSerializable(REGION_KEY);
if (regionObj != null) {
region = (WorldRegion) regionObj;
regionId = savedInstanceState.getString(REGION_ID_KEY);
}
if (regionId == null) {
regionId = getArguments().getString(REGION_ID_KEY);
}
if (region == null) {
Object regionObj = getArguments().getSerializable(REGION_KEY);
if (regionObj != null) {
region = (WorldRegion) regionObj;
}
}
this.region = region;
builder = new ItemsListBuilder(getMyApplication(), this.region);
ExpandableListView listView = (ExpandableListView) view.findViewById(android.R.id.list);
listAdapter = new RegionsItemsAdapter(getActivity());
listView.setAdapter(listAdapter);
setListView(listView);
if (builder.build()) {
fillRegionItemsAdapter();
if (regionId != null) {
ItemsListBuilder builder = getDownloadActivity().getItemsBuilder(regionId);
if (builder != null && builder.build()) {
fillRegionItemsAdapter(builder);
listAdapter.notifyDataSetChanged();
expandAllGroups();
}
}
return view;
}
@Override
public void onSaveInstanceState(Bundle outState) {
outState.putSerializable(REGION_KEY, region);
outState.putString(REGION_ID_KEY, regionId);
super.onSaveInstanceState(outState);
}
@ -100,7 +89,7 @@ public class RegionItemsFragment extends OsmandExpandableListFragment {
if (obj instanceof WorldRegion) {
WorldRegion region = (WorldRegion) obj;
((RegionDialogFragment) getParentFragment())
.onRegionSelected(region);
.onRegionSelected(region.getRegionId());
return true;
} else {
return false;
@ -117,17 +106,12 @@ public class RegionItemsFragment extends OsmandExpandableListFragment {
return (OsmandApplication) getActivity().getApplication();
}
private void fillRegionItemsAdapter() {
private void fillRegionItemsAdapter(ItemsListBuilder builder) {
if (listAdapter != null) {
listAdapter.clear();
int nextAvailableGroupPos = 0;
if (builder.getRegionMapItems().size() > 0) {
String sectionTitle;
if (builder.getAllResourceItems().size() > 0) {
sectionTitle = "Region maps";
} else {
sectionTitle = "";
}
String sectionTitle = "Region maps";
regionMapsGroupPos = nextAvailableGroupPos++;
listAdapter.add(sectionTitle, builder.getRegionMapItems());
}
@ -136,7 +120,7 @@ public class RegionItemsFragment extends OsmandExpandableListFragment {
if (builder.getRegionMapItems().size() > 0) {
sectionTitle = "Additional maps";
} else {
sectionTitle = "";
sectionTitle = "Regions";
}
additionalMapsGroupPos = nextAvailableGroupPos;
listAdapter.add(sectionTitle, builder.getAllResourceItems());
@ -148,9 +132,9 @@ public class RegionItemsFragment extends OsmandExpandableListFragment {
return (DownloadActivity) getActivity();
}
public static RegionItemsFragment createInstance(WorldRegion region) {
public static RegionItemsFragment createInstance(String regionId) {
Bundle bundle = new Bundle();
bundle.putSerializable(REGION_KEY, region);
bundle.putString(REGION_ID_KEY, regionId);
RegionItemsFragment fragment = new RegionItemsFragment();
fragment.setArguments(bundle);
return fragment;
@ -254,14 +238,6 @@ public class RegionItemsFragment extends OsmandExpandableListFragment {
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
View v = convertView;
String section = getGroup(groupPosition);
/*
if (section.length() == 0) {
LinearLayout emptyLL = new LinearLayout(parent.getContext());
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0);
emptyLL.setLayoutParams(params);
return emptyLL;
}
*/
if (v == null) {
LayoutInflater inflater = (LayoutInflater) getDownloadActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

View file

@ -23,7 +23,6 @@ import net.osmand.plus.WorldRegion;
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
import net.osmand.plus.activities.OsmandExpandableListFragment;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.IndexItem;
import net.osmand.plus.download.newimplementation.DownloadsUiHelper;
import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin;
import net.osmand.plus.srtmplugin.SRTMPlugin;
@ -42,7 +41,6 @@ public class WorldItemsFragment extends OsmandExpandableListFragment {
public static final int RELOAD_ID = 0;
private ItemsListBuilder builder;
private WorldItemsAdapter listAdapter;
private int worldRegionsIndex = -1;
@ -62,8 +60,6 @@ public class WorldItemsFragment extends OsmandExpandableListFragment {
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());
ExpandableListView listView = (ExpandableListView) view.findViewById(android.R.id.list);
listAdapter = new WorldItemsAdapter(getActivity());
listView.setAdapter(listAdapter);
@ -97,7 +93,7 @@ public class WorldItemsFragment extends OsmandExpandableListFragment {
return (OsmandApplication) getActivity().getApplication();
}
private void fillWorldItemsAdapter() {
private void fillWorldItemsAdapter(ItemsListBuilder builder) {
if (listAdapter != null) {
listAdapter.clear();
if (builder.getRegionMapItems().size() > 0) {
@ -109,12 +105,12 @@ public class WorldItemsFragment extends OsmandExpandableListFragment {
int unusedSubIndex = 0;
List<String> voicePromptsItems = new LinkedList<>();
if (!ItemsListBuilder.isVoicePromptsItemsEmpty(ItemsListBuilder.VoicePromptsType.RECORDED)) {
voicePromptsItems.add(ItemsListBuilder.getVoicePromtName(getMyApplication(), ItemsListBuilder.VoicePromptsType.RECORDED));
if (!builder.isVoicePromptsItemsEmpty(ItemsListBuilder.VoicePromptsType.RECORDED)) {
voicePromptsItems.add(builder.getVoicePromtName(ItemsListBuilder.VoicePromptsType.RECORDED));
voicePromptsItemsRecordedSubIndex = unusedSubIndex++;
}
if (!ItemsListBuilder.isVoicePromptsItemsEmpty(ItemsListBuilder.VoicePromptsType.TTS)) {
voicePromptsItems.add(ItemsListBuilder.getVoicePromtName(getMyApplication(), ItemsListBuilder.VoicePromptsType.TTS));
if (!builder.isVoicePromptsItemsEmpty(ItemsListBuilder.VoicePromptsType.TTS)) {
voicePromptsItems.add(builder.getVoicePromtName(ItemsListBuilder.VoicePromptsType.TTS));
voicePromptsItemsTTSSubIndex = unusedSubIndex;
}
if (!voicePromptsItems.isEmpty()) {
@ -130,7 +126,7 @@ public class WorldItemsFragment extends OsmandExpandableListFragment {
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
if (groupPosition == worldRegionsIndex) {
WorldRegion region = (WorldRegion)listAdapter.getChild(groupPosition, childPosition);
DownloadsUiHelper.showDialog(getActivity(), RegionDialogFragment.createInstance(region));
DownloadsUiHelper.showDialog(getActivity(), RegionDialogFragment.createInstance(region.getRegionId()));
return true;
} else if (groupPosition == voicePromptsIndex) {
//
@ -160,8 +156,9 @@ public class WorldItemsFragment extends OsmandExpandableListFragment {
}
public void onCategorizationFinished() {
if (builder.build()) {
fillWorldItemsAdapter();
ItemsListBuilder builder = getDownloadActivity().getItemsBuilder();
if (builder != null && builder.build()) {
fillWorldItemsAdapter(builder);
listAdapter.notifyDataSetChanged();
expandAllGroups();
}