From 971db3f666c64017aa28c81c2fd14da3ad3d3986 Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Tue, 7 Apr 2020 14:47:51 +0300 Subject: [PATCH] apply to all dialog / work in progress --- .../aidlapi/OsmAndCustomizationConstants.java | 4 + .../res/layout/context_menu_action_item.xml | 32 ++++ .../list_item_description_with_image.xml | 26 ++- OsmAnd/res/layout/list_item_move_header.xml | 3 +- OsmAnd/res/layout/profile_edit_list_item.xml | 2 + OsmAnd/res/values/strings.xml | 1 + OsmAnd/res/xml/configure_profile.xml | 5 +- .../net/osmand/plus/ContextMenuAdapter.java | 109 ++++++++++++ .../src/net/osmand/plus/OsmandSettings.java | 23 +++ .../osmand/plus/activities/MapActivity.java | 2 +- .../plus/activities/MapActivityActions.java | 138 +++++++++++---- .../osmand/plus/dashboard/DashboardOnMap.java | 2 + .../osmand/plus/dialogs/ConfigureMapMenu.java | 2 +- .../plus/mapcontextmenu/MapContextMenu.java | 20 ++- .../settings/ConfigureMenuItemsFragment.java | 161 +++++++++--------- .../settings/ConfigureMenuRootFragment.java | 44 +++-- .../settings/ConfigureProfileFragment.java | 7 +- .../settings/RearrangeMenuItemsAdapter.java | 40 ++++- .../ChangeGeneralProfilesPrefBottomSheet.java | 107 ++++++++++-- 19 files changed, 567 insertions(+), 161 deletions(-) create mode 100644 OsmAnd/res/layout/context_menu_action_item.xml diff --git a/OsmAnd-api/src/net/osmand/aidlapi/OsmAndCustomizationConstants.java b/OsmAnd-api/src/net/osmand/aidlapi/OsmAndCustomizationConstants.java index 6657e29bca..3fa80e316f 100644 --- a/OsmAnd-api/src/net/osmand/aidlapi/OsmAndCustomizationConstants.java +++ b/OsmAnd-api/src/net/osmand/aidlapi/OsmAndCustomizationConstants.java @@ -71,6 +71,10 @@ public interface OsmAndCustomizationConstants { //Map Context Menu Actions: String MAP_CONTEXT_MENU_ACTIONS = "point.actions."; + String MAP_CONTEXT_MENU_ADD_ID = MAP_CONTEXT_MENU_ACTIONS + "add"; + String MAP_CONTEXT_MENU_MARKER_ID = MAP_CONTEXT_MENU_ACTIONS + "marker"; + String MAP_CONTEXT_MENU_SHARE_ID = MAP_CONTEXT_MENU_ACTIONS + "share"; + String MAP_CONTEXT_MENU_MORE_ID = MAP_CONTEXT_MENU_ACTIONS + "more"; String MAP_CONTEXT_MENU_DIRECTIONS_FROM_ID = MAP_CONTEXT_MENU_ACTIONS + "directions_from"; String MAP_CONTEXT_MENU_SEARCH_NEARBY = MAP_CONTEXT_MENU_ACTIONS + "search_nearby"; String MAP_CONTEXT_MENU_CHANGE_MARKER_POSITION = MAP_CONTEXT_MENU_ACTIONS + "change_m_position"; diff --git a/OsmAnd/res/layout/context_menu_action_item.xml b/OsmAnd/res/layout/context_menu_action_item.xml new file mode 100644 index 0000000000..a2f3ea3b6d --- /dev/null +++ b/OsmAnd/res/layout/context_menu_action_item.xml @@ -0,0 +1,32 @@ + + + + + + + + + diff --git a/OsmAnd/res/layout/list_item_description_with_image.xml b/OsmAnd/res/layout/list_item_description_with_image.xml index 200ffd6107..72f94ed955 100644 --- a/OsmAnd/res/layout/list_item_description_with_image.xml +++ b/OsmAnd/res/layout/list_item_description_with_image.xml @@ -5,12 +5,30 @@ android:layout_height="wrap_content" android:orientation="vertical"> - + android:background="?attr/activity_background_basic" + tools:paddingEnd="56dp" + tools:paddingStart="56dp" + tools:paddingTop="16dp"> + + + + + + @@ -64,6 +64,7 @@ android:layout_height="wrap_content" android:letterSpacing="@dimen/description_letter_spacing" android:paddingBottom="@dimen/list_header_settings_top_margin" + android:lineSpacingExtra="@dimen/line_spacing_extra_description" android:textColor="?android:textColorSecondary" android:textSize="@dimen/default_desc_text_size" osmand:typeface="@string/font_roboto_regular" diff --git a/OsmAnd/res/layout/profile_edit_list_item.xml b/OsmAnd/res/layout/profile_edit_list_item.xml index 08c2880c37..8f7b962ef5 100644 --- a/OsmAnd/res/layout/profile_edit_list_item.xml +++ b/OsmAnd/res/layout/profile_edit_list_item.xml @@ -12,6 +12,7 @@ android:id="@+id/divider" android:layout_width="match_parent" android:layout_height="1dp" + android:layout_marginBottom="@dimen/content_padding_small" android:background="?attr/dashboard_divider" android:visibility="gone" tools:visibility="visible" /> @@ -79,6 +80,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:letterSpacing="@dimen/description_letter_spacing" + android:lineSpacingExtra="@dimen/line_spacing_extra_description" android:maxLines="4" android:textColor="?android:textColorSecondary" android:textSize="@dimen/default_desc_text_size" diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index dfc59b98cb..6728e3504d 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -34,6 +34,7 @@ Context menu actions Drawer UI Customization + Drawer items, context menu Customize the quantity of items in Drawer, Configure map and context menu.\n\nYou can disable unused plugins, to hide all its controls from the application. Min Square diff --git a/OsmAnd/res/xml/configure_profile.xml b/OsmAnd/res/xml/configure_profile.xml index a7477a6cdf..d86a80620f 100644 --- a/OsmAnd/res/xml/configure_profile.xml +++ b/OsmAnd/res/xml/configure_profile.xml @@ -52,14 +52,13 @@ android:title="@string/profile_appearance" tools:icon="@drawable/ic_action_offroad" /> - + tools:icon="@drawable/ic_action_ui_customization" /> getHiddenItemsIds(@NonNull OsmandApplication app, @NonNull ScreenType type) { + List hiddenItemsIds = null; + switch (type) { + case DRAWER: + hiddenItemsIds = app.getSettings().HIDDEN_DRAWER_ITEMS.getStringsList(); + break; + case CONFIGURE_MAP: + hiddenItemsIds = app.getSettings().HIDDEN_CONFIGURE_MAP_ITEMS.getStringsList(); + break; + case CONTEXT_MENU_ACTIONS: + hiddenItemsIds = app.getSettings().HIDDEN_CONTEXT_MENU_ACTIONS_ITEMS.getStringsList(); + break; + } + return hiddenItemsIds != null ? new ArrayList<>(hiddenItemsIds) : new ArrayList(); + } + + @NonNull + public List getItemsIdsOrder(@NonNull OsmandApplication app, @NonNull ScreenType type) { + List hiddenItemsIds = null; + switch (type) { + case DRAWER: + hiddenItemsIds = app.getSettings().DRAWER_ITEMS_ORDER.getStringsList(); + break; + case CONFIGURE_MAP: + hiddenItemsIds = app.getSettings().CONFIGURE_MAP_ITEMS_ORDER.getStringsList(); + break; + case CONTEXT_MENU_ACTIONS: + hiddenItemsIds = app.getSettings().CONTEXT_MENU_ACTIONS_ITEMS_ORDER.getStringsList(); + break; + } + return hiddenItemsIds != null ? new ArrayList<>(hiddenItemsIds) : new ArrayList(); + } + + public void saveHiddenItemsIds(@NonNull OsmandApplication app, @NonNull ScreenType type, @Nullable List hiddenItemsIds) { + switch (type) { + case DRAWER: + app.getSettings().HIDDEN_DRAWER_ITEMS.setStringsList(hiddenItemsIds); + break; + case CONFIGURE_MAP: + app.getSettings().HIDDEN_CONFIGURE_MAP_ITEMS.setStringsList(hiddenItemsIds); + break; + case CONTEXT_MENU_ACTIONS: + app.getSettings().HIDDEN_CONTEXT_MENU_ACTIONS_ITEMS.setStringsList(hiddenItemsIds); + break; + } + } + + public void saveItemsIdsOrder(@NonNull OsmandApplication app, @NonNull ScreenType type, @Nullable List itemsIdsOrder) { + switch (type) { + case DRAWER: + app.getSettings().DRAWER_ITEMS_ORDER.setStringsList(itemsIdsOrder); + break; + case CONFIGURE_MAP: + app.getSettings().CONFIGURE_MAP_ITEMS_ORDER.setStringsList(itemsIdsOrder); + break; + case CONTEXT_MENU_ACTIONS: + app.getSettings().CONTEXT_MENU_ACTIONS_ITEMS_ORDER.setStringsList(itemsIdsOrder); + break; + } + } + + public String getPrefIdOrder(@NonNull OsmandApplication app, @NonNull ScreenType type) { + switch (type) { + case DRAWER: + return app.getSettings().DRAWER_ITEMS_ORDER.getId(); + case CONFIGURE_MAP: + return app.getSettings().CONFIGURE_MAP_ITEMS_ORDER.getId(); + case CONTEXT_MENU_ACTIONS: + return app.getSettings().CONTEXT_MENU_ACTIONS_ITEMS_ORDER.get(); + } + return ""; + } + + public String getPrefIdHidden(@NonNull OsmandApplication app, @NonNull ScreenType type) { + switch (type) { + case DRAWER: + return app.getSettings().HIDDEN_DRAWER_ITEMS.getId(); + case CONFIGURE_MAP: + return app.getSettings().HIDDEN_CONFIGURE_MAP_ITEMS.getId(); + case CONTEXT_MENU_ACTIONS: + return app.getSettings().HIDDEN_CONTEXT_MENU_ACTIONS_ITEMS.get(); + } + return ""; + } + + public void initItemsCustomOrder(@NonNull OsmandApplication app, @NonNull ScreenType type) { + List savedOrder = getItemsIdsOrder(app, type); + List hiddenItems = getHiddenItemsIds(app, type); + + if (!savedOrder.isEmpty()) { + reorderMenuItems(items, getMenuItemsOrder(savedOrder)); + } + + if (!hiddenItems.isEmpty()) { + List filtered = new ArrayList<>(); + for (ContextMenuItem item : items) { + if (!hiddenItems.contains(item.getId())) { + filtered.add(item); + } + } + items = filtered; + } + } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index b72f6022eb..30385c59f9 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -412,6 +412,11 @@ public class OsmandSettings { ((BooleanPreference) preference).setModeValue(mode, (Boolean) value); return true; } + } else if (preference instanceof ListStringPreference) { + if (value instanceof List) { + ((ListStringPreference) preference).setModeValue(mode, (List) value); + return true; + } } else if (preference instanceof StringPreference) { if (value instanceof String) { ((StringPreference) preference).setModeValue(mode, (String) value); @@ -1078,6 +1083,24 @@ public class OsmandSettings { addValue(value); } } + + public boolean setModeValue(ApplicationMode mode, List values) { + if (values == null || values.size() == 0) { + set(null); + return false; + } + clearAll(); + String vl = get(); + for (String value : values) { + addValue(value); + if (vl == null || vl.isEmpty()) { + vl = value + delimiter; + } else { + vl = vl + value + delimiter; + } + } + return setModeValue(mode, vl); + } } public class EnumIntPreference> extends CommonPreference { diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index ed1420014b..77a0af2fca 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -753,7 +753,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven } ConfigureMenuItemsFragment configureMenuItemsFragment = getConfigureMenuItemsFragment(); if (configureMenuItemsFragment != null) { - configureMenuItemsFragment.showExitDialog(); + configureMenuItemsFragment.exitFragment(); return; } diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java index d81e10f31d..3f081a547c 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java @@ -64,6 +64,7 @@ import net.osmand.plus.routepreparationmenu.WaypointsFragment; import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder; import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.settings.BaseSettingsFragment; +import net.osmand.plus.settings.ConfigureMenuRootFragment.ScreenType; import net.osmand.plus.views.BaseMapLayer; import net.osmand.plus.views.MapControlsLayer; import net.osmand.plus.views.MapTileLayer; @@ -98,11 +99,15 @@ import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_SEARCH_ID; import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_SETTINGS_ID; import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_TRAVEL_GUIDES_ID; 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_AVOID_ROAD; import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_DIRECTIONS_FROM_ID; import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_EDIT_GPX_WP; +import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_MARKER_ID; import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_MEASURE_DISTANCE; +import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_MORE_ID; import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_SEARCH_NEARBY; +import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_SHARE_ID; import static net.osmand.plus.ContextMenuAdapter.PROFILES_CHOSEN_PROFILE_TAG; import static net.osmand.plus.ContextMenuAdapter.PROFILES_CONTROL_BUTTON_TAG; import static net.osmand.plus.ContextMenuAdapter.PROFILES_NORMAL_PROFILE_TAG; @@ -332,9 +337,102 @@ public class MapActivityActions implements DialogProvider { } public void contextMenuPoint(final double latitude, final double longitude, final ContextMenuAdapter iadapter, Object selectedObj) { - final ContextMenuAdapter adapter = iadapter == null ? new ContextMenuAdapter() : iadapter; + final ContextMenuAdapter adapter = getContextMenuAdapter(iadapter, selectedObj); + final ArrayAdapter listAdapter = + adapter.createListAdapter(mapActivity, getMyApplication().getSettings().isLightContent()); + + AdditionalActionsBottomSheetDialogFragment actionsBottomSheetDialogFragment = new AdditionalActionsBottomSheetDialogFragment(); + actionsBottomSheetDialogFragment.setAdapter(adapter, new AdditionalActionsBottomSheetDialogFragment.ContextMenuItemClickListener() { + @Override + public void onItemClick(int position) { + ContextMenuItem item = adapter.getItem(position); + int standardId = item.getTitleId(); + ItemClickListener click = item.getItemClickListener(); + if (click != null) { + click.onContextMenuClick(listAdapter, standardId, position, false, null); + } else if (standardId == R.string.context_menu_item_search) { + mapActivity.showQuickSearch(latitude, longitude); + } else if (standardId == R.string.context_menu_item_directions_from) { + if (OsmAndLocationProvider.isLocationPermissionAvailable(mapActivity)) { + enterDirectionsFromPoint(latitude, longitude); + } else if (!ActivityCompat.shouldShowRequestPermissionRationale(mapActivity, Manifest.permission.ACCESS_FINE_LOCATION)) { + mapActivity.getMyApplication().showToastMessage(R.string.ask_for_location_permission); + } else { + ActivityCompat.requestPermissions(mapActivity, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_LOCATION_FOR_DIRECTIONS_NAVIGATION_PERMISSION); + } + } else if (standardId == R.string.measurement_tool) { + mapActivity.getContextMenu().close(); + MeasurementToolFragment.showInstance(mapActivity.getSupportFragmentManager(), new LatLon(latitude, longitude)); + } else if (standardId == R.string.avoid_road) { + getMyApplication().getAvoidSpecificRoads().addImpassableRoad(mapActivity, new LatLon(latitude, longitude), true, false, null); + } + } + }); + actionsBottomSheetDialogFragment.show(mapActivity.getSupportFragmentManager(), AdditionalActionsBottomSheetDialogFragment.TAG); + } + + public void showActionsBottomSheet(final double latitude, final double longitude, final ContextMenuAdapter adapter) { + final ArrayAdapter listAdapter = + adapter.createListAdapter(mapActivity, getMyApplication().getSettings().isLightContent()); + + AdditionalActionsBottomSheetDialogFragment actionsBottomSheetDialogFragment = new AdditionalActionsBottomSheetDialogFragment(); + actionsBottomSheetDialogFragment.setAdapter(adapter, new AdditionalActionsBottomSheetDialogFragment.ContextMenuItemClickListener() { + @Override + public void onItemClick(int position) { + ContextMenuItem item = adapter.getItem(position); + int standardId = item.getTitleId(); + ItemClickListener click = item.getItemClickListener(); + if (click != null) { + click.onContextMenuClick(listAdapter, standardId, position, false, null); + } else if (standardId == R.string.context_menu_item_search) { + mapActivity.showQuickSearch(latitude, longitude); + } else if (standardId == R.string.context_menu_item_directions_from) { + if (OsmAndLocationProvider.isLocationPermissionAvailable(mapActivity)) { + enterDirectionsFromPoint(latitude, longitude); + } else if (!ActivityCompat.shouldShowRequestPermissionRationale(mapActivity, Manifest.permission.ACCESS_FINE_LOCATION)) { + mapActivity.getMyApplication().showToastMessage(R.string.ask_for_location_permission); + } else { + ActivityCompat.requestPermissions(mapActivity, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_LOCATION_FOR_DIRECTIONS_NAVIGATION_PERMISSION); + } + } else if (standardId == R.string.measurement_tool) { + mapActivity.getContextMenu().close(); + MeasurementToolFragment.showInstance(mapActivity.getSupportFragmentManager(), new LatLon(latitude, longitude)); + } else if (standardId == R.string.avoid_road) { + getMyApplication().getAvoidSpecificRoads().addImpassableRoad(mapActivity, new LatLon(latitude, longitude), true, false, null); + } + } + }); + actionsBottomSheetDialogFragment.show(mapActivity.getSupportFragmentManager(), AdditionalActionsBottomSheetDialogFragment.TAG); + } + + public ContextMenuAdapter getContextMenuAdapter(final ContextMenuAdapter iadapter, Object selectedObj) { + ContextMenuAdapter adapter = iadapter == null ? new ContextMenuAdapter() : iadapter; ItemBuilder itemBuilder = new ItemBuilder(); + adapter.addItem(itemBuilder + .setTitleId(R.string.shared_string_add, mapActivity) + .setId(MAP_CONTEXT_MENU_ADD_ID) + .setIcon(R.drawable.map_action_fav_dark) + .setOrder(0) + .createItem()); + adapter.addItem(itemBuilder + .setTitleId(R.string.shared_string_marker, mapActivity) + .setId(MAP_CONTEXT_MENU_MARKER_ID) + .setIcon(R.drawable.map_action_flag_dark) + .setOrder(1) + .createItem()); + adapter.addItem(itemBuilder + .setTitleId(R.string.shared_string_share, mapActivity) + .setId(MAP_CONTEXT_MENU_SHARE_ID) + .setIcon(R.drawable.map_action_gshare_dark) + .setOrder(2) + .createItem()); + adapter.addItem(itemBuilder + .setTitleId(R.string.shared_string_actions, mapActivity) + .setId(MAP_CONTEXT_MENU_MORE_ID) + .setIcon(R.drawable.map_overflow_menu_white) + .setOrder(3) + .createItem()); adapter.addItem(itemBuilder .setTitleId(R.string.context_menu_item_directions_from, mapActivity) .setId(MAP_CONTEXT_MENU_DIRECTIONS_FROM_ID) @@ -348,7 +446,9 @@ public class MapActivityActions implements DialogProvider { .setOrder(SEARCH_NEAR_ITEM_ORDER) .createItem()); - OsmandPlugin.registerMapContextMenu(mapActivity, latitude, longitude, adapter, selectedObj); +// if (register){ +// OsmandPlugin.registerMapContextMenu(mapActivity, latitude, longitude, adapter, selectedObj); +// } ItemClickListener listener = new ItemClickListener() { @Override @@ -395,38 +495,7 @@ public class MapActivityActions implements DialogProvider { .createItem()); adapter.sortItemsByOrder(); - - final ArrayAdapter listAdapter = - adapter.createListAdapter(mapActivity, getMyApplication().getSettings().isLightContent()); - - AdditionalActionsBottomSheetDialogFragment actionsBottomSheetDialogFragment = new AdditionalActionsBottomSheetDialogFragment(); - actionsBottomSheetDialogFragment.setAdapter(adapter, new AdditionalActionsBottomSheetDialogFragment.ContextMenuItemClickListener() { - @Override - public void onItemClick(int position) { - ContextMenuItem item = adapter.getItem(position); - int standardId = item.getTitleId(); - ItemClickListener click = item.getItemClickListener(); - if (click != null) { - click.onContextMenuClick(listAdapter, standardId, position, false, null); - } else if (standardId == R.string.context_menu_item_search) { - mapActivity.showQuickSearch(latitude, longitude); - } else if (standardId == R.string.context_menu_item_directions_from) { - if (OsmAndLocationProvider.isLocationPermissionAvailable(mapActivity)) { - enterDirectionsFromPoint(latitude, longitude); - } else if (!ActivityCompat.shouldShowRequestPermissionRationale(mapActivity, Manifest.permission.ACCESS_FINE_LOCATION)) { - mapActivity.getMyApplication().showToastMessage(R.string.ask_for_location_permission); - } else { - ActivityCompat.requestPermissions(mapActivity, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_LOCATION_FOR_DIRECTIONS_NAVIGATION_PERMISSION); - } - } else if (standardId == R.string.measurement_tool) { - mapActivity.getContextMenu().close(); - MeasurementToolFragment.showInstance(mapActivity.getSupportFragmentManager(), new LatLon(latitude, longitude)); - } else if (standardId == R.string.avoid_road) { - getMyApplication().getAvoidSpecificRoads().addImpassableRoad(mapActivity, new LatLon(latitude, longitude), true, false, null); - } - } - }); - actionsBottomSheetDialogFragment.show(mapActivity.getSupportFragmentManager(), AdditionalActionsBottomSheetDialogFragment.TAG); + return adapter; } public void enterDirectionsFromPoint(final double latitude, final double longitude) { @@ -1125,6 +1194,7 @@ public class MapActivityActions implements DialogProvider { } menuItemsListView.setDivider(null); final ContextMenuAdapter contextMenuAdapter = createMainOptionsMenu(); + contextMenuAdapter.initItemsCustomOrder(getMyApplication(), ScreenType.DRAWER); contextMenuAdapter.setDefaultLayoutId(R.layout.simple_list_menu_item); final ArrayAdapter simpleListAdapter = contextMenuAdapter.createListAdapter(mapActivity, !nightMode); diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java b/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java index 8815bd0e22..6bc0462bc9 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java @@ -77,6 +77,7 @@ import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin; import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.LocalRoutingParameter; import net.osmand.plus.routing.IRouteInformationListener; import net.osmand.plus.routing.RoutingHelper; +import net.osmand.plus.settings.ConfigureMenuRootFragment.ScreenType; import net.osmand.plus.srtmplugin.ContourLinesMenu; import net.osmand.plus.srtmplugin.SRTMPlugin; import net.osmand.plus.srtmplugin.TerrainFragment; @@ -697,6 +698,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, IRouteInfo cm = mapActivity.getMapLayers().getMapWidgetRegistry().getViewConfigureMenuAdapter(mapActivity); } else if (visibleType == DashboardType.CONFIGURE_MAP) { cm = new ConfigureMapMenu().createListAdapter(mapActivity); + cm.initItemsCustomOrder(getMyApplication(), ScreenType.CONFIGURE_MAP); } else if (visibleType == DashboardType.LIST_MENU) { cm = mapActivity.getMapActions().createMainOptionsMenu(); } else if (visibleType == DashboardType.ROUTE_PREFERENCES) { diff --git a/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java b/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java index 4b991c2b8e..f9336ea1aa 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java @@ -51,6 +51,7 @@ import net.osmand.plus.inapp.InAppPurchaseHelper; import net.osmand.plus.poi.PoiFiltersHelper; import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin; import net.osmand.plus.render.RendererRegistry; +import net.osmand.plus.settings.ConfigureMenuRootFragment.ScreenType; import net.osmand.plus.srtmplugin.SRTMPlugin; import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.corenative.NativeCoreContext; @@ -151,7 +152,6 @@ public class ConfigureMapMenu { adapter.setNightMode(nightMode); createLayersItems(customRules, adapter, ma, themeRes, nightMode); createRenderingAttributeItems(customRules, adapter, ma, themeRes, nightMode); - return adapter; } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java index 2d0377ea0d..b67a70b1c0 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java @@ -1064,16 +1064,24 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL public void buttonMorePressed() { MapActivity mapActivity = getMapActivity(); if (mapActivity != null) { - final ContextMenuAdapter menuAdapter = new ContextMenuAdapter(); LatLon latLon = getLatLon(); - for (OsmandMapLayer layer : mapActivity.getMapView().getLayers()) { - layer.populateObjectContextMenu(latLon, getObject(), menuAdapter, mapActivity); - } - - mapActivity.getMapActions().contextMenuPoint(latLon.getLatitude(), latLon.getLongitude(), menuAdapter, getObject()); + mapActivity.getMapActions().contextMenuPoint(latLon.getLatitude(), latLon.getLongitude(), getAdapter(), getObject()); } } + public ContextMenuAdapter getAdapter() { + final ContextMenuAdapter menuAdapter = new ContextMenuAdapter(); + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { +// LatLon latLon = getLatLon(); +// for (OsmandMapLayer layer : mapActivity.getMapView().getLayers()) { +// layer.populateObjectContextMenu(latLon, getObject(), menuAdapter, mapActivity); +// } + mapActivity.getMapActions().getContextMenuAdapter(menuAdapter, getObject()); + } + return menuAdapter; + } + private void callMenuAction(boolean waitForAddressLookup, MenuAction menuAction) { if (searchingAddress() && waitForAddressLookup) { ProgressDialog dlg = buildSearchActionDialog(); diff --git a/OsmAnd/src/net/osmand/plus/settings/ConfigureMenuItemsFragment.java b/OsmAnd/src/net/osmand/plus/settings/ConfigureMenuItemsFragment.java index 0ecfe40248..6f74f76c3f 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ConfigureMenuItemsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ConfigureMenuItemsFragment.java @@ -5,6 +5,7 @@ import android.content.Context; import android.content.DialogInterface; import android.os.Build; import android.os.Bundle; +import android.view.ContextMenu; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -19,9 +20,11 @@ import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentManager; import androidx.recyclerview.widget.ItemTouchHelper; import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.PagerSnapHelper; import androidx.recyclerview.widget.RecyclerView; import net.osmand.AndroidUtils; +import net.osmand.plus.ApplicationMode; import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuItem; import net.osmand.plus.OsmandApplication; @@ -31,17 +34,21 @@ import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivityActions; import net.osmand.plus.base.BaseOsmAndFragment; import net.osmand.plus.dialogs.ConfigureMapMenu; +import net.osmand.plus.mapcontextmenu.MapContextMenu; import net.osmand.plus.settings.ConfigureMenuRootFragment.ScreenType; +import net.osmand.plus.settings.bottomsheets.ChangeGeneralProfilesPrefBottomSheet; import net.osmand.plus.views.controls.ReorderItemTouchHelperCallback; import net.osmand.plus.settings.RearrangeMenuItemsAdapter.AdapterItem; import net.osmand.plus.settings.RearrangeMenuItemsAdapter.MenuItemsAdapterListener; +import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; +import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_MORE_ID; import static net.osmand.plus.settings.RearrangeMenuItemsAdapter.AdapterItemType.BUTTON; import static net.osmand.plus.settings.RearrangeMenuItemsAdapter.AdapterItemType.DESCRIPTION; import static net.osmand.plus.settings.RearrangeMenuItemsAdapter.AdapterItemType.DIVIDER; @@ -63,6 +70,7 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment { private ScreenType screenType; private boolean nightMode; private boolean wasReset = false; + private boolean isChanged = false; @Override public void onSaveInstanceState(@NonNull Bundle outState) { @@ -100,6 +108,8 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment { contextMenuAdapter = configureMapMenu.createListAdapter((MapActivity) activity); break; case CONTEXT_MENU_ACTIONS: + MapContextMenu menu = ((MapActivity) activity).getContextMenu(); + contextMenuAdapter = menu.getAdapter(); break; } } @@ -111,19 +121,20 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment { hiddenMenuItems = savedInstanceState.getStringArrayList(HIDDEN_ITEMS_KEY); menuItemsOrder = (HashMap) savedInstanceState.getSerializable(ITEMS_ORDER_KEY); } else { - hiddenMenuItems = getHiddenItemsIds(screenType); - menuItemsOrder = contextMenuAdapter.getMenuItemsOrder(getItemsIdsOrder(screenType)); + hiddenMenuItems = contextMenuAdapter.getHiddenItemsIds(app, screenType); + menuItemsOrder = contextMenuAdapter.getMenuItemsOrder(contextMenuAdapter.getItemsIdsOrder(app, screenType)); } } @Nullable @Override - public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable final ViewGroup container, @Nullable Bundle savedInstanceState) { View root = mInflater.inflate(R.layout.edit_arrangement_list_fragment, container, false); Toolbar toolbar = root.findViewById(R.id.toolbar); TextView toolbarTitle = root.findViewById(R.id.toolbar_title); ImageButton toolbarButton = root.findViewById(R.id.close_button); RecyclerView recyclerView = root.findViewById(R.id.profiles_list); + recyclerView.setPadding(0, 0, 0, AndroidUtils.dpToPx(app, 72)); toolbar.setBackgroundColor(nightMode ? getResources().getColor(R.color.list_background_color_dark) : getResources().getColor(R.color.list_background_color_light)); @@ -135,7 +146,7 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment { toolbarButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - showExitDialog(); + exitFragment(); } }); @@ -174,6 +185,7 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment { hiddenMenuItems.remove(menuItemBase.getId()); } wasReset = false; + isChanged = true; rearrangeAdapter.updateItems(getAdapterItems()); } } @@ -182,6 +194,7 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment { public void onItemMoved(String id, int position) { menuItemsOrder.put(id, position); wasReset = false; + isChanged = true; } }; rearrangeAdapter.setListener(listener); @@ -204,19 +217,45 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment { applyButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - if (wasReset) { - resetMenuItems(screenType); - } else { - saveHiddenItemsIds(screenType, hiddenMenuItems); +// if (wasReset) { +// contextMenuAdapter.resetMenuItems(app, screenType); +// } else { + HashMap prefsMap = new HashMap<>(); + prefsMap.put(contextMenuAdapter.getPrefIdHidden(app, screenType), (Serializable) hiddenMenuItems); +// contextMenuAdapter.saveHiddenItemsIds(app, screenType, hiddenMenuItems); + List defItems = contextMenuAdapter.getDefaultItems(screenType); contextMenuAdapter.reorderMenuItems(defItems, menuItemsOrder); List ids = new ArrayList<>(); for (ContextMenuItem item : defItems) { ids.add(item.getId()); } - saveItemsIdsOrder(screenType, ids); - } - dismissFragment(); + prefsMap.put(contextMenuAdapter.getPrefIdOrder(app, screenType), (Serializable) ids); + + FragmentManager fm = getFragmentManager(); + ApplicationMode appMode = app.getSettings().getApplicationMode(); + if (fm != null) { + ChangeGeneralProfilesPrefBottomSheet.showInstance( + fm, + prefsMap, + getTargetFragment(), + false, + appMode, + new ChangeGeneralProfilesPrefBottomSheet.OnChangeSettingListener() { + @Override + public void onApplied() { + dismissFragment(); + } + + @Override + public void onDiscard() { + + } + }); + } +// contextMenuAdapter.saveItemsIdsOrder(app, screenType, ids); +// } +// dismissFragment(); } }); if (Build.VERSION.SDK_INT >= 21) { @@ -231,7 +270,29 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment { List visible = contextMenuAdapter.getItemsForRearrangeAdapter(screenType, hiddenMenuItems, wasReset ? null : menuItemsOrder, false); List hiddenItems = contextMenuAdapter.getItemsForRearrangeAdapter(screenType, hiddenMenuItems, wasReset ? null : menuItemsOrder, true); - items.addAll(visible); + if (screenType == ScreenType.CONTEXT_MENU_ACTIONS) { + List main = new ArrayList<>(); + int actionsIndex = 3; + for (int i = 0; i < visible.size(); i++) { + if (((ContextMenuItem) visible.get(i).getValue()).getId().equals(MAP_CONTEXT_MENU_MORE_ID)) { + actionsIndex = i; + break; + } + } + for (int i = 0; i < actionsIndex + 1; i++) { + main.add(visible.get(i)); + } + items.add(new AdapterItem(HEADER, new RearrangeMenuItemsAdapter.HeaderItem(R.string.main_actions, R.string.main_actions_descr))); + items.addAll(main); + items.add(new AdapterItem(HEADER, new RearrangeMenuItemsAdapter.HeaderItem(R.string.additional_actions, R.string.additional_actions_descr))); + List additional = new ArrayList<>(); + for (int i = 4; i < visible.size(); i++) { + additional.add(visible.get(i)); + } + items.addAll(additional); + } else { + items.addAll(visible); + } if (!hiddenItems.isEmpty()) { items.add(new AdapterItem(HEADER, new RearrangeMenuItemsAdapter.HeaderItem(R.string.shared_string_hidden, R.string.hidden_items_descr))); items.addAll(hiddenItems); @@ -246,6 +307,7 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment { hiddenMenuItems.clear(); menuItemsOrder.clear(); wasReset = true; + isChanged = true; rearrangeAdapter.updateItems(getAdapterItems()); } }))); @@ -261,6 +323,14 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment { return items; } + public void exitFragment() { + if (isChanged) { + showExitDialog(); + } else { + dismissFragment(); + } + } + public void showExitDialog() { Context themedContext = UiUtilities.getThemedContext(getActivity(), nightMode); AlertDialog.Builder dismissDialog = new AlertDialog.Builder(themedContext); @@ -286,71 +356,4 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment { private void setScreenType(@NonNull ScreenType screenType) { this.screenType = screenType; } - - private void resetMenuItems(@NonNull ScreenType screenType) { - saveHiddenItemsIds(screenType, null); - saveItemsIdsOrder(screenType, null); - } - - @NonNull - private List getHiddenItemsIds(@NonNull ScreenType type) { - List hiddenItemsIds = null; - switch (type) { - case DRAWER: - hiddenItemsIds = app.getSettings().HIDDEN_DRAWER_ITEMS.getStringsList(); - break; - case CONFIGURE_MAP: - hiddenItemsIds = app.getSettings().HIDDEN_CONFIGURE_MAP_ITEMS.getStringsList(); - break; - case CONTEXT_MENU_ACTIONS: - hiddenItemsIds = app.getSettings().HIDDEN_CONTEXT_MENU_ACTIONS_ITEMS.getStringsList(); - break; - } - return hiddenItemsIds != null ? new ArrayList<>(hiddenItemsIds) : new ArrayList(); - } - - @NonNull - private List getItemsIdsOrder(@NonNull ScreenType type) { - List hiddenItemsIds = null; - switch (type) { - case DRAWER: - hiddenItemsIds = app.getSettings().DRAWER_ITEMS_ORDER.getStringsList(); - break; - case CONFIGURE_MAP: - hiddenItemsIds = app.getSettings().CONFIGURE_MAP_ITEMS_ORDER.getStringsList(); - break; - case CONTEXT_MENU_ACTIONS: - hiddenItemsIds = app.getSettings().CONTEXT_MENU_ACTIONS_ITEMS_ORDER.getStringsList(); - break; - } - return hiddenItemsIds != null ? new ArrayList<>(hiddenItemsIds) : new ArrayList(); - } - - private void saveHiddenItemsIds(@NonNull ScreenType type, @Nullable List hiddenItemsIds) { - switch (type) { - case DRAWER: - app.getSettings().HIDDEN_DRAWER_ITEMS.setStringsList(hiddenItemsIds); - break; - case CONFIGURE_MAP: - app.getSettings().HIDDEN_CONFIGURE_MAP_ITEMS.setStringsList(hiddenItemsIds); - break; - case CONTEXT_MENU_ACTIONS: - app.getSettings().HIDDEN_CONTEXT_MENU_ACTIONS_ITEMS.setStringsList(hiddenItemsIds); - break; - } - } - - private void saveItemsIdsOrder(@NonNull ScreenType type, @Nullable List itemsIdsOrder) { - switch (type) { - case DRAWER: - app.getSettings().DRAWER_ITEMS_ORDER.setStringsList(itemsIdsOrder); - break; - case CONFIGURE_MAP: - app.getSettings().CONFIGURE_MAP_ITEMS_ORDER.setStringsList(itemsIdsOrder); - break; - case CONTEXT_MENU_ACTIONS: - app.getSettings().CONTEXT_MENU_ACTIONS_ITEMS_ORDER.setStringsList(itemsIdsOrder); - break; - } - } } diff --git a/OsmAnd/src/net/osmand/plus/settings/ConfigureMenuRootFragment.java b/OsmAnd/src/net/osmand/plus/settings/ConfigureMenuRootFragment.java index 238bb5ac9e..c85c4ebd14 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ConfigureMenuRootFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ConfigureMenuRootFragment.java @@ -1,5 +1,6 @@ package net.osmand.plus.settings; +import android.app.Activity; import android.content.Intent; import android.os.Build; import android.os.Bundle; @@ -26,11 +27,15 @@ import androidx.recyclerview.widget.RecyclerView; import net.osmand.AndroidUtils; import net.osmand.PlatformUtil; import net.osmand.plus.ApplicationMode; +import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; +import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.activities.MapActivityActions; import net.osmand.plus.activities.PluginsActivity; import net.osmand.plus.base.BaseOsmAndFragment; +import net.osmand.plus.dialogs.ConfigureMapMenu; import net.osmand.plus.helpers.FontCache; import net.osmand.plus.widgets.style.CustomTypefaceSpan; @@ -41,6 +46,8 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import static net.osmand.plus.settings.ConfigureMenuRootFragment.ScreenType.CONFIGURE_MAP; + public class ConfigureMenuRootFragment extends BaseOsmAndFragment { public static final String TAG = ConfigureMenuRootFragment.class.getName(); @@ -202,22 +209,29 @@ public class ConfigureMenuRootFragment extends BaseOsmAndFragment { } private String getSubTitleText(ScreenType type) { - List hiddenItems = null; - switch (type) { - case DRAWER: - hiddenItems = app.getSettings().HIDDEN_DRAWER_ITEMS.getStringsList(); - break; - case CONFIGURE_MAP: - hiddenItems = app.getSettings().HIDDEN_CONFIGURE_MAP_ITEMS.getStringsList(); - break; - case CONTEXT_MENU_ACTIONS: - hiddenItems = app.getSettings().HIDDEN_CONTEXT_MENU_ACTIONS_ITEMS.getStringsList(); - break; + ContextMenuAdapter contextMenuAdapter = null; + Activity activity = getActivity(); + if (activity instanceof MapActivity) { + switch (type) { + case DRAWER: + MapActivityActions mapActivityActions = new MapActivityActions((MapActivity) activity); + contextMenuAdapter = mapActivityActions.createMainOptionsMenu(); + break; + case CONFIGURE_MAP: + ConfigureMapMenu configureMapMenu = new ConfigureMapMenu(); + contextMenuAdapter = configureMapMenu.createListAdapter((MapActivity) activity); + break; + case CONTEXT_MENU_ACTIONS: + ConfigureMapMenu configureaMapMenu = new ConfigureMapMenu(); + contextMenuAdapter = configureaMapMenu.createListAdapter((MapActivity) activity); + break; + } + int hiddenCount = contextMenuAdapter.getHiddenItemsIds(app, type).size(); + int allCount = contextMenuAdapter.getDefaultItems(type).size(); + String amount = getString(R.string.n_items_of_z, String.valueOf(allCount - hiddenCount), String.valueOf(allCount)); + return getString(R.string.ltr_or_rtl_combine_via_colon, getString(R.string.shared_string_items), amount); } - int hiddenCount = hiddenItems != null ? hiddenItems.size() : 0; - int allCount = 0; - String amount = getString(R.string.n_items_of_z, String.valueOf(allCount - hiddenCount), String.valueOf(allCount)); - return getString(R.string.ltr_or_rtl_combine_via_colon, getString(R.string.shared_string_items), amount); + return ""; } class DescriptionHolder extends RecyclerView.ViewHolder { diff --git a/OsmAnd/src/net/osmand/plus/settings/ConfigureProfileFragment.java b/OsmAnd/src/net/osmand/plus/settings/ConfigureProfileFragment.java index 256c376e42..52a921e68e 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ConfigureProfileFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ConfigureProfileFragment.java @@ -390,9 +390,10 @@ public class ConfigureProfileFragment extends BaseSettingsFragment implements Co return; } Preference uiCustomization = findPreference(UI_CUSTOMIZATION); -// TODO change icon - uiCustomization.setIcon(getContentIcon(getSelectedAppMode().getIconRes())); - uiCustomization.setFragment(ConfigureMenuRootFragment.TAG); + if (uiCustomization != null) { + uiCustomization.setIcon(getContentIcon(R.drawable.ic_action_ui_customization)); + uiCustomization.setFragment(ConfigureMenuRootFragment.TAG); + } } @Override diff --git a/OsmAnd/src/net/osmand/plus/settings/RearrangeMenuItemsAdapter.java b/OsmAnd/src/net/osmand/plus/settings/RearrangeMenuItemsAdapter.java index ec90689e9d..5f92b061f7 100644 --- a/OsmAnd/src/net/osmand/plus/settings/RearrangeMenuItemsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/settings/RearrangeMenuItemsAdapter.java @@ -6,6 +6,7 @@ import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; +import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.TextView; @@ -21,6 +22,7 @@ import net.osmand.plus.ContextMenuItem; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; +import net.osmand.plus.helpers.FontCache; import net.osmand.plus.views.controls.ReorderItemTouchHelperCallback; import net.osmand.plus.settings.ConfigureMenuRootFragment.ScreenType; @@ -29,6 +31,7 @@ import java.util.Collections; import java.util.List; import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_DIVIDER_ID; +import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_MORE_ID; import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_RENDERING_CATEGORY_ID; import static net.osmand.aidlapi.OsmAndCustomizationConstants.RENDERING_ITEMS_ID_SCHEME; import static net.osmand.aidlapi.OsmAndCustomizationConstants.SHOW_CATEGORY_ID; @@ -96,14 +99,30 @@ public class RearrangeMenuItemsAdapter extends RecyclerView.Adapter prefsMap; + + @Nullable + private OnChangeSettingListener listener; + + public void setListener(@Nullable OnChangeSettingListener listener) { + this.listener = listener; + } + @Override public void createMenuItems(Bundle savedInstanceState) { final OsmandApplication app = getMyApplication(); @@ -39,11 +58,12 @@ public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSh if (app == null || args == null) { return; } - final String prefId = args.getString(PREFERENCE_ID); + prefId = args.getString(PREFERENCE_ID); newValue = args.getSerializable(NEW_VALUE_KEY); - if (newValue == null || prefId == null) { - return; - } + prefsMap = (HashMap) args.getSerializable(PREFS_MAP_KEY); +// if (newValue == null || prefId == null) { +// return; +// } items.add(new TitleItem(getString(R.string.change_default_settings))); items.add(new LongDescriptionItem(getString(R.string.apply_preference_to_all_profiles))); @@ -55,8 +75,15 @@ public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSh .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - app.getSettings().setPreferenceForAllModes(prefId, newValue); + if (prefsMap != null) { + savePrefs(app, prefsMap, true); + } else if (newValue != null || prefId != null) { + app.getSettings().setPreferenceForAllModes(prefId, newValue); + } updateTargetSettings(false, true); + if (listener != null) { + listener.onApplied(); + } dismiss(); } }) @@ -72,8 +99,15 @@ public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSh .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - app.getSettings().setPreference(prefId, newValue, getAppMode()); + if (prefsMap != null) { + savePrefs(app, prefsMap, false); + } else if (newValue != null || prefId != null) { + app.getSettings().setPreference(prefId, newValue, getAppMode()); + } updateTargetSettings(false, false); + if (listener != null) { + listener.onApplied(); + } dismiss(); } }) @@ -88,6 +122,9 @@ public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSh @Override public void onClick(View v) { updateTargetSettings(true, false); + if (listener != null) { + listener.onDiscard(); + } dismiss(); } }) @@ -106,6 +143,18 @@ public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSh outState.putSerializable(NEW_VALUE_KEY, newValue); } + private void savePrefs(@NonNull OsmandApplication app, + @NonNull HashMap prefsMap, boolean toAllProfiles) { + List ids = new ArrayList<>(prefsMap.keySet()); + for (String id : ids) { + if (toAllProfiles) { + app.getSettings().setPreferenceForAllModes(id, prefsMap.get(id)); + } else { + app.getSettings().setPreference(id, prefsMap.get(id), getAppMode()); + } + } + } + private void updateTargetSettings(boolean discard, boolean appliedToAllProfiles) { BaseSettingsFragment target = (BaseSettingsFragment) getTargetFragment(); if (target != null) { @@ -129,23 +178,61 @@ public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSh } } - public static void showInstance(@NonNull FragmentManager fm, String prefId, Serializable newValue, Fragment target, - boolean usedOnMap, @Nullable ApplicationMode appMode) { + public static void showInstance(@NonNull FragmentManager fm, + @Nullable String prefId, + @Nullable Serializable newValue, + Fragment target, + boolean usedOnMap, + @Nullable ApplicationMode appMode) { + showFragmentInstance(fm, prefId, newValue, null, target, usedOnMap, appMode, null); + } + + public static void showInstance(@NonNull FragmentManager fm, + @Nullable HashMap prefs, + Fragment target, + boolean usedOnMap, + @Nullable ApplicationMode appMode, + @Nullable OnChangeSettingListener listener) { + showFragmentInstance(fm, null, null, prefs, target, usedOnMap, appMode, listener); + } + + private static void showFragmentInstance(@NonNull FragmentManager fm, + @Nullable String prefId, + @Nullable Serializable newValue, + @Nullable HashMap prefs, + Fragment target, + boolean usedOnMap, + @Nullable ApplicationMode appMode, + @Nullable OnChangeSettingListener listener) { try { if (fm.findFragmentByTag(ChangeGeneralProfilesPrefBottomSheet.TAG) == null) { Bundle args = new Bundle(); - args.putString(PREFERENCE_ID, prefId); - args.putSerializable(NEW_VALUE_KEY, newValue); + if (prefId != null) { + args.putString(PREFERENCE_ID, prefId); + } + if (newValue != null) { + args.putSerializable(NEW_VALUE_KEY, newValue); + } + if (prefs != null) { + args.putSerializable(PREFS_MAP_KEY, prefs); + } ChangeGeneralProfilesPrefBottomSheet fragment = new ChangeGeneralProfilesPrefBottomSheet(); fragment.setArguments(args); fragment.setUsedOnMap(usedOnMap); fragment.setAppMode(appMode); fragment.setTargetFragment(target, 0); + fragment.setListener(listener); fragment.show(fm, ChangeGeneralProfilesPrefBottomSheet.TAG); } } catch (RuntimeException e) { LOG.error("showInstance", e); } } + + public interface OnChangeSettingListener { + void onApplied(); + + void onDiscard(); + } } \ No newline at end of file