Downloads UI fixes

This commit is contained in:
GaidamakUA 2015-10-05 17:35:31 +03:00
commit 0029ef3b39
9 changed files with 324 additions and 116 deletions

View file

@ -69,6 +69,16 @@
tools:src="@drawable/ic_action_import" tools:src="@drawable/ic_action_import"
tools:visibility="visible" tools:visibility="visible"
android:visibility="gone"/> android:visibility="gone"/>
<Button
android:id="@+id/rightButton"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_gravity="center_vertical"
android:layout_marginRight="4dp"
android:text="BUY"
android:visibility="gone"/>
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>

View file

@ -220,7 +220,7 @@ public class AppInitializer implements IProgress {
} }
private void loadWorldRegions() { private void loadWorldRegions() {
app.worldRegion = WorldRegion.loadWorldRegions(app); app.worldRegion.loadWorldRegions(app);
} }
private void initPoiTypes() { private void initPoiTypes() {
@ -274,6 +274,8 @@ public class AppInitializer implements IProgress {
app.selectedGpxHelper = startupInit(new GpxSelectionHelper(app, app.savingTrackHelper), GpxSelectionHelper.class); app.selectedGpxHelper = startupInit(new GpxSelectionHelper(app, app.savingTrackHelper), GpxSelectionHelper.class);
app.favorites = startupInit(new FavouritesDbHelper(app), FavouritesDbHelper.class); app.favorites = startupInit(new FavouritesDbHelper(app), FavouritesDbHelper.class);
app.waypointHelper = startupInit(new WaypointHelper(app), WaypointHelper.class); app.waypointHelper = startupInit(new WaypointHelper(app), WaypointHelper.class);
app.worldRegion = startupInit(new WorldRegion(), WorldRegion.class);
app.worldRegion.initWorld();
app.regions = startupInit(new OsmandRegions(), OsmandRegions.class); app.regions = startupInit(new OsmandRegions(), OsmandRegions.class);
app.regions.setLocale(app.getLanguage()); app.regions.setLocale(app.getLanguage());
app.poiFilters = startupInit(new PoiFiltersHelper(app), PoiFiltersHelper.class); app.poiFilters = startupInit(new PoiFiltersHelper(app), PoiFiltersHelper.class);

View file

@ -3,7 +3,6 @@ package net.osmand.plus;
import android.content.res.Resources; import android.content.res.Resources;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.data.LatLon;
import net.osmand.map.OsmandRegions; import net.osmand.map.OsmandRegions;
import net.osmand.plus.download.DownloadActivityType; import net.osmand.plus.download.DownloadActivityType;
@ -34,9 +33,6 @@ public class WorldRegion implements Serializable {
private String downloadsIdPrefix; private String downloadsIdPrefix;
private String name; private String name;
private LatLon bboxTopLeft;
private LatLon bboxBottomRight;
private Set<DownloadActivityType> resourceTypes; private Set<DownloadActivityType> resourceTypes;
// Hierarchy // Hierarchy
@ -59,14 +55,6 @@ public class WorldRegion implements Serializable {
return name; return name;
} }
public LatLon getBboxTopLeft() {
return bboxTopLeft;
}
public LatLon getBboxBottomRight() {
return bboxBottomRight;
}
public Set<DownloadActivityType> getResourceTypes() { public Set<DownloadActivityType> getResourceTypes() {
return resourceTypes; return resourceTypes;
} }
@ -110,19 +98,17 @@ public class WorldRegion implements Serializable {
return name != null ? name.hashCode() : 0; return name != null ? name.hashCode() : 0;
} }
private WorldRegion() { public WorldRegion() {
superregion = null; superregion = null;
subregions = new LinkedList<>(); subregions = new LinkedList<>();
flattenedSubregions = new LinkedList<>(); flattenedSubregions = new LinkedList<>();
} }
private WorldRegion initWorld() { public void initWorld() {
regionId = null; regionId = null;
downloadsIdPrefix = "world_"; downloadsIdPrefix = "world_";
name = null; name = null;
superregion = null; superregion = null;
return this;
} }
private WorldRegion init(String regionId, OsmandRegions osmandRegions, String name) { private WorldRegion init(String regionId, OsmandRegions osmandRegions, String name) {
@ -179,60 +165,57 @@ public class WorldRegion implements Serializable {
} }
} }
public static WorldRegion loadWorldRegions(OsmandApplication app) { public void loadWorldRegions(OsmandApplication app) {
OsmandRegions osmandRegions = app.getRegions(); OsmandRegions osmandRegions = app.getRegions();
Map<String, String> loadedItems = osmandRegions.getFullNamesToLowercaseCopy(); Map<String, String> loadedItems = osmandRegions.getFullNamesToLowercaseCopy();
if (loadedItems.size() == 0) { if (loadedItems.size() == 0) {
return null; return;
} }
HashMap<String, WorldRegion> regionsLookupTable = new HashMap<>(loadedItems.size()); HashMap<String, WorldRegion> regionsLookupTable = new HashMap<>(loadedItems.size());
// Create root region
WorldRegion entireWorld = new WorldRegion().initWorld();
// Create main regions // Create main regions
Resources res = app.getResources(); Resources res = app.getResources();
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));
entireWorld.addSubregion(africaRegion); addSubregion(africaRegion);
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));
entireWorld.addSubregion(asiaRegion); addSubregion(asiaRegion);
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));
entireWorld.addSubregion(australiaAndOceaniaRegion); addSubregion(australiaAndOceaniaRegion);
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));
entireWorld.addSubregion(centralAmericaRegion); addSubregion(centralAmericaRegion);
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));
entireWorld.addSubregion(europeRegion); addSubregion(europeRegion);
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));
entireWorld.addSubregion(northAmericaRegion); addSubregion(northAmericaRegion);
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));
entireWorld.addSubregion(russiaRegion); addSubregion(russiaRegion);
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));
entireWorld.addSubregion(southAmericaRegion); addSubregion(southAmericaRegion);
regionsLookupTable.put(southAmericaRegion.regionId, southAmericaRegion); regionsLookupTable.put(southAmericaRegion.regionId, southAmericaRegion);
// Process remaining regions // Process remaining regions
@ -271,8 +254,6 @@ public class WorldRegion implements Serializable {
for (String regionId : loadedItems.keySet()) { for (String regionId : loadedItems.keySet()) {
LOG.warn("FullName = " + regionId + " parent=" + osmandRegions.getParentFullName(regionId)); LOG.warn("FullName = " + regionId + " parent=" + osmandRegions.getParentFullName(regionId));
} }
return entireWorld;
} }
private static WorldRegion createRegionAs(String regionId, Map<String, String> loadedItems, OsmandRegions osmandRegions, String localizedName) { private static WorldRegion createRegionAs(String regionId, Map<String, String> loadedItems, OsmandRegions osmandRegions, String localizedName) {

View file

@ -4,33 +4,53 @@ import android.content.res.Resources;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.View; import android.view.View;
import android.widget.Button;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import net.osmand.PlatformUtil;
import net.osmand.access.AccessibleToast;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.WorldRegion; import net.osmand.plus.WorldRegion;
import net.osmand.plus.download.BaseDownloadActivity; import net.osmand.plus.download.BaseDownloadActivity;
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.IndexItem; import net.osmand.plus.download.IndexItem;
import net.osmand.plus.srtmplugin.SRTMPlugin;
public class ItemViewHolder { public class ItemViewHolder {
private static final org.apache.commons.logging.Log LOG = PlatformUtil.getLog(WorldItemsFragment.class);
private final TextView nameTextView; private final TextView nameTextView;
private final TextView descrTextView; private final TextView descrTextView;
private final ImageView leftImageView; private final ImageView leftImageView;
private final ImageView rightImageButton; private final ImageView rightImageButton;
private final Button rightButton;
private final ProgressBar progressBar; private final ProgressBar progressBar;
private boolean srtmDisabled; private boolean srtmDisabled;
private boolean nauticalPluginDisabled;
private boolean freeVersion;
private int textColorPrimary; private int textColorPrimary;
private int textColorSecondary; private int textColorSecondary;
private enum RightButtonAction {
UNKNOWN,
ASK_FOR_SEAMARKS_PLUGIN,
ASK_FOR_SRTM_PLUGIN_PURCHASE,
ASK_FOR_SRTM_PLUGIN_ENABLE,
ASK_FOR_FULL_VERSION_PURCHASE
}
public ItemViewHolder(View convertView) { public ItemViewHolder(View convertView) {
nameTextView = (TextView) convertView.findViewById(R.id.name); nameTextView = (TextView) convertView.findViewById(R.id.name);
descrTextView = (TextView) convertView.findViewById(R.id.description); descrTextView = (TextView) convertView.findViewById(R.id.description);
leftImageView = (ImageView) convertView.findViewById(R.id.leftImageView); leftImageView = (ImageView) convertView.findViewById(R.id.leftImageView);
rightImageButton = (ImageView) convertView.findViewById(R.id.rightImageButton); rightImageButton = (ImageView) convertView.findViewById(R.id.rightImageButton);
rightButton = (Button) convertView.findViewById(R.id.rightButton);
progressBar = (ProgressBar) convertView.findViewById(R.id.progressBar); progressBar = (ProgressBar) convertView.findViewById(R.id.progressBar);
TypedValue typedValue = new TypedValue(); TypedValue typedValue = new TypedValue();
@ -45,15 +65,39 @@ public class ItemViewHolder {
this.srtmDisabled = srtmDisabled; this.srtmDisabled = srtmDisabled;
} }
public void setNauticalPluginDisabled(boolean nauticalPluginDisabled) {
this.nauticalPluginDisabled = nauticalPluginDisabled;
}
public void setFreeVersion(boolean freeVersion) {
this.freeVersion = freeVersion;
}
public void bindIndexItem(final IndexItem indexItem, final DownloadActivity context, boolean showTypeInTitle, boolean showTypeInDesc) { public void bindIndexItem(final IndexItem indexItem, final DownloadActivity context, boolean showTypeInTitle, boolean showTypeInDesc) {
boolean light = context.getMyApplication().getSettings().isLightContent();
boolean disabled = false; boolean disabled = false;
String textButtonCaption = "GET";
RightButtonAction rightButtonAction = RightButtonAction.UNKNOWN;
if (indexItem.getType() == DownloadActivityType.VOICE_FILE) { if (indexItem.getType() == DownloadActivityType.VOICE_FILE) {
nameTextView.setText(indexItem.getVisibleName(context, nameTextView.setText(indexItem.getVisibleName(context,
context.getMyApplication().getRegions())); context.getMyApplication().getRegions()));
} else { } else {
if (indexItem.getSimplifiedFileName().equals(ItemsListBuilder.WORLD_SEAMARKS_KEY) && nauticalPluginDisabled) {
rightButtonAction = RightButtonAction.ASK_FOR_SEAMARKS_PLUGIN;
disabled = true;
}
if (indexItem.getType() == DownloadActivityType.SRTM_COUNTRY_FILE && srtmDisabled) { if (indexItem.getType() == DownloadActivityType.SRTM_COUNTRY_FILE && srtmDisabled) {
nameTextView.setText(context.getString(R.string.srtm_plugin_disabled)); nameTextView.setText(context.getString(R.string.srtm_plugin_disabled));
OsmandPlugin srtmPlugin = OsmandPlugin.getPlugin(SRTMPlugin.class);
if (srtmPlugin == null || srtmPlugin.needsInstallation()) {
rightButtonAction = RightButtonAction.ASK_FOR_SRTM_PLUGIN_PURCHASE;
} else if (!srtmPlugin.isActive()) {
rightButtonAction = RightButtonAction.ASK_FOR_SRTM_PLUGIN_ENABLE;
}
disabled = true;
} else if (indexItem.getType() == DownloadActivityType.WIKIPEDIA_FILE && freeVersion) {
rightButtonAction = RightButtonAction.ASK_FOR_FULL_VERSION_PURCHASE;
disabled = true; disabled = true;
} else if (showTypeInTitle) { } else if (showTypeInTitle) {
nameTextView.setText(indexItem.getType().getString(context)); nameTextView.setText(indexItem.getType().getString(context));
@ -84,6 +128,38 @@ public class ItemViewHolder {
}); });
progressBar.setVisibility(View.GONE); progressBar.setVisibility(View.GONE);
if (rightButtonAction != RightButtonAction.UNKNOWN) {
rightButton.setText(textButtonCaption);
rightButton.setVisibility(View.VISIBLE);
rightImageButton.setVisibility(View.GONE);
final RightButtonAction action = rightButtonAction;
rightButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
switch (action) {
case ASK_FOR_FULL_VERSION_PURCHASE:
AccessibleToast.makeText(context, "Please purchase Full version", Toast.LENGTH_SHORT).show();
break;
case ASK_FOR_SEAMARKS_PLUGIN:
AccessibleToast.makeText(context.getApplicationContext(), "Please turn on Seamarks plugin", Toast.LENGTH_SHORT).show();
break;
case ASK_FOR_SRTM_PLUGIN_PURCHASE:
AccessibleToast.makeText(context, "Please purchase SRTM plugin", Toast.LENGTH_SHORT).show();
break;
case ASK_FOR_SRTM_PLUGIN_ENABLE:
AccessibleToast.makeText(context, "Please activate SRTM plugin", Toast.LENGTH_SHORT).show();
break;
}
}
});
} else {
rightButton.setVisibility(View.GONE);
rightImageButton.setVisibility(View.VISIBLE);
}
if (disabled) { if (disabled) {
leftImageView.setImageDrawable(getContextIcon(context, indexItem.getType().getIconResource(), textColorSecondary)); leftImageView.setImageDrawable(getContextIcon(context, indexItem.getType().getIconResource(), textColorSecondary));
nameTextView.setTextColor(textColorSecondary); nameTextView.setTextColor(textColorSecondary);

View file

@ -2,10 +2,13 @@ package net.osmand.plus.download.items;
import android.content.Context; import android.content.Context;
import net.osmand.Collator;
import net.osmand.OsmAndCollator;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.map.OsmandRegions; import net.osmand.map.OsmandRegions;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.WorldRegion; 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;
@ -91,13 +94,21 @@ public class ItemsListBuilder {
} }
} }
public enum VoicePromptsType {
RECORDED,
TTS
}
private static final org.apache.commons.logging.Log LOG = PlatformUtil.getLog(ItemsListBuilder.class); private static final org.apache.commons.logging.Log LOG = PlatformUtil.getLog(ItemsListBuilder.class);
private static Map<WorldRegion, Map<String, IndexItem>> resourcesByRegions = private static Map<WorldRegion, Map<String, IndexItem>> resourcesByRegions =
new HashMap<>(); new HashMap<>();
private static List<WorldRegion> searchableWorldwideRegionItems = new LinkedList<>(); private static List<WorldRegion> searchableWorldwideRegionItems = new LinkedList<>();
private static final Lock lock = new ReentrantLock();
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<ResourceItem> regionMapItems;
private List<Object> allResourceItems; private List<Object> allResourceItems;
@ -127,6 +138,39 @@ public class ItemsListBuilder {
return list; return list;
} }
public static String getVoicePromtName(Context context, VoicePromptsType type) {
switch (type) {
case RECORDED:
return context.getResources().getString(R.string.index_name_voice);
case TTS:
return context.getResources().getString(R.string.index_name_tts_voice);
default:
return null;
}
}
public static List<IndexItem> getVoicePromptsItems(VoicePromptsType type) {
switch (type) {
case RECORDED:
return voiceRecItems;
case TTS:
return voiceTTSItems;
default:
return null;
}
}
public static boolean isVoicePromptsItemsEmpty(VoicePromptsType type) {
switch (type) {
case RECORDED:
return voiceRecItems.isEmpty();
case TTS:
return voiceTTSItems.isEmpty();
default:
return true;
}
}
public ItemsListBuilder(OsmandApplication app) { public ItemsListBuilder(OsmandApplication app) {
this.app = app; this.app = app;
regionMapItems = new LinkedList<>(); regionMapItems = new LinkedList<>();
@ -159,26 +203,10 @@ public class ItemsListBuilder {
collectSubregionsDataAndItems(); collectSubregionsDataAndItems();
collectResourcesDataAndItems(); 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());
}
}
return true; return true;
} }
public static boolean prepareData(OsmandApplication app, List<IndexItem> resources) { public static boolean prepareData(final OsmandApplication app, List<IndexItem> resources) {
lock.lock(); lock.lock();
try { try {
List<IndexItem> resourcesInRepository; List<IndexItem> resourcesInRepository;
@ -191,58 +219,72 @@ public class ItemsListBuilder {
return false; return false;
} }
boolean doInit = resourcesByRegions.isEmpty(); resourcesByRegions.clear();
boolean initSearchableRegions = searchableWorldwideRegionItems.isEmpty() || doInit; searchableWorldwideRegionItems.clear();
voiceRecItems.clear();
if (initSearchableRegions) { voiceTTSItems.clear();
searchableWorldwideRegionItems.clear();
}
List<WorldRegion> mergedRegions = app.getWorldRegion().getFlattenedSubregions(); List<WorldRegion> mergedRegions = app.getWorldRegion().getFlattenedSubregions();
mergedRegions.add(app.getWorldRegion()); mergedRegions.add(app.getWorldRegion());
boolean voiceFilesProcessed = false;
for (WorldRegion region : mergedRegions) { for (WorldRegion region : mergedRegions) {
if (initSearchableRegions) { searchableWorldwideRegionItems.add(region);
searchableWorldwideRegionItems.add(region);
}
String downloadsIdPrefix = region.getDownloadsIdPrefix(); String downloadsIdPrefix = region.getDownloadsIdPrefix();
Map<String, IndexItem> regionResources = new HashMap<>(); Map<String, IndexItem> regionResources = new HashMap<>();
if (!doInit) { Set<DownloadActivityType> typesSet = new TreeSet<>(new Comparator<DownloadActivityType>() {
regionResources.putAll(resourcesByRegions.get(region)); @Override
} public int compare(DownloadActivityType dat1, DownloadActivityType dat2) {
return dat1.getTag().compareTo(dat2.getTag());
}
});
if (doInit) { for (IndexItem resource : resourcesInRepository) {
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")) {
if (!resource.getSimplifiedFileName().startsWith(downloadsIdPrefix)) { voiceRecItems.add(resource);
continue;
} else if (resource.getSimplifiedFileName().contains(".ttsvoice.zip")) {
voiceTTSItems.add(resource);
continue; continue;
} }
typesSet.add(resource.getType());
regionResources.put(resource.getSimplifiedFileName(), resource);
} }
if (region.getSuperregion() != null && region.getSuperregion().getSuperregion() != app.getWorldRegion()) { if (!resource.getSimplifiedFileName().startsWith(downloadsIdPrefix)) {
if (region.getSuperregion().getResourceTypes() == null) { continue;
region.getSuperregion().setResourceTypes(typesSet);
} else {
region.getSuperregion().getResourceTypes().addAll(typesSet);
}
} }
region.setResourceTypes(typesSet); 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); 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; return true;
} finally { } finally {
@ -325,22 +367,5 @@ public class ItemsListBuilder {
Collections.sort(allResourceItems, new ResourceItemComparator()); Collections.sort(allResourceItems, new ResourceItemComparator());
Collections.sort(regionMapItems, new ResourceItemComparator()); Collections.sort(regionMapItems, new ResourceItemComparator());
/*
boolean nauticalPluginDisabled = OsmandPlugin.getEnabledPlugin(NauticalMapsPlugin.class) == null;
if (nauticalPluginDisabled) {
ResourceItem seamarksMapItem = null;
for (ResourceItem item : regionMapItems) {
if (item.getResourceId().equals(WORLD_SEAMARKS_KEY)) {
seamarksMapItem = item;
break;
}
}
if (seamarksMapItem != null) {
regionMapItems.remove(seamarksMapItem);
}
}
*/
} }
} }

View file

@ -7,17 +7,21 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ExpandableListView; import android.widget.ExpandableListView;
import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
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.WorldRegion; import net.osmand.plus.WorldRegion;
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter; import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
import net.osmand.plus.activities.OsmandExpandableListFragment; import net.osmand.plus.activities.OsmandExpandableListFragment;
import net.osmand.plus.download.DownloadActivity; import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin;
import net.osmand.plus.srtmplugin.SRTMPlugin; import net.osmand.plus.srtmplugin.SRTMPlugin;
import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@ -36,6 +40,8 @@ public class RegionItemsFragment extends OsmandExpandableListFragment {
private ItemsListBuilder builder; private ItemsListBuilder builder;
private RegionsItemsAdapter listAdapter; private RegionsItemsAdapter listAdapter;
private int regionMapsGroupPos = -1;
private int additionalMapsGroupPos = -1;
private static final String REGION_KEY = "world_region_key"; private static final String REGION_KEY = "world_region_key";
private WorldRegion region; private WorldRegion region;
@ -114,11 +120,26 @@ public class RegionItemsFragment extends OsmandExpandableListFragment {
private void fillRegionItemsAdapter() { private void fillRegionItemsAdapter() {
if (listAdapter != null) { if (listAdapter != null) {
listAdapter.clear(); listAdapter.clear();
int nextAvailableGroupPos = 0;
if (builder.getRegionMapItems().size() > 0) { if (builder.getRegionMapItems().size() > 0) {
listAdapter.add("Region maps".toUpperCase(), builder.getRegionMapItems()); String sectionTitle;
if (builder.getAllResourceItems().size() > 0) {
sectionTitle = "Region maps";
} else {
sectionTitle = "";
}
regionMapsGroupPos = nextAvailableGroupPos++;
listAdapter.add(sectionTitle, builder.getRegionMapItems());
} }
if (builder.getAllResourceItems().size() > 0) { if (builder.getAllResourceItems().size() > 0) {
listAdapter.add("Additional maps".toUpperCase(), builder.getAllResourceItems()); String sectionTitle;
if (builder.getRegionMapItems().size() > 0) {
sectionTitle = "Additional maps";
} else {
sectionTitle = "";
}
additionalMapsGroupPos = nextAvailableGroupPos;
listAdapter.add(sectionTitle, builder.getAllResourceItems());
} }
} }
} }
@ -141,10 +162,14 @@ public class RegionItemsFragment extends OsmandExpandableListFragment {
private List<String> sections = new LinkedList<>(); private List<String> sections = new LinkedList<>();
private Context ctx; private Context ctx;
private boolean srtmDisabled; private boolean srtmDisabled;
private boolean nauticalPluginDisabled;
private boolean freeVersion;
public RegionsItemsAdapter(Context ctx) { public RegionsItemsAdapter(Context ctx) {
this.ctx = ctx; this.ctx = ctx;
srtmDisabled = OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) == null; srtmDisabled = OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) == null;
nauticalPluginDisabled = OsmandPlugin.getEnabledPlugin(NauticalMapsPlugin.class) == null;
freeVersion = Version.isFreeVersion(getMyApplication());
TypedArray ta = ctx.getTheme().obtainStyledAttributes(new int[]{android.R.attr.textColorPrimary}); TypedArray ta = ctx.getTheme().obtainStyledAttributes(new int[]{android.R.attr.textColorPrimary});
ta.recycle(); ta.recycle();
} }
@ -181,7 +206,7 @@ public class RegionItemsFragment extends OsmandExpandableListFragment {
final Object child = getChild(groupPosition, childPosition); final Object child = getChild(groupPosition, childPosition);
if (child instanceof ItemsListBuilder.ResourceItem && groupPosition == 0 && getGroupCount() > 1) { if (child instanceof ItemsListBuilder.ResourceItem && groupPosition == regionMapsGroupPos) {
ItemViewHolder viewHolder; ItemViewHolder viewHolder;
if (convertView == null) { if (convertView == null) {
convertView = LayoutInflater.from(parent.getContext()) convertView = LayoutInflater.from(parent.getContext())
@ -192,6 +217,8 @@ public class RegionItemsFragment extends OsmandExpandableListFragment {
viewHolder = (ItemViewHolder) convertView.getTag(); viewHolder = (ItemViewHolder) convertView.getTag();
} }
viewHolder.setSrtmDisabled(srtmDisabled); viewHolder.setSrtmDisabled(srtmDisabled);
viewHolder.setNauticalPluginDisabled(nauticalPluginDisabled);
viewHolder.setFreeVersion(freeVersion);
ItemsListBuilder.ResourceItem item = (ItemsListBuilder.ResourceItem) child; ItemsListBuilder.ResourceItem item = (ItemsListBuilder.ResourceItem) child;
viewHolder.bindIndexItem(item.getIndexItem(), getDownloadActivity(), true, false); viewHolder.bindIndexItem(item.getIndexItem(), getDownloadActivity(), true, false);
@ -206,6 +233,8 @@ public class RegionItemsFragment extends OsmandExpandableListFragment {
viewHolder = (ItemViewHolder) convertView.getTag(); viewHolder = (ItemViewHolder) convertView.getTag();
} }
viewHolder.setSrtmDisabled(srtmDisabled); viewHolder.setSrtmDisabled(srtmDisabled);
viewHolder.setNauticalPluginDisabled(nauticalPluginDisabled);
viewHolder.setFreeVersion(freeVersion);
if (child instanceof WorldRegion) { if (child instanceof WorldRegion) {
viewHolder.bindRegion((WorldRegion) child, getDownloadActivity()); viewHolder.bindRegion((WorldRegion) child, getDownloadActivity());
@ -225,6 +254,13 @@ public class RegionItemsFragment extends OsmandExpandableListFragment {
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
View v = convertView; View v = convertView;
String section = getGroup(groupPosition); 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) { if (v == null) {
LayoutInflater inflater = (LayoutInflater) getDownloadActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE); LayoutInflater inflater = (LayoutInflater) getDownloadActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.download_item_list_section, parent, false); v = inflater.inflate(R.layout.download_item_list_section, parent, false);

View file

@ -0,0 +1,6 @@
package net.osmand.plus.download.items;
public class VoiceDialogFragment {
}

View file

@ -0,0 +1,4 @@
package net.osmand.plus.download.items;
public class VoiceItemsFragment {
}

View file

@ -16,12 +16,17 @@ import android.widget.TextView;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.WorldRegion; import net.osmand.plus.WorldRegion;
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter; import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
import net.osmand.plus.activities.OsmandExpandableListFragment; import net.osmand.plus.activities.OsmandExpandableListFragment;
import net.osmand.plus.download.DownloadActivity; import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.IndexItem;
import net.osmand.plus.download.newimplementation.DownloadsUiHelper; import net.osmand.plus.download.newimplementation.DownloadsUiHelper;
import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin;
import net.osmand.plus.srtmplugin.SRTMPlugin;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@ -40,6 +45,13 @@ public class WorldItemsFragment extends OsmandExpandableListFragment {
private ItemsListBuilder builder; private ItemsListBuilder builder;
private WorldItemsAdapter listAdapter; private WorldItemsAdapter listAdapter;
private int worldRegionsIndex = -1;
private int worldMapsIndex = -1;
private int voicePromptsIndex = -1;
private int voicePromptsItemsRecordedSubIndex = -1;
private int voicePromptsItemsTTSSubIndex = -1;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -66,6 +78,15 @@ public class WorldItemsFragment extends OsmandExpandableListFragment {
return view; return view;
} }
@Override
public void onResume() {
super.onResume();
if (!listAdapter.isEmpty()) {
expandAllGroups();
}
}
private void expandAllGroups() { private void expandAllGroups() {
for (int i = 0; i < listAdapter.getGroupCount(); i++) { for (int i = 0; i < listAdapter.getGroupCount(); i++) {
getExpandableListView().expandGroup(i); getExpandableListView().expandGroup(i);
@ -79,18 +100,40 @@ public class WorldItemsFragment extends OsmandExpandableListFragment {
private void fillWorldItemsAdapter() { private void fillWorldItemsAdapter() {
if (listAdapter != null) { if (listAdapter != null) {
listAdapter.clear(); listAdapter.clear();
listAdapter.add("World regions".toUpperCase(), builder.getRegionsFromAllItems()); if (builder.getRegionMapItems().size() > 0) {
listAdapter.add("World maps".toUpperCase(), builder.getRegionMapItems()); int unusedIndex = 0;
//listAdapter.add("Voice promts".toUpperCase(), null); worldRegionsIndex = unusedIndex++;
listAdapter.add("World regions", builder.getRegionsFromAllItems());
worldMapsIndex = unusedIndex++;
listAdapter.add("World maps", builder.getRegionMapItems());
int unusedSubIndex = 0;
List<String> voicePromptsItems = new LinkedList<>();
if (!ItemsListBuilder.isVoicePromptsItemsEmpty(ItemsListBuilder.VoicePromptsType.RECORDED)) {
voicePromptsItems.add(ItemsListBuilder.getVoicePromtName(getMyApplication(), ItemsListBuilder.VoicePromptsType.RECORDED));
voicePromptsItemsRecordedSubIndex = unusedSubIndex++;
}
if (!ItemsListBuilder.isVoicePromptsItemsEmpty(ItemsListBuilder.VoicePromptsType.TTS)) {
voicePromptsItems.add(ItemsListBuilder.getVoicePromtName(getMyApplication(), ItemsListBuilder.VoicePromptsType.TTS));
voicePromptsItemsTTSSubIndex = unusedSubIndex;
}
if (!voicePromptsItems.isEmpty()) {
voicePromptsIndex = unusedIndex;
listAdapter.add("Voice prompts", voicePromptsItems);
}
}
//listAdapter.add("Voice promts", null);
} }
} }
@Override @Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
if (groupPosition == 0) { if (groupPosition == worldRegionsIndex) {
WorldRegion region = (WorldRegion) listAdapter.getChild(groupPosition, childPosition); WorldRegion region = (WorldRegion)listAdapter.getChild(groupPosition, childPosition);
DownloadsUiHelper.showDialog(getActivity(), RegionDialogFragment.createInstance(region)); DownloadsUiHelper.showDialog(getActivity(), RegionDialogFragment.createInstance(region));
return true; return true;
} else if (groupPosition == voicePromptsIndex) {
//
} }
return false; return false;
} }
@ -126,9 +169,12 @@ public class WorldItemsFragment extends OsmandExpandableListFragment {
private class WorldItemsAdapter extends OsmandBaseExpandableListAdapter { private class WorldItemsAdapter extends OsmandBaseExpandableListAdapter {
Map<String, List> data = new LinkedHashMap<>(); private Map<String, List> data = new LinkedHashMap<>();
List<String> sections = new LinkedList<>(); private List<String> sections = new LinkedList<>();
Context ctx; private Context ctx;
private boolean srtmDisabled;
private boolean nauticalPluginDisabled;
private boolean freeVersion;
private class SimpleViewHolder { private class SimpleViewHolder {
TextView textView; TextView textView;
@ -136,6 +182,9 @@ public class WorldItemsFragment extends OsmandExpandableListFragment {
public WorldItemsAdapter(Context ctx) { public WorldItemsAdapter(Context ctx) {
this.ctx = ctx; this.ctx = ctx;
srtmDisabled = OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) == null;
nauticalPluginDisabled = OsmandPlugin.getEnabledPlugin(NauticalMapsPlugin.class) == null;
freeVersion = Version.isFreeVersion(getMyApplication());
TypedArray ta = ctx.getTheme().obtainStyledAttributes(new int[]{android.R.attr.textColorPrimary}); TypedArray ta = ctx.getTheme().obtainStyledAttributes(new int[]{android.R.attr.textColorPrimary});
ta.recycle(); ta.recycle();
} }
@ -169,8 +218,7 @@ public class WorldItemsFragment extends OsmandExpandableListFragment {
@Override @Override
public int getChildType(int groupPosition, int childPosition) { public int getChildType(int groupPosition, int childPosition) {
final Object child = getChild(groupPosition, childPosition); if (groupPosition == worldRegionsIndex || groupPosition == voicePromptsIndex) {
if (child instanceof WorldRegion) {
return 0; return 0;
} else { } else {
return 1; return 1;
@ -187,8 +235,8 @@ public class WorldItemsFragment extends OsmandExpandableListFragment {
final Object child = getChild(groupPosition, childPosition); final Object child = getChild(groupPosition, childPosition);
if (child instanceof WorldRegion) { if (groupPosition == worldRegionsIndex) {
WorldRegion item = (WorldRegion) child; WorldRegion item = (WorldRegion)child;
SimpleViewHolder viewHolder; SimpleViewHolder viewHolder;
if (convertView == null) { if (convertView == null) {
convertView = LayoutInflater.from(parent.getContext()) convertView = LayoutInflater.from(parent.getContext())
@ -204,7 +252,7 @@ public class WorldItemsFragment extends OsmandExpandableListFragment {
viewHolder.textView.setCompoundDrawablesWithIntrinsicBounds(iconLeft, null, null, null); viewHolder.textView.setCompoundDrawablesWithIntrinsicBounds(iconLeft, null, null, null);
viewHolder.textView.setText(item.getName()); viewHolder.textView.setText(item.getName());
} else if (child instanceof ItemsListBuilder.ResourceItem) { } else if (groupPosition == worldMapsIndex) {
ItemsListBuilder.ResourceItem item = (ItemsListBuilder.ResourceItem) child; ItemsListBuilder.ResourceItem item = (ItemsListBuilder.ResourceItem) child;
ItemViewHolder viewHolder; ItemViewHolder viewHolder;
if (convertView == null) { if (convertView == null) {
@ -215,7 +263,27 @@ public class WorldItemsFragment extends OsmandExpandableListFragment {
} else { } else {
viewHolder = (ItemViewHolder) convertView.getTag(); viewHolder = (ItemViewHolder) convertView.getTag();
} }
viewHolder.setSrtmDisabled(srtmDisabled);
viewHolder.setNauticalPluginDisabled(nauticalPluginDisabled);
viewHolder.setFreeVersion(freeVersion);
viewHolder.bindIndexItem(item.getIndexItem(), getDownloadActivity(), false, false); viewHolder.bindIndexItem(item.getIndexItem(), getDownloadActivity(), false, false);
} else if (groupPosition == voicePromptsIndex) {
String item = (String)child;
SimpleViewHolder viewHolder;
if (convertView == null) {
convertView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.simple_list_menu_item, parent, false);
viewHolder = new SimpleViewHolder();
viewHolder.textView = (TextView) convertView.findViewById(R.id.title);
convertView.setTag(viewHolder);
} else {
viewHolder = (SimpleViewHolder) convertView.getTag();
}
Drawable iconLeft = getMyApplication().getIconsCache()
.getContentIcon(R.drawable.ic_action_volume_up);
viewHolder.textView.setCompoundDrawablesWithIntrinsicBounds(iconLeft, null, null, null);
viewHolder.textView.setText(item);
} }
return convertView; return convertView;