From 366a61ba52cac53bb4f0b7066634bf5640057c54 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Fri, 27 Dec 2019 15:07:16 +0200 Subject: [PATCH] Increment digit on the end of profile name when create new profile. --- .../settings/ProfileAppearanceFragment.java | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java index 4ed0950f2c..369e79d92e 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java @@ -95,7 +95,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { if (baseModeForNewProfile != null) { profile.stringKey = baseModeForNewProfile.getStringKey() + "_" + System.currentTimeMillis(); profile.parent = baseModeForNewProfile; - profile.name = baseModeForNewProfile.toHumanString(getContext()); + profile.name = baseModeForNewProfile.toHumanString(app); profile.color = baseModeForNewProfile.getIconColorInfo(); profile.iconRes = baseModeForNewProfile.getIconRes(); profile.routingProfile = baseModeForNewProfile.getRoutingProfile(); @@ -115,7 +115,11 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { } else { changedProfile.stringKey = profile.stringKey; changedProfile.parent = profile.parent; - changedProfile.name = profile.name; + if (baseModeForNewProfile != null) { + changedProfile.name = createNonDuplicateName(baseModeForNewProfile.toHumanString(app)); + } else { + changedProfile.name = profile.name; + } changedProfile.color = profile.color; changedProfile.iconRes = profile.iconRes; changedProfile.routingProfile = profile.routingProfile; @@ -123,6 +127,21 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { } } + private String createNonDuplicateName(String oldName) { + int suffix = 0; + int i = oldName.length() - 1; + do { + try { + suffix = Integer.parseInt(oldName.substring(i)); + } catch (NumberFormatException e) { + break; + } + i--; + } while (i >= 0); + suffix++; + return oldName.substring(0, i + 1) + suffix; + } + @Override protected void setupPreferences() { findPreference(SELECT_COLOR).setIconSpaceReserved(false);