From fabc631520144913c0a43bfc11e6fa4325809990 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Tue, 18 Feb 2020 23:27:09 +0200 Subject: [PATCH 1/3] Fix doesn`t update profile data selected previously --- .../osmand/plus/activities/MapActivity.java | 2 +- .../settings/ProfileAppearanceFragment.java | 24 ++----------------- 2 files changed, 3 insertions(+), 23 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index b440dbde72..5576793e2c 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -698,7 +698,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven } ProfileAppearanceFragment profileAppearanceFragment = getProfileAppearanceFragment(); if (profileAppearanceFragment != null) { - if (profileAppearanceFragment.isProfileAppearanceChanged(this)) { + if (profileAppearanceFragment.isProfileAppearanceChanged()) { return; } } diff --git a/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java index 24229c2680..67526df6e9 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java @@ -36,13 +36,11 @@ import net.osmand.plus.ApplicationMode; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; import net.osmand.plus.UiUtilities.DialogButtonType; -import net.osmand.plus.activities.MapActivity; import net.osmand.plus.profiles.LocationIcon; import net.osmand.plus.profiles.NavigationIcon; import net.osmand.plus.profiles.ProfileIconColors; import net.osmand.plus.profiles.ProfileIcons; import net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment; -import net.osmand.plus.routing.RouteProvider; import net.osmand.plus.widgets.FlowLayout; import net.osmand.plus.widgets.OsmandTextFieldBoxes; import net.osmand.util.Algorithms; @@ -116,8 +114,6 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { profile.name = baseModeForNewProfile.toHumanString(); profile.color = baseModeForNewProfile.getIconColorInfo(); profile.iconRes = baseModeForNewProfile.getIconRes(); - profile.routingProfile = baseModeForNewProfile.getRoutingProfile(); - profile.routeService = baseModeForNewProfile.getRouteService(); profile.locationIcon = baseModeForNewProfile.getLocationIcon(); profile.navigationIcon = baseModeForNewProfile.getNavigationIcon(); } else { @@ -126,8 +122,6 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { profile.name = getSelectedAppMode().toHumanString(); profile.color = getSelectedAppMode().getIconColorInfo(); profile.iconRes = getSelectedAppMode().getIconRes(); - profile.routingProfile = getSelectedAppMode().getRoutingProfile(); - profile.routeService = getSelectedAppMode().getRouteService(); profile.locationIcon = getSelectedAppMode().getLocationIcon(); profile.navigationIcon = getSelectedAppMode().getNavigationIcon(); } @@ -144,8 +138,6 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { } changedProfile.color = profile.color; changedProfile.iconRes = profile.iconRes; - changedProfile.routingProfile = profile.routingProfile; - changedProfile.routeService = profile.routeService; changedProfile.locationIcon = profile.locationIcon; changedProfile.navigationIcon = profile.navigationIcon; } @@ -384,7 +376,6 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { for (ProfileIconColors color : ProfileIconColors.values()) { View colorItem = createColorItemView(color, colorItems); colorItems.addView(colorItem, new FlowLayout.LayoutParams(0, 0)); - } updateColorSelector(changedProfile.color); } else if (ICON_ITEMS.equals(preference.getKey())) { @@ -659,12 +650,11 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { return false; } if (isNewProfile) { + changedProfile.stringKey = changedProfile.parent.getStringKey() + "_" + System.currentTimeMillis(); ApplicationMode.ApplicationModeBuilder builder = ApplicationMode .createCustomMode(changedProfile.parent, changedProfile.stringKey, app) .setIconResName(ProfileIcons.getResStringByResId(changedProfile.iconRes)) .setUserProfileName(changedProfile.name.trim()) - .setRoutingProfile(changedProfile.routingProfile) - .setRouteService(changedProfile.routeService) .setIconColor(changedProfile.color) .setLocationIcon(changedProfile.locationIcon) .setNavigationIcon(changedProfile.navigationIcon); @@ -679,13 +669,10 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { mode.setParentAppMode(changedProfile.parent); mode.setIconResName(ProfileIcons.getResStringByResId(changedProfile.iconRes)); mode.setUserProfileName(changedProfile.name.trim()); - mode.setRoutingProfile(changedProfile.routingProfile); - mode.setRouteService(changedProfile.routeService); mode.setIconColor(changedProfile.color); mode.setLocationIcon(changedProfile.locationIcon); mode.setNavigationIcon(changedProfile.navigationIcon); } - return true; } @@ -708,7 +695,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { profileNameOtfb.setError(errorMessage, true); } - public boolean isProfileAppearanceChanged(final MapActivity mapActivity) { + public boolean isProfileAppearanceChanged() { hideKeyboard(); if (isChanged()) { AlertDialog.Builder dismissDialog = createWarningDialog(getActivity(), @@ -778,8 +765,6 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { String name; ProfileIconColors color; int iconRes; - String routingProfile; - RouteProvider.RouteService routeService; NavigationIcon navigationIcon; LocationIcon locationIcon; @@ -796,9 +781,6 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { if (parent != null ? !parent.equals(that.parent) : that.parent != null) return false; if (name != null ? !name.equals(that.name) : that.name != null) return false; if (color != that.color) return false; - if (routingProfile != null ? !routingProfile.equals(that.routingProfile) : that.routingProfile != null) - return false; - if (routeService != that.routeService) return false; if (navigationIcon != that.navigationIcon) return false; return locationIcon == that.locationIcon; } @@ -810,8 +792,6 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { result = 31 * result + (name != null ? name.hashCode() : 0); result = 31 * result + (color != null ? color.hashCode() : 0); result = 31 * result + iconRes; - result = 31 * result + (routingProfile != null ? routingProfile.hashCode() : 0); - result = 31 * result + (routeService != null ? routeService.hashCode() : 0); result = 31 * result + (navigationIcon != null ? navigationIcon.hashCode() : 0); result = 31 * result + (locationIcon != null ? locationIcon.hashCode() : 0); return result; From aae885d0ddfbe21aebee280fd757d98c4ab6037c Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Fri, 21 Feb 2020 18:18:25 +0200 Subject: [PATCH 2/3] Refactoring ProfileAppearanceFragment --- .../settings/ProfileAppearanceFragment.java | 48 +++++++++++++------ 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java index 67526df6e9..e349563e52 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java @@ -41,6 +41,7 @@ import net.osmand.plus.profiles.NavigationIcon; import net.osmand.plus.profiles.ProfileIconColors; import net.osmand.plus.profiles.ProfileIcons; import net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment; +import net.osmand.plus.routing.RouteProvider; import net.osmand.plus.widgets.FlowLayout; import net.osmand.plus.widgets.OsmandTextFieldBoxes; import net.osmand.util.Algorithms; @@ -109,21 +110,11 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { isBaseProfileImported = arguments.getBoolean(IS_BASE_PROFILE_IMPORTED); } if (baseModeForNewProfile != null) { - profile.stringKey = baseModeForNewProfile.getStringKey() + "_" + System.currentTimeMillis(); + setupAppProfileObjectFromAppMode(baseModeForNewProfile); profile.parent = baseModeForNewProfile; - profile.name = baseModeForNewProfile.toHumanString(); - profile.color = baseModeForNewProfile.getIconColorInfo(); - profile.iconRes = baseModeForNewProfile.getIconRes(); - profile.locationIcon = baseModeForNewProfile.getLocationIcon(); - profile.navigationIcon = baseModeForNewProfile.getNavigationIcon(); + profile.stringKey = baseModeForNewProfile.getStringKey() + "_" + System.currentTimeMillis(); } else { - profile.stringKey = getSelectedAppMode().getStringKey(); - profile.parent = getSelectedAppMode().getParent(); - profile.name = getSelectedAppMode().toHumanString(); - profile.color = getSelectedAppMode().getIconColorInfo(); - profile.iconRes = getSelectedAppMode().getIconRes(); - profile.locationIcon = getSelectedAppMode().getLocationIcon(); - profile.navigationIcon = getSelectedAppMode().getNavigationIcon(); + setupAppProfileObjectFromAppMode(getSelectedAppMode()); } changedProfile = new ApplicationProfileObject(); if (savedInstanceState != null) { @@ -138,12 +129,26 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { } changedProfile.color = profile.color; changedProfile.iconRes = profile.iconRes; + changedProfile.routingProfile = profile.routingProfile; + changedProfile.routeService = profile.routeService; changedProfile.locationIcon = profile.locationIcon; changedProfile.navigationIcon = profile.navigationIcon; } isNewProfile = ApplicationMode.valueOfStringKey(changedProfile.stringKey, null) == null; } + public void setupAppProfileObjectFromAppMode(ApplicationMode baseModeForNewProfile) { + profile.stringKey = baseModeForNewProfile.getStringKey(); + profile.parent = baseModeForNewProfile.getParent(); + profile.name = baseModeForNewProfile.toHumanString(); + profile.color = baseModeForNewProfile.getIconColorInfo(); + profile.iconRes = baseModeForNewProfile.getIconRes(); + profile.routingProfile = baseModeForNewProfile.getRoutingProfile(); + profile.routeService = baseModeForNewProfile.getRouteService(); + profile.locationIcon = baseModeForNewProfile.getLocationIcon(); + profile.navigationIcon = baseModeForNewProfile.getNavigationIcon(); + } + @Override protected void createToolbar(LayoutInflater inflater, View view) { super.createToolbar(inflater, view); @@ -594,7 +599,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { if (iconItem != null) { AndroidUtils.setBackground(iconItem.findViewById(R.id.backgroundCircle), UiUtilities.tintDrawable(ContextCompat.getDrawable(app, R.drawable.circle_background_light), - UiUtilities.getColorWithAlpha(ContextCompat.getColor(app, changedProfile.color.getColor(isNightMode())), 0.1f))); + UiUtilities.getColorWithAlpha(ContextCompat.getColor(app, changedProfile.color.getColor(isNightMode())), 0.1f))); ImageView outlineCircle = iconItem.findViewById(R.id.outlineCircle); GradientDrawable circleContourDrawable = (GradientDrawable) ContextCompat.getDrawable(app, R.drawable.circle_contour_bg_light); if (circleContourDrawable != null) { @@ -633,6 +638,8 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { deleteImportedProfile(); setupBaseProfileView(profileKey); changedProfile.parent = ApplicationMode.valueOfStringKey(profileKey, ApplicationMode.DEFAULT); + changedProfile.routingProfile = changedProfile.parent.getRoutingProfile(); + changedProfile.routeService = changedProfile.parent.getRouteService(); this.isBaseProfileImported = isBaseProfileImported; } @@ -642,7 +649,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { } private boolean saveProfile() { - if (changedProfile.name.replace(" ", "").length() < 1) { + if (changedProfile.name.trim().isEmpty()) { if (getActivity() != null) { createWarningDialog(getActivity(), R.string.profile_alert_need_profile_name_title, R.string.profile_alert_need_profile_name_msg, R.string.shared_string_dismiss).show(); @@ -655,6 +662,8 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { .createCustomMode(changedProfile.parent, changedProfile.stringKey, app) .setIconResName(ProfileIcons.getResStringByResId(changedProfile.iconRes)) .setUserProfileName(changedProfile.name.trim()) + .setRoutingProfile(changedProfile.routingProfile) + .setRouteService(changedProfile.routeService) .setIconColor(changedProfile.color) .setLocationIcon(changedProfile.locationIcon) .setNavigationIcon(changedProfile.navigationIcon); @@ -669,6 +678,8 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { mode.setParentAppMode(changedProfile.parent); mode.setIconResName(ProfileIcons.getResStringByResId(changedProfile.iconRes)); mode.setUserProfileName(changedProfile.name.trim()); + mode.setRoutingProfile(changedProfile.routingProfile); + mode.setRouteService(changedProfile.routeService); mode.setIconColor(changedProfile.color); mode.setLocationIcon(changedProfile.locationIcon); mode.setNavigationIcon(changedProfile.navigationIcon); @@ -765,6 +776,8 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { String name; ProfileIconColors color; int iconRes; + String routingProfile; + RouteProvider.RouteService routeService; NavigationIcon navigationIcon; LocationIcon locationIcon; @@ -781,6 +794,9 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { if (parent != null ? !parent.equals(that.parent) : that.parent != null) return false; if (name != null ? !name.equals(that.name) : that.name != null) return false; if (color != that.color) return false; + if (routingProfile != null ? !routingProfile.equals(that.routingProfile) : that.routingProfile != null) + return false; + if (routeService != that.routeService) return false; if (navigationIcon != that.navigationIcon) return false; return locationIcon == that.locationIcon; } @@ -792,6 +808,8 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { result = 31 * result + (name != null ? name.hashCode() : 0); result = 31 * result + (color != null ? color.hashCode() : 0); result = 31 * result + iconRes; + result = 31 * result + (routingProfile != null ? routingProfile.hashCode() : 0); + result = 31 * result + (routeService != null ? routeService.hashCode() : 0); result = 31 * result + (navigationIcon != null ? navigationIcon.hashCode() : 0); result = 31 * result + (locationIcon != null ? locationIcon.hashCode() : 0); return result; From e9fb6fc939147a582e1f7f6ba85ce321fdca1a07 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Fri, 21 Feb 2020 18:23:31 +0200 Subject: [PATCH 3/3] Refactoring ProfileAppearanceFragment --- .../osmand/plus/settings/ProfileAppearanceFragment.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java index e349563e52..eddd1d6ccc 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java @@ -112,7 +112,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { if (baseModeForNewProfile != null) { setupAppProfileObjectFromAppMode(baseModeForNewProfile); profile.parent = baseModeForNewProfile; - profile.stringKey = baseModeForNewProfile.getStringKey() + "_" + System.currentTimeMillis(); + profile.stringKey = getUniqueStringKey(baseModeForNewProfile); } else { setupAppProfileObjectFromAppMode(getSelectedAppMode()); } @@ -657,7 +657,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { return false; } if (isNewProfile) { - changedProfile.stringKey = changedProfile.parent.getStringKey() + "_" + System.currentTimeMillis(); + changedProfile.stringKey = getUniqueStringKey(changedProfile.parent); ApplicationMode.ApplicationModeBuilder builder = ApplicationMode .createCustomMode(changedProfile.parent, changedProfile.stringKey, app) .setIconResName(ProfileIcons.getResStringByResId(changedProfile.iconRes)) @@ -687,6 +687,10 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { return true; } + private String getUniqueStringKey(ApplicationMode mode) { + return mode.getStringKey() + "_" + System.currentTimeMillis(); + } + private boolean hasNameDuplicate() { for (ApplicationMode m : ApplicationMode.allPossibleValues()) { if (m.toHumanString().trim().equals(changedProfile.name.trim()) &&