Dialog exit without saving
This commit is contained in:
parent
51fc861817
commit
86e21603d2
7 changed files with 237 additions and 66 deletions
38
OsmAnd/res/layout/bottom_sheet_button.xml
Normal file
38
OsmAnd/res/layout/bottom_sheet_button.xml
Normal 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>
|
|
@ -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>
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
Thx - Hardy
|
||||
|
||||
-->
|
||||
<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="overwrite_track">Overwrite track</string>
|
||||
<string name="shared_string_done">Done</string>
|
||||
<string name="plan_route_select_track_file_for_open">Select a track file for open.</string>
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue