Fix transport stop context menu. Fix top route badge press.

This commit is contained in:
max-klaus 2019-08-03 19:17:47 +03:00
parent da55e5d963
commit e86bde9c61
4 changed files with 53 additions and 20 deletions

View file

@ -8,7 +8,6 @@ import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map;
public class TransportStop extends MapObject { public class TransportStop extends MapObject {
@ -111,6 +110,10 @@ public class TransportStop extends MapObject {
return !isDeleted() && referencesToRoutes != null && referencesToRoutes.length > 0; return !isDeleted() && referencesToRoutes != null && referencesToRoutes.length > 0;
} }
public boolean hasReferencesToRoutesMap() {
return !isDeleted() && referencesToRoutesMap != null && !referencesToRoutesMap.isEmpty();
}
public Amenity getAmenity() { public Amenity getAmenity() {
if (transportStopAggregated != null) { if (transportStopAggregated != null) {
return transportStopAggregated.getAmenity(); return transportStopAggregated.getAmenity();

View file

@ -161,7 +161,7 @@ public class TransportStopController extends MenuController {
private void addTransportStopRoutes(OsmandApplication app, List<TransportStop> stops, List<TransportStopRoute> routes, boolean useEnglishNames) { private void addTransportStopRoutes(OsmandApplication app, List<TransportStop> stops, List<TransportStopRoute> routes, boolean useEnglishNames) {
for (TransportStop tstop : stops) { for (TransportStop tstop : stops) {
if (tstop.hasReferencesToRoutes()) { if (tstop.hasReferencesToRoutesMap()) {
addRoutes(app, routes, useEnglishNames, tstop, transportStop, (int) MapUtils.getDistance(tstop.getLocation(), transportStop.getLocation())); addRoutes(app, routes, useEnglishNames, tstop, transportStop, (int) MapUtils.getDistance(tstop.getLocation(), transportStop.getLocation()));
} }
} }
@ -262,15 +262,19 @@ public class TransportStopController extends MenuController {
private static void processTransportStopAggregated(OsmandApplication app, TransportStop transportStop) { private static void processTransportStopAggregated(OsmandApplication app, TransportStop transportStop) {
TransportStopAggregated stopAggregated = new TransportStopAggregated(); TransportStopAggregated stopAggregated = new TransportStopAggregated();
transportStop.setTransportStopAggregated(stopAggregated); transportStop.setTransportStopAggregated(stopAggregated);
stopAggregated.addLocalTransportStop(transportStop); TransportStop localStop = null;
LatLon loc = transportStop.getLocation(); LatLon loc = transportStop.getLocation();
List<TransportStop> transportStops = findTransportStopsAt(app, loc.getLatitude(), loc.getLongitude(), SHOW_STOPS_RADIUS_METERS); List<TransportStop> transportStops = findTransportStopsAt(app, loc.getLatitude(), loc.getLongitude(), SHOW_STOPS_RADIUS_METERS);
if (transportStops != null) { if (transportStops != null) {
for (TransportStop stop : transportStops) { for (TransportStop stop : transportStops) {
stopAggregated.addNearbyTransportStop(stop); if (localStop == null && transportStop.getLocation().equals(stop.getLocation()) && transportStop.getName().equals(stop.getName())) {
localStop = stop;
} else {
stopAggregated.addNearbyTransportStop(stop);
}
} }
} }
stopAggregated.addLocalTransportStop(localStop == null ? transportStop : localStop);
} }
private static TransportStopAggregated processTransportStopsForAmenity(List<TransportStop> transportStops, Amenity amenity) { private static TransportStopAggregated processTransportStopsForAmenity(List<TransportStop> transportStops, Amenity amenity) {

View file

@ -543,6 +543,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
card.setRouteButtonsVisible(false); card.setRouteButtonsVisible(false);
card.setShowBottomShadow(false); card.setShowBottomShadow(false);
card.setShowTopShadow(false); card.setShowTopShadow(false);
card.setListener(this);
menuCards.add(card); menuCards.add(card);
hasTopCard = true; hasTopCard = true;
} }
@ -668,6 +669,10 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
if (card instanceof SimpleRouteCard) { if (card instanceof SimpleRouteCard) {
hide(); hide();
ChooseRouteFragment.showInstance(mapActivity.getSupportFragmentManager(), 0, MenuState.FULL_SCREEN); ChooseRouteFragment.showInstance(mapActivity.getSupportFragmentManager(), 0, MenuState.FULL_SCREEN);
} else if (card instanceof PublicTransportCard) {
hide();
ChooseRouteFragment.showInstance(mapActivity.getSupportFragmentManager(),
((PublicTransportCard) card).getRouteId(), MenuState.FULL_SCREEN);
} }
} }
} }

View file

@ -106,11 +106,28 @@ public class PublicTransportCard extends BaseCard {
@Override @Override
protected void updateContent() { protected void updateContent() {
List<TransportRouteResultSegment> segments = routeResult.getSegments(); List<TransportRouteResultSegment> segments = routeResult.getSegments();
createRouteBadges(segments); boolean badgesRowClickable = !routeInfoVisible && !routeButtonsVisible;
createRouteBadges(segments, badgesRowClickable);
view.findViewById(R.id.route_info).setVisibility(routeInfoVisible ? View.VISIBLE : View.GONE); view.findViewById(R.id.route_info).setVisibility(routeInfoVisible ? View.VISIBLE : View.GONE);
view.findViewById(R.id.route_buttons).setVisibility(routeButtonsVisible ? View.VISIBLE : View.GONE); view.findViewById(R.id.route_buttons).setVisibility(routeButtonsVisible ? View.VISIBLE : View.GONE);
view.findViewById(R.id.badges_padding).setVisibility(!routeInfoVisible && !routeButtonsVisible ? View.VISIBLE : View.GONE); if (badgesRowClickable) {
view.findViewById(R.id.badges_padding).setVisibility(View.VISIBLE);
view.setBackgroundResource(AndroidUtils.resolveAttribute(view.getContext(), R.attr.card_and_list_background_basic));
View info = view.findViewById(R.id.routes_info_container);
info.setBackgroundResource(AndroidUtils.resolveAttribute(view.getContext(), android.R.attr.selectableItemBackground));
info.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CardListener listener = getListener();
if (listener != null) {
listener.onCardPressed(PublicTransportCard.this);
}
}
});
} else {
view.findViewById(R.id.badges_padding).setVisibility(View.GONE);
}
TextView fromLine = (TextView) view.findViewById(R.id.from_line); TextView fromLine = (TextView) view.findViewById(R.id.from_line);
TextView wayLine = (TextView) view.findViewById(R.id.way_line); TextView wayLine = (TextView) view.findViewById(R.id.way_line);
@ -256,7 +273,7 @@ public class PublicTransportCard extends BaseCard {
return secondLineDesc; return secondLineDesc;
} }
private void createRouteBadges(List<TransportRouteResultSegment> segments) { private void createRouteBadges(List<TransportRouteResultSegment> segments, boolean badgesRowClickable) {
int itemsSpacing = AndroidUtils.dpToPx(app, 6); int itemsSpacing = AndroidUtils.dpToPx(app, 6);
FlowLayout routesBadges = (FlowLayout) view.findViewById(R.id.routes_badges); FlowLayout routesBadges = (FlowLayout) view.findViewById(R.id.routes_badges);
routesBadges.removeAllViews(); routesBadges.removeAllViews();
@ -270,7 +287,7 @@ public class PublicTransportCard extends BaseCard {
if (walkingSegment != null) { if (walkingSegment != null) {
double walkTime = walkingSegment.getRoutingTime(); double walkTime = walkingSegment.getRoutingTime();
if (walkTime > MIN_WALK_TIME) { if (walkTime > MIN_WALK_TIME) {
routesBadges.addView(createWalkRouteBadge(walkingSegment), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing)); routesBadges.addView(createWalkRouteBadge(walkingSegment, badgesRowClickable), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing));
routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing)); routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing));
} }
} else if (s.walkDist > 0) { } else if (s.walkDist > 0) {
@ -283,11 +300,11 @@ public class PublicTransportCard extends BaseCard {
} else { } else {
start = this.startLocation; start = this.startLocation;
} }
routesBadges.addView(createWalkRouteBadge(walkTime, start, end), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing)); routesBadges.addView(createWalkRouteBadge(walkTime, start, end, badgesRowClickable), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing));
routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing)); routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing));
} }
} }
routesBadges.addView(createRouteBadge(s), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing)); routesBadges.addView(createRouteBadge(s, badgesRowClickable), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing));
if (iterator.hasNext()) { if (iterator.hasNext()) {
routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing)); routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing));
} else { } else {
@ -296,7 +313,7 @@ public class PublicTransportCard extends BaseCard {
double walkTime = walkingSegment.getRoutingTime(); double walkTime = walkingSegment.getRoutingTime();
if (walkTime > MIN_WALK_TIME) { if (walkTime > MIN_WALK_TIME) {
routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing)); routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing));
routesBadges.addView(createWalkRouteBadge(walkingSegment), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing)); routesBadges.addView(createWalkRouteBadge(walkingSegment, badgesRowClickable), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing));
} }
} else { } else {
double finishWalkDist = routeResult.getFinishWalkDist(); double finishWalkDist = routeResult.getFinishWalkDist();
@ -306,7 +323,7 @@ public class PublicTransportCard extends BaseCard {
LatLon start = s.getEnd().getLocation(); LatLon start = s.getEnd().getLocation();
LatLon end = this.endLocation; LatLon end = this.endLocation;
routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing)); routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing));
routesBadges.addView(createWalkRouteBadge(walkTime, start, end)); routesBadges.addView(createWalkRouteBadge(walkTime, start, end, badgesRowClickable));
} }
} }
} }
@ -315,7 +332,7 @@ public class PublicTransportCard extends BaseCard {
} }
} }
private View createRouteBadge(@NonNull final TransportRouteResultSegment segment) { private View createRouteBadge(@NonNull final TransportRouteResultSegment segment, boolean badgesRowClickable) {
LinearLayout bageView = (LinearLayout) mapActivity.getLayoutInflater().inflate(R.layout.transport_stop_route_item_with_icon, null, false); LinearLayout bageView = (LinearLayout) mapActivity.getLayoutInflater().inflate(R.layout.transport_stop_route_item_with_icon, null, false);
TransportRoute transportRoute = segment.route; TransportRoute transportRoute = segment.route;
TransportStopRoute transportStopRoute = TransportStopRoute.getTransportStopRoute(transportRoute, segment.getStart()); TransportStopRoute transportStopRoute = TransportStopRoute.getTransportStopRoute(transportRoute, segment.getStart());
@ -333,20 +350,22 @@ public class PublicTransportCard extends BaseCard {
gradientDrawableBg.setColor(bgColor); gradientDrawableBg.setColor(bgColor);
transportStopRouteTextView.setTextColor(UiUtilities.getContrastColor(app, bgColor, true)); transportStopRouteTextView.setTextColor(UiUtilities.getContrastColor(app, bgColor, true));
if (transportCardListener != null) { if (transportCardListener != null && !badgesRowClickable) {
bageView.findViewById(R.id.button).setOnClickListener(new View.OnClickListener() { bageView.findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
transportCardListener.onPublicTransportCardBadgePressed(PublicTransportCard.this, segment); transportCardListener.onPublicTransportCardBadgePressed(PublicTransportCard.this, segment);
} }
}); });
} else {
bageView.findViewById(R.id.button).setBackgroundDrawable(null);
} }
return bageView; return bageView;
} }
private View createWalkRouteBadge(@NonNull final RouteCalculationResult result) { private View createWalkRouteBadge(@NonNull final RouteCalculationResult result, boolean badgesRowClickable) {
View v = createWalkRouteBadge(result.getRoutingTime(), null, null); View v = createWalkRouteBadge(result.getRoutingTime(), null, null, badgesRowClickable);
if (transportCardListener != null) { if (transportCardListener != null && !badgesRowClickable) {
v.setOnClickListener(new View.OnClickListener() { v.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -357,7 +376,7 @@ public class PublicTransportCard extends BaseCard {
return v; return v;
} }
private View createWalkRouteBadge(double walkTime, @Nullable final LatLon start, @Nullable final LatLon end) { private View createWalkRouteBadge(double walkTime, @Nullable final LatLon start, @Nullable final LatLon end, boolean badgesRowClickable) {
LinearLayout bageView = (LinearLayout) getMapActivity().getLayoutInflater().inflate(R.layout.transport_stop_route_item_with_icon, null, false); LinearLayout bageView = (LinearLayout) getMapActivity().getLayoutInflater().inflate(R.layout.transport_stop_route_item_with_icon, null, false);
int activeColor = getActiveColor(); int activeColor = getActiveColor();
@ -372,13 +391,15 @@ public class PublicTransportCard extends BaseCard {
AndroidUtils.setBackground(app, bageView, nightMode, R.drawable.btn_border_active_light, R.drawable.btn_border_active_dark); AndroidUtils.setBackground(app, bageView, nightMode, R.drawable.btn_border_active_light, R.drawable.btn_border_active_dark);
if (transportCardListener != null && start != null && end != null) { if (transportCardListener != null && start != null && end != null && !badgesRowClickable) {
bageView.findViewById(R.id.button).setOnClickListener(new View.OnClickListener() { bageView.findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
transportCardListener.onPublicTransportCardBadgePressed(PublicTransportCard.this, start, end); transportCardListener.onPublicTransportCardBadgePressed(PublicTransportCard.this, start, end);
} }
}); });
} else {
bageView.findViewById(R.id.button).setBackgroundDrawable(null);
} }
return bageView; return bageView;
} }