Fix show Plan route UI after user selection from bottom sheet or choose different animation

This commit is contained in:
Dima-1 2020-09-11 15:24:52 +03:00
parent 8a3cdc0e35
commit df452989d1
4 changed files with 66 additions and 83 deletions

View file

@ -59,6 +59,7 @@ import net.osmand.plus.mapcontextmenu.AdditionalActionsBottomSheetDialogFragment
import net.osmand.plus.mapmarkers.MapMarkersDialogFragment; import net.osmand.plus.mapmarkers.MapMarkersDialogFragment;
import net.osmand.plus.mapmarkers.MarkersPlanRouteContext; import net.osmand.plus.mapmarkers.MarkersPlanRouteContext;
import net.osmand.plus.measurementtool.MeasurementToolFragment; import net.osmand.plus.measurementtool.MeasurementToolFragment;
import net.osmand.plus.measurementtool.StartPlanRouteBottomSheet;
import net.osmand.plus.monitoring.OsmandMonitoringPlugin; import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
import net.osmand.plus.routepreparationmenu.MapRouteInfoMenu; import net.osmand.plus.routepreparationmenu.MapRouteInfoMenu;
import net.osmand.plus.routepreparationmenu.WaypointsFragment; import net.osmand.plus.routepreparationmenu.WaypointsFragment;
@ -929,7 +930,7 @@ public class MapActivityActions implements DialogProvider {
.setListener(new ItemClickListener() { .setListener(new ItemClickListener() {
@Override @Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int position, boolean isChecked, int[] viewCoordinates) { public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int position, boolean isChecked, int[] viewCoordinates) {
MeasurementToolFragment.showInstance(mapActivity.getSupportFragmentManager()); StartPlanRouteBottomSheet.showInstance(mapActivity.getSupportFragmentManager());
return true; return true;
} }
}).createItem()); }).createItem());

View file

@ -1108,11 +1108,7 @@ public class ImportHelper {
} }
private void showPlanRouteFragment() { private void showPlanRouteFragment() {
MeasurementToolFragment fragment = (MeasurementToolFragment) activity.getSupportFragmentManager() MeasurementToolFragment.showInstance(activity.getSupportFragmentManager(), result);
.findFragmentByTag(MeasurementToolFragment.TAG);
if (fragment != null && !fragment.isDetached() && !fragment.isRemoving()) {
fragment.addNewGpxData(result);
}
} }
} }

View file

@ -97,9 +97,7 @@ import static net.osmand.plus.measurementtool.MeasurementEditingContext.Calculat
import static net.osmand.plus.measurementtool.MeasurementEditingContext.SnapToRoadProgressListener; import static net.osmand.plus.measurementtool.MeasurementEditingContext.SnapToRoadProgressListener;
import static net.osmand.plus.measurementtool.SaveAsNewTrackBottomSheetDialogFragment.SaveAsNewTrackFragmentListener; import static net.osmand.plus.measurementtool.SaveAsNewTrackBottomSheetDialogFragment.SaveAsNewTrackFragmentListener;
import static net.osmand.plus.measurementtool.SelectFileBottomSheet.Mode.ADD_TO_TRACK; import static net.osmand.plus.measurementtool.SelectFileBottomSheet.Mode.ADD_TO_TRACK;
import static net.osmand.plus.measurementtool.SelectFileBottomSheet.Mode.OPEN_TRACK;
import static net.osmand.plus.measurementtool.SelectFileBottomSheet.SelectFileListener; import static net.osmand.plus.measurementtool.SelectFileBottomSheet.SelectFileListener;
import static net.osmand.plus.measurementtool.StartPlanRouteBottomSheet.StartPlanRouteListener;
import static net.osmand.plus.measurementtool.command.ClearPointsCommand.ClearCommandMode; import static net.osmand.plus.measurementtool.command.ClearPointsCommand.ClearCommandMode;
import static net.osmand.plus.measurementtool.command.ClearPointsCommand.ClearCommandMode.AFTER; import static net.osmand.plus.measurementtool.command.ClearPointsCommand.ClearCommandMode.AFTER;
import static net.osmand.plus.measurementtool.command.ClearPointsCommand.ClearCommandMode.ALL; import static net.osmand.plus.measurementtool.command.ClearPointsCommand.ClearCommandMode.ALL;
@ -458,9 +456,6 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
if (savedInstanceState == null) { if (savedInstanceState == null) {
if (fileName != null) { if (fileName != null) {
addNewGpxData(getGpxFile(fileName)); addNewGpxData(getGpxFile(fileName));
} else if (editingCtx.isNewData() && planRouteMode && initialPoint == null) {
StartPlanRouteBottomSheet.showInstance(mapActivity.getSupportFragmentManager(),
createStartPlanRouteListener());
} else if (!editingCtx.isNewData() && !editingCtx.hasRoutePoints() && !editingCtx.hasRoute() && editingCtx.getPointsCount() > 1) { } else if (!editingCtx.isNewData() && !editingCtx.hasRoutePoints() && !editingCtx.hasRoute() && editingCtx.getPointsCount() > 1) {
enterApproximationMode(mapActivity); enterApproximationMode(mapActivity);
} }
@ -949,47 +944,6 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
} }
} }
private StartPlanRouteListener createStartPlanRouteListener() {
return new StartPlanRouteListener() {
@Override
public void openExistingTrackOnClick() {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
SelectFileBottomSheet.showInstance(mapActivity.getSupportFragmentManager(),
createSelectFileListener(), OPEN_TRACK);
}
}
@Override
public void openLastEditTrackOnClick(String gpxFileName) {
addNewGpxData(getGpxFile(gpxFileName));
}
@Override
public void dismissButtonOnClick() {
quit(true);
}
};
}
private SelectFileListener createSelectFileListener() {
return new SelectFileListener() {
@Override
public void selectFileOnCLick(String gpxFileName) {
addNewGpxData(getGpxFile(gpxFileName));
}
@Override
public void dismissButtonOnClick() {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
StartPlanRouteBottomSheet.showInstance(mapActivity.getSupportFragmentManager(),
createStartPlanRouteListener());
}
}
};
}
private GPXFile getGpxFile(String gpxFileName) { private GPXFile getGpxFile(String gpxFileName) {
OsmandApplication app = getMyApplication(); OsmandApplication app = getMyApplication();
GPXFile gpxFile = null; GPXFile gpxFile = null;
@ -1933,6 +1887,13 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
return showFragment(fragment, fragmentManager); return showFragment(fragment, fragmentManager);
} }
public static boolean showInstance(FragmentManager fragmentManager, GPXFile gpxFile) {
MeasurementToolFragment fragment = new MeasurementToolFragment();
fragment.addNewGpxData(gpxFile);
fragment.setPlanRouteMode(true);
return showFragment(fragment, fragmentManager);
}
public static boolean showInstance(FragmentManager fragmentManager, MeasurementEditingContext editingCtx, boolean planRoute) { public static boolean showInstance(FragmentManager fragmentManager, MeasurementEditingContext editingCtx, boolean planRoute) {
MeasurementToolFragment fragment = new MeasurementToolFragment(); MeasurementToolFragment fragment = new MeasurementToolFragment();
fragment.setEditingCtx(editingCtx); fragment.setEditingCtx(editingCtx);

View file

@ -9,6 +9,7 @@ import android.view.View;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.view.ContextThemeWrapper; import androidx.appcompat.view.ContextThemeWrapper;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
@ -19,6 +20,7 @@ import net.osmand.IndexConstants;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.BottomSheetBehaviourDialogFragment; import net.osmand.plus.base.BottomSheetBehaviourDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription; import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription;
@ -37,6 +39,7 @@ import java.util.Comparator;
import java.util.List; import java.util.List;
import static net.osmand.plus.helpers.GpxUiHelper.getSortedGPXFilesInfo; import static net.osmand.plus.helpers.GpxUiHelper.getSortedGPXFilesInfo;
import static net.osmand.plus.measurementtool.SelectFileBottomSheet.Mode.OPEN_TRACK;
public class StartPlanRouteBottomSheet extends BottomSheetBehaviourDialogFragment { public class StartPlanRouteBottomSheet extends BottomSheetBehaviourDialogFragment {
@ -47,13 +50,8 @@ public class StartPlanRouteBottomSheet extends BottomSheetBehaviourDialogFragmen
protected View mainView; protected View mainView;
protected GpxTrackAdapter adapter; protected GpxTrackAdapter adapter;
private StartPlanRouteListener listener;
private ImportHelper importHelper; private ImportHelper importHelper;
public void setListener(StartPlanRouteListener listener) {
this.listener = listener;
}
@Override @Override
public void createMenuItems(Bundle savedInstanceState) { public void createMenuItems(Bundle savedInstanceState) {
importHelper = new ImportHelper((AppCompatActivity) getActivity(), getMyApplication(), null); importHelper = new ImportHelper((AppCompatActivity) getActivity(), getMyApplication(), null);
@ -70,6 +68,10 @@ public class StartPlanRouteBottomSheet extends BottomSheetBehaviourDialogFragmen
.setOnClickListener(new View.OnClickListener() { .setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
FragmentActivity activity = getActivity();
if (activity != null) {
MeasurementToolFragment.showInstance(activity.getSupportFragmentManager());
}
dismiss(); dismiss();
} }
}) })
@ -83,10 +85,12 @@ public class StartPlanRouteBottomSheet extends BottomSheetBehaviourDialogFragmen
.setOnClickListener(new View.OnClickListener() { .setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if (listener != null) { MapActivity mapActivity = (MapActivity) getActivity();
listener.openExistingTrackOnClick(); if (mapActivity != null) {
hideBottomSheet();
SelectFileBottomSheet.showInstance(mapActivity.getSupportFragmentManager(),
createSelectFileListener(), OPEN_TRACK);
} }
dismiss();
} }
}) })
.create(); .create();
@ -137,14 +141,15 @@ public class StartPlanRouteBottomSheet extends BottomSheetBehaviourDialogFragmen
@Override @Override
protected int getPeekHeight() { protected int getPeekHeight() {
return AndroidUtils.dpToPx(getContext(), BOTTOM_SHEET_HEIGHT_DP); return AndroidUtils.dpToPx(requiredMyApplication(), BOTTOM_SHEET_HEIGHT_DP);
} }
private void onItemClick(int position, List<GPXInfo> gpxInfoList) { private void onItemClick(int position, List<GPXInfo> gpxInfoList) {
if (position != RecyclerView.NO_POSITION && position < gpxInfoList.size()) { if (position != RecyclerView.NO_POSITION && position < gpxInfoList.size()) {
String fileName = gpxInfoList.get(position).getFileName(); String fileName = gpxInfoList.get(position).getFileName();
if (listener != null) { FragmentActivity activity = getActivity();
listener.openLastEditTrackOnClick(fileName); if (activity != null) {
MeasurementToolFragment.showInstance(activity.getSupportFragmentManager(), fileName);
} }
} }
dismiss(); dismiss();
@ -189,35 +194,55 @@ public class StartPlanRouteBottomSheet extends BottomSheetBehaviourDialogFragmen
} }
} }
public static void showInstance(FragmentManager fragmentManager, StartPlanRouteListener listener) { private SelectFileBottomSheet.SelectFileListener createSelectFileListener() {
return new SelectFileBottomSheet.SelectFileListener() {
@Override
public void selectFileOnCLick(String gpxFileName) {
dismiss();
MapActivity mapActivity = (MapActivity) getActivity();
if (mapActivity != null) {
MeasurementToolFragment.showInstance(mapActivity.getSupportFragmentManager(), gpxFileName);
}
}
@Override
public void dismissButtonOnClick() {
MapActivity mapActivity = (MapActivity) getActivity();
if (mapActivity != null) {
showBottomSheet();
}
}
};
}
public static void showInstance(FragmentManager fragmentManager) {
if (!fragmentManager.isStateSaved()) { if (!fragmentManager.isStateSaved()) {
StartPlanRouteBottomSheet fragment = new StartPlanRouteBottomSheet(); StartPlanRouteBottomSheet fragment = new StartPlanRouteBottomSheet();
fragment.setUsedOnMap(true);
fragment.setRetainInstance(true); fragment.setRetainInstance(true);
fragment.setListener(listener);
fragment.show(fragmentManager, TAG); fragment.show(fragmentManager, TAG);
} }
} }
protected void hideBottomSheet() {
MapActivity mapActivity = (MapActivity) getActivity();
if (mapActivity != null) {
FragmentManager manager = mapActivity.getSupportFragmentManager();
manager.beginTransaction()
.hide(this).commit();
}
}
protected void showBottomSheet() {
MapActivity mapActivity = (MapActivity) getActivity();
if (mapActivity != null) {
FragmentManager manager = mapActivity.getSupportFragmentManager();
manager.beginTransaction()
.show(this).commit();
}
}
@Override @Override
protected int getDismissButtonTextId() { protected int getDismissButtonTextId() {
return R.string.shared_string_cancel; return R.string.shared_string_cancel;
} }
@Override
protected void onDismissButtonClickAction() {
if (listener != null) {
listener.dismissButtonOnClick();
}
}
interface StartPlanRouteListener {
void openExistingTrackOnClick();
void openLastEditTrackOnClick(String fileName);
void dismissButtonOnClick();
}
} }