Merge pull request #10707 from osmandapp/travel_obf_gpx_profile

Travel - vehicle mode
This commit is contained in:
alex-osm 2021-02-09 17:24:20 +03:00 committed by GitHub
commit fee1b8983e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 235 additions and 63 deletions

View file

@ -1,17 +1,32 @@
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<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 color;
String icon;
private RouteActivityType(String nm, String clr) {
RouteActivityType(String nm, String clr) {
this.name = nm;
this.color = clr;
}
@ -24,12 +39,31 @@ public enum RouteActivityType {
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;
}
}
@ -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;
}
}
}

View file

@ -202,8 +202,6 @@ public class EntityParser {
return amenitiesList;
}
private static boolean checkAmenitiesToAdd(Amenity a, List<Amenity> amenitiesList){
// check amenity for duplication
for(Amenity b : amenitiesList){

View file

@ -139,31 +139,83 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="@dimen/content_padding_half"
android:paddingBottom="@dimen/content_padding_small">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/user_name"
<LinearLayout
android:id="@+id/user_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/btn_border_bg_light"
android:gravity="center_vertical"
android:ellipsize="end"
android:maxLines="1"
android:paddingTop="@dimen/subHeaderPadding"
android:paddingBottom="@dimen/subHeaderPadding"
android:paddingLeft="@dimen/bottom_sheet_content_padding_small"
android:paddingRight="@dimen/bottom_sheet_content_padding_small"
android:textAppearance="@style/TextAppearance.ContextMenuSubtitle"
android:textColor="?attr/active_color_basic"
android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_medium"
android:drawablePadding="@dimen/content_padding_small_half"
android:drawableStart="@drawable/ic_action_user_account_16"
android:drawableLeft="@drawable/ic_action_user_account_16"
tools:drawableTint="?attr/wikivoyage_active_color"
tools:text="Lorem Ipsum" />
android:background="?attr/btn_border_bg"
android:layout_marginLeft="@dimen/content_padding_half"
android:layout_marginStart="@dimen/content_padding_half">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/user_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_user_account_16" />
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/user_name"
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>
@ -172,7 +224,6 @@
<View
android:layout_width="match_parent"
android:visibility="invisible"
android:layout_height="1dp"
android:background="?attr/wikivoyage_card_divider_color" />

View file

@ -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="opr_use_dev_url">Use test.openplacereviews.org</string>
<string name="open_place_reviews">OpenPlaceReviews</string>

View file

@ -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);

View file

@ -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;

View file

@ -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;
}

View file

@ -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<RecyclerView.ViewHolder> {
private static final int HEADER_TYPE = 0;
@ -81,7 +85,7 @@ public class SavedArticlesRvAdapter extends RecyclerView.Adapter<RecyclerView.Vi
case ARTICLE_TYPE:
return new ItemVH(inflate(parent, R.layout.wikivoyage_article_card));
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:
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.divider.setVisibility(lastItem ? View.GONE : View.VISIBLE);
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 TravelGpxCard.TravelGpxVH holder = (TravelGpxCard.TravelGpxVH) viewHolder;
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.user.setText(WikiArticleHelper.getPartialContent(article.user));
AndroidUtils.setBackground(app, holder.user, nightMode, R.drawable.btn_border_bg_light, R.drawable.btn_border_bg_dark);
holder.userIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_user_account_16));
holder.user.setText(article.user);
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.diffElevationUp.setText(OsmAndFormatter.getFormattedAlt(article.diffElevationUp, 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) {
final TravelLocalDataHelper helper = app.getTravelHelper().getBookmarksHelper();
final boolean saved = helper.isArticleSaved(article);

View file

@ -2,22 +2,28 @@ 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.DrawableRes;
import androidx.annotation.NonNull;
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;
import net.osmand.plus.R;
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;
import static net.osmand.util.Algorithms.capitalizeFirstLetterAndLowercase;
public class TravelGpxCard extends BaseTravelCard {
public static final int TYPE = 3;
@ -40,10 +46,16 @@ 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);
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.diffElevationUp.setText(OsmAndFormatter.getFormattedAlt(article.diffElevationUp, 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) {
if (article != null) {
final TravelLocalDataHelper helper = app.getTravelHelper().getBookmarksHelper();
@ -92,6 +115,10 @@ public class TravelGpxCard extends BaseTravelCard {
public final TextView title;
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 diffElevationUp;
public final TextView diffElevationDown;
@ -104,6 +131,10 @@ 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);
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);
diffElevationUp = itemView.findViewById(R.id.diff_ele_up);
diffElevationDown = itemView.findViewById(R.id.diff_ele_down);