Merge pull request #9789 from osmandapp/plan_route_bugs_ui_widgets
Show plan route UI after
This commit is contained in:
commit
dde3e10f5a
4 changed files with 66 additions and 83 deletions
|
@ -59,6 +59,7 @@ import net.osmand.plus.mapcontextmenu.AdditionalActionsBottomSheetDialogFragment
|
|||
import net.osmand.plus.mapmarkers.MapMarkersDialogFragment;
|
||||
import net.osmand.plus.mapmarkers.MarkersPlanRouteContext;
|
||||
import net.osmand.plus.measurementtool.MeasurementToolFragment;
|
||||
import net.osmand.plus.measurementtool.StartPlanRouteBottomSheet;
|
||||
import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
|
||||
import net.osmand.plus.routepreparationmenu.MapRouteInfoMenu;
|
||||
import net.osmand.plus.routepreparationmenu.WaypointsFragment;
|
||||
|
@ -929,7 +930,7 @@ public class MapActivityActions implements DialogProvider {
|
|||
.setListener(new ItemClickListener() {
|
||||
@Override
|
||||
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int position, boolean isChecked, int[] viewCoordinates) {
|
||||
MeasurementToolFragment.showInstance(mapActivity.getSupportFragmentManager());
|
||||
StartPlanRouteBottomSheet.showInstance(mapActivity.getSupportFragmentManager());
|
||||
return true;
|
||||
}
|
||||
}).createItem());
|
||||
|
|
|
@ -1108,11 +1108,7 @@ public class ImportHelper {
|
|||
}
|
||||
|
||||
private void showPlanRouteFragment() {
|
||||
MeasurementToolFragment fragment = (MeasurementToolFragment) activity.getSupportFragmentManager()
|
||||
.findFragmentByTag(MeasurementToolFragment.TAG);
|
||||
if (fragment != null && !fragment.isDetached() && !fragment.isRemoving()) {
|
||||
fragment.addNewGpxData(result);
|
||||
}
|
||||
MeasurementToolFragment.showInstance(activity.getSupportFragmentManager(), result);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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.SaveAsNewTrackBottomSheetDialogFragment.SaveAsNewTrackFragmentListener;
|
||||
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.StartPlanRouteBottomSheet.StartPlanRouteListener;
|
||||
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.ALL;
|
||||
|
@ -462,9 +460,6 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
|
|||
if (savedInstanceState == null) {
|
||||
if (fileName != null) {
|
||||
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) {
|
||||
enterApproximationMode(mapActivity);
|
||||
}
|
||||
|
@ -953,47 +948,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) {
|
||||
OsmandApplication app = getMyApplication();
|
||||
GPXFile gpxFile = null;
|
||||
|
@ -1937,6 +1891,13 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
|
|||
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, boolean directionMode) {
|
||||
MeasurementToolFragment fragment = new MeasurementToolFragment();
|
||||
|
|
|
@ -9,6 +9,7 @@ import android.view.View;
|
|||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.view.ContextThemeWrapper;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
@ -19,6 +20,7 @@ import net.osmand.IndexConstants;
|
|||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.base.BottomSheetBehaviourDialogFragment;
|
||||
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
|
||||
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription;
|
||||
|
@ -37,6 +39,7 @@ import java.util.Comparator;
|
|||
import java.util.List;
|
||||
|
||||
import static net.osmand.plus.helpers.GpxUiHelper.getSortedGPXFilesInfo;
|
||||
import static net.osmand.plus.measurementtool.SelectFileBottomSheet.Mode.OPEN_TRACK;
|
||||
|
||||
public class StartPlanRouteBottomSheet extends BottomSheetBehaviourDialogFragment {
|
||||
|
||||
|
@ -47,13 +50,8 @@ public class StartPlanRouteBottomSheet extends BottomSheetBehaviourDialogFragmen
|
|||
|
||||
protected View mainView;
|
||||
protected GpxTrackAdapter adapter;
|
||||
private StartPlanRouteListener listener;
|
||||
private ImportHelper importHelper;
|
||||
|
||||
public void setListener(StartPlanRouteListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createMenuItems(Bundle savedInstanceState) {
|
||||
importHelper = new ImportHelper((AppCompatActivity) getActivity(), getMyApplication(), null);
|
||||
|
@ -70,6 +68,10 @@ public class StartPlanRouteBottomSheet extends BottomSheetBehaviourDialogFragmen
|
|||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
FragmentActivity activity = getActivity();
|
||||
if (activity != null) {
|
||||
MeasurementToolFragment.showInstance(activity.getSupportFragmentManager());
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
})
|
||||
|
@ -83,10 +85,12 @@ public class StartPlanRouteBottomSheet extends BottomSheetBehaviourDialogFragmen
|
|||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (listener != null) {
|
||||
listener.openExistingTrackOnClick();
|
||||
MapActivity mapActivity = (MapActivity) getActivity();
|
||||
if (mapActivity != null) {
|
||||
hideBottomSheet();
|
||||
SelectFileBottomSheet.showInstance(mapActivity.getSupportFragmentManager(),
|
||||
createSelectFileListener(), OPEN_TRACK);
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
})
|
||||
.create();
|
||||
|
@ -137,14 +141,15 @@ public class StartPlanRouteBottomSheet extends BottomSheetBehaviourDialogFragmen
|
|||
|
||||
@Override
|
||||
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) {
|
||||
if (position != RecyclerView.NO_POSITION && position < gpxInfoList.size()) {
|
||||
String fileName = gpxInfoList.get(position).getFileName();
|
||||
if (listener != null) {
|
||||
listener.openLastEditTrackOnClick(fileName);
|
||||
FragmentActivity activity = getActivity();
|
||||
if (activity != null) {
|
||||
MeasurementToolFragment.showInstance(activity.getSupportFragmentManager(), fileName);
|
||||
}
|
||||
}
|
||||
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()) {
|
||||
StartPlanRouteBottomSheet fragment = new StartPlanRouteBottomSheet();
|
||||
fragment.setUsedOnMap(true);
|
||||
fragment.setRetainInstance(true);
|
||||
fragment.setListener(listener);
|
||||
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
|
||||
protected int getDismissButtonTextId() {
|
||||
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();
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue