diff --git a/OsmAnd-java/src/main/java/net/osmand/osm/RouteActivityType.java b/OsmAnd-java/src/main/java/net/osmand/osm/RouteActivityType.java index 28c9b11551..7c54388f64 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/RouteActivityType.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/RouteActivityType.java @@ -1,42 +1,76 @@ package net.osmand.osm; -public enum RouteActivityType { - WATER("Water", "yellow"), WINTER("Winter", "yellow"), SNOWMOBILE("Snowmobile", "yellow"), RIDING("Riding", "yellow"), RACING("Racing", "yellow"), - MOUNTAINBIKE("Mountainbike", "blue"), CYCLING("Cycling", "blue"), - HIKING("Hiking", "orange"), RUNNING("Running", "orange"), WALKING("Walking", "orange"), - OFFROAD("Off-road", "yellow"), - MOTORBIKE("Motorbike", "green"), CAR("Car", "green"); - // less specific bottom order +import java.util.ArrayList; +import java.util.List; +public class RouteActivityType { + private static final List values = new ArrayList<>(); + public static final String DEFAULT_ICON = "special_marker"; + public static final String DEFAULT_COLOR = "orange"; + + public static final RouteActivityType WATER = createType("water", "yellow").icon("special_kayak").reg(); + public static final RouteActivityType WINTER = createType("winter", "yellow").icon("special_skiing").reg(); + public static final RouteActivityType SNOWMOBILE = createType("snowmobile", "yellow").icon("special_snowmobile").reg(); + public static final RouteActivityType RIDING = createType("riding", "yellow").icon("special_horse").reg(); + public static final RouteActivityType RACING = createType("racing", "yellow").icon("raceway").reg(); + public static final RouteActivityType MOUNTAINBIKE = createType("mountainbike", "blue").icon("sport_cycling").reg(); + public static final RouteActivityType CYCLING = createType("cycling", "blue").icon("special_bicycle").reg(); + public static final RouteActivityType HIKING = createType("hiking", "orange").icon("special_trekking").reg(); + public static final RouteActivityType RUNNING = createType("running", "orange").icon("running").reg(); + public static final RouteActivityType WALKING = createType("walking", "orange").icon("special_walking").reg(); + public static final RouteActivityType OFFROAD = createType("offroad", "yellow").icon("special_offroad").reg(); + public static final RouteActivityType MOTORBIKE = createType("motorbike", "green").icon("special_motorcycle").reg(); + public static final RouteActivityType CAR = createType("car", "green").icon("shop_car").reg(); + // less specific bottom order String name; String color; + String icon; - private RouteActivityType(String nm, String clr) { + RouteActivityType(String nm, String clr) { this.name = nm; this.color = clr; } - + public String getName() { return name; } - + public String getColor() { return color; } - + + public String getIcon() { + return icon; + } + + public static RouteActivityType getOrCreateTypeFromName(String name) { + for (RouteActivityType rat : values) { + if (rat.name.equalsIgnoreCase(name)) { + return rat; + } + } + return createType(name.toLowerCase(), DEFAULT_COLOR).icon(DEFAULT_ICON).reg(); + } + + private static RouteActivityTypeBuilder createType(String name, String color) { + RouteActivityTypeBuilder builder = new RouteActivityTypeBuilder(); + builder.routeActivityType = new RouteActivityType(name, color); + return builder; + } + public static RouteActivityType getTypeFromTags(String[] tags) { RouteActivityType activityType = null; for (String tg : tags) { RouteActivityType rat = RouteActivityType.convertFromOsmGPXTag(tg); if (rat != null) { - if (activityType == null || activityType.ordinal() > rat.ordinal()) { + if (activityType == null || values.indexOf(activityType) > values.indexOf(rat)) { activityType = rat; } } } return activityType; } - + public static RouteActivityType convertFromOsmGPXTag(String tg) { String t = tg.toLowerCase(); if ("mountain hiking".equalsIgnoreCase(t)) { @@ -215,4 +249,18 @@ public enum RouteActivityType { return null; } + public static class RouteActivityTypeBuilder { + + private RouteActivityType routeActivityType; + + public RouteActivityTypeBuilder icon(String icon) { + routeActivityType.icon = icon; + return this; + } + + private RouteActivityType reg() { + values.add(routeActivityType); + return routeActivityType; + } + } } \ No newline at end of file diff --git a/OsmAnd-java/src/main/java/net/osmand/osm/edit/EntityParser.java b/OsmAnd-java/src/main/java/net/osmand/osm/edit/EntityParser.java index 9caa54b55c..bd37de6ba0 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/edit/EntityParser.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/edit/EntityParser.java @@ -21,7 +21,7 @@ import net.osmand.osm.edit.Relation.RelationMember; import net.osmand.util.Algorithms; public class EntityParser { - + public static void parseMapObject(MapObject mo, Entity e, Map tags) { mo.setId(e.getId()); if(mo instanceof Amenity) { @@ -123,7 +123,7 @@ public class EntityParser { mo.setName(ref); } } - + private static void setNameFromBrand(MapObject mo, Map tags) { String ref = tags.get(OSMTagKey.BRAND.getValue()); if(ref != null){ @@ -140,7 +140,7 @@ public class EntityParser { op += " [" + ref + "]"; mo.setName(op); } - + private static String getWebSiteURL(Map tagValues, boolean checkWikipedia) { String siteUrl = null; @@ -170,14 +170,14 @@ public class EntityParser { } return siteUrl; } - - + + public static List parseAmenities(MapPoiTypes poiTypes, Entity entity, Map tags, List amenitiesList) { amenitiesList.clear(); // it could be collection of amenities boolean relation = entity instanceof Relation; - boolean purerelation = relation && + boolean purerelation = relation && !("multipolygon".equals(tags.get("type")) || "boundary".equals(tags.get("type"))); Collection> it = MapRenderingTypes.splitTagsIntoDifferentObjects(tags); for (Map ts : it) { @@ -201,9 +201,7 @@ public class EntityParser { } return amenitiesList; } - - - + private static boolean checkAmenitiesToAdd(Amenity a, List amenitiesList){ // check amenity for duplication for(Amenity b : amenitiesList){ @@ -212,9 +210,9 @@ public class EntityParser { } } return true; - + } - + public static Building parseBuilding(Entity e){ Building b = new Building(); parseMapObject(b, e, e.getTags()); @@ -228,7 +226,7 @@ public class EntityParser { List nodes = ((Way) e).getNodes(); for(int i = 0; i < nodes.size(); i++) { Node node = nodes.get(i); - if(node != null && "yes".equals(node.getTag(OSMTagKey.ENTRANCE)) && + if(node != null && "yes".equals(node.getTag(OSMTagKey.ENTRANCE)) && !Algorithms.isEmpty(node.getTag(OSMTagKey.REF))) { b.addEntrance(node.getTag(OSMTagKey.REF), node.getLatLon()); } @@ -236,11 +234,11 @@ public class EntityParser { } return b; } - + public static City parseCity(Node el) { return parseCity(el, CityType.valueFromString(el.getTag(OSMTagKey.PLACE.getValue()))); } - + public static City parseCity(Entity el, CityType t) { if(t == null) { return null; @@ -252,15 +250,15 @@ public class EntityParser { c.setIsin(isin); return c; } - - + + public static TransportRoute parserRoute(Relation r, String ref){ TransportRoute rt = new TransportRoute(); parseMapObject(rt, r, r.getTags()); rt.setRef(ref); return rt; } - + public static TransportStop parseTransportStop(Entity e){ TransportStop st = new TransportStop(); parseMapObject(st, e, e.getTags()); diff --git a/OsmAnd/res/layout/wikivoyage_travel_gpx_card.xml b/OsmAnd/res/layout/wikivoyage_travel_gpx_card.xml index 44077a0dcd..963c27c9f3 100644 --- a/OsmAnd/res/layout/wikivoyage_travel_gpx_card.xml +++ b/OsmAnd/res/layout/wikivoyage_travel_gpx_card.xml @@ -139,31 +139,83 @@ - + android:background="?attr/btn_border_bg" + android:layout_marginLeft="@dimen/content_padding_half" + android:layout_marginStart="@dimen/content_padding_half"> + + + + + + + + + + + + @@ -172,7 +224,6 @@ diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index a15fb40cbd..8b1a73aa95 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -12,6 +12,19 @@ --> + Car + Motorbike + Off-road + Walking + Running + Hiking + Cycling + Mountainbike + Racing + Riding + Snowmobile + Winter + Water Login to OpenPlaceReviews Use test.openplacereviews.org OpenPlaceReviews diff --git a/OsmAnd/src/net/osmand/AndroidUtils.java b/OsmAnd/src/net/osmand/AndroidUtils.java index 545e7b7391..ce7547a2c4 100644 --- a/OsmAnd/src/net/osmand/AndroidUtils.java +++ b/OsmAnd/src/net/osmand/AndroidUtils.java @@ -951,6 +951,12 @@ public class AndroidUtils { return value != null ? value : propertyValue; } + + public static String getActivityTypeStringPropertyName(Context ctx, String propertyName, String defValue) { + String value = getStringByProperty(ctx, "activity_type_" + propertyName + "_name"); + return value != null ? value : defValue; + } + private static String getStringByProperty(@NonNull Context ctx, @NonNull String property) { try { Field field = R.string.class.getField(property); diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java index 185fdc922c..2bcc166c4c 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java @@ -6,8 +6,10 @@ public class TravelGpx extends TravelArticle { public static final String DIFF_ELE_UP = "diff_ele_up"; public static final String DIFF_ELE_DOWN = "diff_ele_down"; public static final String USER = "user"; + public static final String ACTIVITY_TYPE = "route_activity_type"; public String user; + public String activityType; public float totalDistance = 0; public double diffElevationUp = 0; public double diffElevationDown = 0; diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index f230929f1d..0ca0ed8f03 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -58,6 +58,7 @@ import static net.osmand.plus.helpers.GpxUiHelper.getGpxTitle; import static net.osmand.plus.wikivoyage.data.TravelGpx.DIFF_ELE_DOWN; import static net.osmand.plus.wikivoyage.data.TravelGpx.DIFF_ELE_UP; import static net.osmand.plus.wikivoyage.data.TravelGpx.DISTANCE; +import static net.osmand.plus.wikivoyage.data.TravelGpx.ACTIVITY_TYPE; import static net.osmand.plus.wikivoyage.data.TravelGpx.USER; import static net.osmand.util.Algorithms.capitalizeFirstLetter; @@ -203,6 +204,7 @@ public class TravelObfHelper implements TravelHelper { LOG.debug(e.getMessage(), e); } res.user = Algorithms.emptyIfNull(amenity.getTagContent(USER)); + res.activityType = Algorithms.emptyIfNull(amenity.getTagContent(ACTIVITY_TYPE)); articles.put("en", res); return articles; } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesRvAdapter.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesRvAdapter.java index a01de6e6cb..9bccece08d 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesRvAdapter.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesRvAdapter.java @@ -20,6 +20,7 @@ import com.squareup.picasso.RequestCreator; import net.osmand.AndroidUtils; import net.osmand.PicassoUtils; +import net.osmand.osm.RouteActivityType; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; @@ -31,11 +32,14 @@ import net.osmand.plus.wikivoyage.WikivoyageUtils; import net.osmand.plus.wikivoyage.data.TravelArticle; import net.osmand.plus.wikivoyage.data.TravelGpx; import net.osmand.plus.wikivoyage.data.TravelLocalDataHelper; -import net.osmand.plus.wikivoyage.explore.travelcards.TravelGpxCard; +import net.osmand.util.Algorithms; import java.util.ArrayList; import java.util.List; +import static net.osmand.plus.wikivoyage.explore.travelcards.TravelGpxCard.*; +import static net.osmand.util.Algorithms.capitalizeFirstLetterAndLowercase; + public class SavedArticlesRvAdapter extends RecyclerView.Adapter { private static final int HEADER_TYPE = 0; @@ -81,7 +85,7 @@ public class SavedArticlesRvAdapter extends RecyclerView.Adapter