Change targetFragment to MapRouteInfoMenu, static startNavigation

This commit is contained in:
androiddevkotlin 2021-03-28 23:41:49 +03:00
parent 8ee7cd0736
commit 99c432d9ff
3 changed files with 48 additions and 28 deletions

View file

@ -16,6 +16,7 @@ import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.GPXUtilities;
import net.osmand.data.QuadRect; import net.osmand.data.QuadRect;
import net.osmand.data.RotatedTileBox; import net.osmand.data.RotatedTileBox;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
@ -23,11 +24,14 @@ import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.ContextMenuFragment; import net.osmand.plus.base.ContextMenuFragment;
import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.routing.GPXRouteParams;
import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.settings.backend.ApplicationMode; 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; 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(); public static final String TAG = MapRouteInfoMenuFragment.class.getName();
@Nullable @Nullable
@ -101,7 +105,7 @@ public class MapRouteInfoMenuFragment extends ContextMenuFragment {
View view = super.onCreateView(inflater, container, savedInstanceState); View view = super.onCreateView(inflater, container, savedInstanceState);
if (view != null) { 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); modesLayoutToolbar = view.findViewById(R.id.modes_layout_toolbar);
modesLayoutToolbarContainer = view.findViewById(R.id.modes_layout_toolbar_container); modesLayoutToolbarContainer = view.findViewById(R.id.modes_layout_toolbar_container);
modesLayoutListContainer = view.findViewById(R.id.modes_layout_list_container); modesLayoutListContainer = view.findViewById(R.id.modes_layout_list_container);
@ -121,7 +125,7 @@ public class MapRouteInfoMenuFragment extends ContextMenuFragment {
int widthNoShadow = getLandscapeNoShadowWidth(); int widthNoShadow = getLandscapeNoShadowWidth();
modesLayoutToolbar.setLayoutParams(new FrameLayout.LayoutParams(widthNoShadow, ViewGroup.LayoutParams.WRAP_CONTENT)); modesLayoutToolbar.setLayoutParams(new FrameLayout.LayoutParams(widthNoShadow, ViewGroup.LayoutParams.WRAP_CONTENT));
FrameLayout.LayoutParams params = 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.findViewById(R.id.control_buttons).setLayoutParams(params);
View appModesView = view.findViewById(R.id.app_modes); View appModesView = view.findViewById(R.id.app_modes);
AndroidUtils.setPadding(appModesView, 0, 0, appModesView.getPaddingRight(), 0); AndroidUtils.setPadding(appModesView, 0, 0, appModesView.getPaddingRight(), 0);
@ -182,10 +186,10 @@ public class MapRouteInfoMenuFragment extends ContextMenuFragment {
@Override @Override
protected void updateMenuState(int currentMenuState, int newMenuState) { protected void updateMenuState(int currentMenuState, int newMenuState) {
if(getMyApplication().getRoutingHelper().isRouteCalculated() ) { if (getMyApplication().getRoutingHelper().isRouteCalculated()) {
ApplicationMode mV = getMyApplication().getRoutingHelper().getAppMode(); ApplicationMode mV = getMyApplication().getRoutingHelper().getAppMode();
if (newMenuState == MenuState.HEADER_ONLY && currentMenuState == MenuState.HALF_SCREEN) { 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) { } else if (currentMenuState == MenuState.HEADER_ONLY && newMenuState == MenuState.HALF_SCREEN) {
getSettings().OPEN_ONLY_HEADER_STATE_ROUTE_CALCULATED.resetModeToDefault(mV); getSettings().OPEN_ONLY_HEADER_STATE_ROUTE_CALCULATED.resetModeToDefault(mV);
} }
@ -356,7 +360,7 @@ public class MapRouteInfoMenuFragment extends ContextMenuFragment {
return; return;
} }
boolean indeterminate = isPublicTransportMode() || !isOsmandRouting(); 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 (progressBar != null) {
if (progress == 0) { if (progress == 0) {
progressBar.setIndeterminate(indeterminate); progressBar.setIndeterminate(indeterminate);
@ -366,14 +370,14 @@ public class MapRouteInfoMenuFragment extends ContextMenuFragment {
} }
progressBar.setProgress(progress); 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 != null) {
if (progressBarButton.getVisibility() != View.VISIBLE) { if (progressBarButton.getVisibility() != View.VISIBLE) {
progressBarButton.setVisibility(View.VISIBLE); progressBarButton.setVisibility(View.VISIBLE);
} }
progressBarButton.setProgress(indeterminate ? 0 : progress); 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.percent = indeterminate ? 0 : progress / 100f;
textViewExProgress.invalidate(); textViewExProgress.invalidate();
} }
@ -390,11 +394,11 @@ public class MapRouteInfoMenuFragment extends ContextMenuFragment {
if (progressBar != null) { if (progressBar != null) {
progressBar.setVisibility(View.GONE); 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) { if (progressBarButton != null) {
progressBarButton.setProgress(0); 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; textViewExProgress.percent = 0;
} }
@ -501,4 +505,21 @@ public class MapRouteInfoMenuFragment extends ContextMenuFragment {
return false; 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();
}
}
}
} }

View file

@ -21,8 +21,8 @@ import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.plus.helpers.GpxUiHelper.GPXInfo; import net.osmand.plus.helpers.GpxUiHelper.GPXInfo;
import net.osmand.plus.routepreparationmenu.MapRouteInfoMenuFragment;
import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.track.TrackMenuFragment;
import net.osmand.plus.track.TrackSelectSegmentBottomSheet; import net.osmand.plus.track.TrackSelectSegmentBottomSheet;
import java.io.File; import java.io.File;
@ -131,8 +131,8 @@ public class TracksCard extends BaseCard {
} }
} }
if (item.file.getNonEmptySegmentsCount() > 1) { if (item.file.getNonEmptySegmentsCount() > 1) {
Fragment f = mapActivity.getSupportFragmentManager().findFragmentByTag(TrackMenuFragment.TAG); Fragment targetFragment = mapActivity.getSupportFragmentManager().findFragmentByTag(MapRouteInfoMenuFragment.TAG);
TrackSelectSegmentBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), item.file, f); TrackSelectSegmentBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), item.file, targetFragment);
} else { } else {
mapActivity.getMapActions().setGPXRouteParams(item.file); mapActivity.getMapActions().setGPXRouteParams(item.file);
app.getTargetPointsHelper().updateRouteAndRefresh(true); app.getTargetPointsHelper().updateRouteAndRefresh(true);

View file

@ -82,8 +82,8 @@ import net.osmand.plus.myplaces.TrackActivityFragmentAdapter;
import net.osmand.plus.osmedit.OsmEditingPlugin; import net.osmand.plus.osmedit.OsmEditingPlugin;
import net.osmand.plus.routepreparationmenu.cards.BaseCard; import net.osmand.plus.routepreparationmenu.cards.BaseCard;
import net.osmand.plus.routepreparationmenu.cards.BaseCard.CardListener; 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.routing.GPXRouteParams.GPXRouteParamsBuilder;
import net.osmand.plus.search.QuickSearchDialogFragment;
import net.osmand.plus.track.SaveGpxAsyncTask.SaveGpxListener; import net.osmand.plus.track.SaveGpxAsyncTask.SaveGpxListener;
import net.osmand.plus.track.TrackSelectSegmentBottomSheet.OnSegmentSelectedListener; import net.osmand.plus.track.TrackSelectSegmentBottomSheet.OnSegmentSelectedListener;
import net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint; import net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint;
@ -804,7 +804,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
if (gpxFile.getNonEmptySegmentsCount() > 1) { if (gpxFile.getNonEmptySegmentsCount() > 1) {
TrackSelectSegmentBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), gpxFile, this); TrackSelectSegmentBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), gpxFile, this);
} else { } else {
startNavigationForGPX(gpxFile, mapActions); startNavigationForGPX(gpxFile, mapActions, mapActivity);
dismiss(); dismiss();
} }
} }
@ -827,7 +827,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
segment = segments.get(0); 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)); List<GpxDisplayItem> items = TrackDisplayHelper.flatten(displayHelper.getOriginalGroups(filterTypes));
if (segment != null && !Algorithms.isEmpty(items)) { if (segment != null && !Algorithms.isEmpty(items)) {
SplitSegmentDialogFragment.showInstance(fragmentManager, displayHelper, items.get(0), segment); 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) { public static void startNavigationForGPX(final GPXFile gpxFile, MapActivityActions mapActions, final MapActivity mapActivity) {
if (app.getRoutingHelper().isFollowingMode()) { if (mapActivity.getMyApplication().getRoutingHelper().isFollowingMode()) {
mapActions.stopNavigationActionConfirm(null, new Runnable() { mapActions.stopNavigationActionConfirm(null, new Runnable() {
@Override @Override
public void run() { public void run() {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) { if (mapActivity != null) {
mapActivity.getMapActions().enterRoutePlanningModeGivenGpx(gpxFile, null, mapActivity.getMapActions().enterRoutePlanningModeGivenGpx(gpxFile, null,
null, null, true, true, MenuState.HEADER_ONLY); null, null, true, true, MenuState.HEADER_ONLY);
@ -1130,7 +1129,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
public boolean onMenuItemClick(MenuItem item) { public boolean onMenuItemClick(MenuItem item) {
int i = item.getItemId(); int i = item.getItemId();
if (i == R.id.action_edit) { if (i == R.id.action_edit) {
editSegment(segment); editSegment();
return true; return true;
} else if (i == R.id.action_delete) { } else if (i == R.id.action_delete) {
FragmentActivity activity = getActivity(); FragmentActivity activity = getActivity();
@ -1164,7 +1163,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
app.getSettings().GPX_ROUTE_SEGMENT.set(selectedSegment); app.getSettings().GPX_ROUTE_SEGMENT.set(selectedSegment);
MapActivity mapActivity = getMapActivity(); MapActivity mapActivity = getMapActivity();
if (mapActivity != null) { if (mapActivity != null) {
startNavigationForGPX(gpxFile, mapActivity.getMapActions()); startNavigationForGPX(gpxFile, mapActivity.getMapActions(), mapActivity);
GPXRouteParamsBuilder paramsBuilder = app.getRoutingHelper().getCurrentGPXRoute(); GPXRouteParamsBuilder paramsBuilder = app.getRoutingHelper().getCurrentGPXRoute();
if (paramsBuilder != null) { if (paramsBuilder != null) {
paramsBuilder.setSelectedSegment(selectedSegment); 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(); GPXFile gpxFile = getGpx();
openPlanRoute(new GpxData(gpxFile)); openPlanRoute(new GpxData(gpxFile));
hide(); hide();
@ -1219,7 +1218,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
@Override @Override
public void gpxSavingFinished(Exception errorMessage) { public void gpxSavingFinished(Exception errorMessage) {
if (selectedGpxFile != null) { 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.setDisplayGroups(groups, app);
selectedGpxFile.processPoints(app); selectedGpxFile.processPoints(app);
} }