diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 000888d3fd..a4b152b3be 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,6 +11,10 @@ Thx - Hardy --> + A button to show or hide public transport on the map. + Show/hide public transport + Show public transport + Hide public transport • New offline Slope maps\n\n • Full customization of Favorites and GPX Waypoints – custom colors, icons, shapes\n\n diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index 7e9a6742c1..1dbfa86691 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -3747,6 +3747,9 @@ public class OsmandSettings { public final ListStringPreference TRANSPORT_DEFAULT_SETTINGS = (ListStringPreference) new ListStringPreference("transport_default_settings", "transportStops", ",").makeProfile(); + + public final ListStringPreference DISPLAYED_TRANSPORT_SETTINGS = (ListStringPreference) + new ListStringPreference("displayed_transport_settings", null, ",").makeProfile(); public final OsmandPreference SHOW_ARRIVAL_TIME_OTHERWISE_EXPECTED_TIME = new BooleanPreference("show_arrival_time", true).makeProfile(); diff --git a/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java b/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java index 224226f818..e8bf1d7ff1 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java @@ -11,8 +11,6 @@ import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.CompoundButton; import android.widget.CompoundButton.OnCheckedChangeListener; -import android.widget.ImageView; -import android.widget.ListView; import android.widget.Spinner; import android.widget.TextView; @@ -53,8 +51,8 @@ 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.transport.TransportLinesMenu; import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.corenative.NativeCoreContext; import net.osmand.plus.wikipedia.WikipediaPoiMenu; @@ -141,10 +139,20 @@ public class ConfigureMapMenu { ma.getDashboard().updateListAdapter(createListAdapter(ma)); } }); + List customRules = getCustomRules(app); + adapter.setProfileDependent(true); + adapter.setNightMode(nightMode); + createLayersItems(customRules, adapter, ma, themeRes, nightMode); + createRenderingAttributeItems(customRules, adapter, ma, themeRes, nightMode); + return adapter; + } + + public static List getCustomRules(OsmandApplication app) { RenderingRulesStorage renderer = app.getRendererRegistry().getCurrentSelectedRenderer(); List customRules = new ArrayList<>(); boolean useDepthContours = app.getResourceManager().hasDepthContours() - && (InAppPurchaseHelper.isSubscribedToLiveUpdates(app) || InAppPurchaseHelper.isDepthContoursPurchased(app)); + && (InAppPurchaseHelper.isSubscribedToLiveUpdates(app) + || InAppPurchaseHelper.isDepthContoursPurchased(app)); if (renderer != null) { for (RenderingRuleProperty p : renderer.PROPS.getCustomRules()) { if (!RenderingRuleStorageProperties.UI_CATEGORY_HIDDEN.equals(p.getCategory()) @@ -153,11 +161,7 @@ public class ConfigureMapMenu { } } } - adapter.setProfileDependent(true); - adapter.setNightMode(nightMode); - createLayersItems(customRules, adapter, ma, themeRes, nightMode); - createRenderingAttributeItems(customRules, adapter, ma, themeRes, nightMode); - return adapter; + return customRules; } private final class LayerMenuListener extends OnRowItemClick { @@ -193,7 +197,7 @@ public class ConfigureMapMenu { } @Override - public boolean onRowItemClick(ArrayAdapter adapter, View view, int itemId, int pos) { + public boolean onRowItemClick(final ArrayAdapter adapter, View view, int itemId, int pos) { if (itemId == R.string.layer_poi) { showPoiFilterDialog(adapter, adapter.getItem(pos)); return false; @@ -204,6 +208,26 @@ public class ConfigureMapMenu { ma.getDashboard().setDashboardVisibility(true, DashboardOnMap.DashboardType.WIKIPEDIA, AndroidUtils.getCenterViewCoordinates(view)); return false; + } else if (itemId == R.string.rendering_category_transport) { + final ContextMenuItem item = adapter.getItem(pos); + TransportLinesMenu.showTransportsDialog(ma, new CallbackWithObject() { + @Override + public boolean processResult(Boolean result) { + if (item != null) { + item.setSelected(result); + item.setColorRes(result ? R.color.osmand_orange : ContextMenuItem.INVALID_ID); + adapter.notifyDataSetChanged(); + } + return true; + } + }); + boolean selected = TransportLinesMenu.isShowLines(ma.getMyApplication()); + if (!selected && item != null) { + item.setSelected(true); + item.setColorRes(R.color.osmand_orange); + adapter.notifyDataSetChanged(); + } + return false; } else { CompoundButton btn = (CompoundButton) view.findViewById(R.id.toggle_item); if (btn != null && btn.getVisibility() == View.VISIBLE) { @@ -257,6 +281,17 @@ public class ConfigureMapMenu { return true; } }); + } else if (itemId == R.string.rendering_category_transport) { + boolean selected = TransportLinesMenu.isShowLines(ma.getMyApplication()); + TransportLinesMenu.toggleTransportLines(ma, !selected, new CallbackWithObject() { + @Override + public boolean processResult(Boolean result) { + item.setSelected(result); + item.setColorRes(result ? R.color.osmand_orange : ContextMenuItem.INVALID_ID); + adapter.notifyDataSetChanged(); + return true; + } + }); } else if (itemId == R.string.map_markers) { settings.SHOW_MAP_MARKERS.set(isChecked); } else if (itemId == R.string.layer_map) { @@ -364,179 +399,16 @@ public class ConfigureMapMenu { } */ - final List transportRules = new ArrayList<>(); - final List> transportPrefs = new ArrayList<>(); - Iterator it = customRules.iterator(); - while (it.hasNext()) { - RenderingRuleProperty p = it.next(); - if ("transport".equals(p.getCategory()) && p.isBoolean()) { - transportRules.add(p); - final OsmandSettings.CommonPreference pref = activity.getMyApplication().getSettings() - .getCustomRenderBooleanProperty(p.getAttrName()); - transportPrefs.add(pref); - it.remove(); - } - } - selected = false; - for (OsmandSettings.CommonPreference p : transportPrefs) { - if (p.get()) { - selected = true; - break; - } - } - final boolean transportSelected = selected; + selected = TransportLinesMenu.isShowLines(app); adapter.addItem(new ContextMenuItem.ItemBuilder() .setId(TRANSPORT_ID) .setTitleId(R.string.rendering_category_transport, activity) .setIcon(R.drawable.ic_action_transport_bus) .setSecondaryIcon(R.drawable.ic_action_additional_option) - .setSelected(transportSelected) - .setColor(transportSelected ? selectedProfileColorRes : ContextMenuItem.INVALID_ID) - .setListener(new ContextMenuAdapter.OnRowItemClick() { - ArrayAdapter adapter; - boolean transportSelectedInner = transportSelected; + .setSelected(selected) + .setColor(selected ? selectedProfileColorRes : ContextMenuItem.INVALID_ID) + .setListener(l).createItem()); - @Override - public boolean onRowItemClick(ArrayAdapter adapter, View view, int itemId, int position) { - if (transportSelectedInner) { - showTransportDialog(adapter, position); - return false; - } else { - CompoundButton btn = (CompoundButton) view.findViewById(R.id.toggle_item); - if (btn != null && btn.getVisibility() == View.VISIBLE) { - btn.setChecked(!btn.isChecked()); - adapter.getItem(position).setColorRes(btn.isChecked() ? selectedProfileColorRes : ContextMenuItem.INVALID_ID); - adapter.notifyDataSetChanged(); - return false; - } else { - return onContextMenuClick(adapter, itemId, position, false, null); - } - } - } - - @Override - public boolean onContextMenuClick(final ArrayAdapter ad, int itemId, - final int pos, boolean isChecked, int[] viewCoordinates) { - if (transportSelectedInner) { - for (int i = 0; i < transportPrefs.size(); i++) { - transportPrefs.get(i).set(false); - } - transportSelectedInner = false; - ad.getItem(pos).setColorRes(ContextMenuItem.INVALID_ID); - refreshMapComplete(activity); - activity.getMapLayers().updateLayers(activity.getMapView()); - } else { - ad.getItem(pos).setColorRes(selectedProfileColorRes); - showTransportDialog(ad, pos); - } - ad.notifyDataSetChanged(); - return false; - } - - private void showTransportDialog(final ArrayAdapter ad, final int pos) { - final AlertDialog.Builder b = new AlertDialog.Builder(new ContextThemeWrapper(activity, themeRes)); - b.setTitle(activity.getString(R.string.rendering_category_transport)); - - final int[] iconIds = new int[transportPrefs.size()]; - final boolean[] checkedItems = new boolean[transportPrefs.size()]; - for (int i = 0; i < transportPrefs.size(); i++) { - checkedItems[i] = transportPrefs.get(i).get(); - } - final String[] vals = new String[transportRules.size()]; - for (int i = 0; i < transportRules.size(); i++) { - RenderingRuleProperty p = transportRules.get(i); - String propertyName = SettingsActivity.getStringPropertyName(activity, p.getAttrName(), - p.getName()); - vals[i] = propertyName; - if ("transportStops".equals(p.getAttrName())) { - iconIds[i] = R.drawable.ic_action_transport_stop; - } else if ("publicTransportMode".equals(p.getAttrName())) { - iconIds[i] = R.drawable.ic_action_transport_bus; - } else if ("tramTrainRoutes".equals(p.getAttrName())) { - iconIds[i] = R.drawable.ic_action_transport_tram; - } else if ("subwayMode".equals(p.getAttrName())) { - iconIds[i] = R.drawable.ic_action_transport_subway; - } else { - iconIds[i] = R.drawable.ic_action_transport_bus; - } - } - - adapter = new ArrayAdapter(new ContextThemeWrapper(activity, themeRes), R.layout.popup_list_item_icon24_and_menu, R.id.title, vals) { - @NonNull - @Override - public View getView(final int position, View convertView, ViewGroup parent) { - View v = super.getView(position, convertView, parent); - final ImageView icon = (ImageView) v.findViewById(R.id.icon); - if (checkedItems[position]) { - icon.setImageDrawable(app.getUIUtilities().getIcon(iconIds[position], selectedProfileColorRes)); - } else { - icon.setImageDrawable(app.getUIUtilities().getThemedIcon(iconIds[position])); - } - v.findViewById(R.id.divider).setVisibility(View.GONE); - v.findViewById(R.id.description).setVisibility(View.GONE); - v.findViewById(R.id.secondary_icon).setVisibility(View.GONE); - final SwitchCompat check = (SwitchCompat) v.findViewById(R.id.toggle_item); - check.setOnCheckedChangeListener(null); - check.setChecked(checkedItems[position]); - check.setOnCheckedChangeListener(new OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - checkedItems[position] = isChecked; - if (checkedItems[position]) { - icon.setImageDrawable(app.getUIUtilities().getIcon(iconIds[position], selectedProfileColorRes)); - } else { - icon.setImageDrawable(app.getUIUtilities().getThemedIcon(iconIds[position])); - } - } - }); - UiUtilities.setupCompoundButton(nightMode, selectedProfileColor, check); - return v; - } - }; - - final ListView listView = new ListView(activity); - listView.setDivider(null); - listView.setClickable(true); - listView.setAdapter(adapter); - listView.setOnItemClickListener(new ListView.OnItemClickListener() { - @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { - checkedItems[position] = !checkedItems[position]; - adapter.notifyDataSetChanged(); - } - }); - b.setView(listView); - - b.setOnDismissListener(new DialogInterface.OnDismissListener() { - @Override - public void onDismiss(DialogInterface dialog) { - ContextMenuItem item = ad.getItem(pos); - if (item != null) { - item.setSelected(transportSelectedInner); - item.setColorRes(transportSelectedInner ? selectedProfileColorRes : ContextMenuItem.INVALID_ID); - ad.notifyDataSetChanged(); - } - - } - }); - b.setNegativeButton(R.string.shared_string_cancel, null); - b.setPositiveButton(R.string.shared_string_apply, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - transportSelectedInner = false; - for (int i = 0; i < transportPrefs.size(); i++) { - transportPrefs.get(i).set(checkedItems[i]); - if (!transportSelectedInner && checkedItems[i]) { - transportSelectedInner = true; - } - } - refreshMapComplete(activity); - activity.getMapLayers().updateLayers(activity.getMapView()); - } - }); - b.show(); - } - }).createItem()); selected = app.getSelectedGpxHelper().isShowingAnyGpxFiles(); adapter.addItem(new ContextMenuItem.ItemBuilder() .setId(GPX_FILES_ID) diff --git a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionRegistry.java b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionRegistry.java index 714abee320..e778b5e0b7 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionRegistry.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionRegistry.java @@ -34,6 +34,7 @@ import net.osmand.plus.quickaction.actions.NewAction; import net.osmand.plus.quickaction.actions.ShowHideFavoritesAction; import net.osmand.plus.quickaction.actions.ShowHideGpxTracksAction; import net.osmand.plus.quickaction.actions.ShowHidePoiAction; +import net.osmand.plus.quickaction.actions.ShowHideTransportLinesAction; import net.osmand.util.Algorithms; import java.lang.reflect.Type; @@ -223,6 +224,7 @@ public class QuickActionRegistry { quickActionTypes.add(ShowHidePoiAction.TYPE); quickActionTypes.add(MapStyleAction.TYPE); quickActionTypes.add(DayNightModeAction.TYPE); + quickActionTypes.add(ShowHideTransportLinesAction.TYPE); // navigation quickActionTypes.add(NavVoiceAction.TYPE); quickActionTypes.add(NavDirectionsFromAction.TYPE); diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/ShowHideTransportLinesAction.java b/OsmAnd/src/net/osmand/plus/quickaction/actions/ShowHideTransportLinesAction.java new file mode 100644 index 0000000000..61f04f2c6f --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/quickaction/actions/ShowHideTransportLinesAction.java @@ -0,0 +1,61 @@ +package net.osmand.plus.quickaction.actions; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.R; +import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.quickaction.QuickAction; +import net.osmand.plus.quickaction.QuickActionType; +import net.osmand.plus.transport.TransportLinesMenu; + +public class ShowHideTransportLinesAction extends QuickAction { + + public static final QuickActionType TYPE = new QuickActionType(31, + "transport.showhide", ShowHideTransportLinesAction.class) + .nameRes(R.string.quick_action_show_hide_transport) + .iconRes(R.drawable.ic_action_transport_bus).nonEditable() + .category(QuickActionType.CONFIGURE_MAP); + + public ShowHideTransportLinesAction() { + super(TYPE); + } + + public ShowHideTransportLinesAction(QuickAction quickAction) { + super(quickAction); + } + + @Override + public void execute(final MapActivity activity) { + boolean enabled = TransportLinesMenu.isShowLines(activity.getMyApplication()); + TransportLinesMenu.toggleTransportLines(activity, !enabled, null); + } + + @Override + public void drawUI(ViewGroup parent, MapActivity activity) { + + View view = LayoutInflater.from(parent.getContext()) + .inflate(R.layout.quick_action_with_text, parent, false); + + ((TextView) view.findViewById(R.id.text)).setText( + R.string.quick_action_transport_descr); + + parent.addView(view); + } + + @Override + public String getActionText(OsmandApplication application) { + + return TransportLinesMenu.isShowLines(application) + ? application.getString(R.string.quick_action_transport_hide) + : application.getString(R.string.quick_action_transport_show); + } + + @Override + public boolean isActionWithSlash(OsmandApplication application) { + return TransportLinesMenu.isShowLines(application); + } +} diff --git a/OsmAnd/src/net/osmand/plus/transport/TransportLinesMenu.java b/OsmAnd/src/net/osmand/plus/transport/TransportLinesMenu.java new file mode 100644 index 0000000000..8c47ed2838 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/transport/TransportLinesMenu.java @@ -0,0 +1,238 @@ +package net.osmand.plus.transport; + +import android.content.Context; +import android.content.DialogInterface; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.CompoundButton; +import android.widget.ImageView; +import android.widget.ListView; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.app.AlertDialog; +import androidx.appcompat.widget.SwitchCompat; +import androidx.core.content.ContextCompat; + +import net.osmand.CallbackWithObject; +import net.osmand.plus.ApplicationMode; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmandSettings; +import net.osmand.plus.OsmandSettings.CommonPreference; +import net.osmand.plus.R; +import net.osmand.plus.UiUtilities; +import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.activities.SettingsActivity; +import net.osmand.plus.dialogs.ConfigureMapMenu; +import net.osmand.render.RenderingRuleProperty; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class TransportLinesMenu { + + public static final String TRANSPORT_RENDERING_CATEGORY = "transport"; + + public static final String PT_TRANSPORT_STOPS = "transportStops"; + public static final String PT_PUBLIC_TRANSPORT_MODE = "publicTransportMode"; + public static final String PT_TRAM_TRAIN_ROUTES = "tramTrainRoutes"; + public static final String PT_SUBWAY_MODE = "subwayMode"; + + public static void toggleTransportLines(@NonNull MapActivity mapActivity, boolean enable, + @Nullable CallbackWithObject callback) { + OsmandApplication app = mapActivity.getMyApplication(); + OsmandSettings settings = app.getSettings(); + if (enable) { + List enabledTransportIds = settings.DISPLAYED_TRANSPORT_SETTINGS.getStringsList(); + if (enabledTransportIds != null) { + for (CommonPreference pref : getTransportPrefs(app, null)) { + boolean selected = enabledTransportIds.contains(pref.getId()); + pref.set(selected); + } + refreshMap(mapActivity); + } else { + showTransportsDialog(mapActivity, callback); + } + } else { + for (CommonPreference pref : getTransportPrefs(app, null)) { + pref.set(false); + } + refreshMap(mapActivity); + if (callback != null) { + callback.processResult(false); + } + } + } + + public static void showTransportsDialog(@NonNull final MapActivity mapActivity, + @Nullable final CallbackWithObject callback) { + final OsmandApplication app = mapActivity.getMyApplication(); + final OsmandSettings settings = app.getSettings(); + final ApplicationMode appMode = settings.getApplicationMode(); + + final List enabledTransportIds = app.getSettings().DISPLAYED_TRANSPORT_SETTINGS.getStringsList(); + final List transportRules = getTransportRules(app); + final List> transportPrefs = getTransportPrefs(app, transportRules); + + final boolean nightMode = app.getDaynightHelper().isNightModeForMapControls(); + final Context themedCtx = UiUtilities.getThemedContext(mapActivity, nightMode); + final int profileColorResId = appMode.getIconColorInfo().getColor(nightMode); + final int profileColor = ContextCompat.getColor(themedCtx, profileColorResId); + + final AlertDialog.Builder b = new AlertDialog.Builder(themedCtx); + b.setTitle(themedCtx.getString(R.string.rendering_category_transport)); + + final boolean[] checkedItems = new boolean[transportPrefs.size()]; + for (int i = 0; i < transportPrefs.size(); i++) { + boolean selected = enabledTransportIds != null + && enabledTransportIds.contains(transportPrefs.get(i).getId()); + checkedItems[i] = selected; + } + + final int[] iconIds = new int[transportPrefs.size()]; + final String[] vals = new String[transportRules.size()]; + + final Map transportIcons = new HashMap<>(); + transportIcons.put(PT_TRANSPORT_STOPS, R.drawable.ic_action_transport_stop); + transportIcons.put(PT_PUBLIC_TRANSPORT_MODE, R.drawable.ic_action_transport_bus); + transportIcons.put(PT_TRAM_TRAIN_ROUTES, R.drawable.ic_action_transport_tram); + transportIcons.put(PT_SUBWAY_MODE, R.drawable.ic_action_transport_subway); + + for (int i = 0; i < transportRules.size(); i++) { + RenderingRuleProperty p = transportRules.get(i); + String attrName = p.getAttrName(); + String propertyName = SettingsActivity + .getStringPropertyName(themedCtx, attrName, p.getName()); + vals[i] = propertyName; + Integer iconId = transportIcons.get(attrName); + if (iconId != null) { + iconIds[i] = iconId; + } else { + iconIds[i] = R.drawable.ic_action_transport_bus; + } + } + + final ArrayAdapter adapter = new ArrayAdapter(themedCtx, + R.layout.popup_list_item_icon24_and_menu, R.id.title, vals) { + @NonNull + @Override + public View getView(final int position, View convertView, ViewGroup parent) { + View v = super.getView(position, convertView, parent); + final ImageView icon = (ImageView) v.findViewById(R.id.icon); + if (checkedItems[position]) { + icon.setImageDrawable(app.getUIUtilities().getIcon(iconIds[position], profileColorResId)); + } else { + icon.setImageDrawable(app.getUIUtilities().getThemedIcon(iconIds[position])); + } + v.findViewById(R.id.divider).setVisibility(View.GONE); + v.findViewById(R.id.description).setVisibility(View.GONE); + v.findViewById(R.id.secondary_icon).setVisibility(View.GONE); + final SwitchCompat check = (SwitchCompat) v.findViewById(R.id.toggle_item); + check.setOnCheckedChangeListener(null); + check.setChecked(checkedItems[position]); + check.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + checkedItems[position] = isChecked; + if (checkedItems[position]) { + icon.setImageDrawable(app.getUIUtilities().getIcon(iconIds[position], profileColorResId)); + } else { + icon.setImageDrawable(app.getUIUtilities().getThemedIcon(iconIds[position])); + } + } + }); + UiUtilities.setupCompoundButton(nightMode, profileColor, check); + return v; + } + }; + + final ListView listView = new ListView(themedCtx); + listView.setDivider(null); + listView.setClickable(true); + listView.setAdapter(adapter); + listView.setOnItemClickListener(new ListView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + checkedItems[position] = !checkedItems[position]; + adapter.notifyDataSetChanged(); + } + }); + b.setView(listView); + + b.setOnDismissListener(new DialogInterface.OnDismissListener() { + @Override + public void onDismiss(DialogInterface dialog) { + if (callback != null) { + callback.processResult(isShowLines(app)); + } + } + }); + + b.setNegativeButton(R.string.shared_string_cancel, null); + b.setPositiveButton(R.string.shared_string_apply, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + List transportIdsToSave = new ArrayList<>(); + for (int i = 0; i < transportPrefs.size(); i++) { + CommonPreference pref = transportPrefs.get(i); + boolean selected = checkedItems[i]; + if (selected) { + transportIdsToSave.add(pref.getId()); + } + pref.set(selected); + } + settings.DISPLAYED_TRANSPORT_SETTINGS.setStringsListForProfile(appMode, + transportIdsToSave.size() > 0 ? transportIdsToSave : null); + if (callback != null) { + callback.processResult(transportIdsToSave.size() > 0); + } + refreshMap(mapActivity); + } + }); + b.show(); + } + + public static List getTransportRules(OsmandApplication app) { + List transportRules = new ArrayList<>(); + for (RenderingRuleProperty property : ConfigureMapMenu.getCustomRules(app)) { + if (TRANSPORT_RENDERING_CATEGORY.equals(property.getCategory()) && property.isBoolean()) { + transportRules.add(property); + } + } + return transportRules; + } + + public static List> getTransportPrefs(@NonNull OsmandApplication app, + List transportRules) { + if (transportRules == null) { + transportRules = getTransportRules(app); + } + List> transportPrefs = new ArrayList<>(); + for (RenderingRuleProperty property : transportRules) { + final CommonPreference pref = app.getSettings() + .getCustomRenderBooleanProperty(property.getAttrName()); + transportPrefs.add(pref); + } + return transportPrefs; + } + + + private static void refreshMap(MapActivity mapActivity) { + ConfigureMapMenu.refreshMapComplete(mapActivity); + mapActivity.getMapLayers().updateLayers(mapActivity.getMapView()); + } + + public static boolean isShowLines(@NonNull OsmandApplication app) { + ApplicationMode appMode = app.getSettings().getApplicationMode(); + for (CommonPreference pref : getTransportPrefs(app, null)) { + if (pref.getModeValue(appMode)) { + return true; + } + } + return false; + } +}