Fix empty activity type

This commit is contained in:
Dima-1 2021-02-09 16:18:20 +02:00
parent 455518decc
commit 61a1d69c58
3 changed files with 32 additions and 11 deletions

View file

@ -43,7 +43,7 @@ public class RouteActivityType {
return icon;
}
public static RouteActivityType getTypeFromName(String name) {
public static RouteActivityType getOrCreateTypeFromName(String name) {
for (RouteActivityType rat : values) {
if (rat.name.equalsIgnoreCase(name)) {
return rat;

View file

@ -18,12 +18,13 @@ import com.squareup.picasso.Callback;
import com.squareup.picasso.Picasso;
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;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.profiles.ProfileIcons;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.widgets.tools.CropCircleTransformation;
import net.osmand.plus.wikipedia.WikiArticleHelper;
@ -37,6 +38,7 @@ 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> {
@ -140,10 +142,12 @@ public class SavedArticlesRvAdapter extends RecyclerView.Adapter<RecyclerView.Vi
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 activityRes = ProfileIcons.valueOf(article.activityType.toUpperCase());
holder.activityTypeIcon.setImageDrawable(getActiveIcon(activityRes.getResId()));
holder.activityType.setText(activityRes.getTitleId());
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));
@ -165,6 +169,17 @@ public class SavedArticlesRvAdapter extends RecyclerView.Adapter<RecyclerView.Vi
}
}
@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();

View file

@ -18,6 +18,7 @@ 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;
@ -47,10 +48,14 @@ 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);
RouteActivityType activityType = RouteActivityType.getTypeFromName(article.activityType);
holder.activityTypeIcon.setImageDrawable(getActiveIcon(getActivityTypeIcon(activityType)));
holder.activityType.setText(getActivityTypeTitle(activityType));
holder.activityTypeLabel.setVisibility(View.VISIBLE);
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));
@ -75,7 +80,8 @@ public class TravelGpxCard extends BaseTravelCard {
@DrawableRes
private int getActivityTypeIcon(RouteActivityType activityType) {
return app.getResources().getIdentifier("mx_" + activityType.getIcon(), "drawable", app.getPackageName());
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) {