Refactoring ProfileAppearanceFragment

(cherry picked from commit e9fb6fc939)
This commit is contained in:
Dima-1 2020-02-21 18:23:31 +02:00
parent 0fcf07aba2
commit 4eec8bbbca

View file

@ -112,7 +112,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
if (baseModeForNewProfile != null) { if (baseModeForNewProfile != null) {
setupAppProfileObjectFromAppMode(baseModeForNewProfile); setupAppProfileObjectFromAppMode(baseModeForNewProfile);
profile.parent = baseModeForNewProfile; profile.parent = baseModeForNewProfile;
profile.stringKey = baseModeForNewProfile.getStringKey() + "_" + System.currentTimeMillis(); profile.stringKey = getUniqueStringKey(baseModeForNewProfile);
} else { } else {
setupAppProfileObjectFromAppMode(getSelectedAppMode()); setupAppProfileObjectFromAppMode(getSelectedAppMode());
} }
@ -661,7 +661,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
return false; return false;
} }
if (isNewProfile) { if (isNewProfile) {
changedProfile.stringKey = changedProfile.parent.getStringKey() + "_" + System.currentTimeMillis(); changedProfile.stringKey = getUniqueStringKey(changedProfile.parent);
ApplicationMode.ApplicationModeBuilder builder = ApplicationMode ApplicationMode.ApplicationModeBuilder builder = ApplicationMode
.createCustomMode(changedProfile.parent, changedProfile.stringKey, app) .createCustomMode(changedProfile.parent, changedProfile.stringKey, app)
.setIconResName(ProfileIcons.getResStringByResId(changedProfile.iconRes)) .setIconResName(ProfileIcons.getResStringByResId(changedProfile.iconRes))
@ -691,6 +691,10 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
return true; return true;
} }
private String getUniqueStringKey(ApplicationMode mode) {
return mode.getStringKey() + "_" + System.currentTimeMillis();
}
private boolean hasNameDuplicate() { private boolean hasNameDuplicate() {
for (ApplicationMode m : ApplicationMode.allPossibleValues()) { for (ApplicationMode m : ApplicationMode.allPossibleValues()) {
if (m.toHumanString().trim().equals(changedProfile.name.trim()) && if (m.toHumanString().trim().equals(changedProfile.name.trim()) &&