From daba36f28e489eaf985ab754e206c5c24e6b8f95 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Fri, 17 Jul 2020 12:51:41 +0300 Subject: [PATCH] Fix undo, add directions, add rename --- .../MeasurementToolFragment.java | 28 +++++++++++++++++-- .../OptionsBottomSheetDialogFragment.java | 28 +++++++++++++++++-- 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java index 0e7c9c0012..fd3d36c99c 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java @@ -36,8 +36,11 @@ import androidx.recyclerview.widget.ItemTouchHelper; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; +import com.google.android.material.snackbar.Snackbar; + import net.osmand.AndroidUtils; import net.osmand.CallbackWithObject; +import net.osmand.FileUtils; import net.osmand.GPXUtilities; import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.Route; @@ -71,6 +74,7 @@ import net.osmand.plus.measurementtool.command.RemovePointCommand; import net.osmand.plus.measurementtool.command.ReorderPointCommand; import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.settings.backend.OsmandSettings; +import net.osmand.plus.views.MapControlsLayer; import net.osmand.plus.views.controls.ReorderItemTouchHelperCallback; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController; @@ -108,6 +112,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment { private ImageView undoBtn; private ImageView redoBtn; private ImageView mainIcon; + private Snackbar snackbar; private boolean wasCollapseButtonVisible; private boolean progressBarVisible; @@ -591,6 +596,14 @@ public class MeasurementToolFragment extends BaseOsmAndFragment { } } + @Override + public void directions() { + MapControlsLayer mapControlsLayer = mapActivity.getMapLayers().getMapControlsLayer(); + if (mapControlsLayer != null) { + mapControlsLayer.doRoute(false); + } + } + @Override public void addToGpxOnClick() { if (mapActivity != null && measurementLayer != null) { @@ -741,6 +754,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment { private void removePoint(MeasurementToolLayer layer, int position) { editingCtx.getCommandManager().execute(new RemovePointCommand(layer, position)); adapter.notifyDataSetChanged(); + enable(undoBtn); disable(redoBtn); updateText(); saved = false; @@ -1438,9 +1452,17 @@ public class MeasurementToolFragment extends BaseOsmAndFragment { if (openTrackActivity) { dismiss(activity); } else { - Toast.makeText(activity, - MessageFormat.format(getString(R.string.gpx_saved_sucessfully), toSave.getAbsolutePath()), - Toast.LENGTH_LONG).show(); + snackbar = Snackbar.make(activity.getLayout(), + MessageFormat.format(getString(R.string.gpx_saved_sucessfully), toSave.getName()), + Snackbar.LENGTH_LONG) + .setAction(R.string.shared_string_rename, new View.OnClickListener() { + @Override + public void onClick(View view) { + FileUtils.renameFile(getActivity(), toSave, null); + } + }); + UiUtilities.setupSnackbar(snackbar, nightMode); + snackbar.show(); if (close) { dismiss(activity); } diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java index 8ac32fa803..9c6168767c 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java @@ -27,8 +27,12 @@ public class OptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragm @Override public void createMenuItems(Bundle savedInstanceState) { Bundle args = getArguments(); - boolean snapToRoadEnabled = args.getBoolean(SNAP_TO_ROAD_ENABLED_KEY); - boolean addLineMode = args.getBoolean(ADD_LINE_MODE_KEY); + boolean snapToRoadEnabled = false; + boolean addLineMode = false; + if (args != null) { + snapToRoadEnabled = args.getBoolean(SNAP_TO_ROAD_ENABLED_KEY); + addLineMode = args.getBoolean(ADD_LINE_MODE_KEY); + } items.add(new TitleItem(getString(R.string.shared_string_options))); @@ -51,6 +55,24 @@ public class OptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragm items.add(new DividerHalfItem(getContext())); + BaseBottomSheetItem directions = new SimpleBottomSheetItem.Builder() + .setIcon(getContentIcon(R.drawable.ic_action_gdirections_dark)) + .setTitle(getString(R.string.get_directions)) + .setLayoutId(R.layout.bottom_sheet_item_simple) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (listener != null) { + listener.directions(); + } + dismiss(); + } + }) + .create(); + items.add(directions); + + items.add(new DividerHalfItem(getContext())); + if (addLineMode && !snapToRoadEnabled) { BaseBottomSheetItem saveAsNewSegmentItem = new SimpleBottomSheetItem.Builder() .setIcon(getContentIcon(R.drawable.ic_action_polygom_dark)) @@ -151,6 +173,8 @@ public class OptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragm void snapToRoadOnCLick(); + void directions(); + void addToGpxOnClick(); void saveAsNewTrackOnClick();