From 4aa877f7f65b2b28566c7d5476466dceb992e3c6 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Fri, 29 Jan 2021 10:50:05 +0200 Subject: [PATCH 01/14] Travel - vehicle mode --- .../main/java/net/osmand/data/Amenity.java | 20 ++++ .../main/java/net/osmand/osm/MapPoiTypes.java | 8 +- .../res/layout/wikivoyage_travel_gpx_card.xml | 92 ++++++++++++++----- .../plus/wikivoyage/data/TravelGpx.java | 2 + .../plus/wikivoyage/data/TravelObfHelper.java | 2 + .../explore/travelcards/TravelGpxCard.java | 16 +++- 6 files changed, 113 insertions(+), 27 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java b/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java index 861a7c9b93..48e15df815 100644 --- a/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java +++ b/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java @@ -179,6 +179,26 @@ public class Amenity extends MapObject { } } + public void addProfileTag(Entry e) { + if (getAdditionalInfo("profile") == null) { + if (e.getKey().startsWith("tag_")) { + switch (e.getValue().trim()) { + case "bicycle": + case "cycling": + case "mtb": + setAdditionalInfo("profile", "bicycle"); + break; + case "hiking": + case "hike": + case "walking": + case "walk": + setAdditionalInfo("profile", "pedestrian"); + break; + } + } + } + } + @Override public String toStringEn() { return super.toStringEn() + ": " + type.getKeyName() + ":" + subType; diff --git a/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java b/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java index e273fa4e7f..70d35e24ae 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java @@ -915,14 +915,18 @@ public class MapPoiTypes { if (!otag.equals(tag) && !otag.equals("name")) { PoiType pat = poiTypesByTag.get(otag + "/" + e.getValue()); if (pat == null) { - for(String splValue : e.getValue().split(";")) { + for (String splValue : e.getValue().split(";")) { PoiType ps = poiTypesByTag.get(otag + "/" + splValue.trim()); - if(ps != null) { + if (ps != null) { a.setAdditionalInfo(ps.getKeyName(), splValue.trim()); } } pat = poiTypesByTag.get(otag); + if (pat == null && otag.startsWith("tag_")) { + a.addProfileTag(e); + } } + if (pat != null && pat.isAdditional()) { a.setAdditionalInfo(pat.getKeyName(), e.getValue()); } diff --git a/OsmAnd/res/layout/wikivoyage_travel_gpx_card.xml b/OsmAnd/res/layout/wikivoyage_travel_gpx_card.xml index 44077a0dcd..2e11585264 100644 --- a/OsmAnd/res/layout/wikivoyage_travel_gpx_card.xml +++ b/OsmAnd/res/layout/wikivoyage_travel_gpx_card.xml @@ -139,31 +139,82 @@ - + android:background="?attr/btn_border_bg" + android:layout_marginLeft="@dimen/content_padding_half" + android:layout_marginStart="@dimen/content_padding_half"> + + + + + + + + + + + + @@ -172,7 +223,6 @@ diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java index 185fdc922c..91d404510d 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 PROFILE = "profile"; public String user; + public String profile; 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..8622ed0996 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.PROFILE; 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.profile = Algorithms.emptyIfNull(amenity.getTagContent(PROFILE)); articles.put("en", res); return articles; } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java index 1bc2409621..efd81315d3 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java @@ -2,16 +2,17 @@ package net.osmand.plus.wikivoyage.explore.travelcards; import android.graphics.drawable.Drawable; import android.view.View; +import android.widget.ImageView; import android.widget.TextView; import androidx.annotation.NonNull; import androidx.fragment.app.FragmentActivity; import androidx.recyclerview.widget.RecyclerView; -import net.osmand.AndroidUtils; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; +import net.osmand.plus.profiles.ProfileIcons; import net.osmand.plus.track.TrackMenuFragment; import net.osmand.plus.wikivoyage.data.TravelGpx; import net.osmand.plus.wikivoyage.data.TravelLocalDataHelper; @@ -40,10 +41,11 @@ public class TravelGpxCard extends BaseTravelCard { if (viewHolder instanceof TravelGpxVH) { final TravelGpxVH holder = (TravelGpxVH) viewHolder; holder.title.setText(article.getTitle()); - Drawable icon = getActiveIcon(R.drawable.ic_action_user_account_16); - holder.user.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null); + holder.userIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_user_account_16)); holder.user.setText(article.user); - AndroidUtils.setBackground(app, holder.user, nightMode, R.drawable.btn_border_bg_light, R.drawable.btn_border_bg_dark); + ProfileIcons profileRes = ProfileIcons.valueOf(article.profile.toUpperCase()); + holder.profileIcon.setImageDrawable(getActiveIcon(profileRes.getResId())); + holder.profile.setText(profileRes.getTitleId()); holder.distance.setText(OsmAndFormatter.getFormattedDistance(article.totalDistance, app)); holder.diffElevationUp.setText(OsmAndFormatter.getFormattedAlt(article.diffElevationUp, app)); holder.diffElevationDown.setText(OsmAndFormatter.getFormattedAlt(article.diffElevationDown, app)); @@ -92,6 +94,9 @@ public class TravelGpxCard extends BaseTravelCard { public final TextView title; public final TextView user; + public final ImageView userIcon; + public final TextView profile; + public final ImageView profileIcon; public final TextView distance; public final TextView diffElevationUp; public final TextView diffElevationDown; @@ -104,6 +109,9 @@ public class TravelGpxCard extends BaseTravelCard { super(itemView); title = itemView.findViewById(R.id.title); user = itemView.findViewById(R.id.user_name); + userIcon = itemView.findViewById(R.id.user_icon); + profile = itemView.findViewById(R.id.profile); + profileIcon = itemView.findViewById(R.id.profile_icon); distance = itemView.findViewById(R.id.distance); diffElevationUp = itemView.findViewById(R.id.diff_ele_up); diffElevationDown = itemView.findViewById(R.id.diff_ele_down); From 30c5fda90ab673fbf7d5540cc609e71138f0ed9f Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Fri, 29 Jan 2021 11:45:54 +0200 Subject: [PATCH 02/14] Fix UI --- .../res/layout/wikivoyage_travel_gpx_card.xml | 1 + .../explore/SavedArticlesRvAdapter.java | 26 ++++++++++++------- .../explore/travelcards/TravelGpxCard.java | 12 ++++++--- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/OsmAnd/res/layout/wikivoyage_travel_gpx_card.xml b/OsmAnd/res/layout/wikivoyage_travel_gpx_card.xml index 2e11585264..b3aaf7e849 100644 --- a/OsmAnd/res/layout/wikivoyage_travel_gpx_card.xml +++ b/OsmAnd/res/layout/wikivoyage_travel_gpx_card.xml @@ -184,6 +184,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="?attr/btn_border_bg" + android:visibility="gone" android:layout_marginLeft="@dimen/content_padding_half" android:layout_marginStart="@dimen/content_padding_half"> diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesRvAdapter.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesRvAdapter.java index a01de6e6cb..7d1531d5e0 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesRvAdapter.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesRvAdapter.java @@ -18,12 +18,12 @@ import com.squareup.picasso.Callback; import com.squareup.picasso.Picasso; import com.squareup.picasso.RequestCreator; -import net.osmand.AndroidUtils; import net.osmand.PicassoUtils; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; +import net.osmand.plus.profiles.ProfileIcons; import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.widgets.tools.CropCircleTransformation; import net.osmand.plus.wikipedia.WikiArticleHelper; @@ -31,11 +31,13 @@ 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.*; + public class SavedArticlesRvAdapter extends RecyclerView.Adapter { private static final int HEADER_TYPE = 0; @@ -81,7 +83,7 @@ public class SavedArticlesRvAdapter extends RecyclerView.Adapter Date: Fri, 29 Jan 2021 13:40:01 +0200 Subject: [PATCH 03/14] refactoring --- .../main/java/net/osmand/data/Amenity.java | 20 ------- .../main/java/net/osmand/osm/MapPoiTypes.java | 4 -- .../net/osmand/osm/edit/EntityParser.java | 56 +++++++++++++------ 3 files changed, 39 insertions(+), 41 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java b/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java index 48e15df815..861a7c9b93 100644 --- a/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java +++ b/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java @@ -179,26 +179,6 @@ public class Amenity extends MapObject { } } - public void addProfileTag(Entry e) { - if (getAdditionalInfo("profile") == null) { - if (e.getKey().startsWith("tag_")) { - switch (e.getValue().trim()) { - case "bicycle": - case "cycling": - case "mtb": - setAdditionalInfo("profile", "bicycle"); - break; - case "hiking": - case "hike": - case "walking": - case "walk": - setAdditionalInfo("profile", "pedestrian"); - break; - } - } - } - } - @Override public String toStringEn() { return super.toStringEn() + ": " + type.getKeyName() + ":" + subType; diff --git a/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java b/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java index 70d35e24ae..77507de50c 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java @@ -922,11 +922,7 @@ public class MapPoiTypes { } } pat = poiTypesByTag.get(otag); - if (pat == null && otag.startsWith("tag_")) { - a.addProfileTag(e); } - } - if (pat != null && pat.isAdditional()) { a.setAdditionalInfo(pat.getKeyName(), e.getValue()); } 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..9fb55fd64d 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) { @@ -193,6 +193,10 @@ public class EntityParser { if (wbs != null) { am.setAdditionalInfo("wikipedia", wbs); } + String tagCategory = getTagCategory(entity); + if (tagCategory != null) { + am.setAdditionalInfo("profile", tagCategory); + } if (checkAmenitiesToAdd(am, amenitiesList) && !"no".equals(am.getSubType())) { amenitiesList.add(am); } @@ -201,9 +205,27 @@ public class EntityParser { } return amenitiesList; } - - - + + private static String getTagCategory(Entity e) { + Map tags = e.getTags(); + for (String key : tags.keySet()) { + if (key.startsWith("tag_")) { + switch (tags.get(key).trim()) { + case "bicycle": + case "cycling": + case "mtb": + return "bicycle"; + case "hiking": + case "hike": + case "walking": + case "walk": + return "pedestrian"; + } + } + } + return null; + } + private static boolean checkAmenitiesToAdd(Amenity a, List amenitiesList){ // check amenity for duplication for(Amenity b : amenitiesList){ @@ -212,9 +234,9 @@ public class EntityParser { } } return true; - + } - + public static Building parseBuilding(Entity e){ Building b = new Building(); parseMapObject(b, e, e.getTags()); @@ -228,7 +250,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 +258,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 +274,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()); From 2ae5bb6301d52328a1e4eb42a127ebaafbd083dd Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Fri, 29 Jan 2021 13:45:09 +0200 Subject: [PATCH 04/14] refactoring --- OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java b/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java index 77507de50c..e273fa4e7f 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java @@ -915,14 +915,14 @@ public class MapPoiTypes { if (!otag.equals(tag) && !otag.equals("name")) { PoiType pat = poiTypesByTag.get(otag + "/" + e.getValue()); if (pat == null) { - for (String splValue : e.getValue().split(";")) { + for(String splValue : e.getValue().split(";")) { PoiType ps = poiTypesByTag.get(otag + "/" + splValue.trim()); - if (ps != null) { + if(ps != null) { a.setAdditionalInfo(ps.getKeyName(), splValue.trim()); } } pat = poiTypesByTag.get(otag); - } + } if (pat != null && pat.isAdditional()) { a.setAdditionalInfo(pat.getKeyName(), e.getValue()); } From e150d39c61fe9597c8ecac4dee2611b8ae76f353 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Fri, 29 Jan 2021 13:56:10 +0200 Subject: [PATCH 05/14] rename --- .../src/main/java/net/osmand/osm/edit/EntityParser.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 9fb55fd64d..e21927477a 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 @@ -193,9 +193,9 @@ public class EntityParser { if (wbs != null) { am.setAdditionalInfo("wikipedia", wbs); } - String tagCategory = getTagCategory(entity); - if (tagCategory != null) { - am.setAdditionalInfo("profile", tagCategory); + String profileName = getProfileName(entity); + if (profileName != null) { + am.setAdditionalInfo("profile", profileName); } if (checkAmenitiesToAdd(am, amenitiesList) && !"no".equals(am.getSubType())) { amenitiesList.add(am); @@ -206,7 +206,7 @@ public class EntityParser { return amenitiesList; } - private static String getTagCategory(Entity e) { + private static String getProfileName(Entity e) { Map tags = e.getTags(); for (String key : tags.keySet()) { if (key.startsWith("tag_")) { From d8ff9fb1e7e29becba9ce394feff12cb09bac0d5 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Sat, 30 Jan 2021 17:02:37 +0200 Subject: [PATCH 06/14] Add route activity type --- .../net/osmand/osm/edit/EntityParser.java | 24 ------------------- .../res/layout/wikivoyage_travel_gpx_card.xml | 6 ++--- .../plus/wikivoyage/data/TravelGpx.java | 4 ++-- .../plus/wikivoyage/data/TravelObfHelper.java | 4 ++-- .../explore/SavedArticlesRvAdapter.java | 10 ++++---- .../explore/travelcards/TravelGpxCard.java | 22 ++++++++--------- 6 files changed, 23 insertions(+), 47 deletions(-) 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 e21927477a..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 @@ -193,10 +193,6 @@ public class EntityParser { if (wbs != null) { am.setAdditionalInfo("wikipedia", wbs); } - String profileName = getProfileName(entity); - if (profileName != null) { - am.setAdditionalInfo("profile", profileName); - } if (checkAmenitiesToAdd(am, amenitiesList) && !"no".equals(am.getSubType())) { amenitiesList.add(am); } @@ -206,26 +202,6 @@ public class EntityParser { return amenitiesList; } - private static String getProfileName(Entity e) { - Map tags = e.getTags(); - for (String key : tags.keySet()) { - if (key.startsWith("tag_")) { - switch (tags.get(key).trim()) { - case "bicycle": - case "cycling": - case "mtb": - return "bicycle"; - case "hiking": - case "hike": - case "walking": - case "walk": - return "pedestrian"; - } - } - } - return null; - } - private static boolean checkAmenitiesToAdd(Amenity a, List amenitiesList){ // check amenity for duplication for(Amenity b : amenitiesList){ diff --git a/OsmAnd/res/layout/wikivoyage_travel_gpx_card.xml b/OsmAnd/res/layout/wikivoyage_travel_gpx_card.xml index b3aaf7e849..963c27c9f3 100644 --- a/OsmAnd/res/layout/wikivoyage_travel_gpx_card.xml +++ b/OsmAnd/res/layout/wikivoyage_travel_gpx_card.xml @@ -180,7 +180,7 @@ Date: Tue, 2 Feb 2021 23:34:57 +0200 Subject: [PATCH 07/14] Add activity types --- .../net/osmand/osm/RouteActivityType.java | 50 +++++++++++++++---- OsmAnd/res/values/strings.xml | 13 +++++ .../explore/travelcards/TravelGpxCard.java | 21 +++++--- 3 files changed, 67 insertions(+), 17 deletions(-) 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..06471b933f 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/RouteActivityType.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/RouteActivityType.java @@ -1,29 +1,58 @@ 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"); + WATER("Water", "yellow", "ic_action_motorboat", "activity_type_water"), + WINTER("Winter", "yellow", "ic_action_skiing", "activity_type_winter"), + SNOWMOBILE("Snowmobile", "yellow", "ic_action_snowmobile", "activity_type_snowmobile"), + RIDING("Riding", "yellow", "ic_action_horse", "activity_type_riding"), + RACING("Racing", "yellow", "ic_action_point_destination", "activity_type_racing"), + MOUNTAINBIKE("Mountainbike", "blue", "ic_action_bicycle_dark", "activity_type_mountainbike"), + CYCLING("Cycling", "blue", "ic_action_bicycle_dark", "activity_type_cycling"), + HIKING("Hiking", "orange", "ic_action_trekking_dark", "activity_type_hiking"), + RUNNING("Running", "orange", "ic_action_pedestrian_dark", "activity_type_running"), + WALKING("Walking", "orange", "ic_action_pedestrian_dark", "activity_type_walking"), + OFFROAD("Off-road", "yellow", "ic_action_offroad", "activity_type_offroad"), + MOTORBIKE("Motorbike", "green", "ic_action_motorcycle_dark", "activity_type_motorbike"), + CAR("Car", "green", "ic_action_car_dark", "activity_type_car"); // less specific bottom order String name; String color; + String icon; + String title; - private RouteActivityType(String nm, String clr) { + RouteActivityType(String nm, String clr, String icon, String title) { this.name = nm; this.color = clr; + this.icon = icon; + this.title = title; } - + public String getName() { return name; } - + public String getColor() { return color; } - + + public String getIcon() { + return icon; + } + + public String getTitle() { + return title; + } + + public static RouteActivityType getTypeFromName(String name) { + for (RouteActivityType rat : values()) { + if (rat.name().equalsIgnoreCase(name)) { + return rat; + } + } + return null; + } + public static RouteActivityType getTypeFromTags(String[] tags) { RouteActivityType activityType = null; for (String tg : tags) { @@ -36,7 +65,7 @@ public enum RouteActivityType { } return activityType; } - + public static RouteActivityType convertFromOsmGPXTag(String tg) { String t = tg.toLowerCase(); if ("mountain hiking".equalsIgnoreCase(t)) { @@ -214,5 +243,4 @@ public enum RouteActivityType { } return null; } - } \ No newline at end of file diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 1d23e9db07..f17e06d46f 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 Hillshade / Slope / Contour lines Select edits for upload Uploaded %1$d of %2$d diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java index 3677da0f41..c602f02a03 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java @@ -9,14 +9,13 @@ import androidx.annotation.NonNull; import androidx.fragment.app.FragmentActivity; import androidx.recyclerview.widget.RecyclerView; +import net.osmand.osm.RouteActivityType; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; -import net.osmand.plus.profiles.ProfileIcons; import net.osmand.plus.track.TrackMenuFragment; import net.osmand.plus.wikivoyage.data.TravelGpx; import net.osmand.plus.wikivoyage.data.TravelLocalDataHelper; -import net.osmand.util.Algorithms; import java.io.File; @@ -44,10 +43,10 @@ public class TravelGpxCard extends BaseTravelCard { holder.title.setText(article.getTitle()); holder.userIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_user_account_16)); holder.user.setText(article.user); - if (!Algorithms.isEmpty(article.activityType)) { - ProfileIcons profileRes = ProfileIcons.valueOf(article.activityType.toUpperCase()); - holder.activityTypeIcon.setImageDrawable(getActiveIcon(profileRes.getResId())); - holder.activityType.setText(profileRes.getTitleId()); + RouteActivityType activityType = RouteActivityType.getTypeFromName(article.activityType); + if (activityType != null) { + holder.activityTypeIcon.setImageDrawable(getActivityTypeIcon(activityType)); + holder.activityType.setText(getActivityTypeName(activityType)); holder.activityTypeLabel.setVisibility(View.VISIBLE); } holder.distance.setText(OsmAndFormatter.getFormattedDistance(article.totalDistance, app)); @@ -72,6 +71,16 @@ public class TravelGpxCard extends BaseTravelCard { } } + private Drawable getActivityTypeIcon(RouteActivityType activityType) { + int iconId = app.getResources().getIdentifier(activityType.getIcon(), "drawable", app.getPackageName()); + return getActiveIcon(iconId > 0 ? iconId : R.drawable.ic_action_route_distance); + } + + private int getActivityTypeName(RouteActivityType activityType) { + int titleId = app.getResources().getIdentifier(activityType.getTitle(), "string", app.getPackageName()); + return titleId > 0 ? titleId : R.string.layer_route; + } + private void updateSaveButton(final TravelGpxVH holder) { if (article != null) { final TravelLocalDataHelper helper = app.getTravelHelper().getBookmarksHelper(); From 0672f140aff60eb727954001436c345daaf6fa61 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Wed, 3 Feb 2021 11:24:22 +0200 Subject: [PATCH 08/14] Check resource --- .../explore/travelcards/TravelGpxCard.java | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java index c602f02a03..69772bac1c 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java @@ -5,7 +5,9 @@ import android.view.View; import android.widget.ImageView; import android.widget.TextView; +import androidx.annotation.DrawableRes; import androidx.annotation.NonNull; +import androidx.annotation.StringRes; import androidx.fragment.app.FragmentActivity; import androidx.recyclerview.widget.RecyclerView; @@ -45,9 +47,13 @@ public class TravelGpxCard extends BaseTravelCard { holder.user.setText(article.user); RouteActivityType activityType = RouteActivityType.getTypeFromName(article.activityType); if (activityType != null) { - holder.activityTypeIcon.setImageDrawable(getActivityTypeIcon(activityType)); - holder.activityType.setText(getActivityTypeName(activityType)); - holder.activityTypeLabel.setVisibility(View.VISIBLE); + int iconId = getActivityTypeIcon(activityType); + int titleId = getActivityTypeTitle(activityType); + if (iconId > 0 && titleId > 0) { + holder.activityTypeIcon.setImageDrawable(getActiveIcon(iconId)); + holder.activityType.setText(titleId); + holder.activityTypeLabel.setVisibility(View.VISIBLE); + } } holder.distance.setText(OsmAndFormatter.getFormattedDistance(article.totalDistance, app)); holder.diffElevationUp.setText(OsmAndFormatter.getFormattedAlt(article.diffElevationUp, app)); @@ -71,14 +77,14 @@ public class TravelGpxCard extends BaseTravelCard { } } - private Drawable getActivityTypeIcon(RouteActivityType activityType) { - int iconId = app.getResources().getIdentifier(activityType.getIcon(), "drawable", app.getPackageName()); - return getActiveIcon(iconId > 0 ? iconId : R.drawable.ic_action_route_distance); + @DrawableRes + private int getActivityTypeIcon(RouteActivityType activityType) { + return app.getResources().getIdentifier(activityType.getIcon(), "drawable", app.getPackageName()); } - private int getActivityTypeName(RouteActivityType activityType) { - int titleId = app.getResources().getIdentifier(activityType.getTitle(), "string", app.getPackageName()); - return titleId > 0 ? titleId : R.string.layer_route; + @StringRes + private int getActivityTypeTitle(RouteActivityType activityType) { + return app.getResources().getIdentifier(activityType.getTitle(), "string", app.getPackageName()); } private void updateSaveButton(final TravelGpxVH holder) { From e9b02ae74bb32b9151740c595ab6dfa0f355c79a Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Wed, 3 Feb 2021 16:52:24 +0200 Subject: [PATCH 09/14] Renew activity icon --- .../net/osmand/osm/RouteActivityType.java | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) 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 06471b933f..e7a7a0600a 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/RouteActivityType.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/RouteActivityType.java @@ -1,19 +1,19 @@ package net.osmand.osm; public enum RouteActivityType { - WATER("Water", "yellow", "ic_action_motorboat", "activity_type_water"), - WINTER("Winter", "yellow", "ic_action_skiing", "activity_type_winter"), - SNOWMOBILE("Snowmobile", "yellow", "ic_action_snowmobile", "activity_type_snowmobile"), - RIDING("Riding", "yellow", "ic_action_horse", "activity_type_riding"), - RACING("Racing", "yellow", "ic_action_point_destination", "activity_type_racing"), - MOUNTAINBIKE("Mountainbike", "blue", "ic_action_bicycle_dark", "activity_type_mountainbike"), - CYCLING("Cycling", "blue", "ic_action_bicycle_dark", "activity_type_cycling"), - HIKING("Hiking", "orange", "ic_action_trekking_dark", "activity_type_hiking"), - RUNNING("Running", "orange", "ic_action_pedestrian_dark", "activity_type_running"), - WALKING("Walking", "orange", "ic_action_pedestrian_dark", "activity_type_walking"), - OFFROAD("Off-road", "yellow", "ic_action_offroad", "activity_type_offroad"), - MOTORBIKE("Motorbike", "green", "ic_action_motorcycle_dark", "activity_type_motorbike"), - CAR("Car", "green", "ic_action_car_dark", "activity_type_car"); + WATER("Water", "yellow", "mx_special_kayak", "activity_type_water"), + WINTER("Winter", "yellow", "mx_special_skiing", "activity_type_winter"), + SNOWMOBILE("Snowmobile", "yellow", "mx_special_snowmobile", "activity_type_snowmobile"), + RIDING("Riding", "yellow", "mx_special_horse", "activity_type_riding"), + RACING("Racing", "yellow", "mx_raceway", "activity_type_racing"), + MOUNTAINBIKE("Mountainbike", "blue", "mx_sport_cycling", "activity_type_mountainbike"), + CYCLING("Cycling", "blue", "mx_special_bicycle", "activity_type_cycling"), + HIKING("Hiking", "orange", "mx_special_trekking", "activity_type_hiking"), + RUNNING("Running", "orange", "mx_running", "activity_type_running"), + WALKING("Walking", "orange", " mx_special_walking", "activity_type_walking"), + OFFROAD("Off-road", "yellow", "mx_special_offroad", "activity_type_offroad"), + MOTORBIKE("Motorbike", "green", "mx_special_motorcycle", "activity_type_motorbike"), + CAR("Car", "green", "mx_shop_car", "activity_type_car"); // less specific bottom order String name; From f20a8882bde3bdc16dac8f828c7a39635255fdeb Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Sat, 6 Feb 2021 13:11:49 +0200 Subject: [PATCH 10/14] Fix get activity type name and icon --- .../net/osmand/osm/RouteActivityType.java | 34 ++++++++----------- OsmAnd/res/values/strings.xml | 26 +++++++------- OsmAnd/src/net/osmand/AndroidUtils.java | 6 ++++ .../explore/travelcards/TravelGpxCard.java | 19 ++++++----- 4 files changed, 43 insertions(+), 42 deletions(-) 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 e7a7a0600a..6f8a0b0e9a 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/RouteActivityType.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/RouteActivityType.java @@ -1,31 +1,29 @@ package net.osmand.osm; public enum RouteActivityType { - WATER("Water", "yellow", "mx_special_kayak", "activity_type_water"), - WINTER("Winter", "yellow", "mx_special_skiing", "activity_type_winter"), - SNOWMOBILE("Snowmobile", "yellow", "mx_special_snowmobile", "activity_type_snowmobile"), - RIDING("Riding", "yellow", "mx_special_horse", "activity_type_riding"), - RACING("Racing", "yellow", "mx_raceway", "activity_type_racing"), - MOUNTAINBIKE("Mountainbike", "blue", "mx_sport_cycling", "activity_type_mountainbike"), - CYCLING("Cycling", "blue", "mx_special_bicycle", "activity_type_cycling"), - HIKING("Hiking", "orange", "mx_special_trekking", "activity_type_hiking"), - RUNNING("Running", "orange", "mx_running", "activity_type_running"), - WALKING("Walking", "orange", " mx_special_walking", "activity_type_walking"), - OFFROAD("Off-road", "yellow", "mx_special_offroad", "activity_type_offroad"), - MOTORBIKE("Motorbike", "green", "mx_special_motorcycle", "activity_type_motorbike"), - CAR("Car", "green", "mx_shop_car", "activity_type_car"); + WATER("water", "yellow", "special_kayak"), + WINTER("winter", "yellow", "special_skiing"), + SNOWMOBILE("snowmobile", "yellow", "special_snowmobile"), + RIDING("riding", "yellow", "special_horse"), + RACING("racing", "yellow", "raceway"), + MOUNTAINBIKE("mountainbike", "blue", "sport_cycling"), + CYCLING("cycling", "blue", "special_bicycle"), + HIKING("hiking", "orange", "special_trekking"), + RUNNING("running", "orange", "running"), + WALKING("walking", "orange", "special_walking"), + OFFROAD("offroad", "yellow", "special_offroad"), + MOTORBIKE("motorbike", "green", "special_motorcycle"), + CAR("car", "green", "shop_car"); // less specific bottom order String name; String color; String icon; - String title; - RouteActivityType(String nm, String clr, String icon, String title) { + RouteActivityType(String nm, String clr, String icon) { this.name = nm; this.color = clr; this.icon = icon; - this.title = title; } public String getName() { @@ -40,10 +38,6 @@ public enum RouteActivityType { return icon; } - public String getTitle() { - return title; - } - public static RouteActivityType getTypeFromName(String name) { for (RouteActivityType rat : values()) { if (rat.name().equalsIgnoreCase(name)) { diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 0c2feea060..8b1a73aa95 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -12,19 +12,19 @@ --> - Car - Motorbike - Off-road - Walking - Running - Hiking - Cycling - Mountainbike - Racing - Riding - Snowmobile - Winter - Water + 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/explore/travelcards/TravelGpxCard.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java index 69772bac1c..119df5a54a 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java @@ -7,10 +7,10 @@ import android.widget.TextView; import androidx.annotation.DrawableRes; import androidx.annotation.NonNull; -import androidx.annotation.StringRes; import androidx.fragment.app.FragmentActivity; import androidx.recyclerview.widget.RecyclerView; +import net.osmand.AndroidUtils; import net.osmand.osm.RouteActivityType; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; @@ -21,6 +21,8 @@ import net.osmand.plus.wikivoyage.data.TravelLocalDataHelper; import java.io.File; +import static net.osmand.util.Algorithms.capitalizeFirstLetterAndLowercase; + public class TravelGpxCard extends BaseTravelCard { public static final int TYPE = 3; @@ -48,12 +50,11 @@ public class TravelGpxCard extends BaseTravelCard { RouteActivityType activityType = RouteActivityType.getTypeFromName(article.activityType); if (activityType != null) { int iconId = getActivityTypeIcon(activityType); - int titleId = getActivityTypeTitle(activityType); - if (iconId > 0 && titleId > 0) { + if (iconId > 0) { holder.activityTypeIcon.setImageDrawable(getActiveIcon(iconId)); - holder.activityType.setText(titleId); - holder.activityTypeLabel.setVisibility(View.VISIBLE); } + holder.activityType.setText(getActivityTypeTitle(activityType)); + holder.activityTypeLabel.setVisibility(View.VISIBLE); } holder.distance.setText(OsmAndFormatter.getFormattedDistance(article.totalDistance, app)); holder.diffElevationUp.setText(OsmAndFormatter.getFormattedAlt(article.diffElevationUp, app)); @@ -79,12 +80,12 @@ public class TravelGpxCard extends BaseTravelCard { @DrawableRes private int getActivityTypeIcon(RouteActivityType activityType) { - return app.getResources().getIdentifier(activityType.getIcon(), "drawable", app.getPackageName()); + return app.getResources().getIdentifier("mx_" + activityType.getIcon(), "drawable", app.getPackageName()); } - @StringRes - private int getActivityTypeTitle(RouteActivityType activityType) { - return app.getResources().getIdentifier(activityType.getTitle(), "string", app.getPackageName()); + private String getActivityTypeTitle(RouteActivityType activityType) { + return AndroidUtils.getActivityTypeStringPropertyName(app, activityType.getName(), + capitalizeFirstLetterAndLowercase(activityType.getName())); } private void updateSaveButton(final TravelGpxVH holder) { From e261150279158cfe3d1e4afbf42391756f9d3a20 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Mon, 8 Feb 2021 16:41:10 +0200 Subject: [PATCH 11/14] Convert RouteActivityType to class --- .../net/osmand/osm/RouteActivityType.java | 64 +++++++++++++------ 1 file changed, 44 insertions(+), 20 deletions(-) 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 6f8a0b0e9a..01d5a5c98e 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/RouteActivityType.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/RouteActivityType.java @@ -1,29 +1,32 @@ package net.osmand.osm; -public enum RouteActivityType { - WATER("water", "yellow", "special_kayak"), - WINTER("winter", "yellow", "special_skiing"), - SNOWMOBILE("snowmobile", "yellow", "special_snowmobile"), - RIDING("riding", "yellow", "special_horse"), - RACING("racing", "yellow", "raceway"), - MOUNTAINBIKE("mountainbike", "blue", "sport_cycling"), - CYCLING("cycling", "blue", "special_bicycle"), - HIKING("hiking", "orange", "special_trekking"), - RUNNING("running", "orange", "running"), - WALKING("walking", "orange", "special_walking"), - OFFROAD("offroad", "yellow", "special_offroad"), - MOTORBIKE("motorbike", "green", "special_motorcycle"), - CAR("car", "green", "shop_car"); - // 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 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; - RouteActivityType(String nm, String clr, String icon) { + RouteActivityType(String nm, String clr) { this.name = nm; this.color = clr; - this.icon = icon; } public String getName() { @@ -39,20 +42,26 @@ public enum RouteActivityType { } public static RouteActivityType getTypeFromName(String name) { - for (RouteActivityType rat : values()) { - if (rat.name().equalsIgnoreCase(name)) { + for (RouteActivityType rat : values) { + if (rat.name.equalsIgnoreCase(name)) { return rat; } } return null; } + 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; } } @@ -237,4 +246,19 @@ 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 From 2efd0cad00b55700fe06d7faa55b7ce0fb2a37b9 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Mon, 8 Feb 2021 18:27:18 +0200 Subject: [PATCH 12/14] Add custom activity type --- .../src/main/java/net/osmand/osm/RouteActivityType.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 01d5a5c98e..65fa50bf68 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/RouteActivityType.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/RouteActivityType.java @@ -5,6 +5,8 @@ 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(); @@ -47,7 +49,7 @@ public class RouteActivityType { return rat; } } - return null; + return createType(name.toLowerCase(), DEFAULT_COLOR).icon(DEFAULT_ICON).reg(); } private static RouteActivityTypeBuilder createType(String name, String color) { From 455518decc5632ff10cd5938f9e7ad17342b4fdf Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Mon, 8 Feb 2021 18:44:21 +0200 Subject: [PATCH 13/14] Add custom activity type --- .../wikivoyage/explore/travelcards/TravelGpxCard.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java index 119df5a54a..795980df32 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java @@ -48,14 +48,9 @@ public class TravelGpxCard extends BaseTravelCard { holder.userIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_user_account_16)); holder.user.setText(article.user); RouteActivityType activityType = RouteActivityType.getTypeFromName(article.activityType); - if (activityType != null) { - int iconId = getActivityTypeIcon(activityType); - if (iconId > 0) { - holder.activityTypeIcon.setImageDrawable(getActiveIcon(iconId)); - } - holder.activityType.setText(getActivityTypeTitle(activityType)); - holder.activityTypeLabel.setVisibility(View.VISIBLE); - } + holder.activityTypeIcon.setImageDrawable(getActiveIcon(getActivityTypeIcon(activityType))); + holder.activityType.setText(getActivityTypeTitle(activityType)); + holder.activityTypeLabel.setVisibility(View.VISIBLE); holder.distance.setText(OsmAndFormatter.getFormattedDistance(article.totalDistance, app)); holder.diffElevationUp.setText(OsmAndFormatter.getFormattedAlt(article.diffElevationUp, app)); holder.diffElevationDown.setText(OsmAndFormatter.getFormattedAlt(article.diffElevationDown, app)); From 61a1d69c58c3e2bdbfb217b4f23d43bdc18f0602 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Tue, 9 Feb 2021 16:18:20 +0200 Subject: [PATCH 14/14] Fix empty activity type --- .../net/osmand/osm/RouteActivityType.java | 2 +- .../explore/SavedArticlesRvAdapter.java | 25 +++++++++++++++---- .../explore/travelcards/TravelGpxCard.java | 16 ++++++++---- 3 files changed, 32 insertions(+), 11 deletions(-) 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 65fa50bf68..7c54388f64 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/RouteActivityType.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/RouteActivityType.java @@ -43,7 +43,7 @@ public class RouteActivityType { return icon; } - public static RouteActivityType getTypeFromName(String name) { + public static RouteActivityType getOrCreateTypeFromName(String name) { for (RouteActivityType rat : values) { if (rat.name.equalsIgnoreCase(name)) { return rat; diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesRvAdapter.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesRvAdapter.java index 002b5587d4..9bccece08d 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesRvAdapter.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesRvAdapter.java @@ -18,12 +18,13 @@ import com.squareup.picasso.Callback; import com.squareup.picasso.Picasso; 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; import net.osmand.plus.UiUtilities; -import net.osmand.plus.profiles.ProfileIcons; import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.widgets.tools.CropCircleTransformation; import net.osmand.plus.wikipedia.WikiArticleHelper; @@ -37,6 +38,7 @@ 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 { @@ -140,10 +142,12 @@ public class SavedArticlesRvAdapter extends RecyclerView.Adapter