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;
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");
WATER("Water", "yellow", "ic_action_motorboat", "activity_type_water"),
WINTER("Winter", "yellow", "ic_action_skiing", "activity_type_winter"),
SNOWMOBILE("Snowmobile", "yellow", "ic_action_snowmobile", "activity_type_snowmobile"),
RIDING("Riding", "yellow", "ic_action_horse", "activity_type_riding"),
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
String name;
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.color = clr;
this.icon = icon;
this.title = title;
}
public String getName() {
@ -24,6 +36,23 @@ public enum RouteActivityType {
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) {
RouteActivityType activityType = null;
for (String tg : tags) {
@ -214,5 +243,4 @@ public enum RouteActivityType {
}
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="toast_select_edits_for_upload">Select edits for upload</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.recyclerview.widget.RecyclerView;
import net.osmand.osm.RouteActivityType;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.profiles.ProfileIcons;
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;
@ -44,10 +43,10 @@ public class TravelGpxCard extends BaseTravelCard {
holder.title.setText(article.getTitle());
holder.userIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_user_account_16));
holder.user.setText(article.user);
if (!Algorithms.isEmpty(article.activityType)) {
ProfileIcons profileRes = ProfileIcons.valueOf(article.activityType.toUpperCase());
holder.activityTypeIcon.setImageDrawable(getActiveIcon(profileRes.getResId()));
holder.activityType.setText(profileRes.getTitleId());
RouteActivityType activityType = RouteActivityType.getTypeFromName(article.activityType);
if (activityType != null) {
holder.activityTypeIcon.setImageDrawable(getActivityTypeIcon(activityType));
holder.activityType.setText(getActivityTypeName(activityType));
holder.activityTypeLabel.setVisibility(View.VISIBLE);
}
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) {
if (article != null) {
final TravelLocalDataHelper helper = app.getTravelHelper().getBookmarksHelper();