Added top badges card for selected route

This commit is contained in:
max-klaus 2019-08-03 15:54:18 +03:00
parent 67ff4adf74
commit da55e5d963
4 changed files with 62 additions and 4 deletions

View file

@ -36,14 +36,20 @@
<net.osmand.plus.widgets.FlowLayout
android:id="@+id/routes_badges"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp" />
android:layout_height="wrap_content" />
<View
android:id="@+id/badges_padding"
android:layout_width="match_parent"
android:layout_height="10dp"
android:visibility="gone"/>
<LinearLayout
android:id="@+id/routes_info"
android:id="@+id/route_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="4dp"
android:paddingBottom="14dp">
<net.osmand.plus.widgets.TextViewEx
@ -68,6 +74,7 @@
</LinearLayout>
<LinearLayout
android:id="@+id/route_buttons"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="@dimen/route_info_details_padding"

View file

@ -147,6 +147,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
private boolean nightMode;
private boolean switched;
private boolean routeSelected;
private AddressLookupRequest startPointRequest;
private AddressLookupRequest targetPointRequest;
@ -335,6 +336,10 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
}
}
public boolean isRouteSelected() {
return routeSelected;
}
public void setVisible(boolean visible) {
if (visible) {
if (showMenu) {
@ -528,12 +533,26 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
LatLon endLocation = transportRoutingHelper.getEndLocation();
int approxPedestrianTime = (int) MapUtils.getDistance(startLocation, endLocation);
boolean showPedestrianCard = approxPedestrianTime < travelTime + 60 && approxPedestrianTime < MAX_PEDESTRIAN_ROUTE_DURATION;
boolean hasTopCard = false;
if (routes.size() > 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<Boolean> 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();

View file

@ -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);
}

View file

@ -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<TransportRouteResultSegment> 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);