Add space in between name and digit, check all names
This commit is contained in:
parent
366a61ba52
commit
7b1921e598
1 changed files with 20 additions and 2 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue