Fix transport stop context menu. Fix top route badge press.
This commit is contained in:
parent
da55e5d963
commit
e86bde9c61
4 changed files with 53 additions and 20 deletions
|
@ -8,7 +8,6 @@ import java.util.Arrays;
|
|||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class TransportStop extends MapObject {
|
||||
|
||||
|
@ -111,6 +110,10 @@ public class TransportStop extends MapObject {
|
|||
return !isDeleted() && referencesToRoutes != null && referencesToRoutes.length > 0;
|
||||
}
|
||||
|
||||
public boolean hasReferencesToRoutesMap() {
|
||||
return !isDeleted() && referencesToRoutesMap != null && !referencesToRoutesMap.isEmpty();
|
||||
}
|
||||
|
||||
public Amenity getAmenity() {
|
||||
if (transportStopAggregated != null) {
|
||||
return transportStopAggregated.getAmenity();
|
||||
|
|
|
@ -161,7 +161,7 @@ public class TransportStopController extends MenuController {
|
|||
|
||||
private void addTransportStopRoutes(OsmandApplication app, List<TransportStop> stops, List<TransportStopRoute> routes, boolean useEnglishNames) {
|
||||
for (TransportStop tstop : stops) {
|
||||
if (tstop.hasReferencesToRoutes()) {
|
||||
if (tstop.hasReferencesToRoutesMap()) {
|
||||
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) {
|
||||
TransportStopAggregated stopAggregated = new TransportStopAggregated();
|
||||
transportStop.setTransportStopAggregated(stopAggregated);
|
||||
stopAggregated.addLocalTransportStop(transportStop);
|
||||
|
||||
TransportStop localStop = null;
|
||||
LatLon loc = transportStop.getLocation();
|
||||
List<TransportStop> transportStops = findTransportStopsAt(app, loc.getLatitude(), loc.getLongitude(), SHOW_STOPS_RADIUS_METERS);
|
||||
if (transportStops != null) {
|
||||
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) {
|
||||
|
|
|
@ -543,6 +543,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
|
|||
card.setRouteButtonsVisible(false);
|
||||
card.setShowBottomShadow(false);
|
||||
card.setShowTopShadow(false);
|
||||
card.setListener(this);
|
||||
menuCards.add(card);
|
||||
hasTopCard = true;
|
||||
}
|
||||
|
@ -668,6 +669,10 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
|
|||
if (card instanceof SimpleRouteCard) {
|
||||
hide();
|
||||
ChooseRouteFragment.showInstance(mapActivity.getSupportFragmentManager(), 0, MenuState.FULL_SCREEN);
|
||||
} else if (card instanceof PublicTransportCard) {
|
||||
hide();
|
||||
ChooseRouteFragment.showInstance(mapActivity.getSupportFragmentManager(),
|
||||
((PublicTransportCard) card).getRouteId(), MenuState.FULL_SCREEN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -106,11 +106,28 @@ public class PublicTransportCard extends BaseCard {
|
|||
@Override
|
||||
protected void updateContent() {
|
||||
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_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 wayLine = (TextView) view.findViewById(R.id.way_line);
|
||||
|
@ -256,7 +273,7 @@ public class PublicTransportCard extends BaseCard {
|
|||
return secondLineDesc;
|
||||
}
|
||||
|
||||
private void createRouteBadges(List<TransportRouteResultSegment> segments) {
|
||||
private void createRouteBadges(List<TransportRouteResultSegment> segments, boolean badgesRowClickable) {
|
||||
int itemsSpacing = AndroidUtils.dpToPx(app, 6);
|
||||
FlowLayout routesBadges = (FlowLayout) view.findViewById(R.id.routes_badges);
|
||||
routesBadges.removeAllViews();
|
||||
|
@ -270,7 +287,7 @@ public class PublicTransportCard extends BaseCard {
|
|||
if (walkingSegment != null) {
|
||||
double walkTime = walkingSegment.getRoutingTime();
|
||||
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));
|
||||
}
|
||||
} else if (s.walkDist > 0) {
|
||||
|
@ -283,11 +300,11 @@ public class PublicTransportCard extends BaseCard {
|
|||
} else {
|
||||
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(createRouteBadge(s), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing));
|
||||
routesBadges.addView(createRouteBadge(s, badgesRowClickable), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing));
|
||||
if (iterator.hasNext()) {
|
||||
routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing));
|
||||
} else {
|
||||
|
@ -296,7 +313,7 @@ public class PublicTransportCard extends BaseCard {
|
|||
double walkTime = walkingSegment.getRoutingTime();
|
||||
if (walkTime > MIN_WALK_TIME) {
|
||||
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 {
|
||||
double finishWalkDist = routeResult.getFinishWalkDist();
|
||||
|
@ -306,7 +323,7 @@ public class PublicTransportCard extends BaseCard {
|
|||
LatLon start = s.getEnd().getLocation();
|
||||
LatLon end = this.endLocation;
|
||||
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);
|
||||
TransportRoute transportRoute = segment.route;
|
||||
TransportStopRoute transportStopRoute = TransportStopRoute.getTransportStopRoute(transportRoute, segment.getStart());
|
||||
|
@ -333,20 +350,22 @@ public class PublicTransportCard extends BaseCard {
|
|||
gradientDrawableBg.setColor(bgColor);
|
||||
transportStopRouteTextView.setTextColor(UiUtilities.getContrastColor(app, bgColor, true));
|
||||
|
||||
if (transportCardListener != null) {
|
||||
if (transportCardListener != null && !badgesRowClickable) {
|
||||
bageView.findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
transportCardListener.onPublicTransportCardBadgePressed(PublicTransportCard.this, segment);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
bageView.findViewById(R.id.button).setBackgroundDrawable(null);
|
||||
}
|
||||
return bageView;
|
||||
}
|
||||
|
||||
private View createWalkRouteBadge(@NonNull final RouteCalculationResult result) {
|
||||
View v = createWalkRouteBadge(result.getRoutingTime(), null, null);
|
||||
if (transportCardListener != null) {
|
||||
private View createWalkRouteBadge(@NonNull final RouteCalculationResult result, boolean badgesRowClickable) {
|
||||
View v = createWalkRouteBadge(result.getRoutingTime(), null, null, badgesRowClickable);
|
||||
if (transportCardListener != null && !badgesRowClickable) {
|
||||
v.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
@ -357,7 +376,7 @@ public class PublicTransportCard extends BaseCard {
|
|||
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);
|
||||
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);
|
||||
|
||||
if (transportCardListener != null && start != null && end != null) {
|
||||
if (transportCardListener != null && start != null && end != null && !badgesRowClickable) {
|
||||
bageView.findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
transportCardListener.onPublicTransportCardBadgePressed(PublicTransportCard.this, start, end);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
bageView.findViewById(R.id.button).setBackgroundDrawable(null);
|
||||
}
|
||||
return bageView;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue