Add space in between name and digit, check all names

This commit is contained in:
Dima-1 2019-12-27 16:56:44 +02:00
parent 366a61ba52
commit 7b1921e598

View file

@ -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