diff --git a/OsmAnd-java/src/main/java/net/osmand/router/TransportRoutePlanner.java b/OsmAnd-java/src/main/java/net/osmand/router/TransportRoutePlanner.java index 2b26566cf0..a8e1677bc4 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/TransportRoutePlanner.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/TransportRoutePlanner.java @@ -509,6 +509,10 @@ public class TransportRoutePlanner { return cfg.getChangeTime(); } + public double getBoardingTime() { + return cfg.getBoardingTime(); + } + public int getChanges() { return segments.size() - 1; } diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/ChooseRouteFragment.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/ChooseRouteFragment.java index ea7a34c5a7..4436f20e28 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/ChooseRouteFragment.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/ChooseRouteFragment.java @@ -64,6 +64,7 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe public static final String TAG = "ChooseRouteFragment"; public static final String ROUTE_INDEX_KEY = "route_index_key"; public static final String ROUTE_INFO_STATE_KEY = "route_info_state_key"; + public static final String INITIAL_MENU_STATE_KEY = "initial_menu_state_key"; @Nullable private LockableViewPager viewPager; @@ -94,10 +95,12 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe TransportRoutingHelper transportRoutingHelper = app.getTransportRoutingHelper(); List routes = transportRoutingHelper.getRoutes(); int routeIndex = 0; + int initialMenuState = MenuState.HEADER_ONLY; Bundle args = getArguments(); if (args != null) { routeIndex = args.getInt(ROUTE_INDEX_KEY); routeInfoMenuState = args.getInt(ROUTE_INFO_STATE_KEY, -1); + initialMenuState = args.getInt(INITIAL_MENU_STATE_KEY, initialMenuState); } if (routes != null && !routes.isEmpty()) { publicTransportMode = true; @@ -112,7 +115,7 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe this.viewPager = viewPager; viewPager.setClipToPadding(false); //viewPager.setPageMargin(-60); - final RoutesPagerAdapter pagerAdapter = new RoutesPagerAdapter(getChildFragmentManager(), publicTransportMode ? routes.size() : 1); + final RoutesPagerAdapter pagerAdapter = new RoutesPagerAdapter(getChildFragmentManager(), publicTransportMode ? routes.size() : 1, initialMenuState); viewPager.setAdapter(pagerAdapter); viewPager.setCurrentItem(routeIndex); viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @@ -575,9 +578,11 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe if (viewPager != null) { int currentItem = viewPager.getCurrentItem(); List> routeDetailsFragments = this.routeDetailsFragments; - if (routeDetailsFragments.size() > currentItem) { - WeakReference ref = routeDetailsFragments.get(currentItem); - return ref.get(); + for (WeakReference ref : routeDetailsFragments) { + RouteDetailsFragment f = ref.get(); + if (f != null && f.getRouteId() == currentItem) { + return f; + } } } return null; @@ -646,9 +651,9 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe int i = 0; List> routeDetailsFragments = this.routeDetailsFragments; for (WeakReference ref : routeDetailsFragments) { - boolean current = i == currentItem; RouteDetailsFragment f = ref.get(); if (f != null) { + boolean current = f.getRouteId() == currentItem; if (!current && f.getCurrentMenuState() != menuState) { f.openMenuScreen(menuState, false); } @@ -686,12 +691,14 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe } } - static boolean showFromRouteInfo(FragmentManager fragmentManager, int routeIndex, int routeInfoState) { + static boolean showFromRouteInfo(FragmentManager fragmentManager, int routeIndex, + int routeInfoState, int initialMenuState) { try { ChooseRouteFragment fragment = new ChooseRouteFragment(); Bundle args = new Bundle(); args.putInt(ROUTE_INDEX_KEY, routeIndex); args.putInt(ROUTE_INFO_STATE_KEY, routeInfoState); + args.putInt(INITIAL_MENU_STATE_KEY, initialMenuState); fragment.setArguments(args); fragmentManager.beginTransaction() .add(R.id.routeMenuContainer, fragment, TAG) @@ -704,10 +711,12 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe public class RoutesPagerAdapter extends FragmentPagerAdapter { private int routesCount; + private int initialMenuState; - RoutesPagerAdapter(FragmentManager fm, int routesCount) { + RoutesPagerAdapter(FragmentManager fm, int routesCount, int initialMenuState) { super(fm); this.routesCount = routesCount; + this.initialMenuState = initialMenuState; } @Override @@ -718,7 +727,7 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe @Override public Fragment getItem(int position) { Bundle args = new Bundle(); - args.putInt(ContextMenuFragment.MENU_STATE_KEY, MenuState.HEADER_ONLY); + args.putInt(ContextMenuFragment.MENU_STATE_KEY, initialMenuState); args.putInt(RouteDetailsFragment.ROUTE_ID_KEY, position); return Fragment.instantiate(ChooseRouteFragment.this.getContext(), RouteDetailsFragment.class.getName(), args); } diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java index 83ae9cf7a9..226689ce29 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java @@ -609,7 +609,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener if (mapActivity != null) { if (card instanceof SimpleRouteCard) { hide(); - ChooseRouteFragment.showFromRouteInfo(mapActivity.getSupportFragmentManager(), 0, getCurrentMenuState()); + ChooseRouteFragment.showFromRouteInfo(mapActivity.getSupportFragmentManager(), 0, getCurrentMenuState(), MenuState.FULL_SCREEN); } } } @@ -634,14 +634,15 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener if (buttonIndex == PublicTransportCard.DETAILS_BUTTON_INDEX) { hide(); ChooseRouteFragment.showFromRouteInfo(mapActivity.getSupportFragmentManager(), - ((PublicTransportCard) card).getRouteId(), getCurrentMenuState()); + ((PublicTransportCard) card).getRouteId(), getCurrentMenuState(), MenuState.FULL_SCREEN); } else if (buttonIndex == PublicTransportCard.SHOW_BUTTON_INDEX) { setupCards(); openMenuHeaderOnly(); } } else if (card instanceof SimpleRouteCard) { hide(); - ChooseRouteFragment.showFromRouteInfo(mapActivity.getSupportFragmentManager(), 0, getCurrentMenuState()); + ChooseRouteFragment.showFromRouteInfo(mapActivity.getSupportFragmentManager(), 0, + getCurrentMenuState(), MenuState.FULL_SCREEN); } } } @@ -1263,7 +1264,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener if (app.getRoutingHelper().isPublicTransportMode()) { if (isTransportRouteCalculated()) { ChooseRouteFragment.showFromRouteInfo(mapActivity.getSupportFragmentManager(), - app.getTransportRoutingHelper().getCurrentRoute(), getCurrentMenuState()); + app.getTransportRoutingHelper().getCurrentRoute(), getCurrentMenuState(), MenuState.HEADER_ONLY); } } else { mapActivity.getMapLayers().getMapControlsLayer().startNavigation(); diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteDetailsFragment.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteDetailsFragment.java index c9ff8efdac..babb4d75b9 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteDetailsFragment.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteDetailsFragment.java @@ -130,6 +130,10 @@ public class RouteDetailsFragment extends ContextMenuFragment implements PublicT return false; } + public int getRouteId() { + return routeId; + } + @Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -292,7 +296,7 @@ public class RouteDetailsFragment extends ContextMenuFragment implements PublicT } private void buildSegmentItem(View view, final TransportRouteResultSegment segment, - final TransportRouteResultSegment nextSegment, int[] startTime, double walkSpeed, double changeTime) { + final TransportRouteResultSegment nextSegment, int[] startTime, double walkSpeed, double boardingTime) { OsmandApplication app = requireMyApplication(); TransportRoute transportRoute = segment.route; List stops = segment.getTravelStops(); @@ -318,6 +322,7 @@ public class RouteDetailsFragment extends ContextMenuFragment implements PublicT Drawable icon = getContentIcon(drawableResId); Typeface typeface = FontCache.getRobotoMedium(app); + startTime[0] += (int) boardingTime; String timeText = OsmAndFormatter.getFormattedDurationShortMinutes(startTime[0]); SpannableString secondaryText = new SpannableString(getString(R.string.sit_on_the_stop)); @@ -386,7 +391,7 @@ public class RouteDetailsFragment extends ContextMenuFragment implements PublicT depTime = startTime[0] + arrivalTime; } // TODO: fix later for schedule - startTime[0] += (int) segment.travelTime + (nextSegment != null ? changeTime / 2 : 0); + startTime[0] += (int) segment.getTravelTime(); String textTime = OsmAndFormatter.getFormattedDurationShortMinutes(startTime[0]); secondaryText = new SpannableString(getString(R.string.exit_at)); @@ -467,7 +472,7 @@ public class RouteDetailsFragment extends ContextMenuFragment implements PublicT if (first) { buildStartItem(parent, startPoint, startTime, segment, routeResult.getWalkSpeed()); } - buildSegmentItem(parent, segment, !last ? segments.get(i + 1) : null, startTime, routeResult.getWalkSpeed(), routeResult.getChangeTime()); + buildSegmentItem(parent, segment, !last ? segments.get(i + 1) : null, startTime, routeResult.getWalkSpeed(), routeResult.getBoardingTime()); if (last) { buildDestinationItem(parent, endPoint, startTime, segment, routeResult.getWalkSpeed()); }