From 3d7e607c05b3af96b4b4aefb0aee866e118d5355 Mon Sep 17 00:00:00 2001 From: Chumva Date: Tue, 5 Jun 2018 17:04:38 +0300 Subject: [PATCH] add opening for edit actions dialog --- .../SelectMapViewQuickActionsBottomSheet.java | 46 +++++++++++-------- .../plus/quickaction/SwitchableAction.java | 5 ++ .../quickaction/actions/MapOverlayAction.java | 5 +- .../quickaction/actions/MapSourceAction.java | 5 +- .../quickaction/actions/MapStyleAction.java | 7 +-- .../actions/MapUnderlayAction.java | 5 +- 6 files changed, 44 insertions(+), 29 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/dialogs/SelectMapViewQuickActionsBottomSheet.java b/OsmAnd/src/net/osmand/plus/dialogs/SelectMapViewQuickActionsBottomSheet.java index 8a36d882ee..bf32c12fbb 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/SelectMapViewQuickActionsBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/SelectMapViewQuickActionsBottomSheet.java @@ -7,6 +7,7 @@ import android.content.res.ColorStateList; import android.os.Bundle; import android.support.annotation.ColorInt; import android.support.annotation.Nullable; +import android.support.v4.app.FragmentManager; import android.support.v4.util.Pair; import android.support.v4.widget.CompoundButtonCompat; import android.support.v4.widget.NestedScrollView; @@ -29,6 +30,7 @@ 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.simpleitems.TitleItem; +import net.osmand.plus.quickaction.CreateEditActionDialog; import net.osmand.plus.quickaction.QuickActionFactory; import net.osmand.plus.quickaction.actions.MapStyleAction; import net.osmand.plus.quickaction.actions.MapSourceAction; @@ -44,6 +46,11 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.Map; +import static net.osmand.plus.quickaction.SwitchableAction.KEY_ACTIONS_MAP; +import static net.osmand.plus.quickaction.SwitchableAction.KEY_ID; +import static net.osmand.plus.quickaction.SwitchableAction.KEY_TYPE; +import static net.osmand.plus.quickaction.actions.MapStyleAction.KEY_STYLES; + public class SelectMapViewQuickActionsBottomSheet extends MenuBottomSheetDialogFragment { public static final String TAG = SelectMapViewQuickActionsBottomSheet.class.getSimpleName(); @@ -52,7 +59,6 @@ public class SelectMapViewQuickActionsBottomSheet extends MenuBottomSheetDialogF private static final String LAYER_OSM_VECTOR = "LAYER_OSM_VECTOR"; private static final String KEY_NO_OVERLAY = "no_overlay"; private static final String KEY_NO_UNDERLAY = "no_underlay"; - private static final String MAP = "map"; private LinearLayout stylesContainer; private View.OnClickListener onClickListener; @@ -63,6 +69,7 @@ public class SelectMapViewQuickActionsBottomSheet extends MenuBottomSheetDialogF private HashMap pairsMap; private String selectedItem; private int type; + private long id; @Override @SuppressWarnings("unchecked") @@ -76,11 +83,12 @@ public class SelectMapViewQuickActionsBottomSheet extends MenuBottomSheetDialogF } Bundle args = getArguments(); - type = args.getInt("type"); + type = args.getInt(KEY_TYPE); + id = args.getLong(KEY_ID); if (type == MapStyleAction.TYPE) { - stylesList = args.getStringArrayList("test"); + stylesList = args.getStringArrayList(KEY_STYLES); } else { - pairsMap = (HashMap) args.getSerializable(MAP); + pairsMap = (HashMap) args.getSerializable(KEY_ACTIONS_MAP); } OsmandApplication app = (OsmandApplication) context.getApplicationContext(); settings = app.getSettings(); @@ -174,18 +182,12 @@ public class SelectMapViewQuickActionsBottomSheet extends MenuBottomSheetDialogF @Override protected void onDismissButtonClickAction() { MapActivity mapActivity = getMapActivity(); - if (mapActivity == null) { + FragmentManager fm = getFragmentManager(); + if (mapActivity == null || fm == null) { return; } - if (type == MapStyleAction.TYPE) { - changeMapStyle(mapActivity); - } else if (type == MapSourceAction.TYPE) { - changeMapSource(mapActivity); - } else if (type == MapOverlayAction.TYPE) { - changeMapOverlay(mapActivity); - } else if (type == MapUnderlayAction.TYPE) { - changeMapUnderlay(mapActivity); - } + CreateEditActionDialog dialog = CreateEditActionDialog.newInstance(id); + dialog.show(fm, CreateEditActionDialog.TAG); } @@ -318,17 +320,21 @@ public class SelectMapViewQuickActionsBottomSheet extends MenuBottomSheetDialogF onClickListener = new View.OnClickListener() { @Override public void onClick(View v) { - Context context = getContext(); - if (context == null) { + MapActivity mapActivity = getMapActivity(); + if (mapActivity == null) { return; } selectedItem = (String) v.getTag(); if (type == MapStyleAction.TYPE) { - Toast.makeText(context, selectedItem, Toast.LENGTH_SHORT).show(); - } else { - Toast.makeText(context, pairsMap.get(selectedItem), Toast.LENGTH_SHORT).show(); + changeMapStyle(mapActivity); + } else if (type == MapSourceAction.TYPE) { + changeMapSource(mapActivity); + } else if (type == MapOverlayAction.TYPE) { + changeMapOverlay(mapActivity); + } else if (type == MapUnderlayAction.TYPE) { + changeMapUnderlay(mapActivity); } - populateItemsList(); + dismiss(); } }; } diff --git a/OsmAnd/src/net/osmand/plus/quickaction/SwitchableAction.java b/OsmAnd/src/net/osmand/plus/quickaction/SwitchableAction.java index 8b41e0f9c2..ef9197a41f 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/SwitchableAction.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/SwitchableAction.java @@ -24,7 +24,12 @@ import java.util.List; public abstract class SwitchableAction extends QuickAction { + public static final String KEY_ACTIONS_MAP = "actions_map"; + public static final String KEY_TYPE = "type"; + public static final String KEY_ID = "id"; + protected static final String KEY_DIALOG = "dialog"; + private transient EditText title; protected SwitchableAction(int type) { diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/MapOverlayAction.java b/OsmAnd/src/net/osmand/plus/quickaction/actions/MapOverlayAction.java index 0eefef4750..3660a1adeb 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/actions/MapOverlayAction.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/actions/MapOverlayAction.java @@ -94,8 +94,9 @@ public class MapOverlayAction extends SwitchableAction> { hashMap.put(pair.first, pair.second); } Bundle args = new Bundle(); - args.putInt("type", TYPE); - args.putSerializable("map", hashMap); + args.putInt(KEY_TYPE, TYPE); + args.putLong(KEY_ID, id); + args.putSerializable(KEY_ACTIONS_MAP, hashMap); fragment.setArguments(args); fragment.show(activity.getSupportFragmentManager(), SelectMapViewQuickActionsBottomSheet.TAG); diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/MapSourceAction.java b/OsmAnd/src/net/osmand/plus/quickaction/actions/MapSourceAction.java index 2b32244697..ac848653db 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/actions/MapSourceAction.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/actions/MapSourceAction.java @@ -88,8 +88,9 @@ public class MapSourceAction extends SwitchableAction> { hashMap.put(pair.first, pair.second); } Bundle args = new Bundle(); - args.putInt("type", TYPE); - args.putSerializable("map", hashMap); + args.putInt(KEY_TYPE, TYPE); + args.putLong(KEY_ID, id); + args.putSerializable(KEY_ACTIONS_MAP, hashMap); fragment.setArguments(args); fragment.show(activity.getSupportFragmentManager(), SelectMapViewQuickActionsBottomSheet.TAG); diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/MapStyleAction.java b/OsmAnd/src/net/osmand/plus/quickaction/actions/MapStyleAction.java index d3628ec79d..0da936a786 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/actions/MapStyleAction.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/actions/MapStyleAction.java @@ -31,7 +31,7 @@ public class MapStyleAction extends SwitchableAction { public static final int TYPE = 14; - private final static String KEY_STYLES = "styles"; + public final static String KEY_STYLES = "styles"; public MapStyleAction() { super(TYPE); @@ -49,8 +49,9 @@ public class MapStyleAction extends SwitchableAction { if (showBottomSheetStyles) { SelectMapViewQuickActionsBottomSheet fragment = new SelectMapViewQuickActionsBottomSheet(); Bundle args = new Bundle(); - args.putStringArrayList("test", (ArrayList) mapStyles); - args.putInt("type", TYPE); + args.putStringArrayList(KEY_STYLES, (ArrayList) mapStyles); + args.putInt(KEY_TYPE, TYPE); + args.putLong(KEY_ID, id); fragment.setArguments(args); fragment.show(activity.getSupportFragmentManager(), SelectMapViewQuickActionsBottomSheet.TAG); diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/MapUnderlayAction.java b/OsmAnd/src/net/osmand/plus/quickaction/actions/MapUnderlayAction.java index 39c14c4dba..cf936ce6bd 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/actions/MapUnderlayAction.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/actions/MapUnderlayAction.java @@ -93,8 +93,9 @@ public class MapUnderlayAction extends SwitchableAction> { hashMap.put(pair.first, pair.second); } Bundle args = new Bundle(); - args.putInt("type", TYPE); - args.putSerializable("map", hashMap); + args.putInt(KEY_TYPE, TYPE); + args.putLong(KEY_ID, id); + args.putSerializable(KEY_ACTIONS_MAP, hashMap); fragment.setArguments(args); fragment.show(activity.getSupportFragmentManager(), SelectMapViewQuickActionsBottomSheet.TAG);