Fix double "back" button clicking for close "Configure profile" screen after profile changed

This commit is contained in:
Nazar-Kutz 2020-01-06 14:27:32 +02:00
parent 04497938f0
commit 7a0a0d17a7

View file

@ -205,11 +205,16 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
if (getActivity() != null) { if (getActivity() != null) {
hideKeyboard(); hideKeyboard();
if (isChanged()) { if (isChanged()) {
if (saveNewProfile()) { boolean isNew = ApplicationMode.valueOfStringKey(changedProfile.stringKey, null) == null;
if (saveProfile(isNew)) {
profile = changedProfile; profile = changedProfile;
ProfileAppearanceFragment.this.dismiss(); if (isNew) {
BaseSettingsFragment.showInstance(getMapActivity(), SettingsScreenType.CONFIGURE_PROFILE, ProfileAppearanceFragment.this.dismiss();
ApplicationMode.valueOfStringKey(changedProfile.stringKey, null)); BaseSettingsFragment.showInstance(getMapActivity(), SettingsScreenType.CONFIGURE_PROFILE,
ApplicationMode.valueOfStringKey(changedProfile.stringKey, null));
} else {
getActivity().onBackPressed();
}
} }
} }
} }
@ -498,7 +503,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
} }
} }
private boolean saveNewProfile() { private boolean saveProfile(boolean isNew) {
if (changedProfile.name.replace(" ", "").length() < 1) { if (changedProfile.name.replace(" ", "").length() < 1) {
if (getActivity() != null) { if (getActivity() != null) {
createWarningDialog(getActivity(), createWarningDialog(getActivity(),
@ -514,13 +519,11 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
.setRoutingProfile(changedProfile.routingProfile) .setRoutingProfile(changedProfile.routingProfile)
.setColor(changedProfile.color); .setColor(changedProfile.color);
boolean newProfile = ApplicationMode.valueOfStringKey(changedProfile.stringKey, null) == null;
ApplicationMode mode = ApplicationMode.saveProfile(builder, getMyApplication()); ApplicationMode mode = ApplicationMode.saveProfile(builder, getMyApplication());
if (!ApplicationMode.values(app).contains(mode)) { if (!ApplicationMode.values(app).contains(mode)) {
ApplicationMode.changeProfileAvailability(mode, true, getMyApplication()); ApplicationMode.changeProfileAvailability(mode, true, getMyApplication());
} }
if (newProfile) { if (isNew) {
app.getSettings().copyPreferencesFromProfile(changedProfile.parent, mode); app.getSettings().copyPreferencesFromProfile(changedProfile.parent, mode);
} }
return true; return true;