Add activity types

This commit is contained in:
Dima-1 2021-02-02 23:34:57 +02:00
parent 7f678334c2
commit 055c681f4b
3 changed files with 67 additions and 17 deletions

View file

@ -1,19 +1,31 @@
package net.osmand.osm; package net.osmand.osm;
public enum RouteActivityType { public enum RouteActivityType {
WATER("Water", "yellow"), WINTER("Winter", "yellow"), SNOWMOBILE("Snowmobile", "yellow"), RIDING("Riding", "yellow"), RACING("Racing", "yellow"), WATER("Water", "yellow", "ic_action_motorboat", "activity_type_water"),
MOUNTAINBIKE("Mountainbike", "blue"), CYCLING("Cycling", "blue"), WINTER("Winter", "yellow", "ic_action_skiing", "activity_type_winter"),
HIKING("Hiking", "orange"), RUNNING("Running", "orange"), WALKING("Walking", "orange"), SNOWMOBILE("Snowmobile", "yellow", "ic_action_snowmobile", "activity_type_snowmobile"),
OFFROAD("Off-road", "yellow"), RIDING("Riding", "yellow", "ic_action_horse", "activity_type_riding"),
MOTORBIKE("Motorbike", "green"), CAR("Car", "green"); 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 // less specific bottom order
String name; String name;
String color; 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.name = nm;
this.color = clr; this.color = clr;
this.icon = icon;
this.title = title;
} }
public String getName() { public String getName() {
@ -24,6 +36,23 @@ public enum RouteActivityType {
return color; 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) { public static RouteActivityType getTypeFromTags(String[] tags) {
RouteActivityType activityType = null; RouteActivityType activityType = null;
for (String tg : tags) { for (String tg : tags) {
@ -214,5 +243,4 @@ public enum RouteActivityType {
} }
return null; return null;
} }
} }

View file

@ -12,6 +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="hillshade_slope_contour_lines">Hillshade / Slope / Contour lines</string> <string name="hillshade_slope_contour_lines">Hillshade / Slope / Contour lines</string>
<string name="toast_select_edits_for_upload">Select edits for upload</string> <string name="toast_select_edits_for_upload">Select edits for upload</string>
<string name="uploaded_count">Uploaded %1$d of %2$d</string> <string name="uploaded_count">Uploaded %1$d of %2$d</string>

View file

@ -9,14 +9,13 @@ 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.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.profiles.ProfileIcons;
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;
@ -44,10 +43,10 @@ public class TravelGpxCard extends BaseTravelCard {
holder.title.setText(article.getTitle()); holder.title.setText(article.getTitle());
holder.userIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_user_account_16)); holder.userIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_user_account_16));
holder.user.setText(article.user); holder.user.setText(article.user);
if (!Algorithms.isEmpty(article.activityType)) { RouteActivityType activityType = RouteActivityType.getTypeFromName(article.activityType);
ProfileIcons profileRes = ProfileIcons.valueOf(article.activityType.toUpperCase()); if (activityType != null) {
holder.activityTypeIcon.setImageDrawable(getActiveIcon(profileRes.getResId())); holder.activityTypeIcon.setImageDrawable(getActivityTypeIcon(activityType));
holder.activityType.setText(profileRes.getTitleId()); holder.activityType.setText(getActivityTypeName(activityType));
holder.activityTypeLabel.setVisibility(View.VISIBLE); holder.activityTypeLabel.setVisibility(View.VISIBLE);
} }
holder.distance.setText(OsmAndFormatter.getFormattedDistance(article.totalDistance, app)); 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) { private void updateSaveButton(final TravelGpxVH holder) {
if (article != null) { if (article != null) {
final TravelLocalDataHelper helper = app.getTravelHelper().getBookmarksHelper(); final TravelLocalDataHelper helper = app.getTravelHelper().getBookmarksHelper();