Merge pull request #10306 from osmandapp/Dismiss-buttons
Dismiss buttons
This commit is contained in:
commit
8727610bfb
9 changed files with 129 additions and 45 deletions
|
@ -2655,7 +2655,7 @@
|
|||
<string name="files_limit">%1$d files left</string>
|
||||
<string name="available_downloads_left">%1$d files left to download</string>
|
||||
<string name="install_paid">Full version</string>
|
||||
<string name="cancel_route">Dismiss route</string>
|
||||
<string name="cancel_route">Dismiss route?</string>
|
||||
<string name="cancel_navigation">Stop navigation</string>
|
||||
<string name="clear_destination">Clear destination</string>
|
||||
<string name="download_using_mobile_internet">Not connected to Wi-Fi. Use current connection to the Internet to download?</string>
|
||||
|
|
|
@ -19,7 +19,6 @@ import android.view.KeyEvent;
|
|||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
@ -55,8 +54,6 @@ import net.osmand.plus.FavouritesDbHelper;
|
|||
import net.osmand.plus.GPXDatabase.GpxDataItem;
|
||||
import net.osmand.plus.GpxSelectionHelper;
|
||||
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
|
||||
import net.osmand.plus.mapmarkers.MapMarkersHelper;
|
||||
import net.osmand.plus.mapmarkers.MapMarker;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
import net.osmand.plus.SQLiteTileSource;
|
||||
|
@ -68,6 +65,8 @@ import net.osmand.plus.helpers.ExternalApiHelper;
|
|||
import net.osmand.plus.helpers.LockHelper;
|
||||
import net.osmand.plus.mapcontextmenu.MapContextMenu;
|
||||
import net.osmand.plus.mapcontextmenu.other.IContextMenuButtonListener;
|
||||
import net.osmand.plus.mapmarkers.MapMarker;
|
||||
import net.osmand.plus.mapmarkers.MapMarkersHelper;
|
||||
import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
|
||||
import net.osmand.plus.myplaces.TrackBitmapDrawer;
|
||||
import net.osmand.plus.quickaction.QuickAction;
|
||||
|
@ -79,11 +78,11 @@ import net.osmand.plus.routing.RouteDirectionInfo;
|
|||
import net.osmand.plus.routing.RoutingHelper;
|
||||
import net.osmand.plus.routing.VoiceRouter;
|
||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||
import net.osmand.plus.settings.backend.ExportSettingsType;
|
||||
import net.osmand.plus.settings.backend.OsmAndAppCustomization;
|
||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||
import net.osmand.plus.settings.backend.backup.ProfileSettingsItem;
|
||||
import net.osmand.plus.settings.backend.backup.SettingsHelper;
|
||||
import net.osmand.plus.settings.backend.ExportSettingsType;
|
||||
import net.osmand.plus.settings.backend.backup.SettingsItem;
|
||||
import net.osmand.plus.views.OsmandMapLayer;
|
||||
import net.osmand.plus.views.OsmandMapTileView;
|
||||
|
@ -598,8 +597,7 @@ public class OsmandAidlApi {
|
|||
final RoutingHelper routingHelper = app.getRoutingHelper();
|
||||
boolean force = intent.getBooleanExtra(AIDL_FORCE, true);
|
||||
if (routingHelper.isFollowingMode() && !force) {
|
||||
AlertDialog dlg = mapActivity.getMapActions().stopNavigationActionConfirm();
|
||||
dlg.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
mapActivity.getMapActions().stopNavigationActionConfirm(new DialogInterface.OnDismissListener() {
|
||||
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
|
@ -665,8 +663,7 @@ public class OsmandAidlApi {
|
|||
final RoutingHelper routingHelper = app.getRoutingHelper();
|
||||
boolean force = intent.getBooleanExtra(AIDL_FORCE, true);
|
||||
if (routingHelper.isFollowingMode() && !force) {
|
||||
AlertDialog dlg = mapActivity.getMapActions().stopNavigationActionConfirm();
|
||||
dlg.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
mapActivity.getMapActions().stopNavigationActionConfirm(new DialogInterface.OnDismissListener() {
|
||||
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
|
|
|
@ -3,6 +3,7 @@ package net.osmand.plus.activities;
|
|||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.DialogInterface.OnDismissListener;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.net.Uri;
|
||||
|
@ -39,8 +40,6 @@ import net.osmand.plus.ContextMenuAdapter;
|
|||
import net.osmand.plus.ContextMenuAdapter.ItemClickListener;
|
||||
import net.osmand.plus.ContextMenuItem;
|
||||
import net.osmand.plus.ContextMenuItem.ItemBuilder;
|
||||
import net.osmand.plus.mapmarkers.MapMarkersHelper;
|
||||
import net.osmand.plus.mapmarkers.MapMarker;
|
||||
import net.osmand.plus.OsmAndLocationProvider;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
|
@ -56,11 +55,14 @@ import net.osmand.plus.download.IndexItem;
|
|||
import net.osmand.plus.liveupdates.OsmLiveActivity;
|
||||
import net.osmand.plus.mapcontextmenu.AdditionalActionsBottomSheetDialogFragment;
|
||||
import net.osmand.plus.mapcontextmenu.AdditionalActionsBottomSheetDialogFragment.ContextMenuItemClickListener;
|
||||
import net.osmand.plus.mapmarkers.MapMarker;
|
||||
import net.osmand.plus.mapmarkers.MapMarkersDialogFragment;
|
||||
import net.osmand.plus.mapmarkers.MapMarkersHelper;
|
||||
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.osmedit.dialogs.DismissRouteBottomSheetFragment;
|
||||
import net.osmand.plus.profiles.RoutingProfileDataObject;
|
||||
import net.osmand.plus.routepreparationmenu.MapRouteInfoMenu;
|
||||
import net.osmand.plus.routepreparationmenu.WaypointsFragment;
|
||||
|
@ -75,7 +77,6 @@ import net.osmand.plus.views.OsmandMapTileView;
|
|||
import net.osmand.plus.views.layers.MapControlsLayer;
|
||||
import net.osmand.plus.wikipedia.WikipediaDialogFragment;
|
||||
import net.osmand.plus.wikivoyage.WikivoyageWelcomeDialogFragment;
|
||||
import net.osmand.plus.wikivoyage.data.TravelDbHelper;
|
||||
import net.osmand.plus.wikivoyage.data.TravelHelper;
|
||||
import net.osmand.plus.wikivoyage.explore.WikivoyageExploreActivity;
|
||||
import net.osmand.router.GeneralRouter;
|
||||
|
@ -1122,26 +1123,12 @@ public class MapActivityActions implements DialogProvider {
|
|||
}
|
||||
}
|
||||
|
||||
public AlertDialog stopNavigationActionConfirm() {
|
||||
return stopNavigationActionConfirm(null);
|
||||
public void stopNavigationActionConfirm(@Nullable OnDismissListener listener) {
|
||||
stopNavigationActionConfirm(listener, null);
|
||||
}
|
||||
|
||||
public AlertDialog stopNavigationActionConfirm(final Runnable onStopAction) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(mapActivity);
|
||||
// Stop the navigation
|
||||
builder.setTitle(getString(R.string.cancel_route));
|
||||
builder.setMessage(getString(R.string.stop_routing_confirm));
|
||||
builder.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
stopNavigationWithoutConfirm();
|
||||
if (onStopAction != null) {
|
||||
onStopAction.run();
|
||||
}
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(R.string.shared_string_no, null);
|
||||
return builder.show();
|
||||
public void stopNavigationActionConfirm(@Nullable OnDismissListener listener, @Nullable Runnable onStopAction) {
|
||||
DismissRouteBottomSheetFragment.showInstance(mapActivity.getSupportFragmentManager(), listener, onStopAction);
|
||||
}
|
||||
|
||||
public void whereAmIDialog() {
|
||||
|
|
|
@ -315,7 +315,7 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra
|
|||
}
|
||||
}
|
||||
|
||||
boolean useVerticalButtons() {
|
||||
protected boolean useVerticalButtons() {
|
||||
Activity activity = requireActivity();
|
||||
int rightBottomButtonTextId = getRightBottomButtonTextId();
|
||||
if (getDismissButtonTextId() != DEFAULT_VALUE && rightBottomButtonTextId != DEFAULT_VALUE) {
|
||||
|
|
|
@ -11,7 +11,6 @@ import android.widget.LinearLayout;
|
|||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
|
||||
import net.osmand.plus.R;
|
||||
|
@ -85,14 +84,13 @@ public class DashNavigationFragment extends DashBaseFragment {
|
|||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
AlertDialog dlg = map.getMapActions().stopNavigationActionConfirm();
|
||||
dlg.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
map.getMapActions().stopNavigationActionConfirm(new DialogInterface.OnDismissListener() {
|
||||
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
setupNavigation();
|
||||
DashWaypointsFragment f = dashboard.getFragmentByClass(DashWaypointsFragment.class);
|
||||
if(f != null) {
|
||||
if (f != null) {
|
||||
f.onOpenDash();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ import android.os.ParcelFileDescriptor;
|
|||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
@ -293,8 +292,7 @@ public class ExternalApiHelper {
|
|||
|
||||
final RoutingHelper routingHelper = app.getRoutingHelper();
|
||||
if (routingHelper.isFollowingMode() && !force) {
|
||||
AlertDialog dlg = mapActivity.getMapActions().stopNavigationActionConfirm();
|
||||
dlg.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
mapActivity.getMapActions().stopNavigationActionConfirm(new DialogInterface.OnDismissListener() {
|
||||
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
|
@ -353,8 +351,7 @@ public class ExternalApiHelper {
|
|||
|
||||
final RoutingHelper routingHelper = app.getRoutingHelper();
|
||||
if (routingHelper.isFollowingMode() && !force) {
|
||||
AlertDialog dlg = mapActivity.getMapActions().stopNavigationActionConfirm();
|
||||
dlg.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
mapActivity.getMapActions().stopNavigationActionConfirm(new DialogInterface.OnDismissListener() {
|
||||
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
|
@ -667,8 +664,7 @@ public class ExternalApiHelper {
|
|||
}
|
||||
final RoutingHelper routingHelper = app.getRoutingHelper();
|
||||
if (routingHelper.isFollowingMode() && !force) {
|
||||
AlertDialog dlg = mapActivity.getMapActions().stopNavigationActionConfirm();
|
||||
dlg.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
mapActivity.getMapActions().stopNavigationActionConfirm(new DialogInterface.OnDismissListener() {
|
||||
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
|
|
|
@ -886,7 +886,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
|
|||
app.getTargetPointsHelper().updateRouteAndRefresh(true);
|
||||
app.getRoutingHelper().recalculateRouteDueToSettingsChange();
|
||||
} else {
|
||||
mapActivity.getMapActions().stopNavigationActionConfirm(new Runnable() {
|
||||
mapActivity.getMapActions().stopNavigationActionConfirm(null , new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
|
|
|
@ -0,0 +1,106 @@
|
|||
package net.osmand.plus.osmedit.dialogs;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.DialogInterface.OnDismissListener;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.UiUtilities.DialogButtonType;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
|
||||
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
|
||||
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription;
|
||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerSpaceItem;
|
||||
|
||||
public class DismissRouteBottomSheetFragment extends MenuBottomSheetDialogFragment {
|
||||
|
||||
public static final String TAG = DismissRouteBottomSheetFragment.class.getSimpleName();
|
||||
|
||||
private Runnable onStopAction;
|
||||
private OnDismissListener dismissListener;
|
||||
|
||||
@Override
|
||||
public void createMenuItems(Bundle savedInstanceState) {
|
||||
BaseBottomSheetItem descriptionItem = new BottomSheetItemWithDescription.Builder()
|
||||
.setDescription(getString(R.string.stop_routing_confirm))
|
||||
.setTitle(getString(R.string.cancel_route))
|
||||
.setLayoutId(R.layout.bottom_sheet_item_list_title_with_descr)
|
||||
.create();
|
||||
|
||||
items.add(descriptionItem);
|
||||
|
||||
int padding = getResources().getDimensionPixelSize(R.dimen.content_padding_small);
|
||||
items.add(new DividerSpaceItem(requireContext(), padding));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean useVerticalButtons() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getDismissButtonTextId() {
|
||||
return R.string.shared_string_cancel;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getRightBottomButtonTextId() {
|
||||
return R.string.shared_string_dismiss;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DialogButtonType getRightBottomButtonType() {
|
||||
return DialogButtonType.PRIMARY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSecondDividerHeight() {
|
||||
return getResources().getDimensionPixelSize(R.dimen.bottom_sheet_icon_margin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRightBottomButtonClick() {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
mapActivity.getMapActions().stopNavigationWithoutConfirm();
|
||||
}
|
||||
if (onStopAction != null) {
|
||||
onStopAction.run();
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDismiss(@NonNull DialogInterface dialog) {
|
||||
super.onDismiss(dialog);
|
||||
FragmentActivity activity = getActivity();
|
||||
if (activity != null && !activity.isChangingConfigurations() && dismissListener != null) {
|
||||
dismissListener.onDismiss(dialog);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public MapActivity getMapActivity() {
|
||||
Activity activity = getActivity();
|
||||
if (activity instanceof MapActivity) {
|
||||
return (MapActivity) activity;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void showInstance(@NonNull FragmentManager fragmentManager, @Nullable OnDismissListener listener, @Nullable Runnable onStopAction) {
|
||||
if (!fragmentManager.isStateSaved()) {
|
||||
DismissRouteBottomSheetFragment fragment = new DismissRouteBottomSheetFragment();
|
||||
fragment.dismissListener = listener;
|
||||
fragment.onStopAction = onStopAction;
|
||||
fragment.setRetainInstance(true);
|
||||
fragment.show(fragmentManager, TAG);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -339,7 +339,7 @@ public class MapControlsLayer extends OsmandMapLayer {
|
|||
public void stopNavigation() {
|
||||
mapRouteInfoMenu.hide();
|
||||
if (mapActivity.getRoutingHelper().isFollowingMode()) {
|
||||
mapActivity.getMapActions().stopNavigationActionConfirm();
|
||||
mapActivity.getMapActions().stopNavigationActionConfirm(null);
|
||||
} else {
|
||||
mapActivity.getMapActions().stopNavigationWithoutConfirm();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue