From 136907eb355010e246c2e4525efd6407a5fee8aa Mon Sep 17 00:00:00 2001 From: max-klaus Date: Sat, 3 Aug 2019 15:54:18 +0300 Subject: [PATCH] Added top badges card for selected route --- OsmAnd/res/layout/transport_route_card.xml | 13 ++++++++--- .../MapRouteInfoMenu.java | 23 ++++++++++++++++++- .../MapRouteInfoMenuFragment.java | 8 +++++++ .../cards/PublicTransportCard.java | 22 ++++++++++++++++++ 4 files changed, 62 insertions(+), 4 deletions(-) diff --git a/OsmAnd/res/layout/transport_route_card.xml b/OsmAnd/res/layout/transport_route_card.xml index 6998e5f39d..5b39bf06c0 100644 --- a/OsmAnd/res/layout/transport_route_card.xml +++ b/OsmAnd/res/layout/transport_route_card.xml @@ -36,14 +36,20 @@ + android:layout_height="wrap_content" /> + + 1 && routeSelected) { + int currentRoute = app.getTransportRoutingHelper().getCurrentRoute(); + if (currentRoute >= 0 && currentRoute < routes.size()) { + route = routes.get(currentRoute); + PublicTransportCard card = new PublicTransportCard(mapActivity, startLocation, endLocation, route, currentRoute); + card.setRouteInfoVisible(false); + card.setRouteButtonsVisible(false); + card.setShowBottomShadow(false); + card.setShowTopShadow(false); + menuCards.add(card); + hasTopCard = true; + } + } for (int i = 0; i < routes.size(); i++) { route = routes.get(i); PublicTransportCard card = new PublicTransportCard(mapActivity, startLocation, endLocation, route, i); card.setShowButtonCustomTitle(mapActivity.getString(R.string.shared_string_show_on_map)); card.setShowBottomShadow(i == routes.size() - 1 && !showPedestrianCard); - card.setShowTopShadow(i != 0); + card.setShowTopShadow(i != 0 || hasTopCard); card.setListener(this); menuCards.add(card); } @@ -1901,6 +1920,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener @Override public void newRouteIsCalculated(boolean newRoute, ValueHolder showToast) { directionInfo = -1; + routeSelected = false; updateMenu(); if (isVisible()) { showToast.value = false; @@ -2067,6 +2087,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener } removeTargetPointListener(); } else if (fragment instanceof ChooseRouteFragment) { + routeSelected = true; MapRouteMenuStateHolder holder = new MapRouteMenuStateHolder(MapRouteMenuType.ROUTE_DETAILS, currentMenuState, fragment.getArguments()); if (!menuBackStack.empty() && menuBackStack.peek().type == holder.type) { menuBackStack.pop(); diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenuFragment.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenuFragment.java index a40fd91d8a..b4fdea0fbc 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenuFragment.java @@ -250,6 +250,14 @@ public class MapRouteInfoMenuFragment extends ContextMenuFragment { menuTitleHeight = view.findViewById(R.id.route_menu_top_shadow_all).getHeight() + view.findViewById(R.id.control_buttons).getHeight() - view.findViewById(R.id.buttons_shadow).getHeight(); + LinearLayout cardsContainer = getCardsContainer(); + if (menu != null && cardsContainer != null && cardsContainer.getChildCount() > 0 && menu.isRouteSelected()) { + View topRouteCard = cardsContainer.getChildAt(0); + View badgesView = topRouteCard.findViewById(R.id.routes_badges); + View badgesPaddingView = topRouteCard.findViewById(R.id.badges_padding); + int paddingHeight = badgesPaddingView != null ? badgesPaddingView.getHeight() : 0; + menuTitleHeight += badgesView != null ? badgesView.getBottom() + paddingHeight : 0; + } super.calculateLayout(view, initLayout); } diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/PublicTransportCard.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/PublicTransportCard.java index 3fa0511e0b..fe08483876 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/PublicTransportCard.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/PublicTransportCard.java @@ -48,6 +48,8 @@ public class PublicTransportCard extends BaseCard { private int routeId; private String showButtonCustomTitle; + private boolean routeInfoVisible = true; + private boolean routeButtonsVisible = true; public interface PublicTransportCardListener { void onPublicTransportCardBadgePressed(@NonNull PublicTransportCard card, @NonNull TransportRouteResultSegment segment); @@ -85,11 +87,31 @@ public class PublicTransportCard extends BaseCard { this.showButtonCustomTitle = showButtonCustomTitle; } + public boolean isRouteInfoVisible() { + return routeInfoVisible; + } + + public void setRouteInfoVisible(boolean routeInfoVisible) { + this.routeInfoVisible = routeInfoVisible; + } + + public boolean isRouteButtonsVisible() { + return routeButtonsVisible; + } + + public void setRouteButtonsVisible(boolean routeButtonsVisible) { + this.routeButtonsVisible = routeButtonsVisible; + } + @Override protected void updateContent() { List segments = routeResult.getSegments(); createRouteBadges(segments); + 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); + TextView fromLine = (TextView) view.findViewById(R.id.from_line); TextView wayLine = (TextView) view.findViewById(R.id.way_line);