Merge pull request #9580 from osmandapp/plan_route_exit_wo_saving

Plan route Exit dialog
This commit is contained in:
Vitaliy 2020-08-14 12:37:01 +03:00 committed by GitHub
commit caf66773ea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 257 additions and 86 deletions

View file

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
android:id="@+id/button"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="@dimen/dialog_button_height"
android:layout_marginStart="@dimen/content_padding"
android:layout_marginEnd="@dimen/content_padding"
android:layout_marginLeft="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding">
<LinearLayout
android:id="@+id/button_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:duplicateParentState="true"
tools:ignore="UselessParent">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/button_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/content_padding_small"
android:paddingRight="@dimen/content_padding_small"
android:gravity="center"
android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_medium"
android:duplicateParentState="true"
tools:text="Button"
android:paddingStart="@dimen/content_padding_small"
android:paddingEnd="@dimen/content_padding_small" />
</LinearLayout>
</LinearLayout>

View file

@ -242,6 +242,7 @@
<dimen name="measurement_tool_select_radius">20dp</dimen>
<dimen name="bottom_sheet_content_margin">16dp</dimen>
<dimen name="bottom_sheet_exit_button_margin">18dp</dimen>
<dimen name="bottom_sheet_content_margin_small">8dp</dimen>
<dimen name="content_padding">16dp</dimen>
<dimen name="content_padding_small">12dp</dimen>

View file

@ -11,8 +11,9 @@
Thx - Hardy
-->
<string name="in_case_of_reverse_direction">In case of reverse direction</string>
<string name="plan_route_exit_dialog_descr">Are you sure you want to close Plan route without saving? You will lost all changes.</string>
<string name="street_level_imagery">Street-level imagery</string>
<string name="rourte_between_points_add_track_desc">Select a track file for which a new segment will be added.</string>
<string name="navigation_profile">Navigation profile</string>
<string name="threshold_distance">Threshold distance</string>

View file

@ -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() {

View file

@ -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);
}
}
}

View file

@ -0,0 +1,88 @@
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;
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 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
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 targetFragment = getTargetFragment();
if (targetFragment != null) {
targetFragment.onActivityResult(REQUEST_CODE, EXIT_RESULT_CODE, null);
}
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 targetFragment = getTargetFragment();
if (targetFragment != null) {
targetFragment.onActivityResult(REQUEST_CODE, SAVE_RESULT_CODE, null);
}
dismiss();
}
})
.create());
}
@Override
protected int getDismissButtonTextId() {
return R.string.shared_string_close;
}
public static void showInstance(@NonNull FragmentManager fragmentManager, @Nullable Fragment targetFragment) {
if (!fragmentManager.isStateSaved()) {
ExitBottomSheetDialogFragment fragment = new ExitBottomSheetDialogFragment();
fragment.setTargetFragment(targetFragment, REQUEST_CODE);
fragment.show(fragmentManager, TAG);
}
}
}

View file

@ -161,6 +161,9 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
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());
@ -221,7 +224,9 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
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);
}
@ -423,13 +428,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
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);
@ -614,13 +613,14 @@ 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 (requestCode) {
case SnapTrackWarningBottomSheet.REQUEST_CODE:
switch (resultCode) {
case SnapTrackWarningBottomSheet.CANCEL_REQUEST_CODE:
case SnapTrackWarningBottomSheet.CANCEL_RESULT_CODE:
toolBarController.setSaveViewVisible(true);
updateToolbar();
break;
case SnapTrackWarningBottomSheet.CONTINUE_REQUEST_CODE:
case SnapTrackWarningBottomSheet.CONTINUE_RESULT_CODE:
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
GpxApproximationFragment.showInstance(mapActivity.getSupportFragmentManager(),
@ -628,6 +628,16 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
}
break;
}
break;
case ExitBottomSheetDialogFragment.REQUEST_CODE:
switch (resultCode) {
case ExitBottomSheetDialogFragment.EXIT_RESULT_CODE:
dismiss(getMapActivity());
break;
case ExitBottomSheetDialogFragment.SAVE_RESULT_CODE:
openSaveAsNewTrackMenu(getMapActivity());
break;
}
}
}
@ -675,14 +685,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
@Override
public void saveAsNewTrackOnClick() {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
if (editingCtx.getPointsCount() > 0) {
openSaveAsNewTrackMenu(mapActivity);
} else {
Toast.makeText(mapActivity, getString(R.string.none_point_error), Toast.LENGTH_SHORT).show();
}
}
openSaveAsNewTrackMenu(getMapActivity());
}
@Override
@ -814,6 +817,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
@Override
public void openLastEditTrackOnClick(String gpxFileName) {
addNewGpxData(getGpxFile(gpxFileName));
saved = true;
}
@Override
@ -828,6 +832,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
@Override
public void selectFileOnCLick(String gpxFileName) {
addNewGpxData(getGpxFile(gpxFileName));
saved = true;
}
@Override
@ -1074,10 +1079,16 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
}
private void openSaveAsNewTrackMenu(MapActivity mapActivity) {
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 void showAddToTrackDialog(final MapActivity mapActivity) {
@ -1779,51 +1790,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
dismiss(mapActivity);
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(UiUtilities.getThemedContext(mapActivity, nightMode));
if (editingCtx.isNewData()) {
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);
}
}

View file

@ -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);
}
}