From 8ce078f189ffa092a4ac06b830baa23df3b12b87 Mon Sep 17 00:00:00 2001 From: nazar-kutz Date: Fri, 19 Mar 2021 17:58:43 +0200 Subject: [PATCH] add "Customize route line" button to ProfileAppearanceFragment --- OsmAnd/res/xml/profile_appearance.xml | 7 +++++ .../fragments/ProfileAppearanceFragment.java | 28 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/OsmAnd/res/xml/profile_appearance.xml b/OsmAnd/res/xml/profile_appearance.xml index 87ec511b69..b037591e16 100644 --- a/OsmAnd/res/xml/profile_appearance.xml +++ b/OsmAnd/res/xml/profile_appearance.xml @@ -76,4 +76,11 @@ android:title="@string/select_navigation_icon" android:selectable="false"/> + + \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/ProfileAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/ProfileAppearanceFragment.java index b649ccf8cd..939e8124c7 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/ProfileAppearanceFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/ProfileAppearanceFragment.java @@ -74,6 +74,7 @@ import java.util.List; import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_SETTINGS_ID; import static net.osmand.plus.profiles.SelectProfileBottomSheet.PROFILES_LIST_UPDATED_ARG; import static net.osmand.plus.profiles.SelectProfileBottomSheet.PROFILE_KEY_ARG; +import static net.osmand.plus.routing.TransportRoutingHelper.PUBLIC_TRANSPORT_KEY; public class ProfileAppearanceFragment extends BaseSettingsFragment implements OnSelectProfileCallback, CardListener, ColorPickerListener { @@ -91,6 +92,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment implements O private static final String LOCATION_ICON_ITEMS = "location_icon_items"; private static final String SELECT_NAV_ICON = "select_nav_icon"; private static final String NAV_ICON_ITEMS = "nav_icon_items"; + private static final String CUSTOMIZE_ROUTE_LINE = "customize_route_line"; private static final String PROFILE_NAME_KEY = "profile_name_key"; private static final String PROFILE_STRINGKEY_KEY = "profile_stringkey_key"; @@ -235,10 +237,13 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment implements O findPreference(SELECT_ICON).setIconSpaceReserved(false); findPreference(SELECT_LOCATION_ICON).setIconSpaceReserved(false); findPreference(SELECT_NAV_ICON).setIconSpaceReserved(false); + findPreference(CUSTOMIZE_ROUTE_LINE).setIcon( + getIcon(R.drawable.ic_action_route_distance, getActiveColorRes())); if (getSelectedAppMode().equals(ApplicationMode.DEFAULT) && !isNewProfile) { findPreference(SELECT_ICON).setVisible(false); findPreference(ICON_ITEMS).setVisible(false); } + updateRouteLinePreference(); } @SuppressLint("InlinedApi") @@ -709,6 +714,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment implements O changedProfile.routingProfile = changedProfile.parent.getRoutingProfile(); changedProfile.routeService = changedProfile.parent.getRouteService(); this.isBaseProfileImported = isBaseProfileImported; + updateRouteLinePreference(); } private void setupBaseProfileView(String stringKey) { @@ -716,6 +722,15 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment implements O baseProfileName.setText(Algorithms.capitalizeFirstLetter(mode.toHumanString())); } + private void updateRouteLinePreference() { + Preference preference = findPreference(CUSTOMIZE_ROUTE_LINE); + if (preference != null) { + boolean isDefaultProfile = getSelectedAppMode().equals(ApplicationMode.DEFAULT); + boolean isPublicTransport = PUBLIC_TRANSPORT_KEY.equals(changedProfile.routingProfile); + preference.setVisible(!isDefaultProfile && !isPublicTransport); + } + } + private boolean checkProfileName() { if (Algorithms.isBlank(changedProfile.name)) { Activity activity = getActivity(); @@ -967,6 +982,19 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment implements O } } + @Override + public boolean onPreferenceClick(Preference preference) { + String prefId = preference.getKey(); + if (CUSTOMIZE_ROUTE_LINE.equals(prefId)) { + MapActivity mapActivity = getMapActivity(); + ApplicationMode appMode = getSelectedAppMode(); + if (mapActivity != null && appMode != null) { + RouteLineAppearanceFragment.showInstance(mapActivity, appMode, this); + } + } + return super.onPreferenceClick(preference); + } + @Override public void onCardButtonPressed(@NonNull BaseCard card, int buttonIndex) { }