Merge pull request #10707 from osmandapp/travel_obf_gpx_profile
Travel - vehicle mode
This commit is contained in:
commit
fee1b8983e
9 changed files with 235 additions and 63 deletions
|
@ -1,42 +1,76 @@
|
||||||
package net.osmand.osm;
|
package net.osmand.osm;
|
||||||
|
|
||||||
public enum RouteActivityType {
|
import java.util.ArrayList;
|
||||||
WATER("Water", "yellow"), WINTER("Winter", "yellow"), SNOWMOBILE("Snowmobile", "yellow"), RIDING("Riding", "yellow"), RACING("Racing", "yellow"),
|
import java.util.List;
|
||||||
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
|
|
||||||
|
|
||||||
|
public class RouteActivityType {
|
||||||
|
private static final List<RouteActivityType> 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 name;
|
||||||
String color;
|
String color;
|
||||||
|
String icon;
|
||||||
|
|
||||||
private RouteActivityType(String nm, String clr) {
|
RouteActivityType(String nm, String clr) {
|
||||||
this.name = nm;
|
this.name = nm;
|
||||||
this.color = clr;
|
this.color = clr;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getColor() {
|
public String getColor() {
|
||||||
return color;
|
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) {
|
public static RouteActivityType getTypeFromTags(String[] tags) {
|
||||||
RouteActivityType activityType = null;
|
RouteActivityType activityType = null;
|
||||||
for (String tg : tags) {
|
for (String tg : tags) {
|
||||||
RouteActivityType rat = RouteActivityType.convertFromOsmGPXTag(tg);
|
RouteActivityType rat = RouteActivityType.convertFromOsmGPXTag(tg);
|
||||||
if (rat != null) {
|
if (rat != null) {
|
||||||
if (activityType == null || activityType.ordinal() > rat.ordinal()) {
|
if (activityType == null || values.indexOf(activityType) > values.indexOf(rat)) {
|
||||||
activityType = rat;
|
activityType = rat;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return activityType;
|
return activityType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RouteActivityType convertFromOsmGPXTag(String tg) {
|
public static RouteActivityType convertFromOsmGPXTag(String tg) {
|
||||||
String t = tg.toLowerCase();
|
String t = tg.toLowerCase();
|
||||||
if ("mountain hiking".equalsIgnoreCase(t)) {
|
if ("mountain hiking".equalsIgnoreCase(t)) {
|
||||||
|
@ -215,4 +249,18 @@ public enum RouteActivityType {
|
||||||
return null;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -21,7 +21,7 @@ import net.osmand.osm.edit.Relation.RelationMember;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
public class EntityParser {
|
public class EntityParser {
|
||||||
|
|
||||||
public static void parseMapObject(MapObject mo, Entity e, Map<String, String> tags) {
|
public static void parseMapObject(MapObject mo, Entity e, Map<String, String> tags) {
|
||||||
mo.setId(e.getId());
|
mo.setId(e.getId());
|
||||||
if(mo instanceof Amenity) {
|
if(mo instanceof Amenity) {
|
||||||
|
@ -123,7 +123,7 @@ public class EntityParser {
|
||||||
mo.setName(ref);
|
mo.setName(ref);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setNameFromBrand(MapObject mo, Map<String, String> tags) {
|
private static void setNameFromBrand(MapObject mo, Map<String, String> tags) {
|
||||||
String ref = tags.get(OSMTagKey.BRAND.getValue());
|
String ref = tags.get(OSMTagKey.BRAND.getValue());
|
||||||
if(ref != null){
|
if(ref != null){
|
||||||
|
@ -140,7 +140,7 @@ public class EntityParser {
|
||||||
op += " [" + ref + "]";
|
op += " [" + ref + "]";
|
||||||
mo.setName(op);
|
mo.setName(op);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static String getWebSiteURL(Map<String, String> tagValues, boolean checkWikipedia) {
|
private static String getWebSiteURL(Map<String, String> tagValues, boolean checkWikipedia) {
|
||||||
String siteUrl = null;
|
String siteUrl = null;
|
||||||
|
@ -170,14 +170,14 @@ public class EntityParser {
|
||||||
}
|
}
|
||||||
return siteUrl;
|
return siteUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static List<Amenity> parseAmenities(MapPoiTypes poiTypes, Entity entity, Map<String, String> tags,
|
public static List<Amenity> parseAmenities(MapPoiTypes poiTypes, Entity entity, Map<String, String> tags,
|
||||||
List<Amenity> amenitiesList) {
|
List<Amenity> amenitiesList) {
|
||||||
amenitiesList.clear();
|
amenitiesList.clear();
|
||||||
// it could be collection of amenities
|
// it could be collection of amenities
|
||||||
boolean relation = entity instanceof Relation;
|
boolean relation = entity instanceof Relation;
|
||||||
boolean purerelation = relation &&
|
boolean purerelation = relation &&
|
||||||
!("multipolygon".equals(tags.get("type")) || "boundary".equals(tags.get("type")));
|
!("multipolygon".equals(tags.get("type")) || "boundary".equals(tags.get("type")));
|
||||||
Collection<Map<String, String>> it = MapRenderingTypes.splitTagsIntoDifferentObjects(tags);
|
Collection<Map<String, String>> it = MapRenderingTypes.splitTagsIntoDifferentObjects(tags);
|
||||||
for (Map<String, String> ts : it) {
|
for (Map<String, String> ts : it) {
|
||||||
|
@ -201,9 +201,7 @@ public class EntityParser {
|
||||||
}
|
}
|
||||||
return amenitiesList;
|
return amenitiesList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private static boolean checkAmenitiesToAdd(Amenity a, List<Amenity> amenitiesList){
|
private static boolean checkAmenitiesToAdd(Amenity a, List<Amenity> amenitiesList){
|
||||||
// check amenity for duplication
|
// check amenity for duplication
|
||||||
for(Amenity b : amenitiesList){
|
for(Amenity b : amenitiesList){
|
||||||
|
@ -212,9 +210,9 @@ public class EntityParser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Building parseBuilding(Entity e){
|
public static Building parseBuilding(Entity e){
|
||||||
Building b = new Building();
|
Building b = new Building();
|
||||||
parseMapObject(b, e, e.getTags());
|
parseMapObject(b, e, e.getTags());
|
||||||
|
@ -228,7 +226,7 @@ public class EntityParser {
|
||||||
List<Node> nodes = ((Way) e).getNodes();
|
List<Node> nodes = ((Way) e).getNodes();
|
||||||
for(int i = 0; i < nodes.size(); i++) {
|
for(int i = 0; i < nodes.size(); i++) {
|
||||||
Node node = nodes.get(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))) {
|
!Algorithms.isEmpty(node.getTag(OSMTagKey.REF))) {
|
||||||
b.addEntrance(node.getTag(OSMTagKey.REF), node.getLatLon());
|
b.addEntrance(node.getTag(OSMTagKey.REF), node.getLatLon());
|
||||||
}
|
}
|
||||||
|
@ -236,11 +234,11 @@ public class EntityParser {
|
||||||
}
|
}
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static City parseCity(Node el) {
|
public static City parseCity(Node el) {
|
||||||
return parseCity(el, CityType.valueFromString(el.getTag(OSMTagKey.PLACE.getValue())));
|
return parseCity(el, CityType.valueFromString(el.getTag(OSMTagKey.PLACE.getValue())));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static City parseCity(Entity el, CityType t) {
|
public static City parseCity(Entity el, CityType t) {
|
||||||
if(t == null) {
|
if(t == null) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -252,15 +250,15 @@ public class EntityParser {
|
||||||
c.setIsin(isin);
|
c.setIsin(isin);
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static TransportRoute parserRoute(Relation r, String ref){
|
public static TransportRoute parserRoute(Relation r, String ref){
|
||||||
TransportRoute rt = new TransportRoute();
|
TransportRoute rt = new TransportRoute();
|
||||||
parseMapObject(rt, r, r.getTags());
|
parseMapObject(rt, r, r.getTags());
|
||||||
rt.setRef(ref);
|
rt.setRef(ref);
|
||||||
return rt;
|
return rt;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TransportStop parseTransportStop(Entity e){
|
public static TransportStop parseTransportStop(Entity e){
|
||||||
TransportStop st = new TransportStop();
|
TransportStop st = new TransportStop();
|
||||||
parseMapObject(st, e, e.getTags());
|
parseMapObject(st, e, e.getTags());
|
||||||
|
|
|
@ -139,31 +139,83 @@
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical"
|
|
||||||
android:paddingTop="@dimen/content_padding_half"
|
android:paddingTop="@dimen/content_padding_half"
|
||||||
android:paddingBottom="@dimen/content_padding_small">
|
android:paddingBottom="@dimen/content_padding_small">
|
||||||
|
|
||||||
<net.osmand.plus.widgets.TextViewEx
|
<LinearLayout
|
||||||
android:id="@+id/user_name"
|
android:id="@+id/user_label"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="@drawable/btn_border_bg_light"
|
android:background="?attr/btn_border_bg"
|
||||||
android:gravity="center_vertical"
|
android:layout_marginLeft="@dimen/content_padding_half"
|
||||||
android:ellipsize="end"
|
android:layout_marginStart="@dimen/content_padding_half">
|
||||||
android:maxLines="1"
|
|
||||||
android:paddingTop="@dimen/subHeaderPadding"
|
<androidx.appcompat.widget.AppCompatImageView
|
||||||
android:paddingBottom="@dimen/subHeaderPadding"
|
android:id="@+id/user_icon"
|
||||||
android:paddingLeft="@dimen/bottom_sheet_content_padding_small"
|
android:layout_width="@dimen/poi_icon_size"
|
||||||
android:paddingRight="@dimen/bottom_sheet_content_padding_small"
|
android:layout_height="@dimen/poi_icon_size"
|
||||||
android:textAppearance="@style/TextAppearance.ContextMenuSubtitle"
|
android:layout_gravity="center_vertical"
|
||||||
android:textColor="?attr/active_color_basic"
|
android:layout_marginLeft="@dimen/content_padding_small_half"
|
||||||
android:textSize="@dimen/default_desc_text_size"
|
android:layout_marginStart="@dimen/content_padding_small_half"
|
||||||
osmand:typeface="@string/font_roboto_medium"
|
android:contentDescription="@string/shared_string_icon"
|
||||||
android:drawablePadding="@dimen/content_padding_small_half"
|
tools:src="@drawable/ic_action_user_account_16" />
|
||||||
android:drawableStart="@drawable/ic_action_user_account_16"
|
|
||||||
android:drawableLeft="@drawable/ic_action_user_account_16"
|
<net.osmand.plus.widgets.TextViewEx
|
||||||
tools:drawableTint="?attr/wikivoyage_active_color"
|
android:id="@+id/user_name"
|
||||||
tools:text="Lorem Ipsum" />
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:paddingTop="@dimen/subHeaderPadding"
|
||||||
|
android:paddingBottom="@dimen/subHeaderPadding"
|
||||||
|
android:paddingLeft="@dimen/content_padding_small_half"
|
||||||
|
android:paddingRight="@dimen/content_padding_small_half"
|
||||||
|
android:textAppearance="@style/TextAppearance.ContextMenuSubtitle"
|
||||||
|
android:textColor="?attr/active_color_basic"
|
||||||
|
android:textSize="@dimen/default_desc_text_size"
|
||||||
|
osmand:typeface="@string/font_roboto_medium"
|
||||||
|
tools:drawableTint="?attr/wikivoyage_active_color"
|
||||||
|
tools:text="@string/mapillary_menu_title_username" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/activity_type_label"
|
||||||
|
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">
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.AppCompatImageView
|
||||||
|
android:id="@+id/activity_type_icon"
|
||||||
|
android:layout_width="@dimen/poi_icon_size"
|
||||||
|
android:layout_height="@dimen/poi_icon_size"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:layout_marginLeft="@dimen/content_padding_small_half"
|
||||||
|
android:layout_marginStart="@dimen/content_padding_small_half"
|
||||||
|
android:contentDescription="@string/shared_string_icon"
|
||||||
|
tools:src="@drawable/ic_action_bicycle_dark" />
|
||||||
|
|
||||||
|
<net.osmand.plus.widgets.TextViewEx
|
||||||
|
android:id="@+id/activity_type"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:paddingTop="@dimen/subHeaderPadding"
|
||||||
|
android:paddingBottom="@dimen/subHeaderPadding"
|
||||||
|
android:paddingLeft="@dimen/content_padding_small_half"
|
||||||
|
android:paddingRight="@dimen/content_padding_small_half"
|
||||||
|
android:textAppearance="@style/TextAppearance.ContextMenuSubtitle"
|
||||||
|
android:textColor="?attr/active_color_basic"
|
||||||
|
android:textSize="@dimen/default_desc_text_size"
|
||||||
|
osmand:typeface="@string/font_roboto_medium"
|
||||||
|
tools:drawableTint="?attr/wikivoyage_active_color"
|
||||||
|
tools:text="@string/shared_string_profiles" />
|
||||||
|
</LinearLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
@ -172,7 +224,6 @@
|
||||||
|
|
||||||
<View
|
<View
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:visibility="invisible"
|
|
||||||
android:layout_height="1dp"
|
android:layout_height="1dp"
|
||||||
android:background="?attr/wikivoyage_card_divider_color" />
|
android:background="?attr/wikivoyage_card_divider_color" />
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,19 @@
|
||||||
|
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
<string name="activity_type_car_name">Car</string>
|
||||||
|
<string name="activity_type_motorbike_name">Motorbike</string>
|
||||||
|
<string name="activity_type_offroad_name">Off-road</string>
|
||||||
|
<string name="activity_type_walking_name">Walking</string>
|
||||||
|
<string name="activity_type_running_name">Running</string>
|
||||||
|
<string name="activity_type_hiking_name">Hiking</string>
|
||||||
|
<string name="activity_type_cycling_name">Cycling</string>
|
||||||
|
<string name="activity_type_mountainbike_name">Mountainbike</string>
|
||||||
|
<string name="activity_type_racing_name">Racing</string>
|
||||||
|
<string name="activity_type_riding_name">Riding</string>
|
||||||
|
<string name="activity_type_snowmobile_name">Snowmobile</string>
|
||||||
|
<string name="activity_type_winter_name">Winter</string>
|
||||||
|
<string name="activity_type_water_name">Water</string>
|
||||||
<string name="login_open_place_reviews">Login to OpenPlaceReviews</string>
|
<string name="login_open_place_reviews">Login to OpenPlaceReviews</string>
|
||||||
<string name="opr_use_dev_url">Use test.openplacereviews.org</string>
|
<string name="opr_use_dev_url">Use test.openplacereviews.org</string>
|
||||||
<string name="open_place_reviews">OpenPlaceReviews</string>
|
<string name="open_place_reviews">OpenPlaceReviews</string>
|
||||||
|
|
|
@ -951,6 +951,12 @@ public class AndroidUtils {
|
||||||
return value != null ? value : propertyValue;
|
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) {
|
private static String getStringByProperty(@NonNull Context ctx, @NonNull String property) {
|
||||||
try {
|
try {
|
||||||
Field field = R.string.class.getField(property);
|
Field field = R.string.class.getField(property);
|
||||||
|
|
|
@ -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_UP = "diff_ele_up";
|
||||||
public static final String DIFF_ELE_DOWN = "diff_ele_down";
|
public static final String DIFF_ELE_DOWN = "diff_ele_down";
|
||||||
public static final String USER = "user";
|
public static final String USER = "user";
|
||||||
|
public static final String ACTIVITY_TYPE = "route_activity_type";
|
||||||
|
|
||||||
public String user;
|
public String user;
|
||||||
|
public String activityType;
|
||||||
public float totalDistance = 0;
|
public float totalDistance = 0;
|
||||||
public double diffElevationUp = 0;
|
public double diffElevationUp = 0;
|
||||||
public double diffElevationDown = 0;
|
public double diffElevationDown = 0;
|
||||||
|
|
|
@ -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_DOWN;
|
||||||
import static net.osmand.plus.wikivoyage.data.TravelGpx.DIFF_ELE_UP;
|
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.DISTANCE;
|
||||||
|
import static net.osmand.plus.wikivoyage.data.TravelGpx.ACTIVITY_TYPE;
|
||||||
import static net.osmand.plus.wikivoyage.data.TravelGpx.USER;
|
import static net.osmand.plus.wikivoyage.data.TravelGpx.USER;
|
||||||
import static net.osmand.util.Algorithms.capitalizeFirstLetter;
|
import static net.osmand.util.Algorithms.capitalizeFirstLetter;
|
||||||
|
|
||||||
|
@ -203,6 +204,7 @@ public class TravelObfHelper implements TravelHelper {
|
||||||
LOG.debug(e.getMessage(), e);
|
LOG.debug(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
res.user = Algorithms.emptyIfNull(amenity.getTagContent(USER));
|
res.user = Algorithms.emptyIfNull(amenity.getTagContent(USER));
|
||||||
|
res.activityType = Algorithms.emptyIfNull(amenity.getTagContent(ACTIVITY_TYPE));
|
||||||
articles.put("en", res);
|
articles.put("en", res);
|
||||||
return articles;
|
return articles;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ import com.squareup.picasso.RequestCreator;
|
||||||
|
|
||||||
import net.osmand.AndroidUtils;
|
import net.osmand.AndroidUtils;
|
||||||
import net.osmand.PicassoUtils;
|
import net.osmand.PicassoUtils;
|
||||||
|
import net.osmand.osm.RouteActivityType;
|
||||||
import net.osmand.plus.OsmAndFormatter;
|
import net.osmand.plus.OsmAndFormatter;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.R;
|
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.TravelArticle;
|
||||||
import net.osmand.plus.wikivoyage.data.TravelGpx;
|
import net.osmand.plus.wikivoyage.data.TravelGpx;
|
||||||
import net.osmand.plus.wikivoyage.data.TravelLocalDataHelper;
|
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.ArrayList;
|
||||||
import java.util.List;
|
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<RecyclerView.ViewHolder> {
|
public class SavedArticlesRvAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||||
|
|
||||||
private static final int HEADER_TYPE = 0;
|
private static final int HEADER_TYPE = 0;
|
||||||
|
@ -81,7 +85,7 @@ public class SavedArticlesRvAdapter extends RecyclerView.Adapter<RecyclerView.Vi
|
||||||
case ARTICLE_TYPE:
|
case ARTICLE_TYPE:
|
||||||
return new ItemVH(inflate(parent, R.layout.wikivoyage_article_card));
|
return new ItemVH(inflate(parent, R.layout.wikivoyage_article_card));
|
||||||
case GPX_TYPE:
|
case GPX_TYPE:
|
||||||
return new TravelGpxCard.TravelGpxVH(inflate(parent, R.layout.wikivoyage_travel_gpx_card));
|
return new TravelGpxVH(inflate(parent, R.layout.wikivoyage_travel_gpx_card));
|
||||||
default:
|
default:
|
||||||
throw new RuntimeException("Unsupported view type: " + viewType);
|
throw new RuntimeException("Unsupported view type: " + viewType);
|
||||||
}
|
}
|
||||||
|
@ -132,14 +136,20 @@ public class SavedArticlesRvAdapter extends RecyclerView.Adapter<RecyclerView.Vi
|
||||||
holder.rightButton.setCompoundDrawablesWithIntrinsicBounds(null, null, deleteIcon, null);
|
holder.rightButton.setCompoundDrawablesWithIntrinsicBounds(null, null, deleteIcon, null);
|
||||||
holder.divider.setVisibility(lastItem ? View.GONE : View.VISIBLE);
|
holder.divider.setVisibility(lastItem ? View.GONE : View.VISIBLE);
|
||||||
holder.shadow.setVisibility(lastItem ? View.VISIBLE : View.GONE);
|
holder.shadow.setVisibility(lastItem ? View.VISIBLE : View.GONE);
|
||||||
} else if (viewHolder instanceof TravelGpxCard.TravelGpxVH) {
|
} else if (viewHolder instanceof TravelGpxVH) {
|
||||||
final TravelGpx article = (TravelGpx) getItem(position);
|
final TravelGpx article = (TravelGpx) getItem(position);
|
||||||
final TravelGpxCard.TravelGpxVH holder = (TravelGpxCard.TravelGpxVH) viewHolder;
|
final TravelGpxVH holder = (TravelGpxVH) viewHolder;
|
||||||
holder.title.setText(article.getTitle());
|
holder.title.setText(article.getTitle());
|
||||||
Drawable icon = getActiveIcon(R.drawable.ic_action_user_account_16);
|
holder.userIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_user_account_16));
|
||||||
holder.user.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
|
holder.user.setText(article.user);
|
||||||
holder.user.setText(WikiArticleHelper.getPartialContent(article.user));
|
String activityTypeKey = article.activityType;
|
||||||
AndroidUtils.setBackground(app, holder.user, nightMode, R.drawable.btn_border_bg_light, R.drawable.btn_border_bg_dark);
|
if (!Algorithms.isEmpty(activityTypeKey)) {
|
||||||
|
RouteActivityType activityType = RouteActivityType.getOrCreateTypeFromName(activityTypeKey);
|
||||||
|
int activityTypeIcon = getActivityTypeIcon(activityType);
|
||||||
|
holder.activityTypeIcon.setImageDrawable(getActiveIcon(activityTypeIcon));
|
||||||
|
holder.activityType.setText(getActivityTypeTitle(activityType));
|
||||||
|
holder.activityTypeLabel.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
holder.distance.setText(OsmAndFormatter.getFormattedDistance(article.totalDistance, app));
|
holder.distance.setText(OsmAndFormatter.getFormattedDistance(article.totalDistance, app));
|
||||||
holder.diffElevationUp.setText(OsmAndFormatter.getFormattedAlt(article.diffElevationUp, app));
|
holder.diffElevationUp.setText(OsmAndFormatter.getFormattedAlt(article.diffElevationUp, app));
|
||||||
holder.diffElevationDown.setText(OsmAndFormatter.getFormattedAlt(article.diffElevationDown, app));
|
holder.diffElevationDown.setText(OsmAndFormatter.getFormattedAlt(article.diffElevationDown, app));
|
||||||
|
@ -159,7 +169,18 @@ public class SavedArticlesRvAdapter extends RecyclerView.Adapter<RecyclerView.Vi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateSaveButton(final TravelGpxCard.TravelGpxVH holder, final TravelGpx article) {
|
@DrawableRes
|
||||||
|
private int getActivityTypeIcon(RouteActivityType activityType) {
|
||||||
|
int iconId = app.getResources().getIdentifier("mx_" + activityType.getIcon(), "drawable", app.getPackageName());
|
||||||
|
return iconId != 0 ? iconId : R.drawable.mx_special_marker;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getActivityTypeTitle(RouteActivityType activityType) {
|
||||||
|
return AndroidUtils.getActivityTypeStringPropertyName(app, activityType.getName(),
|
||||||
|
capitalizeFirstLetterAndLowercase(activityType.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateSaveButton(final TravelGpxVH holder, final TravelGpx article) {
|
||||||
if (article != null) {
|
if (article != null) {
|
||||||
final TravelLocalDataHelper helper = app.getTravelHelper().getBookmarksHelper();
|
final TravelLocalDataHelper helper = app.getTravelHelper().getBookmarksHelper();
|
||||||
final boolean saved = helper.isArticleSaved(article);
|
final boolean saved = helper.isArticleSaved(article);
|
||||||
|
|
|
@ -2,22 +2,28 @@ package net.osmand.plus.wikivoyage.explore.travelcards;
|
||||||
|
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.annotation.DrawableRes;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.fragment.app.FragmentActivity;
|
import androidx.fragment.app.FragmentActivity;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import net.osmand.AndroidUtils;
|
import net.osmand.AndroidUtils;
|
||||||
|
import net.osmand.osm.RouteActivityType;
|
||||||
import net.osmand.plus.OsmAndFormatter;
|
import net.osmand.plus.OsmAndFormatter;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.track.TrackMenuFragment;
|
import net.osmand.plus.track.TrackMenuFragment;
|
||||||
import net.osmand.plus.wikivoyage.data.TravelGpx;
|
import net.osmand.plus.wikivoyage.data.TravelGpx;
|
||||||
import net.osmand.plus.wikivoyage.data.TravelLocalDataHelper;
|
import net.osmand.plus.wikivoyage.data.TravelLocalDataHelper;
|
||||||
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
|
import static net.osmand.util.Algorithms.capitalizeFirstLetterAndLowercase;
|
||||||
|
|
||||||
public class TravelGpxCard extends BaseTravelCard {
|
public class TravelGpxCard extends BaseTravelCard {
|
||||||
|
|
||||||
public static final int TYPE = 3;
|
public static final int TYPE = 3;
|
||||||
|
@ -40,10 +46,16 @@ public class TravelGpxCard extends BaseTravelCard {
|
||||||
if (viewHolder instanceof TravelGpxVH) {
|
if (viewHolder instanceof TravelGpxVH) {
|
||||||
final TravelGpxVH holder = (TravelGpxVH) viewHolder;
|
final TravelGpxVH holder = (TravelGpxVH) viewHolder;
|
||||||
holder.title.setText(article.getTitle());
|
holder.title.setText(article.getTitle());
|
||||||
Drawable icon = getActiveIcon(R.drawable.ic_action_user_account_16);
|
holder.userIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_user_account_16));
|
||||||
holder.user.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
|
|
||||||
holder.user.setText(article.user);
|
holder.user.setText(article.user);
|
||||||
AndroidUtils.setBackground(app, holder.user, nightMode, R.drawable.btn_border_bg_light, R.drawable.btn_border_bg_dark);
|
String activityTypeKey = article.activityType;
|
||||||
|
if (!Algorithms.isEmpty(activityTypeKey)) {
|
||||||
|
RouteActivityType activityType = RouteActivityType.getOrCreateTypeFromName(activityTypeKey);
|
||||||
|
int activityTypeIcon = getActivityTypeIcon(activityType);
|
||||||
|
holder.activityTypeIcon.setImageDrawable(getActiveIcon(activityTypeIcon));
|
||||||
|
holder.activityType.setText(getActivityTypeTitle(activityType));
|
||||||
|
holder.activityTypeLabel.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
holder.distance.setText(OsmAndFormatter.getFormattedDistance(article.totalDistance, app));
|
holder.distance.setText(OsmAndFormatter.getFormattedDistance(article.totalDistance, app));
|
||||||
holder.diffElevationUp.setText(OsmAndFormatter.getFormattedAlt(article.diffElevationUp, app));
|
holder.diffElevationUp.setText(OsmAndFormatter.getFormattedAlt(article.diffElevationUp, app));
|
||||||
holder.diffElevationDown.setText(OsmAndFormatter.getFormattedAlt(article.diffElevationDown, app));
|
holder.diffElevationDown.setText(OsmAndFormatter.getFormattedAlt(article.diffElevationDown, app));
|
||||||
|
@ -66,6 +78,17 @@ public class TravelGpxCard extends BaseTravelCard {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DrawableRes
|
||||||
|
private int getActivityTypeIcon(RouteActivityType activityType) {
|
||||||
|
int iconId = app.getResources().getIdentifier("mx_" + activityType.getIcon(), "drawable", app.getPackageName());
|
||||||
|
return iconId != 0 ? iconId : R.drawable.mx_special_marker;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getActivityTypeTitle(RouteActivityType activityType) {
|
||||||
|
return AndroidUtils.getActivityTypeStringPropertyName(app, activityType.getName(),
|
||||||
|
capitalizeFirstLetterAndLowercase(activityType.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
private void updateSaveButton(final TravelGpxVH holder) {
|
private void updateSaveButton(final TravelGpxVH holder) {
|
||||||
if (article != null) {
|
if (article != null) {
|
||||||
final TravelLocalDataHelper helper = app.getTravelHelper().getBookmarksHelper();
|
final TravelLocalDataHelper helper = app.getTravelHelper().getBookmarksHelper();
|
||||||
|
@ -92,6 +115,10 @@ public class TravelGpxCard extends BaseTravelCard {
|
||||||
|
|
||||||
public final TextView title;
|
public final TextView title;
|
||||||
public final TextView user;
|
public final TextView user;
|
||||||
|
public final ImageView userIcon;
|
||||||
|
public final TextView activityType;
|
||||||
|
public final ImageView activityTypeIcon;
|
||||||
|
public final View activityTypeLabel;
|
||||||
public final TextView distance;
|
public final TextView distance;
|
||||||
public final TextView diffElevationUp;
|
public final TextView diffElevationUp;
|
||||||
public final TextView diffElevationDown;
|
public final TextView diffElevationDown;
|
||||||
|
@ -104,6 +131,10 @@ public class TravelGpxCard extends BaseTravelCard {
|
||||||
super(itemView);
|
super(itemView);
|
||||||
title = itemView.findViewById(R.id.title);
|
title = itemView.findViewById(R.id.title);
|
||||||
user = itemView.findViewById(R.id.user_name);
|
user = itemView.findViewById(R.id.user_name);
|
||||||
|
userIcon = itemView.findViewById(R.id.user_icon);
|
||||||
|
activityType = itemView.findViewById(R.id.activity_type);
|
||||||
|
activityTypeIcon = itemView.findViewById(R.id.activity_type_icon);
|
||||||
|
activityTypeLabel = itemView.findViewById(R.id.activity_type_label);
|
||||||
distance = itemView.findViewById(R.id.distance);
|
distance = itemView.findViewById(R.id.distance);
|
||||||
diffElevationUp = itemView.findViewById(R.id.diff_ele_up);
|
diffElevationUp = itemView.findViewById(R.id.diff_ele_up);
|
||||||
diffElevationDown = itemView.findViewById(R.id.diff_ele_down);
|
diffElevationDown = itemView.findViewById(R.id.diff_ele_down);
|
||||||
|
|
Loading…
Reference in a new issue