Fix get activity type name and icon
This commit is contained in:
parent
df3c171a9c
commit
f20a8882bd
4 changed files with 43 additions and 42 deletions
|
@ -1,31 +1,29 @@
|
||||||
package net.osmand.osm;
|
package net.osmand.osm;
|
||||||
|
|
||||||
public enum RouteActivityType {
|
public enum RouteActivityType {
|
||||||
WATER("Water", "yellow", "mx_special_kayak", "activity_type_water"),
|
WATER("water", "yellow", "special_kayak"),
|
||||||
WINTER("Winter", "yellow", "mx_special_skiing", "activity_type_winter"),
|
WINTER("winter", "yellow", "special_skiing"),
|
||||||
SNOWMOBILE("Snowmobile", "yellow", "mx_special_snowmobile", "activity_type_snowmobile"),
|
SNOWMOBILE("snowmobile", "yellow", "special_snowmobile"),
|
||||||
RIDING("Riding", "yellow", "mx_special_horse", "activity_type_riding"),
|
RIDING("riding", "yellow", "special_horse"),
|
||||||
RACING("Racing", "yellow", "mx_raceway", "activity_type_racing"),
|
RACING("racing", "yellow", "raceway"),
|
||||||
MOUNTAINBIKE("Mountainbike", "blue", "mx_sport_cycling", "activity_type_mountainbike"),
|
MOUNTAINBIKE("mountainbike", "blue", "sport_cycling"),
|
||||||
CYCLING("Cycling", "blue", "mx_special_bicycle", "activity_type_cycling"),
|
CYCLING("cycling", "blue", "special_bicycle"),
|
||||||
HIKING("Hiking", "orange", "mx_special_trekking", "activity_type_hiking"),
|
HIKING("hiking", "orange", "special_trekking"),
|
||||||
RUNNING("Running", "orange", "mx_running", "activity_type_running"),
|
RUNNING("running", "orange", "running"),
|
||||||
WALKING("Walking", "orange", " mx_special_walking", "activity_type_walking"),
|
WALKING("walking", "orange", "special_walking"),
|
||||||
OFFROAD("Off-road", "yellow", "mx_special_offroad", "activity_type_offroad"),
|
OFFROAD("offroad", "yellow", "special_offroad"),
|
||||||
MOTORBIKE("Motorbike", "green", "mx_special_motorcycle", "activity_type_motorbike"),
|
MOTORBIKE("motorbike", "green", "special_motorcycle"),
|
||||||
CAR("Car", "green", "mx_shop_car", "activity_type_car");
|
CAR("car", "green", "shop_car");
|
||||||
// less specific bottom order
|
// less specific bottom order
|
||||||
|
|
||||||
String name;
|
String name;
|
||||||
String color;
|
String color;
|
||||||
String icon;
|
String icon;
|
||||||
String title;
|
|
||||||
|
|
||||||
RouteActivityType(String nm, String clr, String icon, String title) {
|
RouteActivityType(String nm, String clr, String icon) {
|
||||||
this.name = nm;
|
this.name = nm;
|
||||||
this.color = clr;
|
this.color = clr;
|
||||||
this.icon = icon;
|
this.icon = icon;
|
||||||
this.title = title;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
@ -40,10 +38,6 @@ public enum RouteActivityType {
|
||||||
return icon;
|
return icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTitle() {
|
|
||||||
return title;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static RouteActivityType getTypeFromName(String name) {
|
public static RouteActivityType getTypeFromName(String name) {
|
||||||
for (RouteActivityType rat : values()) {
|
for (RouteActivityType rat : values()) {
|
||||||
if (rat.name().equalsIgnoreCase(name)) {
|
if (rat.name().equalsIgnoreCase(name)) {
|
||||||
|
|
|
@ -12,19 +12,19 @@
|
||||||
|
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<string name="activity_type_car">Car</string>
|
<string name="activity_type_car_name">Car</string>
|
||||||
<string name="activity_type_motorbike">Motorbike</string>
|
<string name="activity_type_motorbike_name">Motorbike</string>
|
||||||
<string name="activity_type_offroad">Off-road</string>
|
<string name="activity_type_offroad_name">Off-road</string>
|
||||||
<string name="activity_type_walking">Walking</string>
|
<string name="activity_type_walking_name">Walking</string>
|
||||||
<string name="activity_type_running">Running</string>
|
<string name="activity_type_running_name">Running</string>
|
||||||
<string name="activity_type_hiking">Hiking</string>
|
<string name="activity_type_hiking_name">Hiking</string>
|
||||||
<string name="activity_type_cycling">Cycling</string>
|
<string name="activity_type_cycling_name">Cycling</string>
|
||||||
<string name="activity_type_mountainbike">Mountainbike</string>
|
<string name="activity_type_mountainbike_name">Mountainbike</string>
|
||||||
<string name="activity_type_racing">Racing</string>
|
<string name="activity_type_racing_name">Racing</string>
|
||||||
<string name="activity_type_riding">Riding</string>
|
<string name="activity_type_riding_name">Riding</string>
|
||||||
<string name="activity_type_snowmobile">Snowmobile</string>
|
<string name="activity_type_snowmobile_name">Snowmobile</string>
|
||||||
<string name="activity_type_winter">Winter</string>
|
<string name="activity_type_winter_name">Winter</string>
|
||||||
<string name="activity_type_water">Water</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);
|
||||||
|
|
|
@ -7,10 +7,10 @@ import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.annotation.DrawableRes;
|
import androidx.annotation.DrawableRes;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.StringRes;
|
|
||||||
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.osm.RouteActivityType;
|
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;
|
||||||
|
@ -21,6 +21,8 @@ import net.osmand.plus.wikivoyage.data.TravelLocalDataHelper;
|
||||||
|
|
||||||
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;
|
||||||
|
@ -48,12 +50,11 @@ public class TravelGpxCard extends BaseTravelCard {
|
||||||
RouteActivityType activityType = RouteActivityType.getTypeFromName(article.activityType);
|
RouteActivityType activityType = RouteActivityType.getTypeFromName(article.activityType);
|
||||||
if (activityType != null) {
|
if (activityType != null) {
|
||||||
int iconId = getActivityTypeIcon(activityType);
|
int iconId = getActivityTypeIcon(activityType);
|
||||||
int titleId = getActivityTypeTitle(activityType);
|
if (iconId > 0) {
|
||||||
if (iconId > 0 && titleId > 0) {
|
|
||||||
holder.activityTypeIcon.setImageDrawable(getActiveIcon(iconId));
|
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.distance.setText(OsmAndFormatter.getFormattedDistance(article.totalDistance, app));
|
||||||
holder.diffElevationUp.setText(OsmAndFormatter.getFormattedAlt(article.diffElevationUp, app));
|
holder.diffElevationUp.setText(OsmAndFormatter.getFormattedAlt(article.diffElevationUp, app));
|
||||||
|
@ -79,12 +80,12 @@ public class TravelGpxCard extends BaseTravelCard {
|
||||||
|
|
||||||
@DrawableRes
|
@DrawableRes
|
||||||
private int getActivityTypeIcon(RouteActivityType activityType) {
|
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 String getActivityTypeTitle(RouteActivityType activityType) {
|
||||||
private int getActivityTypeTitle(RouteActivityType activityType) {
|
return AndroidUtils.getActivityTypeStringPropertyName(app, activityType.getName(),
|
||||||
return app.getResources().getIdentifier(activityType.getTitle(), "string", app.getPackageName());
|
capitalizeFirstLetterAndLowercase(activityType.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateSaveButton(final TravelGpxVH holder) {
|
private void updateSaveButton(final TravelGpxVH holder) {
|
||||||
|
|
Loading…
Reference in a new issue