From 1736b3c789c064e417f59316dc55a602e7067a86 Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Wed, 29 Apr 2020 15:22:47 +0300 Subject: [PATCH] context menu actions fixes / tracker item fix / ui fixes --- .../aidlapi/OsmAndCustomizationConstants.java | 3 + OsmAnd/res/values/strings.xml | 2 + .../net/osmand/plus/ContextMenuAdapter.java | 5 +- .../src/net/osmand/plus/OsmandSettings.java | 28 +++++- .../plus/activities/MapActivityActions.java | 4 +- .../audionotes/AudioVideoNotesPlugin.java | 6 ++ .../MapContextMenuFragment.java | 34 ++++++-- .../settings/ConfigureMenuItemsFragment.java | 86 ++++++++++++++++--- .../settings/ConfigureMenuRootFragment.java | 42 ++++++--- .../settings/RearrangeMenuItemsAdapter.java | 68 +++++++++++++-- 10 files changed, 233 insertions(+), 45 deletions(-) diff --git a/OsmAnd-api/src/net/osmand/aidlapi/OsmAndCustomizationConstants.java b/OsmAnd-api/src/net/osmand/aidlapi/OsmAndCustomizationConstants.java index 8d884efc9a..de443bedf3 100644 --- a/OsmAnd-api/src/net/osmand/aidlapi/OsmAndCustomizationConstants.java +++ b/OsmAnd-api/src/net/osmand/aidlapi/OsmAndCustomizationConstants.java @@ -91,6 +91,9 @@ public interface OsmAndCustomizationConstants { String MAP_CONTEXT_MENU_CREATE_POI = MAP_CONTEXT_MENU_ACTIONS + "create_poi"; String MAP_CONTEXT_MENU_MODIFY_OSM_NOTE = MAP_CONTEXT_MENU_ACTIONS + "modify_osm_note"; String MAP_CONTEXT_MENU_OPEN_OSM_NOTE = MAP_CONTEXT_MENU_ACTIONS + "open_osm_note"; + String MAP_CONTEXT_MENU_AUDIO_NOTE = MAP_CONTEXT_MENU_ACTIONS + "audio_note"; + String MAP_CONTEXT_MENU_VIDEO_NOTE = MAP_CONTEXT_MENU_ACTIONS + "video_note"; + String MAP_CONTEXT_MENU_PHOTO_NOTE = MAP_CONTEXT_MENU_ACTIONS + "photo_note"; //Plug-in's IDs: String PLUGIN_OSMAND_MONITOR = "osmand.monitoring"; diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 13317babd6..72cd559796 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,6 +11,8 @@ Thx - Hardy --> + Add / Edit + Parking positions Create/Edit POI Unsupported action %1$s Extra maps diff --git a/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java b/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java index fb088a3124..e10b815284 100644 --- a/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java +++ b/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java @@ -49,6 +49,7 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Set; +import static net.osmand.aidl.ConnectedApp.AIDL_LAYERS_PREFIX; import static net.osmand.aidlapi.OsmAndCustomizationConstants.APP_PROFILES_ID; public class ContextMenuAdapter { @@ -171,7 +172,7 @@ public class ContextMenuAdapter { return order; } } - return defaultOrder; + return defaultOrder == -1 ? items.size() - 1 : defaultOrder; } public ArrayAdapter createListAdapter(final Activity activity, final boolean lightTheme) { @@ -579,7 +580,7 @@ public class ContextMenuAdapter { List items = new ArrayList<>(); for (ContextMenuItem item : this.items) { String id = item.getId(); - if (id != null && id.startsWith(idScheme) && !APP_PROFILES_ID.equals(id)) { + if (id != null && id.startsWith(idScheme) && !APP_PROFILES_ID.equals(id) || id != null && id.startsWith(AIDL_LAYERS_PREFIX)) { items.add(item); } } diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index 462b61dc32..e372d6aeaf 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -81,6 +81,7 @@ import java.util.Map; import java.util.Set; import java.util.StringTokenizer; +import static net.osmand.aidl.ConnectedApp.AIDL_LAYERS_PREFIX; import static net.osmand.aidlapi.OsmAndCustomizationConstants.CONFIGURE_MAP_ITEM_ID_SCHEME; import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_ITEM_ID_SCHEME; import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_ACTIONS; @@ -1176,8 +1177,10 @@ public class OsmandSettings { public static class ContextMenuItemsSettings implements Serializable { public static final String HIDDEN = "hidden"; public static final String ORDER = "order"; + public static final String MAIN_ACTIONS = "main_actions"; private List hiddenIds = new ArrayList<>(); private List orderIds = new ArrayList<>(); + private List mainActionIds = new ArrayList<>(); public ContextMenuItemsSettings() { @@ -1188,6 +1191,12 @@ public class OsmandSettings { this.orderIds = orderIds; } + public ContextMenuItemsSettings(@NonNull List mainActionIds, @NonNull List hiddenIds, @NonNull List orderIds) { + this.mainActionIds = mainActionIds; + this.hiddenIds = hiddenIds; + this.orderIds = orderIds; + } + public void readFromJsonString(String jsonString, @NonNull String idScheme) { if (Algorithms.isEmpty(jsonString)) { return; @@ -1196,6 +1205,9 @@ public class OsmandSettings { JSONObject json = new JSONObject(jsonString); hiddenIds = readIdsList(json.optJSONArray(HIDDEN), idScheme); orderIds = readIdsList(json.optJSONArray(ORDER), idScheme); + if (idScheme.equals(MAP_CONTEXT_MENU_ACTIONS)) { + mainActionIds = readIdsList(json.optJSONArray(MAIN_ACTIONS), idScheme); + } } catch (JSONException e) { LOG.error("Error converting to json string: " + e); } @@ -1206,7 +1218,11 @@ public class OsmandSettings { if (jsonArray != null) { for (int i = 0; i < jsonArray.length(); i++) { String id = jsonArray.optString(i); - list.add(idScheme + id); + if (id.startsWith(AIDL_LAYERS_PREFIX)) { + list.add(id); + } else { + list.add(idScheme + id); + } } } return list; @@ -1217,6 +1233,9 @@ public class OsmandSettings { JSONObject json = new JSONObject(); json.put(HIDDEN, getJsonArray(hiddenIds, idScheme)); json.put(ORDER, getJsonArray(orderIds, idScheme)); + if (idScheme.equals(MAP_CONTEXT_MENU_ACTIONS)) { + json.put(MAIN_ACTIONS, getJsonArray(mainActionIds, idScheme)); + } return json.toString(); } catch (JSONException e) { LOG.error("Error converting to json string: " + e); @@ -1241,6 +1260,10 @@ public class OsmandSettings { public List getOrderIds() { return Collections.unmodifiableList(orderIds); } + + public List getMainActionIds() { + return Collections.unmodifiableList(mainActionIds); + } } public class EnumIntPreference> extends CommonPreference { @@ -3581,6 +3604,9 @@ public class OsmandSettings { @Nullable public ContextMenuItemsPreference getContextMenuItemsPreference(@NonNull String id) { + if (id.startsWith(AIDL_LAYERS_PREFIX)) { + return CONFIGURE_MAP_ITEMS; + } for (ContextMenuItemsPreference preference : CONTEXT_MENU_ITEMS_PREFERENCES) { if (id.startsWith(preference.idScheme)) { return preference; diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java index 20b6ece7d0..6fc213a82a 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java @@ -1038,7 +1038,9 @@ public class MapActivityActions implements DialogProvider { ItemBuilder divider = new ItemBuilder().setLayout(R.layout.drawer_divider); divider.setId(DRAWER_DIVIDER_ID); - divider.setPosition(dividerItemIndex >= 0 ? dividerItemIndex : 8); + int position = dividerItemIndex >= 0 ? dividerItemIndex : 8; + divider.setPosition(position); + divider.setOrder(position); optionsMenuHelper.addItem(divider.createItem()); return optionsMenuHelper; diff --git a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java index 39c625b988..fc70ac67ca 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java @@ -96,6 +96,9 @@ import java.util.Map; import java.util.Timer; import java.util.TimerTask; +import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_AUDIO_NOTE; +import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_PHOTO_NOTE; +import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_VIDEO_NOTE; import static net.osmand.aidlapi.OsmAndCustomizationConstants.RECORDING_LAYER; @@ -660,6 +663,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { return; } adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.recording_context_menu_arecord, app) + .setId(MAP_CONTEXT_MENU_AUDIO_NOTE) .setIcon(R.drawable.ic_action_micro_dark) .setOrder(TAKE_AUDIO_NOTE_ITEM_ORDER) .setListener(new ContextMenuAdapter.ItemClickListener() { @@ -672,6 +676,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { }) .createItem()); adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.recording_context_menu_vrecord, app) + .setId(MAP_CONTEXT_MENU_VIDEO_NOTE) .setIcon(R.drawable.ic_action_video_dark) .setOrder(TAKE_VIDEO_NOTE_ITEM_ORDER) .setListener(new ItemClickListener() { @@ -684,6 +689,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { }) .createItem()); adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.recording_context_menu_precord, app) + .setId(MAP_CONTEXT_MENU_PHOTO_NOTE) .setIcon(R.drawable.ic_action_photo_dark) .setOrder(TAKE_PHOTO_NOTE_ITEM_ORDER) .setListener(new ItemClickListener() { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java index 519d209714..0e5c76af04 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java @@ -568,6 +568,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo // TODO refactor section ContextMenuAdapter adapter = menu.getActionsContextMenuAdapter(false); List items = new ArrayList<>(); + List mainIds = app.getSettings().CONTEXT_MENU_ACTIONS_ITEMS.get().getMainActionIds(); for (ContextMenuItem item : adapter.getItems()) { if (!item.isHidden()) { items.add(item); @@ -575,11 +576,22 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo } ContextMenuAdapter mainAdapter = new ContextMenuAdapter(requireMyApplication()); ContextMenuAdapter additionalAdapter = new ContextMenuAdapter(requireMyApplication()); - for (int i = 0; i < items.size(); i++) { - if (i < MAIN_BUTTONS_QUANTITY) { - mainAdapter.addItem(items.get(i)); - } else { - additionalAdapter.addItem(items.get(i)); + + if (!mainIds.isEmpty()){ + for (ContextMenuItem item : items) { + if (mainIds.contains(item.getId())) { + mainAdapter.addItem(item); + } else { + additionalAdapter.addItem(item); + } + } + } else { + for (int i = 0; i < items.size(); i++) { + if (i < MAIN_BUTTONS_QUANTITY) { + mainAdapter.addItem(items.get(i)); + } else { + additionalAdapter.addItem(items.get(i)); + } } } LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( @@ -591,9 +603,15 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo ContextMenuItemClickListener mainListener = menu.getContextMenuItemClickListener(mainAdapter); ContextMenuItemClickListener additionalListener = menu.getContextMenuItemClickListener(additionalAdapter); - int mainButtonsQuantity = Math.min(MAIN_BUTTONS_QUANTITY, items.size()); - for (int i = 0; i < mainButtonsQuantity; i++) { - buttons.addView(getActionView(items.get(i), i, mainAdapter, additionalAdapter, mainListener, additionalListener), params); + if (!mainIds.isEmpty()){ + for (ContextMenuItem item: mainAdapter.getItems()) { + buttons.addView(getActionView(item, mainAdapter.getItems().indexOf(item), mainAdapter, additionalAdapter, mainListener, additionalListener), params); + } + } else { + int mainButtonsQuantity = Math.min(MAIN_BUTTONS_QUANTITY, items.size()); + for (int i = 0; i < mainButtonsQuantity; i++) { + buttons.addView(getActionView(items.get(i), i, mainAdapter, additionalAdapter, mainListener, additionalListener), params); + } } buttons.setGravity(Gravity.CENTER); diff --git a/OsmAnd/src/net/osmand/plus/settings/ConfigureMenuItemsFragment.java b/OsmAnd/src/net/osmand/plus/settings/ConfigureMenuItemsFragment.java index 0c38dd14fd..8ccffa7dab 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ConfigureMenuItemsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ConfigureMenuItemsFragment.java @@ -68,12 +68,14 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment private static final String ITEM_TYPE_KEY = "item_type_key"; private static final String ITEMS_ORDER_KEY = "items_order_key"; private static final String HIDDEN_ITEMS_KEY = "hidden_items_key"; + private static final String MAIN_ACTIONS_ITEMS_KEY = "main_actions_items_key"; private static final String CONFIGURE_MENU_ITEMS_TAG = "configure_menu_items_tag"; private static final String IS_CHANGED_KEY = "is_changed_key"; private RearrangeMenuItemsAdapter rearrangeAdapter; private HashMap menuItemsOrder; private ContextMenuAdapter contextMenuAdapter; private List hiddenMenuItems; + private List mainActionItems; private ApplicationMode appMode; private LayoutInflater mInflater; private OsmandApplication app; @@ -81,6 +83,7 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment private boolean nightMode; private boolean wasReset = false; private boolean isChanged = false; + private Activity activity; @Override public void onSaveInstanceState(@NonNull Bundle outState) { @@ -90,6 +93,9 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment outState.putSerializable(ITEM_TYPE_KEY, screenType); outState.putString(APP_MODE_KEY, appMode.getStringKey()); outState.putBoolean(IS_CHANGED_KEY, isChanged); + if (screenType == ScreenType.CONTEXT_MENU_ACTIONS) { + outState.putStringArrayList(MAIN_ACTIONS_ITEMS_KEY, new ArrayList<>(mainActionItems)); + } } public static ConfigureMenuItemsFragment showInstance( @@ -127,14 +133,15 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); app = requireMyApplication(); - nightMode = app.getSettings().OSMAND_THEME.getModeValue(appMode) == OsmandSettings.OSMAND_DARK_THEME; - mInflater = UiUtilities.getInflater(app, nightMode); if (savedInstanceState != null) { appMode = ApplicationMode.valueOfStringKey(savedInstanceState.getString(APP_MODE_KEY), null); screenType = (ScreenType) savedInstanceState.getSerializable(ITEM_TYPE_KEY); hiddenMenuItems = savedInstanceState.getStringArrayList(HIDDEN_ITEMS_KEY); menuItemsOrder = (HashMap) savedInstanceState.getSerializable(ITEMS_ORDER_KEY); isChanged = savedInstanceState.getBoolean(IS_CHANGED_KEY); + if (screenType == ScreenType.CONTEXT_MENU_ACTIONS) { + mainActionItems = savedInstanceState.getStringArrayList(MAIN_ACTIONS_ITEMS_KEY); + } } else { hiddenMenuItems = new ArrayList<>(getSettingForScreen(app, screenType).getModeValue(appMode).getHiddenIds()); menuItemsOrder = new HashMap<>(); @@ -143,6 +150,10 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment menuItemsOrder.put(orderIds.get(i), i); } } + nightMode = app.getSettings().OSMAND_THEME.getModeValue(appMode) == OsmandSettings.OSMAND_DARK_THEME; + mInflater = UiUtilities.getInflater(app, nightMode); + mainActionItems = new ArrayList<>(); + activity = getActivity(); instantiateContextMenuAdapter(); if (menuItemsOrder.isEmpty()) { List defItems = contextMenuAdapter.getDefaultItems(); @@ -151,10 +162,23 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment menuItemsOrder.put(defItems.get(i).getId(), i); } } + if (screenType == ScreenType.CONTEXT_MENU_ACTIONS) { + initDefaultMainActions(); + } + } + + private void initDefaultMainActions() { + List defItems = contextMenuAdapter.getDefaultItems(); + initDefaultOrders(defItems); + mainActionItems = new ArrayList<>(getSettingForScreen(app, screenType).getModeValue(appMode).getMainActionIds()); + if (mainActionItems.isEmpty()) { + for (int i = 0; i < MAIN_BUTTONS_QUANTITY; i++) { + mainActionItems.add(defItems.get(i).getId()); + } + } } private void instantiateContextMenuAdapter() { - Activity activity = getActivity(); if (activity instanceof MapActivity) { switch (screenType) { case DRAWER: @@ -214,6 +238,9 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment @Override public void onDragOrSwipeEnded(RecyclerView.ViewHolder holder) { + if (screenType == ScreenType.CONTEXT_MENU_ACTIONS) { + mainActionItems = rearrangeAdapter.getMainActionsIds(); + } toPosition = holder.getAdapterPosition(); if (toPosition >= 0 && fromPosition >= 0 && toPosition != fromPosition) { rearrangeAdapter.notifyDataSetChanged(); @@ -226,10 +253,14 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment if (rearrangeMenuAdapterItem.getValue() instanceof ContextMenuItem) { ContextMenuItem menuItemBase = (ContextMenuItem) rearrangeMenuAdapterItem.getValue(); menuItemBase.setHidden(!menuItemBase.isHidden()); + String id = menuItemBase.getId(); if (menuItemBase.isHidden()) { - hiddenMenuItems.add(menuItemBase.getId()); + hiddenMenuItems.add(id); + if (screenType == ScreenType.CONTEXT_MENU_ACTIONS) { + mainActionItems.remove(id); + } } else { - hiddenMenuItems.remove(menuItemBase.getId()); + hiddenMenuItems.remove(id); } wasReset = false; isChanged = true; @@ -273,7 +304,12 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment } } FragmentManager fm = getFragmentManager(); - OsmandSettings.ContextMenuItemsSettings prefToSave = new OsmandSettings.ContextMenuItemsSettings(hiddenMenuItems, ids); + OsmandSettings.ContextMenuItemsSettings prefToSave; + if (screenType == ScreenType.CONTEXT_MENU_ACTIONS) { + prefToSave = new OsmandSettings.ContextMenuItemsSettings(mainActionItems, hiddenMenuItems, ids); + } else { + prefToSave = new OsmandSettings.ContextMenuItemsSettings(hiddenMenuItems, ids); + } if (fm != null) { ChangeGeneralProfilesPrefBottomSheet.showInstance(fm, getSettingForScreen(app, screenType).getId(), @@ -301,6 +337,22 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment return root; } + @Override + public void onResume() { + super.onResume(); + if (activity instanceof MapActivity) { + ((MapActivity) activity).disableDrawer(); + } + } + + @Override + public void onStop() { + super.onStop(); + if (activity instanceof MapActivity) { + ((MapActivity) activity).enableDrawer(); + } + } + private List getAdapterItems() { List items = new ArrayList<>(); items.add(new RearrangeMenuAdapterItem(DESCRIPTION, screenType)); @@ -322,18 +374,20 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment } List main = new ArrayList<>(); - int actionsIndex = Math.min(MAIN_BUTTONS_QUANTITY, visible.size()); - for (int i = 0; i < actionsIndex; i++) { - main.add(visible.get(i)); + List additional = new ArrayList<>(); + for (RearrangeMenuAdapterItem adapterItem : visible) { + if (mainActionItems.contains(((ContextMenuItem) adapterItem.getValue()).getId())) { + main.add(adapterItem); + } else { + additional.add(adapterItem); + } } items.add(new RearrangeMenuAdapterItem(HEADER, new RearrangeMenuItemsAdapter.HeaderItem(R.string.main_actions, R.string.main_actions_descr))); items.addAll(main); - items.add(new RearrangeMenuAdapterItem(HEADER, new RearrangeMenuItemsAdapter.HeaderItem(R.string.additional_actions, R.string.additional_actions_descr))); - List additional = new ArrayList<>(); - for (int i = MAIN_BUTTONS_QUANTITY; i < visible.size(); i++) { - additional.add(visible.get(i)); + if (!additional.isEmpty()) { + items.add(new RearrangeMenuAdapterItem(HEADER, new RearrangeMenuItemsAdapter.HeaderItem(R.string.additional_actions, R.string.additional_actions_descr))); + items.addAll(additional); } - items.addAll(additional); } else { items.addAll(visible); } @@ -354,6 +408,10 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment isChanged = true; getSettingForScreen(app, screenType).resetModeToDefault(appMode); instantiateContextMenuAdapter(); + if (screenType == ScreenType.CONTEXT_MENU_ACTIONS) { + mainActionItems.clear(); + initDefaultMainActions(); + } rearrangeAdapter.updateItems(getAdapterItems()); } }))); diff --git a/OsmAnd/src/net/osmand/plus/settings/ConfigureMenuRootFragment.java b/OsmAnd/src/net/osmand/plus/settings/ConfigureMenuRootFragment.java index 5b6370b6c8..246b248013 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ConfigureMenuRootFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ConfigureMenuRootFragment.java @@ -59,10 +59,11 @@ public class ConfigureMenuRootFragment extends BaseOsmAndFragment { private LayoutInflater mInflater; private boolean nightMode; private ApplicationMode appMode; + private Activity activity; public static boolean showInstance(@NonNull FragmentManager fragmentManager, - Fragment target, - @NonNull ApplicationMode appMode) { + Fragment target, + @NonNull ApplicationMode appMode) { try { ConfigureMenuRootFragment fragment = new ConfigureMenuRootFragment(); fragment.setAppMode(appMode); @@ -86,6 +87,7 @@ public class ConfigureMenuRootFragment extends BaseOsmAndFragment { app = requireMyApplication(); nightMode = app.getSettings().OSMAND_THEME.getModeValue(appMode) == OsmandSettings.OSMAND_DARK_THEME; mInflater = UiUtilities.getInflater(app, nightMode); + activity = getActivity(); } @Nullable @@ -118,9 +120,9 @@ public class ConfigureMenuRootFragment extends BaseOsmAndFragment { toolbarSubTitle.setText(appMode.toHumanString()); toolbarSubTitle.setVisibility(View.VISIBLE); List items = new ArrayList<>(); - String plugins = getString(R.string.prefs_plugins); - String description = String.format(getString(R.string.ui_customization_description), plugins); - items.add(description); + String plugins = getString(R.string.prefs_plugins); + String description = String.format(getString(R.string.ui_customization_description), plugins); + items.add(description); items.addAll(Arrays.asList(ScreenType.values())); CustomizationItemsAdapter adapter = new CustomizationItemsAdapter(items, new OnCustomizationItemClickListener() { @Override @@ -141,11 +143,11 @@ public class ConfigureMenuRootFragment extends BaseOsmAndFragment { @Override public int getStatusBarColorId() { - View view = getView(); - if (view != null && Build.VERSION.SDK_INT >= 23 && !nightMode) { - view.setSystemUiVisibility(view.getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); - } - return nightMode ? R.color.activity_background_dark : R.color.activity_background_light; + View view = getView(); + if (view != null && Build.VERSION.SDK_INT >= 23 && !nightMode) { + view.setSystemUiVisibility(view.getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); + } + return nightMode ? R.color.activity_background_dark : R.color.activity_background_light; } @Override @@ -154,6 +156,22 @@ public class ConfigureMenuRootFragment extends BaseOsmAndFragment { outState.putString(APP_MODE_KEY, getAppMode().getStringKey()); } + @Override + public void onResume() { + super.onResume(); + if (activity instanceof MapActivity) { + ((MapActivity) activity).disableDrawer(); + } + } + + @Override + public void onStop() { + super.onStop(); + if (activity instanceof MapActivity) { + ((MapActivity) activity).enableDrawer(); + } + } + public void setAppMode(ApplicationMode appMode) { this.appMode = appMode; } @@ -202,9 +220,9 @@ public class ConfigureMenuRootFragment extends BaseOsmAndFragment { final Object currentItem = items.get(position); if (holder instanceof DescriptionHolder) { DescriptionHolder descriptionHolder = (DescriptionHolder) holder; - String plugins = getString(R.string.prefs_plugins); + String plugins = getString(R.string.prefs_plugins); setupClickableText( - descriptionHolder.description, (String) currentItem, plugins, new Intent(app, PluginsActivity.class)); + descriptionHolder.description, (String) currentItem, plugins, new Intent(app, PluginsActivity.class)); descriptionHolder.image.setVisibility(View.GONE); } else { final ScreenType item = (ScreenType) currentItem; diff --git a/OsmAnd/src/net/osmand/plus/settings/RearrangeMenuItemsAdapter.java b/OsmAnd/src/net/osmand/plus/settings/RearrangeMenuItemsAdapter.java index 9733d51d74..2e6882c8d5 100644 --- a/OsmAnd/src/net/osmand/plus/settings/RearrangeMenuItemsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/settings/RearrangeMenuItemsAdapter.java @@ -28,19 +28,27 @@ import net.osmand.plus.views.controls.ReorderItemTouchHelperCallback; import net.osmand.plus.settings.ConfigureMenuRootFragment.ScreenType; +import java.util.ArrayList; import java.util.Collections; import java.util.List; +import static net.osmand.aidl.ConnectedApp.AIDL_LAYERS_PREFIX; import static net.osmand.aidlapi.OsmAndCustomizationConstants.CONTOUR_LINES; import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_BUILDS_ID; import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_DIVIDER_ID; import static net.osmand.aidlapi.OsmAndCustomizationConstants.GPX_FILES_ID; +import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_ACTIONS; import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_ADD_GPX_WAYPOINT; +import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_ADD_ID; +import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_AUDIO_NOTE; import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_CREATE_POI; import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_EDIT_GPX_WP; +import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_MARK_AS_PARKING_LOC; import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_MODIFY_OSM_NOTE; import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_MORE_ID; import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_OPEN_OSM_NOTE; +import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_PHOTO_NOTE; +import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_VIDEO_NOTE; import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_RENDERING_CATEGORY_ID; import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_SOURCE_ID; import static net.osmand.aidlapi.OsmAndCustomizationConstants.OSM_EDITS; @@ -209,6 +217,9 @@ public class RearrangeMenuItemsAdapter extends RecyclerView.Adapter= headerMaxIndex || menuItemFrom.getId().equals(MAP_CONTEXT_MENU_MORE_ID)) { + return false; + } + Collections.swap(items, from, to); + notifyItemMoved(from, to); + return true; + } + if (itemFrom instanceof ContextMenuItem && itemTo instanceof ContextMenuItem) { ContextMenuItem menuItemFrom = (ContextMenuItem) itemFrom; @@ -247,17 +274,23 @@ public class RearrangeMenuItemsAdapter extends RecyclerView.Adapter buttonMoreIndex) { - return false; +// item "Actions" should not left "Main actions" section + if (menuItemFrom.getId().equals(MAP_CONTEXT_MENU_MORE_ID) || menuItemTo.getId().equals(MAP_CONTEXT_MENU_MORE_ID)) { + int additionalHeaderIndex = 0; + for (int i = 0; i < items.size(); i++) { + Object value = items.get(i).getValue(); + if (value instanceof HeaderItem && ((HeaderItem) value).titleRes == R.string.additional_actions) { + additionalHeaderIndex = i; + break; + } } - } else if (menuItemTo.getId().equals(MAP_CONTEXT_MENU_MORE_ID)) { - if (from > buttonMoreIndex) { + if (to >= additionalHeaderIndex || from > additionalHeaderIndex) { return false; } } @@ -348,6 +381,7 @@ public class RearrangeMenuItemsAdapter extends RecyclerView.Adapter getMainActionsIds() { + List ids = new ArrayList<>(); + for (RearrangeMenuAdapterItem adapterItem : items) { + Object value = adapterItem.getValue(); + if (value instanceof ContextMenuItem) { + ids.add(((ContextMenuItem) value).getId()); + } else if (value instanceof HeaderItem + && (((HeaderItem) value).titleRes == R.string.additional_actions + || ((HeaderItem) value).titleRes == R.string.shared_string_hidden)) { + break; + } + } + return ids; + } }