add opening for edit actions dialog

This commit is contained in:
Chumva 2018-06-05 17:04:38 +03:00 committed by Alex Sytnyk
parent 18be0c4aa9
commit 3d7e607c05
6 changed files with 44 additions and 29 deletions

View file

@ -7,6 +7,7 @@ import android.content.res.ColorStateList;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.ColorInt; import android.support.annotation.ColorInt;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.app.FragmentManager;
import android.support.v4.util.Pair; import android.support.v4.util.Pair;
import android.support.v4.widget.CompoundButtonCompat; import android.support.v4.widget.CompoundButtonCompat;
import android.support.v4.widget.NestedScrollView; 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.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; 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.QuickActionFactory;
import net.osmand.plus.quickaction.actions.MapStyleAction; import net.osmand.plus.quickaction.actions.MapStyleAction;
import net.osmand.plus.quickaction.actions.MapSourceAction; import net.osmand.plus.quickaction.actions.MapSourceAction;
@ -44,6 +46,11 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; 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 class SelectMapViewQuickActionsBottomSheet extends MenuBottomSheetDialogFragment {
public static final String TAG = SelectMapViewQuickActionsBottomSheet.class.getSimpleName(); 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 LAYER_OSM_VECTOR = "LAYER_OSM_VECTOR";
private static final String KEY_NO_OVERLAY = "no_overlay"; private static final String KEY_NO_OVERLAY = "no_overlay";
private static final String KEY_NO_UNDERLAY = "no_underlay"; private static final String KEY_NO_UNDERLAY = "no_underlay";
private static final String MAP = "map";
private LinearLayout stylesContainer; private LinearLayout stylesContainer;
private View.OnClickListener onClickListener; private View.OnClickListener onClickListener;
@ -63,6 +69,7 @@ public class SelectMapViewQuickActionsBottomSheet extends MenuBottomSheetDialogF
private HashMap<String, String> pairsMap; private HashMap<String, String> pairsMap;
private String selectedItem; private String selectedItem;
private int type; private int type;
private long id;
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ -76,11 +83,12 @@ public class SelectMapViewQuickActionsBottomSheet extends MenuBottomSheetDialogF
} }
Bundle args = getArguments(); Bundle args = getArguments();
type = args.getInt("type"); type = args.getInt(KEY_TYPE);
id = args.getLong(KEY_ID);
if (type == MapStyleAction.TYPE) { if (type == MapStyleAction.TYPE) {
stylesList = args.getStringArrayList("test"); stylesList = args.getStringArrayList(KEY_STYLES);
} else { } else {
pairsMap = (HashMap<String, String>) args.getSerializable(MAP); pairsMap = (HashMap<String, String>) args.getSerializable(KEY_ACTIONS_MAP);
} }
OsmandApplication app = (OsmandApplication) context.getApplicationContext(); OsmandApplication app = (OsmandApplication) context.getApplicationContext();
settings = app.getSettings(); settings = app.getSettings();
@ -174,18 +182,12 @@ public class SelectMapViewQuickActionsBottomSheet extends MenuBottomSheetDialogF
@Override @Override
protected void onDismissButtonClickAction() { protected void onDismissButtonClickAction() {
MapActivity mapActivity = getMapActivity(); MapActivity mapActivity = getMapActivity();
if (mapActivity == null) { FragmentManager fm = getFragmentManager();
if (mapActivity == null || fm == null) {
return; return;
} }
if (type == MapStyleAction.TYPE) { CreateEditActionDialog dialog = CreateEditActionDialog.newInstance(id);
changeMapStyle(mapActivity); dialog.show(fm, CreateEditActionDialog.TAG);
} else if (type == MapSourceAction.TYPE) {
changeMapSource(mapActivity);
} else if (type == MapOverlayAction.TYPE) {
changeMapOverlay(mapActivity);
} else if (type == MapUnderlayAction.TYPE) {
changeMapUnderlay(mapActivity);
}
} }
@ -318,17 +320,21 @@ public class SelectMapViewQuickActionsBottomSheet extends MenuBottomSheetDialogF
onClickListener = new View.OnClickListener() { onClickListener = new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
Context context = getContext(); MapActivity mapActivity = getMapActivity();
if (context == null) { if (mapActivity == null) {
return; return;
} }
selectedItem = (String) v.getTag(); selectedItem = (String) v.getTag();
if (type == MapStyleAction.TYPE) { if (type == MapStyleAction.TYPE) {
Toast.makeText(context, selectedItem, Toast.LENGTH_SHORT).show(); changeMapStyle(mapActivity);
} else { } else if (type == MapSourceAction.TYPE) {
Toast.makeText(context, pairsMap.get(selectedItem), Toast.LENGTH_SHORT).show(); changeMapSource(mapActivity);
} else if (type == MapOverlayAction.TYPE) {
changeMapOverlay(mapActivity);
} else if (type == MapUnderlayAction.TYPE) {
changeMapUnderlay(mapActivity);
} }
populateItemsList(); dismiss();
} }
}; };
} }

View file

@ -24,7 +24,12 @@ import java.util.List;
public abstract class SwitchableAction<T> extends QuickAction { public abstract class SwitchableAction<T> 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"; protected static final String KEY_DIALOG = "dialog";
private transient EditText title; private transient EditText title;
protected SwitchableAction(int type) { protected SwitchableAction(int type) {

View file

@ -94,8 +94,9 @@ public class MapOverlayAction extends SwitchableAction<Pair<String, String>> {
hashMap.put(pair.first, pair.second); hashMap.put(pair.first, pair.second);
} }
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putInt("type", TYPE); args.putInt(KEY_TYPE, TYPE);
args.putSerializable("map", hashMap); args.putLong(KEY_ID, id);
args.putSerializable(KEY_ACTIONS_MAP, hashMap);
fragment.setArguments(args); fragment.setArguments(args);
fragment.show(activity.getSupportFragmentManager(), fragment.show(activity.getSupportFragmentManager(),
SelectMapViewQuickActionsBottomSheet.TAG); SelectMapViewQuickActionsBottomSheet.TAG);

View file

@ -88,8 +88,9 @@ public class MapSourceAction extends SwitchableAction<Pair<String, String>> {
hashMap.put(pair.first, pair.second); hashMap.put(pair.first, pair.second);
} }
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putInt("type", TYPE); args.putInt(KEY_TYPE, TYPE);
args.putSerializable("map", hashMap); args.putLong(KEY_ID, id);
args.putSerializable(KEY_ACTIONS_MAP, hashMap);
fragment.setArguments(args); fragment.setArguments(args);
fragment.show(activity.getSupportFragmentManager(), fragment.show(activity.getSupportFragmentManager(),
SelectMapViewQuickActionsBottomSheet.TAG); SelectMapViewQuickActionsBottomSheet.TAG);

View file

@ -31,7 +31,7 @@ public class MapStyleAction extends SwitchableAction<String> {
public static final int TYPE = 14; public static final int TYPE = 14;
private final static String KEY_STYLES = "styles"; public final static String KEY_STYLES = "styles";
public MapStyleAction() { public MapStyleAction() {
super(TYPE); super(TYPE);
@ -49,8 +49,9 @@ public class MapStyleAction extends SwitchableAction<String> {
if (showBottomSheetStyles) { if (showBottomSheetStyles) {
SelectMapViewQuickActionsBottomSheet fragment = new SelectMapViewQuickActionsBottomSheet(); SelectMapViewQuickActionsBottomSheet fragment = new SelectMapViewQuickActionsBottomSheet();
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putStringArrayList("test", (ArrayList<String>) mapStyles); args.putStringArrayList(KEY_STYLES, (ArrayList<String>) mapStyles);
args.putInt("type", TYPE); args.putInt(KEY_TYPE, TYPE);
args.putLong(KEY_ID, id);
fragment.setArguments(args); fragment.setArguments(args);
fragment.show(activity.getSupportFragmentManager(), fragment.show(activity.getSupportFragmentManager(),
SelectMapViewQuickActionsBottomSheet.TAG); SelectMapViewQuickActionsBottomSheet.TAG);

View file

@ -93,8 +93,9 @@ public class MapUnderlayAction extends SwitchableAction<Pair<String, String>> {
hashMap.put(pair.first, pair.second); hashMap.put(pair.first, pair.second);
} }
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putInt("type", TYPE); args.putInt(KEY_TYPE, TYPE);
args.putSerializable("map", hashMap); args.putLong(KEY_ID, id);
args.putSerializable(KEY_ACTIONS_MAP, hashMap);
fragment.setArguments(args); fragment.setArguments(args);
fragment.show(activity.getSupportFragmentManager(), fragment.show(activity.getSupportFragmentManager(),
SelectMapViewQuickActionsBottomSheet.TAG); SelectMapViewQuickActionsBottomSheet.TAG);