From 7b1921e5983bbeddd486942a1e17e02fa239b172 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Fri, 27 Dec 2019 16:56:44 +0200 Subject: [PATCH] Add space in between name and digit, check all names --- .../settings/ProfileAppearanceFragment.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java index 369e79d92e..72b5e8d2f3 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java @@ -132,14 +132,32 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { int i = oldName.length() - 1; do { try { + if (oldName.charAt(i) == ' ' || oldName.charAt(i) == '-') { + throw new NumberFormatException(); + } suffix = Integer.parseInt(oldName.substring(i)); } catch (NumberFormatException e) { break; } i--; } while (i >= 0); - suffix++; - return oldName.substring(0, i + 1) + suffix; + String newName; + String divider = suffix == 0 ? " " : ""; + do { + suffix++; + newName = oldName.substring(0, i + 1) + divider + suffix; + } + while (hasThatName(newName)); + return newName; + } + + boolean hasThatName(String newName) { + for (ApplicationMode m : ApplicationMode.allPossibleValues()) { + if (m.toHumanString(app).equals(newName)) { + return true; + } + } + return false; } @Override