Merge pull request #8500 from osmandapp/Fix_update_routing_profile

Fix doesn`t update profile data selected previously
This commit is contained in:
max-klaus 2020-02-22 12:34:39 +03:00 committed by GitHub
commit 70634dc35e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 24 deletions

View file

@ -698,7 +698,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
} }
ProfileAppearanceFragment profileAppearanceFragment = getProfileAppearanceFragment(); ProfileAppearanceFragment profileAppearanceFragment = getProfileAppearanceFragment();
if (profileAppearanceFragment != null) { if (profileAppearanceFragment != null) {
if (profileAppearanceFragment.isProfileAppearanceChanged(this)) { if (profileAppearanceFragment.isProfileAppearanceChanged()) {
return; return;
} }
} }

View file

@ -36,7 +36,6 @@ import net.osmand.plus.ApplicationMode;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.UiUtilities; import net.osmand.plus.UiUtilities;
import net.osmand.plus.UiUtilities.DialogButtonType; import net.osmand.plus.UiUtilities.DialogButtonType;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.profiles.LocationIcon; import net.osmand.plus.profiles.LocationIcon;
import net.osmand.plus.profiles.NavigationIcon; import net.osmand.plus.profiles.NavigationIcon;
import net.osmand.plus.profiles.ProfileIconColors; import net.osmand.plus.profiles.ProfileIconColors;
@ -111,25 +110,11 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
isBaseProfileImported = arguments.getBoolean(IS_BASE_PROFILE_IMPORTED); isBaseProfileImported = arguments.getBoolean(IS_BASE_PROFILE_IMPORTED);
} }
if (baseModeForNewProfile != null) { if (baseModeForNewProfile != null) {
profile.stringKey = baseModeForNewProfile.getStringKey() + "_" + System.currentTimeMillis(); setupAppProfileObjectFromAppMode(baseModeForNewProfile);
profile.parent = baseModeForNewProfile; profile.parent = baseModeForNewProfile;
profile.name = baseModeForNewProfile.toHumanString(); profile.stringKey = getUniqueStringKey(baseModeForNewProfile);
profile.color = baseModeForNewProfile.getIconColorInfo();
profile.iconRes = baseModeForNewProfile.getIconRes();
profile.routingProfile = baseModeForNewProfile.getRoutingProfile();
profile.routeService = baseModeForNewProfile.getRouteService();
profile.locationIcon = baseModeForNewProfile.getLocationIcon();
profile.navigationIcon = baseModeForNewProfile.getNavigationIcon();
} else { } else {
profile.stringKey = getSelectedAppMode().getStringKey(); setupAppProfileObjectFromAppMode(getSelectedAppMode());
profile.parent = getSelectedAppMode().getParent();
profile.name = getSelectedAppMode().toHumanString();
profile.color = getSelectedAppMode().getIconColorInfo();
profile.iconRes = getSelectedAppMode().getIconRes();
profile.routingProfile = getSelectedAppMode().getRoutingProfile();
profile.routeService = getSelectedAppMode().getRouteService();
profile.locationIcon = getSelectedAppMode().getLocationIcon();
profile.navigationIcon = getSelectedAppMode().getNavigationIcon();
} }
changedProfile = new ApplicationProfileObject(); changedProfile = new ApplicationProfileObject();
if (savedInstanceState != null) { if (savedInstanceState != null) {
@ -152,6 +137,18 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
isNewProfile = ApplicationMode.valueOfStringKey(changedProfile.stringKey, null) == null; isNewProfile = ApplicationMode.valueOfStringKey(changedProfile.stringKey, null) == null;
} }
public void setupAppProfileObjectFromAppMode(ApplicationMode baseModeForNewProfile) {
profile.stringKey = baseModeForNewProfile.getStringKey();
profile.parent = baseModeForNewProfile.getParent();
profile.name = baseModeForNewProfile.toHumanString();
profile.color = baseModeForNewProfile.getIconColorInfo();
profile.iconRes = baseModeForNewProfile.getIconRes();
profile.routingProfile = baseModeForNewProfile.getRoutingProfile();
profile.routeService = baseModeForNewProfile.getRouteService();
profile.locationIcon = baseModeForNewProfile.getLocationIcon();
profile.navigationIcon = baseModeForNewProfile.getNavigationIcon();
}
@Override @Override
protected void createToolbar(LayoutInflater inflater, View view) { protected void createToolbar(LayoutInflater inflater, View view) {
super.createToolbar(inflater, view); super.createToolbar(inflater, view);
@ -388,7 +385,6 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
for (ProfileIconColors color : ProfileIconColors.values()) { for (ProfileIconColors color : ProfileIconColors.values()) {
View colorItem = createColorItemView(color, colorItems); View colorItem = createColorItemView(color, colorItems);
colorItems.addView(colorItem, new FlowLayout.LayoutParams(0, 0)); colorItems.addView(colorItem, new FlowLayout.LayoutParams(0, 0));
} }
updateColorSelector(changedProfile.color); updateColorSelector(changedProfile.color);
} else if (ICON_ITEMS.equals(preference.getKey())) { } else if (ICON_ITEMS.equals(preference.getKey())) {
@ -607,7 +603,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
if (iconItem != null) { if (iconItem != null) {
AndroidUtils.setBackground(iconItem.findViewById(R.id.backgroundCircle), AndroidUtils.setBackground(iconItem.findViewById(R.id.backgroundCircle),
UiUtilities.tintDrawable(ContextCompat.getDrawable(app, R.drawable.circle_background_light), UiUtilities.tintDrawable(ContextCompat.getDrawable(app, R.drawable.circle_background_light),
UiUtilities.getColorWithAlpha(ContextCompat.getColor(app, changedProfile.color.getColor(isNightMode())), 0.1f))); UiUtilities.getColorWithAlpha(ContextCompat.getColor(app, changedProfile.color.getColor(isNightMode())), 0.1f)));
ImageView outlineCircle = iconItem.findViewById(R.id.outlineCircle); ImageView outlineCircle = iconItem.findViewById(R.id.outlineCircle);
GradientDrawable circleContourDrawable = (GradientDrawable) ContextCompat.getDrawable(app, R.drawable.circle_contour_bg_light); GradientDrawable circleContourDrawable = (GradientDrawable) ContextCompat.getDrawable(app, R.drawable.circle_contour_bg_light);
if (circleContourDrawable != null) { if (circleContourDrawable != null) {
@ -646,6 +642,8 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
deleteImportedProfile(); deleteImportedProfile();
setupBaseProfileView(profileKey); setupBaseProfileView(profileKey);
changedProfile.parent = ApplicationMode.valueOfStringKey(profileKey, ApplicationMode.DEFAULT); changedProfile.parent = ApplicationMode.valueOfStringKey(profileKey, ApplicationMode.DEFAULT);
changedProfile.routingProfile = changedProfile.parent.getRoutingProfile();
changedProfile.routeService = changedProfile.parent.getRouteService();
this.isBaseProfileImported = isBaseProfileImported; this.isBaseProfileImported = isBaseProfileImported;
} }
@ -655,7 +653,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
} }
private boolean saveProfile() { private boolean saveProfile() {
if (changedProfile.name.replace(" ", "").length() < 1) { if (changedProfile.name.trim().isEmpty()) {
if (getActivity() != null) { if (getActivity() != null) {
createWarningDialog(getActivity(), createWarningDialog(getActivity(),
R.string.profile_alert_need_profile_name_title, R.string.profile_alert_need_profile_name_msg, R.string.shared_string_dismiss).show(); R.string.profile_alert_need_profile_name_title, R.string.profile_alert_need_profile_name_msg, R.string.shared_string_dismiss).show();
@ -663,6 +661,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
return false; return false;
} }
if (isNewProfile) { if (isNewProfile) {
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))
@ -689,10 +688,13 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
mode.setLocationIcon(changedProfile.locationIcon); mode.setLocationIcon(changedProfile.locationIcon);
mode.setNavigationIcon(changedProfile.navigationIcon); mode.setNavigationIcon(changedProfile.navigationIcon);
} }
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()) &&
@ -712,7 +714,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
profileNameOtfb.setError(errorMessage, true); profileNameOtfb.setError(errorMessage, true);
} }
public boolean isProfileAppearanceChanged(final MapActivity mapActivity) { public boolean isProfileAppearanceChanged() {
hideKeyboard(); hideKeyboard();
if (isChanged()) { if (isChanged()) {
AlertDialog.Builder dismissDialog = createWarningDialog(getActivity(), AlertDialog.Builder dismissDialog = createWarningDialog(getActivity(),