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; package net.osmand.plus;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
@ -85,7 +87,7 @@ public class WorldRegion {
public void initWorld() { public void initWorld() {
regionId = ""; regionId = "";
downloadsId= WORLD; downloadsId = WORLD;
name = ""; name = "";
superregion = null; superregion = null;
} }
@ -109,26 +111,10 @@ public class WorldRegion {
return this; return this;
} }
private void addSubregion(WorldRegion subregion, WorldRegion world) {
private WorldRegion init(String regionId, String name) {
this.regionId = regionId;
this.downloadsId = regionId.toLowerCase() ;
this.name = name;
return this;
}
private void addSubregion(WorldRegion subregion) {
subregion.superregion = this; subregion.superregion = this;
subregions.add(subregion); subregions.add(subregion);
propagateSubregionToFlattenedHierarchy(subregion); world.flattenedSubregions.add(subregion);
}
private void propagateSubregionToFlattenedHierarchy(WorldRegion subregion) {
if (superregion != null) {
superregion.propagateSubregionToFlattenedHierarchy(subregion);
} else {
flattenedSubregions.add(subregion);
}
} }
public void loadWorldRegions(OsmandApplication app) { public void loadWorldRegions(OsmandApplication app) {
@ -143,42 +129,42 @@ public class WorldRegion {
WorldRegion africaRegion = createRegionAs(AFRICA_REGION_ID, WorldRegion africaRegion = createRegionAs(AFRICA_REGION_ID,
loadedItems, osmandRegions, res.getString(R.string.index_name_africa)); loadedItems, osmandRegions, res.getString(R.string.index_name_africa));
addSubregion(africaRegion); addSubregion(africaRegion, this);
regionsLookupTable.put(africaRegion.regionId, africaRegion); regionsLookupTable.put(africaRegion.regionId, africaRegion);
WorldRegion asiaRegion = createRegionAs(ASIA_REGION_ID, WorldRegion asiaRegion = createRegionAs(ASIA_REGION_ID,
loadedItems, osmandRegions, res.getString(R.string.index_name_asia)); loadedItems, osmandRegions, res.getString(R.string.index_name_asia));
addSubregion(asiaRegion); addSubregion(asiaRegion, this);
regionsLookupTable.put(asiaRegion.regionId, asiaRegion); regionsLookupTable.put(asiaRegion.regionId, asiaRegion);
WorldRegion australiaAndOceaniaRegion = createRegionAs(AUSTRALIA_AND_OCEANIA_REGION_ID, WorldRegion australiaAndOceaniaRegion = createRegionAs(AUSTRALIA_AND_OCEANIA_REGION_ID,
loadedItems, osmandRegions, res.getString(R.string.index_name_oceania)); loadedItems, osmandRegions, res.getString(R.string.index_name_oceania));
addSubregion(australiaAndOceaniaRegion); addSubregion(australiaAndOceaniaRegion, this);
regionsLookupTable.put(australiaAndOceaniaRegion.regionId, australiaAndOceaniaRegion); regionsLookupTable.put(australiaAndOceaniaRegion.regionId, australiaAndOceaniaRegion);
WorldRegion centralAmericaRegion = createRegionAs(CENTRAL_AMERICA_REGION_ID, WorldRegion centralAmericaRegion = createRegionAs(CENTRAL_AMERICA_REGION_ID,
loadedItems, osmandRegions, res.getString(R.string.index_name_central_america)); loadedItems, osmandRegions, res.getString(R.string.index_name_central_america));
addSubregion(centralAmericaRegion); addSubregion(centralAmericaRegion, this);
regionsLookupTable.put(centralAmericaRegion.regionId, centralAmericaRegion); regionsLookupTable.put(centralAmericaRegion.regionId, centralAmericaRegion);
WorldRegion europeRegion = createRegionAs(EUROPE_REGION_ID, WorldRegion europeRegion = createRegionAs(EUROPE_REGION_ID,
loadedItems, osmandRegions, res.getString(R.string.index_name_europe)); loadedItems, osmandRegions, res.getString(R.string.index_name_europe));
addSubregion(europeRegion); addSubregion(europeRegion, this);
regionsLookupTable.put(europeRegion.regionId, europeRegion); regionsLookupTable.put(europeRegion.regionId, europeRegion);
WorldRegion northAmericaRegion = createRegionAs(NORTH_AMERICA_REGION_ID, WorldRegion northAmericaRegion = createRegionAs(NORTH_AMERICA_REGION_ID,
loadedItems, osmandRegions, res.getString(R.string.index_name_north_america)); loadedItems, osmandRegions, res.getString(R.string.index_name_north_america));
addSubregion(northAmericaRegion); addSubregion(northAmericaRegion, this);
regionsLookupTable.put(northAmericaRegion.regionId, northAmericaRegion); regionsLookupTable.put(northAmericaRegion.regionId, northAmericaRegion);
WorldRegion russiaRegion = createRegionAs(RUSSIA_REGION_ID, WorldRegion russiaRegion = createRegionAs(RUSSIA_REGION_ID,
loadedItems, osmandRegions, res.getString(R.string.index_name_russia)); loadedItems, osmandRegions, res.getString(R.string.index_name_russia));
addSubregion(russiaRegion); addSubregion(russiaRegion, this);
regionsLookupTable.put(russiaRegion.regionId, russiaRegion); regionsLookupTable.put(russiaRegion.regionId, russiaRegion);
WorldRegion southAmericaRegion = createRegionAs(SOUTH_AMERICA_REGION_ID, WorldRegion southAmericaRegion = createRegionAs(SOUTH_AMERICA_REGION_ID,
loadedItems, osmandRegions, res.getString(R.string.index_name_south_america)); loadedItems, osmandRegions, res.getString(R.string.index_name_south_america));
addSubregion(southAmericaRegion); addSubregion(southAmericaRegion, this);
regionsLookupTable.put(southAmericaRegion.regionId, southAmericaRegion); regionsLookupTable.put(southAmericaRegion.regionId, southAmericaRegion);
// Process all regions // Process all regions
@ -199,7 +185,7 @@ public class WorldRegion {
} }
WorldRegion newRegion = new WorldRegion().init(regionId, osmandRegions, null); WorldRegion newRegion = new WorldRegion().init(regionId, osmandRegions, null);
parentRegion.addSubregion(newRegion); parentRegion.addSubregion(newRegion, this);
regionsLookupTable.put(newRegion.regionId, newRegion); regionsLookupTable.put(newRegion.regionId, newRegion);
// Remove // Remove
@ -212,6 +198,14 @@ public class WorldRegion {
break; 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) { if (loadedItems.size() > 0) {
LOG.warn("Found orphaned regions: " + loadedItems.size()); LOG.warn("Found orphaned regions: " + loadedItems.size());
for (String regionId : loadedItems.keySet()) { 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, private static WorldRegion createRegionAs(String regionId, Map<String, String> loadedItems,
OsmandRegions osmandRegions, String localizedName) { OsmandRegions osmandRegions, String localizedName) {
WorldRegion worldRegion = new WorldRegion().init(regionId, osmandRegions, localizedName); WorldRegion worldRegion = new WorldRegion().init(regionId, osmandRegions, localizedName);

View file

@ -1,6 +1,7 @@
package net.osmand.plus.download; package net.osmand.plus.download;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.Context;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -53,7 +54,7 @@ public class DownloadResourceGroup {
} }
public boolean containsIndexItem() { public boolean containsIndexItem() {
return isHeader() && this != SUBREGIONS; return isHeader() && this != SUBREGIONS && this != VOICE_GROUP;
} }
public boolean isHeader() { public boolean isHeader() {
@ -203,8 +204,14 @@ public class DownloadResourceGroup {
return null; return null;
} }
public String getName() { public String getName(Context ctx) {
return id; if (region != null) {
return region.getName();
} else if (type != null && type.resId != -1) {
return ctx.getString(type.resId);
} else {
return id;
}
} }
public String getUniqueId() { public String getUniqueId() {

View file

@ -170,10 +170,10 @@ public class DownloadResources extends DownloadResourceGroup {
this.rawResources = resources; this.rawResources = resources;
DownloadResourceGroup voiceGroup = new DownloadResourceGroup(this, DownloadResourceGroupType.VOICE_GROUP); DownloadResourceGroup voiceGroup = new DownloadResourceGroup(this, DownloadResourceGroupType.VOICE_GROUP);
DownloadResourceGroup voiceScreenRec = new DownloadResourceGroup(this, DownloadResourceGroupType.VOICE_REC); DownloadResourceGroup voiceScreenRec = new DownloadResourceGroup(voiceGroup, DownloadResourceGroupType.VOICE_REC);
DownloadResourceGroup voiceRec = new DownloadResourceGroup(this, DownloadResourceGroupType.VOICE_HEADER_REC); DownloadResourceGroup voiceScreenTTS = new DownloadResourceGroup(voiceGroup, DownloadResourceGroupType.VOICE_TTS);
DownloadResourceGroup voiceTTS = new DownloadResourceGroup(this, DownloadResourceGroupType.VOICE_TTS); DownloadResourceGroup voiceRec = new DownloadResourceGroup(voiceGroup, DownloadResourceGroupType.VOICE_HEADER_REC);
DownloadResourceGroup voiceScreenTTS = new DownloadResourceGroup(this, DownloadResourceGroupType.VOICE_HEADER_TTS); DownloadResourceGroup voiceTTS = new DownloadResourceGroup(voiceGroup, DownloadResourceGroupType.VOICE_HEADER_TTS);
voiceScreenTTS.addGroup(voiceTTS); voiceScreenTTS.addGroup(voiceTTS);
voiceScreenRec.addGroup(voiceRec); voiceScreenRec.addGroup(voiceRec);
voiceGroup.addGroup(voiceScreenRec); voiceGroup.addGroup(voiceScreenRec);
@ -194,6 +194,7 @@ public class DownloadResources extends DownloadResourceGroup {
} else { } else {
voiceRec.addItem(ii); voiceRec.addItem(ii);
} }
continue;
} }
String basename = ii.getBasename().toLowerCase(); String basename = ii.getBasename().toLowerCase();
WorldRegion wg = downloadIdForRegion.get(basename); WorldRegion wg = downloadIdForRegion.get(basename);
@ -219,6 +220,7 @@ public class DownloadResources extends DownloadResourceGroup {
DownloadResourceGroup parentGroup = parent.pollFirst(); DownloadResourceGroup parentGroup = parent.pollFirst();
List<WorldRegion> subregions = reg.getSubregions(); List<WorldRegion> subregions = reg.getSubregions();
DownloadResourceGroup mainGrp = new DownloadResourceGroup(parentGroup, DownloadResourceGroupType.REGION, reg.getRegionId()); DownloadResourceGroup mainGrp = new DownloadResourceGroup(parentGroup, DownloadResourceGroupType.REGION, reg.getRegionId());
mainGrp.region = reg;
parentGroup.addGroup(mainGrp); parentGroup.addGroup(mainGrp);
DownloadResourceGroup subRegions = new DownloadResourceGroup(mainGrp, DownloadResourceGroupType.SUBREGIONS); DownloadResourceGroup subRegions = new DownloadResourceGroup(mainGrp, DownloadResourceGroupType.SUBREGIONS);
mainGrp.addGroup(subRegions); mainGrp.addGroup(subRegions);

View file

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

View file

@ -74,7 +74,7 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow
if (savedInstanceState != null) { if (savedInstanceState != null) {
groupId = savedInstanceState.getString(REGION_ID_DLG_KEY); groupId = savedInstanceState.getString(REGION_ID_DLG_KEY);
} }
if (groupId == null) { if (groupId == null && getArguments() != null) {
groupId = getArguments().getString(REGION_ID_DLG_KEY); groupId = getArguments().getString(REGION_ID_DLG_KEY);
} }
if (groupId == null) { if (groupId == null) {
@ -112,9 +112,7 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow
group = indexes.getGroupById(groupId); group = indexes.getGroupById(groupId);
if (group != null) { if (group != null) {
listAdapter.update(group); listAdapter.update(group);
if (group.getRegion() != null) { toolbar.setTitle(group.getName(activity));
toolbar.setTitle(group.getRegion().getName());
}
} }
expandAllGroups(); expandAllGroups();
} }
@ -212,18 +210,14 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow
getDownloadActivity().getDownloadThread().runReloadIndexFiles(); getDownloadActivity().getDownloadThread().runReloadIndexFiles();
return true; return true;
case SEARCH_ID: case SEARCH_ID:
getDownloadActivity().showDialog(getActivity(), SearchDialogFragment.createInstance("")); // FIXME
//getDownloadActivity().showDialog(getActivity(), SearchDialogFragment.createInstance(""));
return true; return true;
default: default:
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
} }
public void onRegionSelected(String regionId) {
final DownloadResourceGroupFragment regionDialogFragment = createInstance(regionId);
getDownloadActivity().showDialog(getActivity(), regionDialogFragment);
}
public static DownloadResourceGroupFragment createInstance(String regionId) { public static DownloadResourceGroupFragment createInstance(String regionId) {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString(REGION_ID_DLG_KEY, regionId); bundle.putString(REGION_ID_DLG_KEY, regionId);
@ -315,12 +309,8 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow
public void bindItem(DownloadResourceGroup group) { public void bindItem(DownloadResourceGroup group) {
Drawable iconLeft = getIconForGroup(group); Drawable iconLeft = getIconForGroup(group);
textView.setCompoundDrawablesWithIntrinsicBounds(iconLeft, null, null, null); textView.setCompoundDrawablesWithIntrinsicBounds(iconLeft, null, null, null);
String name = group.getName(); String name = group.getName(ctx);
WorldRegion region = group.getRegion(); textView.setText(name);
if (region != null) {
name = region.getName();
}
textView.setText(name);
} }
} }

View file

@ -15,7 +15,6 @@ import net.osmand.access.AccessibleToast;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.Version; import net.osmand.plus.Version;
import net.osmand.plus.WorldRegion;
import net.osmand.plus.download.DownloadActivity; import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadActivityType; import net.osmand.plus.download.DownloadActivityType;
import net.osmand.plus.download.DownloadIndexesThread; 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.openseamapsplugin.NauticalMapsPlugin;
import net.osmand.plus.srtmplugin.SRTMPlugin; import net.osmand.plus.srtmplugin.SRTMPlugin;
import java.text.DateFormat;
import java.util.Map;
// FIXME // FIXME
public class ItemViewHolder { 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.DownloadActivity;
import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents; 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"; public static final String TAG = "SearchDialogFragment";
private static final String SEARCH_TEXT_DLG_KEY = "search_text_dlg_key"; private static final String SEARCH_TEXT_DLG_KEY = "search_text_dlg_key";
private String searchText; private String searchText;
SearchView search; private SearchView search;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
@ -139,4 +139,5 @@ public class SearchDialogFragment extends DialogFragment implements DownloadEven
fragment.setArguments(bundle); fragment.setArguments(bundle);
return fragment; return fragment;
} }
*/
} }

View file

@ -29,7 +29,7 @@ import android.widget.Filter;
import android.widget.Filterable; import android.widget.Filterable;
import android.widget.ListView; import android.widget.ListView;
public class SearchItemsFragment extends Fragment implements DownloadEvents { public class SearchItemsFragment { /*extends Fragment implements DownloadEvents {
public static final String TAG = "SearchItemsFragment"; public static final String TAG = "SearchItemsFragment";
private SearchItemsAdapter listAdapter; private SearchItemsAdapter listAdapter;
@ -332,4 +332,5 @@ public class SearchItemsFragment extends Fragment implements DownloadEvents {
} }
} }
} }
*/
} }