Fix get activity type name and icon

This commit is contained in:
Dima-1 2021-02-06 13:11:49 +02:00
parent df3c171a9c
commit f20a8882bd
4 changed files with 43 additions and 42 deletions

View file

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

View file

@ -12,19 +12,19 @@
-->
<string name="activity_type_car">Car</string>
<string name="activity_type_motorbike">Motorbike</string>
<string name="activity_type_offroad">Off-road</string>
<string name="activity_type_walking">Walking</string>
<string name="activity_type_running">Running</string>
<string name="activity_type_hiking">Hiking</string>
<string name="activity_type_cycling">Cycling</string>
<string name="activity_type_mountainbike">Mountainbike</string>
<string name="activity_type_racing">Racing</string>
<string name="activity_type_riding">Riding</string>
<string name="activity_type_snowmobile">Snowmobile</string>
<string name="activity_type_winter">Winter</string>
<string name="activity_type_water">Water</string>
<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

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