Skip to content

Commit

Permalink
Add route type in selection menu
Browse files Browse the repository at this point in the history
  • Loading branch information
0xRe1nk0 committed Jul 31, 2023
1 parent 40c7c9f commit 8087b78
Showing 1 changed file with 27 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package net.osmand.plus.mapcontextmenu.other;

import static net.osmand.plus.utils.AndroidUtils.getActivityTypeStringPropertyName;
import static net.osmand.router.network.NetworkRouteSelector.RouteKey;
import static net.osmand.util.Algorithms.capitalizeFirstLetterAndLowercase;

import android.graphics.drawable.Drawable;
import android.util.Pair;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
Expand Down Expand Up @@ -84,15 +89,7 @@ public void onClick(View view) {
// Text line 2
TextView line2 = convertView.findViewById(R.id.context_menu_line2);
line2.setTextColor(ContextCompat.getColor(getContext(), R.color.ctx_menu_subtitle_color));
StringBuilder line2Str = new StringBuilder(item.getTypeStr());
String streetStr = item.getStreetStr();
if (!Algorithms.isEmpty(streetStr) && !item.displayStreetNameInTitle()) {
if (line2Str.length() > 0) {
line2Str.append(", ");
}
line2Str.append(streetStr);
}
line2.setText(line2Str);
line2.setText(getSecondLineText(item));
Drawable slIcon = item.getTypeIcon();
line2.setCompoundDrawablesWithIntrinsicBounds(slIcon, null, null, null);
line2.setCompoundDrawablePadding(AndroidUtils.dpToPx(menu.getMapActivity(), 5f));
Expand All @@ -105,6 +102,27 @@ public void onClick(View view) {
return convertView;
}

private String getSecondLineText(MenuObject item) {
StringBuilder line2Str = new StringBuilder(item.getTypeStr());
if (item.getObject() instanceof Pair) {
Pair<?, ?> pair = (Pair<?, ?>) item.getObject();
if (pair.first instanceof RouteKey) {
RouteKey key = (RouteKey) pair.first;
String tag = key.type.getTag();
String routeType = getActivityTypeStringPropertyName(item.getMyApplication(), tag, capitalizeFirstLetterAndLowercase(tag));
line2Str.append(" - ").append(routeType);
}
}
String streetStr = item.getStreetStr();
if (!Algorithms.isEmpty(streetStr) && !item.displayStreetNameInTitle()) {
if (line2Str.length() > 0) {
line2Str.append(", ");
}
line2Str.append(streetStr);
}
return line2Str.toString();
}

public interface OnClickListener {
void onClick(int position);
}
Expand Down

0 comments on commit 8087b78

Please sign in to comment.