This commit is contained in:
Victor Shcherb 2015-10-19 19:50:40 +02:00
commit b774830e30
8 changed files with 65 additions and 60 deletions

View file

@ -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;
@ -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<WorldRegion> nameComparator = new Comparator<WorldRegion>() {
@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<WorldRegion> 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<String, String> loadedItems,
OsmandRegions osmandRegions, String localizedName) {
WorldRegion worldRegion = new WorldRegion().init(regionId, osmandRegions, localizedName);

View file

@ -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,9 +204,15 @@ public class DownloadResourceGroup {
return null;
}
public String getName() {
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() {
if (parentGroup == null) {

View file

@ -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<WorldRegion> 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);

View file

@ -132,16 +132,19 @@ public class IndexItem implements Comparable<IndexItem> {
public boolean isOutdated() {
FIXME;
//FIXME;
return false;
}
public String getLocalDate() {
FIXME;
//FIXME;
return "FIXME";
}
public boolean isDownloaded() {
// return listAlreadyDownloaded.containsKey(getTargetFileName());
/*
Map<String,String> indexFileNames = context.getIndexFileNames();
if (indexFileNames != null && indexItem.isAlreadyDownloaded(indexFileNames)) {
boolean outdated = false;
@ -155,6 +158,8 @@ public class IndexItem implements Comparable<IndexItem> {
date = updatableResource ? indexActivatedFileNames.get(sfName) : indexFileNames.get(sfName);
outdated = DownloadActivity.downloadListIndexThread.checkIfItemOutdated(indexItem);
}
*/
return false; // FIXME
}
public String getVisibleName(Context ctx, OsmandRegions osmandRegions) {

View file

@ -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,11 +309,7 @@ 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();
}
String name = group.getName(ctx);
textView.setText(name);
}
}

View file

@ -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 {

View file

@ -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;
}
*/
}

View file

@ -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 {
}
}
}
*/
}