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:visibility="visible"
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>

View file

@ -220,7 +220,7 @@ public class AppInitializer implements IProgress {
}
private void loadWorldRegions() {
app.worldRegion = WorldRegion.loadWorldRegions(app);
app.worldRegion.loadWorldRegions(app);
}
private void initPoiTypes() {
@ -274,6 +274,8 @@ public class AppInitializer implements IProgress {
app.selectedGpxHelper = startupInit(new GpxSelectionHelper(app, app.savingTrackHelper), GpxSelectionHelper.class);
app.favorites = startupInit(new FavouritesDbHelper(app), FavouritesDbHelper.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.setLocale(app.getLanguage());
app.poiFilters = startupInit(new PoiFiltersHelper(app), PoiFiltersHelper.class);

View file

@ -3,7 +3,6 @@ package net.osmand.plus;
import android.content.res.Resources;
import net.osmand.PlatformUtil;
import net.osmand.data.LatLon;
import net.osmand.map.OsmandRegions;
import net.osmand.plus.download.DownloadActivityType;
@ -34,9 +33,6 @@ public class WorldRegion implements Serializable {
private String downloadsIdPrefix;
private String name;
private LatLon bboxTopLeft;
private LatLon bboxBottomRight;
private Set<DownloadActivityType> resourceTypes;
// Hierarchy
@ -59,14 +55,6 @@ public class WorldRegion implements Serializable {
return name;
}
public LatLon getBboxTopLeft() {
return bboxTopLeft;
}
public LatLon getBboxBottomRight() {
return bboxBottomRight;
}
public Set<DownloadActivityType> getResourceTypes() {
return resourceTypes;
}
@ -110,19 +98,17 @@ public class WorldRegion implements Serializable {
return name != null ? name.hashCode() : 0;
}
private WorldRegion() {
public WorldRegion() {
superregion = null;
subregions = new LinkedList<>();
flattenedSubregions = new LinkedList<>();
}
private WorldRegion initWorld() {
public void initWorld() {
regionId = null;
downloadsIdPrefix = "world_";
name = null;
superregion = null;
return this;
}
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();
Map<String, String> loadedItems = osmandRegions.getFullNamesToLowercaseCopy();
if (loadedItems.size() == 0) {
return null;
return;
}
HashMap<String, WorldRegion> regionsLookupTable = new HashMap<>(loadedItems.size());
// Create root region
WorldRegion entireWorld = new WorldRegion().initWorld();
// Create main regions
Resources res = app.getResources();
WorldRegion africaRegion = createRegionAs(AFRICA_REGION_ID,
loadedItems, osmandRegions, res.getString(R.string.index_name_africa));
entireWorld.addSubregion(africaRegion);
addSubregion(africaRegion);
regionsLookupTable.put(africaRegion.regionId, africaRegion);
WorldRegion asiaRegion = createRegionAs(ASIA_REGION_ID,
loadedItems, osmandRegions, res.getString(R.string.index_name_asia));
entireWorld.addSubregion(asiaRegion);
addSubregion(asiaRegion);
regionsLookupTable.put(asiaRegion.regionId, asiaRegion);
WorldRegion australiaAndOceaniaRegion = createRegionAs(AUSTRALIA_AND_OCEANIA_REGION_ID,
loadedItems, osmandRegions, res.getString(R.string.index_name_oceania));
entireWorld.addSubregion(australiaAndOceaniaRegion);
addSubregion(australiaAndOceaniaRegion);
regionsLookupTable.put(australiaAndOceaniaRegion.regionId, australiaAndOceaniaRegion);
WorldRegion centralAmericaRegion = createRegionAs(CENTRAL_AMERICA_REGION_ID,
loadedItems, osmandRegions, res.getString(R.string.index_name_central_america));
entireWorld.addSubregion(centralAmericaRegion);
addSubregion(centralAmericaRegion);
regionsLookupTable.put(centralAmericaRegion.regionId, centralAmericaRegion);
WorldRegion europeRegion = createRegionAs(EUROPE_REGION_ID,
loadedItems, osmandRegions, res.getString(R.string.index_name_europe));
entireWorld.addSubregion(europeRegion);
addSubregion(europeRegion);
regionsLookupTable.put(europeRegion.regionId, europeRegion);
WorldRegion northAmericaRegion = createRegionAs(NORTH_AMERICA_REGION_ID,
loadedItems, osmandRegions, res.getString(R.string.index_name_north_america));
entireWorld.addSubregion(northAmericaRegion);
addSubregion(northAmericaRegion);
regionsLookupTable.put(northAmericaRegion.regionId, northAmericaRegion);
WorldRegion russiaRegion = createRegionAs(RUSSIA_REGION_ID,
loadedItems, osmandRegions, res.getString(R.string.index_name_russia));
entireWorld.addSubregion(russiaRegion);
addSubregion(russiaRegion);
regionsLookupTable.put(russiaRegion.regionId, russiaRegion);
WorldRegion southAmericaRegion = createRegionAs(SOUTH_AMERICA_REGION_ID,
loadedItems, osmandRegions, res.getString(R.string.index_name_south_america));
entireWorld.addSubregion(southAmericaRegion);
addSubregion(southAmericaRegion);
regionsLookupTable.put(southAmericaRegion.regionId, southAmericaRegion);
// Process remaining regions
@ -271,8 +254,6 @@ public class WorldRegion implements Serializable {
for (String regionId : loadedItems.keySet()) {
LOG.warn("FullName = " + regionId + " parent=" + osmandRegions.getParentFullName(regionId));
}
return entireWorld;
}
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.util.TypedValue;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ProgressBar;
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.WorldRegion;
import net.osmand.plus.download.BaseDownloadActivity;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadActivityType;
import net.osmand.plus.download.IndexItem;
import net.osmand.plus.srtmplugin.SRTMPlugin;
public class ItemViewHolder {
private static final org.apache.commons.logging.Log LOG = PlatformUtil.getLog(WorldItemsFragment.class);
private final TextView nameTextView;
private final TextView descrTextView;
private final ImageView leftImageView;
private final ImageView rightImageButton;
private final Button rightButton;
private final ProgressBar progressBar;
private boolean srtmDisabled;
private boolean nauticalPluginDisabled;
private boolean freeVersion;
private int textColorPrimary;
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) {
nameTextView = (TextView) convertView.findViewById(R.id.name);
descrTextView = (TextView) convertView.findViewById(R.id.description);
leftImageView = (ImageView) convertView.findViewById(R.id.leftImageView);
rightImageButton = (ImageView) convertView.findViewById(R.id.rightImageButton);
rightButton = (Button) convertView.findViewById(R.id.rightButton);
progressBar = (ProgressBar) convertView.findViewById(R.id.progressBar);
TypedValue typedValue = new TypedValue();
@ -45,15 +65,39 @@ public class ItemViewHolder {
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) {
boolean light = context.getMyApplication().getSettings().isLightContent();
boolean disabled = false;
String textButtonCaption = "GET";
RightButtonAction rightButtonAction = RightButtonAction.UNKNOWN;
if (indexItem.getType() == DownloadActivityType.VOICE_FILE) {
nameTextView.setText(indexItem.getVisibleName(context,
context.getMyApplication().getRegions()));
} 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) {
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;
} else if (showTypeInTitle) {
nameTextView.setText(indexItem.getType().getString(context));
@ -84,6 +128,38 @@ public class ItemViewHolder {
});
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) {
leftImageView.setImageDrawable(getContextIcon(context, indexItem.getType().getIconResource(), textColorSecondary));
nameTextView.setTextColor(textColorSecondary);

View file

@ -2,10 +2,13 @@ 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;
@ -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 Map<WorldRegion, Map<String, IndexItem>> resourcesByRegions =
new HashMap<>();
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<Object> allResourceItems;
@ -127,6 +138,39 @@ public class ItemsListBuilder {
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) {
this.app = app;
regionMapItems = new LinkedList<>();
@ -159,26 +203,10 @@ public class ItemsListBuilder {
collectSubregionsDataAndItems();
collectResourcesDataAndItems();
LOG.warn("getRegionMapItems >>>");
for (ResourceItem resourceItem : getRegionMapItems()) {
LOG.warn("resId=" + resourceItem.getIndexItem().getFileName() + " title=" + resourceItem.getTitle());
}
LOG.warn("getAllResourceItems >>>");
for (Object obj : getAllResourceItems()) {
if (obj instanceof WorldRegion) {
WorldRegion item = (WorldRegion) obj;
LOG.warn("W resId=" + item.getRegionId() + " title=" + item.getName());
} else if (obj instanceof ResourceItem) {
ResourceItem resourceItem = (ResourceItem) obj;
LOG.warn("R resId=" + resourceItem.getIndexItem().getFileName() + " title=" + resourceItem.getTitle());
}
}
return true;
}
public static boolean prepareData(OsmandApplication app, List<IndexItem> resources) {
public static boolean prepareData(final OsmandApplication app, List<IndexItem> resources) {
lock.lock();
try {
List<IndexItem> resourcesInRepository;
@ -191,58 +219,72 @@ public class ItemsListBuilder {
return false;
}
boolean doInit = resourcesByRegions.isEmpty();
boolean initSearchableRegions = searchableWorldwideRegionItems.isEmpty() || doInit;
if (initSearchableRegions) {
searchableWorldwideRegionItems.clear();
}
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) {
if (initSearchableRegions) {
searchableWorldwideRegionItems.add(region);
}
searchableWorldwideRegionItems.add(region);
String downloadsIdPrefix = region.getDownloadsIdPrefix();
Map<String, IndexItem> regionResources = new HashMap<>();
if (!doInit) {
regionResources.putAll(resourcesByRegions.get(region));
}
Set<DownloadActivityType> typesSet = new TreeSet<>(new Comparator<DownloadActivityType>() {
@Override
public int compare(DownloadActivityType dat1, DownloadActivityType dat2) {
return dat1.getTag().compareTo(dat2.getTag());
}
});
if (doInit) {
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) {
for (IndexItem resource : resourcesInRepository) {
if (!resource.getSimplifiedFileName().startsWith(downloadsIdPrefix)) {
if (!voiceFilesProcessed) {
if (resource.getSimplifiedFileName().endsWith(".voice.zip")) {
voiceRecItems.add(resource);
continue;
} else if (resource.getSimplifiedFileName().contains(".ttsvoice.zip")) {
voiceTTSItems.add(resource);
continue;
}
typesSet.add(resource.getType());
regionResources.put(resource.getSimplifiedFileName(), resource);
}
if (region.getSuperregion() != null && region.getSuperregion().getSuperregion() != app.getWorldRegion()) {
if (region.getSuperregion().getResourceTypes() == null) {
region.getSuperregion().setResourceTypes(typesSet);
} else {
region.getSuperregion().getResourceTypes().addAll(typesSet);
}
if (!resource.getSimplifiedFileName().startsWith(downloadsIdPrefix)) {
continue;
}
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);
}
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 {
@ -325,22 +367,5 @@ public class ItemsListBuilder {
Collections.sort(allResourceItems, 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.ViewGroup;
import android.widget.ExpandableListView;
import android.widget.LinearLayout;
import android.widget.TextView;
import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.Version;
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.openseamapsplugin.NauticalMapsPlugin;
import net.osmand.plus.srtmplugin.SRTMPlugin;
import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
@ -36,6 +40,8 @@ public class RegionItemsFragment extends OsmandExpandableListFragment {
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;
@ -114,11 +120,26 @@ public class RegionItemsFragment extends OsmandExpandableListFragment {
private void fillRegionItemsAdapter() {
if (listAdapter != null) {
listAdapter.clear();
int nextAvailableGroupPos = 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) {
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 Context ctx;
private boolean srtmDisabled;
private boolean nauticalPluginDisabled;
private boolean freeVersion;
public RegionsItemsAdapter(Context 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});
ta.recycle();
}
@ -181,7 +206,7 @@ public class RegionItemsFragment extends OsmandExpandableListFragment {
final Object child = getChild(groupPosition, childPosition);
if (child instanceof ItemsListBuilder.ResourceItem && groupPosition == 0 && getGroupCount() > 1) {
if (child instanceof ItemsListBuilder.ResourceItem && groupPosition == regionMapsGroupPos) {
ItemViewHolder viewHolder;
if (convertView == null) {
convertView = LayoutInflater.from(parent.getContext())
@ -192,6 +217,8 @@ public class RegionItemsFragment extends OsmandExpandableListFragment {
viewHolder = (ItemViewHolder) convertView.getTag();
}
viewHolder.setSrtmDisabled(srtmDisabled);
viewHolder.setNauticalPluginDisabled(nauticalPluginDisabled);
viewHolder.setFreeVersion(freeVersion);
ItemsListBuilder.ResourceItem item = (ItemsListBuilder.ResourceItem) child;
viewHolder.bindIndexItem(item.getIndexItem(), getDownloadActivity(), true, false);
@ -206,6 +233,8 @@ public class RegionItemsFragment extends OsmandExpandableListFragment {
viewHolder = (ItemViewHolder) convertView.getTag();
}
viewHolder.setSrtmDisabled(srtmDisabled);
viewHolder.setNauticalPluginDisabled(nauticalPluginDisabled);
viewHolder.setFreeVersion(freeVersion);
if (child instanceof WorldRegion) {
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) {
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);
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.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.Version;
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;
import org.apache.commons.logging.Log;
@ -40,6 +45,13 @@ public class WorldItemsFragment extends OsmandExpandableListFragment {
private ItemsListBuilder builder;
private WorldItemsAdapter listAdapter;
private int worldRegionsIndex = -1;
private int worldMapsIndex = -1;
private int voicePromptsIndex = -1;
private int voicePromptsItemsRecordedSubIndex = -1;
private int voicePromptsItemsTTSSubIndex = -1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -66,6 +78,15 @@ public class WorldItemsFragment extends OsmandExpandableListFragment {
return view;
}
@Override
public void onResume() {
super.onResume();
if (!listAdapter.isEmpty()) {
expandAllGroups();
}
}
private void expandAllGroups() {
for (int i = 0; i < listAdapter.getGroupCount(); i++) {
getExpandableListView().expandGroup(i);
@ -79,18 +100,40 @@ public class WorldItemsFragment extends OsmandExpandableListFragment {
private void fillWorldItemsAdapter() {
if (listAdapter != null) {
listAdapter.clear();
listAdapter.add("World regions".toUpperCase(), builder.getRegionsFromAllItems());
listAdapter.add("World maps".toUpperCase(), builder.getRegionMapItems());
//listAdapter.add("Voice promts".toUpperCase(), null);
if (builder.getRegionMapItems().size() > 0) {
int unusedIndex = 0;
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
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
if (groupPosition == 0) {
WorldRegion region = (WorldRegion) listAdapter.getChild(groupPosition, childPosition);
if (groupPosition == worldRegionsIndex) {
WorldRegion region = (WorldRegion)listAdapter.getChild(groupPosition, childPosition);
DownloadsUiHelper.showDialog(getActivity(), RegionDialogFragment.createInstance(region));
return true;
} else if (groupPosition == voicePromptsIndex) {
//
}
return false;
}
@ -126,9 +169,12 @@ public class WorldItemsFragment extends OsmandExpandableListFragment {
private class WorldItemsAdapter extends OsmandBaseExpandableListAdapter {
Map<String, List> data = new LinkedHashMap<>();
List<String> sections = new LinkedList<>();
Context ctx;
private Map<String, List> data = new LinkedHashMap<>();
private List<String> sections = new LinkedList<>();
private Context ctx;
private boolean srtmDisabled;
private boolean nauticalPluginDisabled;
private boolean freeVersion;
private class SimpleViewHolder {
TextView textView;
@ -136,6 +182,9 @@ public class WorldItemsFragment extends OsmandExpandableListFragment {
public WorldItemsAdapter(Context 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});
ta.recycle();
}
@ -169,8 +218,7 @@ public class WorldItemsFragment extends OsmandExpandableListFragment {
@Override
public int getChildType(int groupPosition, int childPosition) {
final Object child = getChild(groupPosition, childPosition);
if (child instanceof WorldRegion) {
if (groupPosition == worldRegionsIndex || groupPosition == voicePromptsIndex) {
return 0;
} else {
return 1;
@ -187,8 +235,8 @@ public class WorldItemsFragment extends OsmandExpandableListFragment {
final Object child = getChild(groupPosition, childPosition);
if (child instanceof WorldRegion) {
WorldRegion item = (WorldRegion) child;
if (groupPosition == worldRegionsIndex) {
WorldRegion item = (WorldRegion)child;
SimpleViewHolder viewHolder;
if (convertView == null) {
convertView = LayoutInflater.from(parent.getContext())
@ -204,7 +252,7 @@ public class WorldItemsFragment extends OsmandExpandableListFragment {
viewHolder.textView.setCompoundDrawablesWithIntrinsicBounds(iconLeft, null, null, null);
viewHolder.textView.setText(item.getName());
} else if (child instanceof ItemsListBuilder.ResourceItem) {
} else if (groupPosition == worldMapsIndex) {
ItemsListBuilder.ResourceItem item = (ItemsListBuilder.ResourceItem) child;
ItemViewHolder viewHolder;
if (convertView == null) {
@ -215,7 +263,27 @@ public class WorldItemsFragment extends OsmandExpandableListFragment {
} else {
viewHolder = (ItemViewHolder) convertView.getTag();
}
viewHolder.setSrtmDisabled(srtmDisabled);
viewHolder.setNauticalPluginDisabled(nauticalPluginDisabled);
viewHolder.setFreeVersion(freeVersion);
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;