From 4eec8bbbca6564bab647cd6cf4e08a5717439b31 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Fri, 21 Feb 2020 18:23:31 +0200 Subject: [PATCH] Refactoring ProfileAppearanceFragment (cherry picked from commit e9fb6fc939147a582e1f7f6ba85ce321fdca1a07) --- .../osmand/plus/settings/ProfileAppearanceFragment.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java index 42bb95849f..fb8c17708d 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java @@ -112,7 +112,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { if (baseModeForNewProfile != null) { setupAppProfileObjectFromAppMode(baseModeForNewProfile); profile.parent = baseModeForNewProfile; - profile.stringKey = baseModeForNewProfile.getStringKey() + "_" + System.currentTimeMillis(); + profile.stringKey = getUniqueStringKey(baseModeForNewProfile); } else { setupAppProfileObjectFromAppMode(getSelectedAppMode()); } @@ -661,7 +661,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { return false; } if (isNewProfile) { - changedProfile.stringKey = changedProfile.parent.getStringKey() + "_" + System.currentTimeMillis(); + changedProfile.stringKey = getUniqueStringKey(changedProfile.parent); ApplicationMode.ApplicationModeBuilder builder = ApplicationMode .createCustomMode(changedProfile.parent, changedProfile.stringKey, app) .setIconResName(ProfileIcons.getResStringByResId(changedProfile.iconRes)) @@ -691,6 +691,10 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { return true; } + private String getUniqueStringKey(ApplicationMode mode) { + return mode.getStringKey() + "_" + System.currentTimeMillis(); + } + private boolean hasNameDuplicate() { for (ApplicationMode m : ApplicationMode.allPossibleValues()) { if (m.toHumanString().trim().equals(changedProfile.name.trim()) &&