From 86e21603d24d53820aff4804d1c38da9e17fabcc Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Wed, 5 Aug 2020 12:41:41 +0300 Subject: [PATCH 1/3] Dialog exit without saving --- OsmAnd/res/layout/bottom_sheet_button.xml | 38 ++++++++ OsmAnd/res/values/sizes.xml | 1 + OsmAnd/res/values/strings.xml | 1 + .../bottomsheetmenu/BaseBottomSheetItem.java | 2 +- .../BottomSheetItemButton.java | 76 +++++++++++++++ .../ExitBottomSheetDialogFragment.java | 90 ++++++++++++++++++ .../MeasurementToolFragment.java | 95 ++++++------------- 7 files changed, 237 insertions(+), 66 deletions(-) create mode 100644 OsmAnd/res/layout/bottom_sheet_button.xml create mode 100644 OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemButton.java create mode 100644 OsmAnd/src/net/osmand/plus/measurementtool/ExitBottomSheetDialogFragment.java diff --git a/OsmAnd/res/layout/bottom_sheet_button.xml b/OsmAnd/res/layout/bottom_sheet_button.xml new file mode 100644 index 0000000000..04affc5879 --- /dev/null +++ b/OsmAnd/res/layout/bottom_sheet_button.xml @@ -0,0 +1,38 @@ + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/values/sizes.xml b/OsmAnd/res/values/sizes.xml index a9ab89109c..091f8fe562 100644 --- a/OsmAnd/res/values/sizes.xml +++ b/OsmAnd/res/values/sizes.xml @@ -242,6 +242,7 @@ 20dp 16dp + 18dp 8dp 16dp 12dp diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index a31be91aa8..428a0a4562 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,6 +11,7 @@ Thx - Hardy --> + Are you sure you want to close Plan route without saving? You will lost all changes. Overwrite track Done Select a track file for open. diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BaseBottomSheetItem.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BaseBottomSheetItem.java index d57467a7e9..1914756d21 100644 --- a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BaseBottomSheetItem.java +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BaseBottomSheetItem.java @@ -21,7 +21,7 @@ public class BaseBottomSheetItem { protected int layoutId = INVALID_ID; private Object tag; private boolean disabled; - private View.OnClickListener onClickListener; + protected View.OnClickListener onClickListener; protected int position = INVALID_POSITION; public View getView() { diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemButton.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemButton.java new file mode 100644 index 0000000000..286ca832dc --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemButton.java @@ -0,0 +1,76 @@ +package net.osmand.plus.base.bottomsheetmenu; + +import android.content.Context; +import android.graphics.drawable.Drawable; +import android.view.View; +import android.view.ViewGroup; +import android.widget.LinearLayout; + +import androidx.annotation.ColorRes; +import androidx.annotation.LayoutRes; + +import net.osmand.plus.R; + +import static net.osmand.plus.UiUtilities.*; +import static net.osmand.plus.UiUtilities.DialogButtonType.PRIMARY; + +public class BottomSheetItemButton extends SimpleBottomSheetItem { + + protected CharSequence description; + + DialogButtonType buttonType; + + LinearLayout buttonView; + + public BottomSheetItemButton(View customView, + @LayoutRes int layoutId, + Object tag, + boolean disabled, + View.OnClickListener onClickListener, + int position, + Drawable icon, + Drawable background, + CharSequence title, + @ColorRes int titleColorId, + boolean iconHidden, + DialogButtonType buttonType) { + super(customView, layoutId, tag, disabled, onClickListener, position, icon, background, title, + titleColorId, iconHidden); + this.buttonType = buttonType; + } + + @Override + public void inflate(Context context, ViewGroup container, boolean nightMode) { + super.inflate(context, container, nightMode); + buttonView = view.findViewById(R.id.button); + if (buttonView != null) { + setupDialogButton(nightMode, buttonView, buttonType, title); + buttonView.setOnClickListener(onClickListener); + } + } + + public static class Builder extends SimpleBottomSheetItem.Builder { + + protected DialogButtonType buttonType = PRIMARY; + + public Builder setButtonType(DialogButtonType buttonType) { + this.buttonType = buttonType; + return this; + } + + public BottomSheetItemButton create() { + return new BottomSheetItemButton(customView, + layoutId, + tag, + disabled, + onClickListener, + position, + icon, + background, + title, + titleColorId, + iconHidden, + buttonType); + } + } +} diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/ExitBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/ExitBottomSheetDialogFragment.java new file mode 100644 index 0000000000..d32bc0ca0b --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/measurementtool/ExitBottomSheetDialogFragment.java @@ -0,0 +1,90 @@ +package net.osmand.plus.measurementtool; + +import android.os.Bundle; +import android.view.View; + +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; + +import net.osmand.plus.R; +import net.osmand.plus.UiUtilities; +import net.osmand.plus.base.MenuBottomSheetDialogFragment; +import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemButton; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerSpaceItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.ShortDescriptionItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; + +public class ExitBottomSheetDialogFragment extends MenuBottomSheetDialogFragment { + + public static final String TAG = ExitBottomSheetDialogFragment.class.getSimpleName(); + + @Override + public void createMenuItems(Bundle savedInstanceState) { + + items.add(new TitleItem(getString(R.string.exit_without_saving))); + + items.add(new ShortDescriptionItem.Builder() + .setDescription(getString(R.string.plan_route_exit_dialog_descr)) + .setDescriptionColorId(nightMode ? R.color.text_color_primary_dark : R.color.text_color_primary_light) + .setLayoutId(R.layout.bottom_sheet_item_description_long) + .create()); + + items.add(new DividerSpaceItem(getContext(), + getResources().getDimensionPixelSize(R.dimen.bottom_sheet_exit_button_margin))); + + items.add(new BottomSheetItemButton.Builder() + .setButtonType(UiUtilities.DialogButtonType.SECONDARY) + .setTitle(getString(R.string.shared_string_exit)) + .setLayoutId(R.layout.bottom_sheet_button) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Fragment target = getTargetFragment(); + if (target instanceof ExitFragmentListener) { + ((ExitFragmentListener) target).exitOnClick(); + } + dismiss(); + } + }) + .create()); + + items.add(new DividerSpaceItem(getContext(), + getResources().getDimensionPixelSize(R.dimen.bottom_sheet_icon_margin))); + + items.add(new BottomSheetItemButton.Builder() + .setTitle(getString(R.string.shared_string_save)) + .setLayoutId(R.layout.bottom_sheet_button) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Fragment target = getTargetFragment(); + if (target instanceof ExitFragmentListener) { + ((ExitFragmentListener) target).saveOnClick(); + } + dismiss(); + } + }) + .create()); + } + + @Override + protected int getDismissButtonTextId() { + return R.string.shared_string_close; + } + + public static void showInstance(FragmentManager fragmentManager, Fragment target) { + if (!fragmentManager.isStateSaved()) { + ExitBottomSheetDialogFragment fragment = new ExitBottomSheetDialogFragment(); + fragment.setUsedOnMap(true); + fragment.setTargetFragment(target, 0); + fragment.show(fragmentManager, TAG); + } + } + + interface ExitFragmentListener { + + void exitOnClick(); + + void saveOnClick(); + } +} diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java index bc28b3995e..71fcfb71a6 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java @@ -78,7 +78,6 @@ 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; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarControllerType; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarView; @@ -96,9 +95,10 @@ import static net.osmand.plus.measurementtool.SelectFileBottomSheet.SelectFileLi import static net.osmand.plus.measurementtool.StartPlanRouteBottomSheet.StartPlanRouteListener; -public class MeasurementToolFragment extends BaseOsmAndFragment { +public class MeasurementToolFragment extends BaseOsmAndFragment + implements ExitBottomSheetDialogFragment.ExitFragmentListener { - public static final String TAG = "MeasurementToolFragment"; + public static final String TAG = MeasurementToolFragment.class.getSimpleName(); private RecyclerView pointsRv; private String previousToolBarTitle = ""; @@ -123,6 +123,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment { private boolean progressBarVisible; private boolean pointsListOpened; private boolean planRouteMode = false; + private boolean firstShow = true; private Boolean saved; private boolean portrait; private boolean nightMode; @@ -154,6 +155,9 @@ public class MeasurementToolFragment extends BaseOsmAndFragment { @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { final MapActivity mapActivity = (MapActivity) getActivity(); + if (mapActivity == null) { + return null; + } final MeasurementToolLayer measurementLayer = mapActivity.getMapLayers().getMeasurementToolLayer(); editingCtx.setApplication(mapActivity.getMyApplication()); @@ -434,13 +438,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment { if (editingCtx.getPointsCount() > 0) { if (newGpxData != null && newGpxData.getActionType() == ActionType.EDIT_SEGMENT && editingCtx.isInSnapToRoadMode()) { - if (mapActivity != null) { - if (editingCtx.getPointsCount() > 0) { openSaveAsNewTrackMenu(mapActivity); - } else { - Toast.makeText(mapActivity, getString(R.string.none_point_error), Toast.LENGTH_SHORT).show(); - } - } } else { if (newGpxData == null) { final File dir = mapActivity.getMyApplication().getAppPath(IndexConstants.GPX_INDEX_DIR); @@ -480,9 +478,10 @@ public class MeasurementToolFragment extends BaseOsmAndFragment { initMeasurementMode(newGpxData); - if (planRouteMode) { + if (planRouteMode && firstShow) { StartPlanRouteBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), createStartPlanRouteListener()); + firstShow = false; } return view; } @@ -582,6 +581,16 @@ public class MeasurementToolFragment extends BaseOsmAndFragment { return getIcon(id, nightMode ? R.color.osmand_orange : R.color.color_myloc_distance); } + @Override + public void exitOnClick() { + dismiss(getMapActivity()); + } + + @Override + public void saveOnClick() { + openSaveAsNewTrackMenu(getMapActivity()); + } + private void showProgressBar() { ProgressBar progressBar = (ProgressBar) mainView.findViewById(R.id.snap_to_road_progress_bar); progressBar.setVisibility(View.VISIBLE); @@ -647,13 +656,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment { @Override public void saveAsNewTrackOnClick() { - if (mapActivity != null && measurementLayer != null) { - if (editingCtx.getPointsCount() > 0) { openSaveAsNewTrackMenu(mapActivity); - } else { - Toast.makeText(mapActivity, getString(R.string.none_point_error), Toast.LENGTH_SHORT).show(); - } - } } @Override @@ -1006,10 +1009,16 @@ public class MeasurementToolFragment extends BaseOsmAndFragment { } private void openSaveAsNewTrackMenu(MapActivity mapActivity) { - SaveAsNewTrackBottomSheetDialogFragment fragment = new SaveAsNewTrackBottomSheetDialogFragment(); - fragment.setUsedOnMap(true); - fragment.setListener(createSaveAsNewTrackFragmentListener()); - fragment.show(mapActivity.getSupportFragmentManager(), SaveAsNewTrackBottomSheetDialogFragment.TAG); + if (mapActivity != null) { + if (editingCtx.getPointsCount() > 0) { + SaveAsNewTrackBottomSheetDialogFragment fragment = new SaveAsNewTrackBottomSheetDialogFragment(); + fragment.setUsedOnMap(true); + fragment.setListener(createSaveAsNewTrackFragmentListener()); + fragment.show(mapActivity.getSupportFragmentManager(), SaveAsNewTrackBottomSheetDialogFragment.TAG); + } else { + Toast.makeText(mapActivity, getString(R.string.none_point_error), Toast.LENGTH_SHORT).show(); + } + } } private AlertDialog showAddToTrackDialog(final MapActivity mapActivity) { @@ -1718,51 +1727,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment { dismiss(mapActivity); return; } - AlertDialog.Builder builder = new AlertDialog.Builder(UiUtilities.getThemedContext(mapActivity, nightMode)); - if (editingCtx.getNewGpxData() == null) { - final File dir = mapActivity.getMyApplication().getAppPath(IndexConstants.GPX_INDEX_DIR); - final View view = UiUtilities.getInflater(mapActivity, nightMode).inflate(R.layout.close_measurement_tool_dialog, null); - final SwitchCompat showOnMapToggle = (SwitchCompat) view.findViewById(R.id.toggle_show_on_map); - - view.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - showOnMapToggle.setChecked(!showOnMapToggle.isChecked()); - } - }); - - builder.setView(view); - builder.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - if (showOnMapToggle.isChecked()) { - final String name = new SimpleDateFormat("yyyy-MM-dd_HH-mm_EEE", Locale.US).format(new Date()); - String fileName = name + GPX_FILE_EXT; - File fout = new File(dir, fileName); - int ind = 1; - while (fout.exists()) { - fileName = name + "_" + (++ind) + GPX_FILE_EXT; - fout = new File(dir, fileName); - } - saveNewGpx(dir, fileName, true, SaveType.LINE, true); - } else { - dismiss(mapActivity); - } - } - }); - UiUtilities.setupCompoundButton(showOnMapToggle, nightMode, UiUtilities.CompoundButtonType.GLOBAL); - } else { - builder.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - dismiss(mapActivity); - } - }); - } - builder.setTitle(getString(R.string.exit_without_saving)) - .setMessage(getString(R.string.unsaved_changes_will_be_lost)) - .setNegativeButton(R.string.shared_string_cancel, null); - builder.show(); + ExitBottomSheetDialogFragment.showInstance(mapActivity.getSupportFragmentManager(), this); } } From a9bb3d49a4e319d847b936364bf88c37ba27bed6 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Thu, 6 Aug 2020 14:17:34 +0300 Subject: [PATCH 2/3] Fix first show --- .../plus/measurementtool/MeasurementToolFragment.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java index 71fcfb71a6..2638521845 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java @@ -94,7 +94,6 @@ import static net.osmand.IndexConstants.GPX_FILE_EXT; import static net.osmand.plus.measurementtool.SelectFileBottomSheet.SelectFileListener; import static net.osmand.plus.measurementtool.StartPlanRouteBottomSheet.StartPlanRouteListener; - public class MeasurementToolFragment extends BaseOsmAndFragment implements ExitBottomSheetDialogFragment.ExitFragmentListener { @@ -123,7 +122,6 @@ public class MeasurementToolFragment extends BaseOsmAndFragment private boolean progressBarVisible; private boolean pointsListOpened; private boolean planRouteMode = false; - private boolean firstShow = true; private Boolean saved; private boolean portrait; private boolean nightMode; @@ -153,7 +151,8 @@ public class MeasurementToolFragment extends BaseOsmAndFragment @Nullable @Override - public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, + @Nullable Bundle savedInstanceState) { final MapActivity mapActivity = (MapActivity) getActivity(); if (mapActivity == null) { return null; @@ -219,7 +218,8 @@ public class MeasurementToolFragment extends BaseOsmAndFragment downIcon = getContentIcon(R.drawable.ic_action_arrow_down); pointsSt = getString(R.string.shared_string_gpx_points).toLowerCase(); - View view = UiUtilities.getInflater(getContext(), nightMode).inflate(R.layout.fragment_measurement_tool, null); + View view = UiUtilities.getInflater(getContext(), nightMode).inflate(R.layout.fragment_measurement_tool, + container,false); mainView = view.findViewById(R.id.main_view); AndroidUtils.setBackground(mapActivity, mainView, nightMode, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark); @@ -478,10 +478,9 @@ public class MeasurementToolFragment extends BaseOsmAndFragment initMeasurementMode(newGpxData); - if (planRouteMode && firstShow) { + if (planRouteMode && savedInstanceState == null) { StartPlanRouteBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), createStartPlanRouteListener()); - firstShow = false; } return view; } From 89fa1bea313d8a48cec5ac907dd4fc60499f1ad1 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Tue, 11 Aug 2020 16:34:08 +0300 Subject: [PATCH 3/3] Fix merge conflicts, small refactoring --- .../ExitBottomSheetDialogFragment.java | 30 ++++---- .../MeasurementToolFragment.java | 71 ++++++++++--------- .../SnapTrackWarningBottomSheet.java | 8 +-- 3 files changed, 56 insertions(+), 53 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/ExitBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/ExitBottomSheetDialogFragment.java index d32bc0ca0b..a7c946cf00 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/ExitBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/ExitBottomSheetDialogFragment.java @@ -3,6 +3,8 @@ package net.osmand.plus.measurementtool; import android.os.Bundle; import android.view.View; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; @@ -16,6 +18,10 @@ import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; public class ExitBottomSheetDialogFragment extends MenuBottomSheetDialogFragment { + public static final int REQUEST_CODE = 1001; + public static final int SAVE_RESULT_CODE = 2; + public static final int EXIT_RESULT_CODE = 3; + public static final String TAG = ExitBottomSheetDialogFragment.class.getSimpleName(); @Override @@ -39,9 +45,9 @@ public class ExitBottomSheetDialogFragment extends MenuBottomSheetDialogFragment .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - Fragment target = getTargetFragment(); - if (target instanceof ExitFragmentListener) { - ((ExitFragmentListener) target).exitOnClick(); + Fragment targetFragment = getTargetFragment(); + if (targetFragment != null) { + targetFragment.onActivityResult(REQUEST_CODE, EXIT_RESULT_CODE, null); } dismiss(); } @@ -57,9 +63,9 @@ public class ExitBottomSheetDialogFragment extends MenuBottomSheetDialogFragment .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - Fragment target = getTargetFragment(); - if (target instanceof ExitFragmentListener) { - ((ExitFragmentListener) target).saveOnClick(); + Fragment targetFragment = getTargetFragment(); + if (targetFragment != null) { + targetFragment.onActivityResult(REQUEST_CODE, SAVE_RESULT_CODE, null); } dismiss(); } @@ -72,19 +78,11 @@ public class ExitBottomSheetDialogFragment extends MenuBottomSheetDialogFragment return R.string.shared_string_close; } - public static void showInstance(FragmentManager fragmentManager, Fragment target) { + public static void showInstance(@NonNull FragmentManager fragmentManager, @Nullable Fragment targetFragment) { if (!fragmentManager.isStateSaved()) { ExitBottomSheetDialogFragment fragment = new ExitBottomSheetDialogFragment(); - fragment.setUsedOnMap(true); - fragment.setTargetFragment(target, 0); + fragment.setTargetFragment(targetFragment, REQUEST_CODE); fragment.show(fragmentManager, TAG); } } - - interface ExitFragmentListener { - - void exitOnClick(); - - void saveOnClick(); - } } diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java index 69e2d9070b..fd36871325 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java @@ -103,8 +103,6 @@ import static net.osmand.plus.measurementtool.SelectFileBottomSheet.Mode.OPEN_TR import static net.osmand.plus.measurementtool.SelectFileBottomSheet.SelectFileListener; import static net.osmand.plus.measurementtool.StartPlanRouteBottomSheet.StartPlanRouteListener; -public class MeasurementToolFragment extends BaseOsmAndFragment - implements ExitBottomSheetDialogFragment.ExitFragmentListener { public class MeasurementToolFragment extends BaseOsmAndFragment implements RouteBetweenPointsFragmentListener, GpxApproximationFragmentListener, OptionsFragmentListener { @@ -222,14 +220,16 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route downIcon = getContentIcon(R.drawable.ic_action_arrow_down); pointsSt = getString(R.string.shared_string_gpx_points).toLowerCase(); - View view = UiUtilities.getInflater(getContext(), nightMode).inflate(R.layout.fragment_measurement_tool, - container,false); + View view = UiUtilities.getInflater(getContext(), nightMode) + .inflate(R.layout.fragment_measurement_tool, container, false); mainView = view.findViewById(R.id.main_view); AndroidUtils.setBackground(mapActivity, mainView, nightMode, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark); pointsListContainer = view.findViewById(R.id.points_list_container); if (portrait && pointsListContainer != null) { - final int backgroundColor = ContextCompat.getColor(mapActivity, nightMode ? R.color.activity_background_color_dark : R.color.activity_background_color_light); + final int backgroundColor = ContextCompat.getColor(mapActivity, nightMode + ? R.color.activity_background_color_dark + : R.color.activity_background_color_light); pointsListContainer.setBackgroundColor(backgroundColor); } @@ -605,16 +605,6 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route return getIcon(id, nightMode ? R.color.osmand_orange : R.color.color_myloc_distance); } - @Override - public void exitOnClick() { - dismiss(getMapActivity()); - } - - @Override - public void saveOnClick() { - openSaveAsNewTrackMenu(getMapActivity()); - } - private void showProgressBar() { ProgressBar progressBar = (ProgressBar) mainView.findViewById(R.id.snap_to_road_progress_bar); progressBar.setVisibility(View.VISIBLE); @@ -659,25 +649,38 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route @Override public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); - if (requestCode == SnapTrackWarningBottomSheet.REQUEST_CODE) { - switch (resultCode) { - case SnapTrackWarningBottomSheet.CANCEL_REQUEST_CODE: - toolBarController.setSaveViewVisible(true); - updateToolbar(); - break; - case SnapTrackWarningBottomSheet.CONTINUE_REQUEST_CODE: - MapActivity mapActivity = getMapActivity(); - if (mapActivity != null) { - try { - gpxApproximator = new GpxApproximator(requireMyApplication(), new LocationsHolder(editingCtx.getPoints())); - GpxApproximationFragment.showInstance(mapActivity.getSupportFragmentManager(), - this, gpxApproximator.getMode(), (int) gpxApproximator.getPointApproximation()); - } catch (IOException e) { + switch (requestCode) { + case SnapTrackWarningBottomSheet.REQUEST_CODE: + switch (resultCode) { + case SnapTrackWarningBottomSheet.CANCEL_RESULT_CODE: + toolBarController.setSaveViewVisible(true); + updateToolbar(); + break; + case SnapTrackWarningBottomSheet.CONTINUE_RESULT_CODE: + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { + try { + gpxApproximator = new GpxApproximator(requireMyApplication(), + new LocationsHolder(editingCtx.getPoints())); + GpxApproximationFragment.showInstance(mapActivity.getSupportFragmentManager(), + this, gpxApproximator.getMode(), + (int) gpxApproximator.getPointApproximation()); + } catch (IOException e) { + } } - } - break; - } + break; + } + break; + case ExitBottomSheetDialogFragment.REQUEST_CODE: + switch (resultCode) { + case ExitBottomSheetDialogFragment.EXIT_RESULT_CODE: + dismiss(getMapActivity()); + break; + case ExitBottomSheetDialogFragment.SAVE_RESULT_CODE: + openSaveAsNewTrackMenu(getMapActivity()); + break; + } } } @@ -725,7 +728,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route @Override public void saveAsNewTrackOnClick() { - openSaveAsNewTrackMenu(mapActivity); + openSaveAsNewTrackMenu(getMapActivity()); } @Override @@ -857,6 +860,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route @Override public void openLastEditTrackOnClick(String gpxFileName) { addNewGpxData(getGpxFile(gpxFileName)); + saved = true; } @Override @@ -871,6 +875,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route @Override public void selectFileOnCLick(String gpxFileName) { addNewGpxData(getGpxFile(gpxFileName)); + saved = true; } @Override diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/SnapTrackWarningBottomSheet.java b/OsmAnd/src/net/osmand/plus/measurementtool/SnapTrackWarningBottomSheet.java index f91aba9464..666cb58b3f 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/SnapTrackWarningBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/SnapTrackWarningBottomSheet.java @@ -23,8 +23,8 @@ import org.apache.commons.logging.Log; public class SnapTrackWarningBottomSheet extends MenuBottomSheetDialogFragment { public static final int REQUEST_CODE = 1000; - public static final int CANCEL_REQUEST_CODE = 2; - public static final int CONTINUE_REQUEST_CODE = 3; + public static final int CANCEL_RESULT_CODE = 2; + public static final int CONTINUE_RESULT_CODE = 3; public static final String TAG = SnapTrackWarningBottomSheet.class.getSimpleName(); private static final Log LOG = PlatformUtil.getLog(SnapTrackWarningBottomSheet.class); @@ -58,7 +58,7 @@ public class SnapTrackWarningBottomSheet extends MenuBottomSheetDialogFragment { protected void onRightBottomButtonClick() { Fragment fragment = getTargetFragment(); if (fragment != null) { - fragment.onActivityResult(REQUEST_CODE, CONTINUE_REQUEST_CODE, null); + fragment.onActivityResult(REQUEST_CODE, CONTINUE_RESULT_CODE, null); } dismiss(); } @@ -77,7 +77,7 @@ public class SnapTrackWarningBottomSheet extends MenuBottomSheetDialogFragment { } Fragment fragment = getTargetFragment(); if (fragment != null) { - fragment.onActivityResult(REQUEST_CODE, CANCEL_REQUEST_CODE, null); + fragment.onActivityResult(REQUEST_CODE, CANCEL_RESULT_CODE, null); } }