Change targetFragment to MapRouteInfoMenu, static startNavigation
This commit is contained in:
parent
8ee7cd0736
commit
99c432d9ff
3 changed files with 48 additions and 28 deletions
|
@ -16,6 +16,7 @@ import androidx.annotation.Nullable;
|
|||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.GPXUtilities;
|
||||
import net.osmand.data.QuadRect;
|
||||
import net.osmand.data.RotatedTileBox;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
|
@ -23,11 +24,14 @@ import net.osmand.plus.R;
|
|||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.base.ContextMenuFragment;
|
||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||
import net.osmand.plus.routing.GPXRouteParams;
|
||||
import net.osmand.plus.routing.RoutingHelper;
|
||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||
import net.osmand.plus.track.TrackMenuFragment;
|
||||
import net.osmand.plus.track.TrackSelectSegmentBottomSheet;
|
||||
import net.osmand.plus.widgets.TextViewExProgress;
|
||||
|
||||
public class MapRouteInfoMenuFragment extends ContextMenuFragment {
|
||||
public class MapRouteInfoMenuFragment extends ContextMenuFragment implements TrackSelectSegmentBottomSheet.OnSegmentSelectedListener {
|
||||
public static final String TAG = MapRouteInfoMenuFragment.class.getName();
|
||||
|
||||
@Nullable
|
||||
|
@ -95,13 +99,13 @@ public class MapRouteInfoMenuFragment extends ContextMenuFragment {
|
|||
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
Bundle savedInstanceState) {
|
||||
MapActivity mapActivity = requireMapActivity();
|
||||
menu = mapActivity.getMapRouteInfoMenu();
|
||||
|
||||
View view = super.onCreateView(inflater, container, savedInstanceState);
|
||||
if (view != null) {
|
||||
bottomContainer = (FrameLayout) view.findViewById(R.id.bottom_container);
|
||||
bottomContainer = view.findViewById(R.id.bottom_container);
|
||||
modesLayoutToolbar = view.findViewById(R.id.modes_layout_toolbar);
|
||||
modesLayoutToolbarContainer = view.findViewById(R.id.modes_layout_toolbar_container);
|
||||
modesLayoutListContainer = view.findViewById(R.id.modes_layout_list_container);
|
||||
|
@ -121,7 +125,7 @@ public class MapRouteInfoMenuFragment extends ContextMenuFragment {
|
|||
int widthNoShadow = getLandscapeNoShadowWidth();
|
||||
modesLayoutToolbar.setLayoutParams(new FrameLayout.LayoutParams(widthNoShadow, ViewGroup.LayoutParams.WRAP_CONTENT));
|
||||
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(widthNoShadow, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
params.gravity = Gravity.BOTTOM|Gravity.START;
|
||||
params.gravity = Gravity.BOTTOM | Gravity.START;
|
||||
view.findViewById(R.id.control_buttons).setLayoutParams(params);
|
||||
View appModesView = view.findViewById(R.id.app_modes);
|
||||
AndroidUtils.setPadding(appModesView, 0, 0, appModesView.getPaddingRight(), 0);
|
||||
|
@ -182,15 +186,15 @@ public class MapRouteInfoMenuFragment extends ContextMenuFragment {
|
|||
|
||||
@Override
|
||||
protected void updateMenuState(int currentMenuState, int newMenuState) {
|
||||
if(getMyApplication().getRoutingHelper().isRouteCalculated() ) {
|
||||
if (getMyApplication().getRoutingHelper().isRouteCalculated()) {
|
||||
ApplicationMode mV = getMyApplication().getRoutingHelper().getAppMode();
|
||||
if (newMenuState == MenuState.HEADER_ONLY && currentMenuState == MenuState.HALF_SCREEN) {
|
||||
getSettings().OPEN_ONLY_HEADER_STATE_ROUTE_CALCULATED.setModeValue(mV,true);
|
||||
getSettings().OPEN_ONLY_HEADER_STATE_ROUTE_CALCULATED.setModeValue(mV, true);
|
||||
} else if (currentMenuState == MenuState.HEADER_ONLY && newMenuState == MenuState.HALF_SCREEN) {
|
||||
getSettings().OPEN_ONLY_HEADER_STATE_ROUTE_CALCULATED.resetModeToDefault(mV);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setViewY(int y, boolean animated, boolean adjustMapPos) {
|
||||
|
@ -347,7 +351,7 @@ public class MapRouteInfoMenuFragment extends ContextMenuFragment {
|
|||
OsmandApplication app = getMyApplication();
|
||||
return app != null && app.getRoutingHelper().isOsmandRouting();
|
||||
}
|
||||
|
||||
|
||||
public void updateRouteCalculationProgress(int progress) {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
View mainView = getMainView();
|
||||
|
@ -356,7 +360,7 @@ public class MapRouteInfoMenuFragment extends ContextMenuFragment {
|
|||
return;
|
||||
}
|
||||
boolean indeterminate = isPublicTransportMode() || !isOsmandRouting();
|
||||
ProgressBar progressBar = (ProgressBar) mainView.findViewById(R.id.progress_bar);
|
||||
ProgressBar progressBar = mainView.findViewById(R.id.progress_bar);
|
||||
if (progressBar != null) {
|
||||
if (progress == 0) {
|
||||
progressBar.setIndeterminate(indeterminate);
|
||||
|
@ -366,14 +370,14 @@ public class MapRouteInfoMenuFragment extends ContextMenuFragment {
|
|||
}
|
||||
progressBar.setProgress(progress);
|
||||
}
|
||||
ProgressBar progressBarButton = (ProgressBar) view.findViewById(R.id.progress_bar_button);
|
||||
ProgressBar progressBarButton = view.findViewById(R.id.progress_bar_button);
|
||||
if (progressBarButton != null) {
|
||||
if (progressBarButton.getVisibility() != View.VISIBLE) {
|
||||
progressBarButton.setVisibility(View.VISIBLE);
|
||||
}
|
||||
progressBarButton.setProgress(indeterminate ? 0 : progress);
|
||||
}
|
||||
TextViewExProgress textViewExProgress = (TextViewExProgress) view.findViewById(R.id.start_button_descr);
|
||||
TextViewExProgress textViewExProgress = view.findViewById(R.id.start_button_descr);
|
||||
textViewExProgress.percent = indeterminate ? 0 : progress / 100f;
|
||||
textViewExProgress.invalidate();
|
||||
}
|
||||
|
@ -390,11 +394,11 @@ public class MapRouteInfoMenuFragment extends ContextMenuFragment {
|
|||
if (progressBar != null) {
|
||||
progressBar.setVisibility(View.GONE);
|
||||
}
|
||||
ProgressBar progressBarButton = (ProgressBar) view.findViewById(R.id.progress_bar_button);
|
||||
ProgressBar progressBarButton = view.findViewById(R.id.progress_bar_button);
|
||||
if (progressBarButton != null) {
|
||||
progressBarButton.setProgress(0);
|
||||
}
|
||||
TextViewExProgress textViewExProgress = (TextViewExProgress) view.findViewById(R.id.start_button_descr);
|
||||
TextViewExProgress textViewExProgress = view.findViewById(R.id.start_button_descr);
|
||||
textViewExProgress.percent = 0;
|
||||
}
|
||||
|
||||
|
@ -501,4 +505,21 @@ public class MapRouteInfoMenuFragment extends ContextMenuFragment {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSegmentSelect(GPXUtilities.GPXFile gpxFile, int selectedSegment) {
|
||||
if (getMyApplication() != null) {
|
||||
getMyApplication().getSettings().GPX_ROUTE_SEGMENT.set(selectedSegment);
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
TrackMenuFragment.startNavigationForGPX(gpxFile, mapActivity.getMapActions(), mapActivity);
|
||||
GPXRouteParams.GPXRouteParamsBuilder paramsBuilder = getMyApplication().getRoutingHelper().getCurrentGPXRoute();
|
||||
if (paramsBuilder != null) {
|
||||
paramsBuilder.setSelectedSegment(selectedSegment);
|
||||
getMyApplication().getRoutingHelper().onSettingsChanged(true);
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -21,8 +21,8 @@ import net.osmand.plus.R;
|
|||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.helpers.GpxUiHelper;
|
||||
import net.osmand.plus.helpers.GpxUiHelper.GPXInfo;
|
||||
import net.osmand.plus.routepreparationmenu.MapRouteInfoMenuFragment;
|
||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||
import net.osmand.plus.track.TrackMenuFragment;
|
||||
import net.osmand.plus.track.TrackSelectSegmentBottomSheet;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -131,8 +131,8 @@ public class TracksCard extends BaseCard {
|
|||
}
|
||||
}
|
||||
if (item.file.getNonEmptySegmentsCount() > 1) {
|
||||
Fragment f = mapActivity.getSupportFragmentManager().findFragmentByTag(TrackMenuFragment.TAG);
|
||||
TrackSelectSegmentBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), item.file, f);
|
||||
Fragment targetFragment = mapActivity.getSupportFragmentManager().findFragmentByTag(MapRouteInfoMenuFragment.TAG);
|
||||
TrackSelectSegmentBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), item.file, targetFragment);
|
||||
} else {
|
||||
mapActivity.getMapActions().setGPXRouteParams(item.file);
|
||||
app.getTargetPointsHelper().updateRouteAndRefresh(true);
|
||||
|
|
|
@ -82,8 +82,8 @@ import net.osmand.plus.myplaces.TrackActivityFragmentAdapter;
|
|||
import net.osmand.plus.osmedit.OsmEditingPlugin;
|
||||
import net.osmand.plus.routepreparationmenu.cards.BaseCard;
|
||||
import net.osmand.plus.routepreparationmenu.cards.BaseCard.CardListener;
|
||||
import net.osmand.plus.search.QuickSearchDialogFragment;
|
||||
import net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder;
|
||||
import net.osmand.plus.search.QuickSearchDialogFragment;
|
||||
import net.osmand.plus.track.SaveGpxAsyncTask.SaveGpxListener;
|
||||
import net.osmand.plus.track.TrackSelectSegmentBottomSheet.OnSegmentSelectedListener;
|
||||
import net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint;
|
||||
|
@ -804,7 +804,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
|
|||
if (gpxFile.getNonEmptySegmentsCount() > 1) {
|
||||
TrackSelectSegmentBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), gpxFile, this);
|
||||
} else {
|
||||
startNavigationForGPX(gpxFile, mapActions);
|
||||
startNavigationForGPX(gpxFile, mapActions, mapActivity);
|
||||
dismiss();
|
||||
}
|
||||
}
|
||||
|
@ -827,7 +827,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
|
|||
segment = segments.get(0);
|
||||
}
|
||||
}
|
||||
GpxDisplayItemType[] filterTypes = new GpxDisplayItemType[] {GpxDisplayItemType.TRACK_SEGMENT};
|
||||
GpxDisplayItemType[] filterTypes = new GpxDisplayItemType[]{GpxDisplayItemType.TRACK_SEGMENT};
|
||||
List<GpxDisplayItem> items = TrackDisplayHelper.flatten(displayHelper.getOriginalGroups(filterTypes));
|
||||
if (segment != null && !Algorithms.isEmpty(items)) {
|
||||
SplitSegmentDialogFragment.showInstance(fragmentManager, displayHelper, items.get(0), segment);
|
||||
|
@ -904,12 +904,11 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
|
|||
}
|
||||
}
|
||||
|
||||
private void startNavigationForGPX(final GPXFile gpxFile, MapActivityActions mapActions) {
|
||||
if (app.getRoutingHelper().isFollowingMode()) {
|
||||
public static void startNavigationForGPX(final GPXFile gpxFile, MapActivityActions mapActions, final MapActivity mapActivity) {
|
||||
if (mapActivity.getMyApplication().getRoutingHelper().isFollowingMode()) {
|
||||
mapActions.stopNavigationActionConfirm(null, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
mapActivity.getMapActions().enterRoutePlanningModeGivenGpx(gpxFile, null,
|
||||
null, null, true, true, MenuState.HEADER_ONLY);
|
||||
|
@ -1130,7 +1129,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
|
|||
public boolean onMenuItemClick(MenuItem item) {
|
||||
int i = item.getItemId();
|
||||
if (i == R.id.action_edit) {
|
||||
editSegment(segment);
|
||||
editSegment();
|
||||
return true;
|
||||
} else if (i == R.id.action_delete) {
|
||||
FragmentActivity activity = getActivity();
|
||||
|
@ -1164,7 +1163,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
|
|||
app.getSettings().GPX_ROUTE_SEGMENT.set(selectedSegment);
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
startNavigationForGPX(gpxFile, mapActivity.getMapActions());
|
||||
startNavigationForGPX(gpxFile, mapActivity.getMapActions(), mapActivity);
|
||||
GPXRouteParamsBuilder paramsBuilder = app.getRoutingHelper().getCurrentGPXRoute();
|
||||
if (paramsBuilder != null) {
|
||||
paramsBuilder.setSelectedSegment(selectedSegment);
|
||||
|
@ -1174,7 +1173,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
|
|||
}
|
||||
}
|
||||
|
||||
private void editSegment(TrkSegment segment) {
|
||||
private void editSegment() {
|
||||
GPXFile gpxFile = getGpx();
|
||||
openPlanRoute(new GpxData(gpxFile));
|
||||
hide();
|
||||
|
@ -1219,7 +1218,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
|
|||
@Override
|
||||
public void gpxSavingFinished(Exception errorMessage) {
|
||||
if (selectedGpxFile != null) {
|
||||
List<GpxDisplayGroup> groups = displayHelper.getDisplayGroups(new GpxDisplayItemType[] {GpxDisplayItemType.TRACK_SEGMENT});
|
||||
List<GpxDisplayGroup> groups = displayHelper.getDisplayGroups(new GpxDisplayItemType[]{GpxDisplayItemType.TRACK_SEGMENT});
|
||||
selectedGpxFile.setDisplayGroups(groups, app);
|
||||
selectedGpxFile.processPoints(app);
|
||||
}
|
||||
|
@ -1313,7 +1312,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
|
|||
}
|
||||
|
||||
public static void showInstance(@NonNull MapActivity mapActivity,
|
||||
@Nullable String path,
|
||||
@Nullable String path,
|
||||
boolean showCurrentTrack,
|
||||
@Nullable final LatLon latLon,
|
||||
@Nullable final String returnScreenName,
|
||||
|
@ -1332,7 +1331,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
|
|||
}
|
||||
|
||||
public static boolean showInstance(@NonNull MapActivity mapActivity,
|
||||
@NonNull SelectedGpxFile selectedGpxFile,
|
||||
@NonNull SelectedGpxFile selectedGpxFile,
|
||||
@Nullable LatLon latLon,
|
||||
@Nullable String returnScreenName,
|
||||
@Nullable String callingFragmentTag) {
|
||||
|
|
Loading…
Reference in a new issue