From 04497938f01b013b0c68a42e6efff238d50b4fa4 Mon Sep 17 00:00:00 2001 From: Nazar-Kutz Date: Mon, 6 Jan 2020 13:18:41 +0200 Subject: [PATCH] Fix manage profiles --- OsmAnd/res/layout/preference_text_field.xml | 1 + .../src/net/osmand/plus/ApplicationMode.java | 1 + OsmAnd/src/net/osmand/plus/UiUtilities.java | 59 ++++++++++++++----- ...lectMapStyleBottomSheetDialogFragment.java | 4 +- .../net/osmand/plus/helpers/GpxUiHelper.java | 6 +- .../DirectionIndicationDialogFragment.java | 14 +++-- .../monitoring/OsmandMonitoringPlugin.java | 6 +- .../rastermaps/OsmandRasterMapsPlugin.java | 3 +- .../settings/ConfigureProfileFragment.java | 3 +- .../settings/ProfileAppearanceFragment.java | 26 +++----- .../plus/settings/ScreenAlertsFragment.java | 4 +- .../plus/settings/TurnScreenOnFragment.java | 4 +- .../plus/settings/VoiceAnnouncesFragment.java | 3 +- .../plus/widgets/OsmandTextFieldBoxes.java | 14 +++++ 14 files changed, 100 insertions(+), 48 deletions(-) diff --git a/OsmAnd/res/layout/preference_text_field.xml b/OsmAnd/res/layout/preference_text_field.xml index be7c364a28..57d531c737 100644 --- a/OsmAnd/res/layout/preference_text_field.xml +++ b/OsmAnd/res/layout/preference_text_field.xml @@ -15,6 +15,7 @@ android:layout_margin="@dimen/list_content_padding" app:primaryColor="@color/active_color_primary_dark" app:secondaryColor="?android:textColorSecondary" + app:errorColor="@color/color_invalid" app:labelText="@string/profile_name_hint"> templates = new ArrayList<>(entriesMap.keySet()); diff --git a/OsmAnd/src/net/osmand/plus/settings/ConfigureProfileFragment.java b/OsmAnd/src/net/osmand/plus/settings/ConfigureProfileFragment.java index 657e856b23..e882cc1c0f 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ConfigureProfileFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ConfigureProfileFragment.java @@ -55,6 +55,7 @@ import org.apache.commons.logging.Log; import java.io.File; import java.util.List; +import static net.osmand.plus.UiUtilities.CompoundButtonType.TOOLBAR; import static net.osmand.plus.profiles.EditProfileFragment.MAP_CONFIG; import static net.osmand.plus.profiles.EditProfileFragment.OPEN_CONFIG_ON_MAP; import static net.osmand.plus.profiles.EditProfileFragment.SCREEN_CONFIG; @@ -141,7 +142,7 @@ public class ConfigureProfileFragment extends BaseSettingsFragment { SwitchCompat switchView = switchContainer.findViewById(R.id.switchWidget); switchView.setChecked(isChecked); - UiUtilities.setupCompoundButton(isNightMode(), getActiveProfileColor(), switchView); + UiUtilities.setupCompoundButton(switchView, isNightMode(), TOOLBAR); TextView title = switchContainer.findViewById(R.id.switchButtonText); title.setText(isChecked ? R.string.shared_string_on : R.string.shared_string_off); diff --git a/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java index b9e7e86081..6b008f87d6 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java @@ -77,6 +77,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { private FlowLayout colorItems; private FlowLayout iconItems; private OsmandTextFieldBoxes profileNameOtfb; + private View saveButton; @Override public void onCreate(Bundle savedInstanceState) { @@ -180,7 +181,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { preferencesContainer.addView(buttonsContainer); View cancelButton = buttonsContainer.findViewById(R.id.dismiss_button); - View saveButton = buttonsContainer.findViewById(R.id.right_bottom_button); + saveButton = buttonsContainer.findViewById(R.id.right_bottom_button); saveButton.setVisibility(View.VISIBLE); buttonsContainer.findViewById(R.id.buttons_divider).setVisibility(View.VISIBLE); @@ -283,7 +284,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { if (PROFILE_NAME.equals(preference.getKey())) { profileName = (EditText) holder.findViewById(R.id.profile_name_et); profileName.setImeOptions(EditorInfo.IME_ACTION_DONE); - profileName.setRawInputType(InputType.TYPE_CLASS_TEXT); + profileName.setRawInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES); profileName.setText(changedProfile.name); profileName.requestFocus(); profileName.addTextChangedListener(new TextWatcher() { @@ -298,6 +299,12 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { @Override public void afterTextChanged(Editable s) { changedProfile.name = s.toString(); + if (hasNameDuplicate()) { + saveButton.setEnabled(false); + profileNameOtfb.setError(app.getString(R.string.profile_alert_duplicate_name_msg), true); + } else { + saveButton.setEnabled(true); + } } }); profileNameOtfb = (OsmandTextFieldBoxes) holder.findViewById(R.id.profile_name_otfb); @@ -500,21 +507,6 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { return false; } - if (hasNameDuplicate()) { - if (getActivity() != null) { - AlertDialog.Builder duplicateNameWarning = createWarningDialog(getActivity(), - R.string.profile_alert_duplicate_name_title, R.string.profile_alert_duplicate_name_msg, R.string.shared_string_dismiss); - duplicateNameWarning.setOnDismissListener(new DialogInterface.OnDismissListener() { - @Override - public void onDismiss(DialogInterface dialog) { - profileName.requestFocus(); - } - }); - duplicateNameWarning.show(); - } - return false; - } - ApplicationMode.ApplicationModeBuilder builder = ApplicationMode .createCustomMode(changedProfile.parent, changedProfile.name.trim(), changedProfile.stringKey) .icon(app, ApplicationMode.ProfileIcons.getResStringByResId(changedProfile.iconRes)) diff --git a/OsmAnd/src/net/osmand/plus/settings/ScreenAlertsFragment.java b/OsmAnd/src/net/osmand/plus/settings/ScreenAlertsFragment.java index 33a618033f..5f54066b5b 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ScreenAlertsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ScreenAlertsFragment.java @@ -18,6 +18,8 @@ import net.osmand.plus.ApplicationMode; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; +import static net.osmand.plus.UiUtilities.CompoundButtonType.TOOLBAR; + public class ScreenAlertsFragment extends BaseSettingsFragment { public static final String TAG = ScreenAlertsFragment.class.getSimpleName(); @@ -78,7 +80,7 @@ public class ScreenAlertsFragment extends BaseSettingsFragment { SwitchCompat switchView = (SwitchCompat) switchContainer.findViewById(R.id.switchWidget); switchView.setChecked(checked); - UiUtilities.setupCompoundButton(isNightMode(), getActiveProfileColor(), switchView); + UiUtilities.setupCompoundButton(switchView, isNightMode(), TOOLBAR); TextView title = switchContainer.findViewById(R.id.switchButtonText); title.setText(checked ? R.string.shared_string_on : R.string.shared_string_off); diff --git a/OsmAnd/src/net/osmand/plus/settings/TurnScreenOnFragment.java b/OsmAnd/src/net/osmand/plus/settings/TurnScreenOnFragment.java index 2d54661159..9def6e7996 100644 --- a/OsmAnd/src/net/osmand/plus/settings/TurnScreenOnFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/TurnScreenOnFragment.java @@ -15,6 +15,8 @@ import net.osmand.plus.UiUtilities; import net.osmand.plus.settings.preferences.ListPreferenceEx; import net.osmand.plus.settings.preferences.SwitchPreferenceEx; +import static net.osmand.plus.UiUtilities.CompoundButtonType.TOOLBAR; + public class TurnScreenOnFragment extends BaseSettingsFragment { public static final String TAG = TurnScreenOnFragment.class.getSimpleName(); @@ -64,7 +66,7 @@ public class TurnScreenOnFragment extends BaseSettingsFragment { SwitchCompat switchView = (SwitchCompat) switchContainer.findViewById(R.id.switchWidget); switchView.setChecked(checked); - UiUtilities.setupCompoundButton(isNightMode(), getActiveProfileColor(), switchView); + UiUtilities.setupCompoundButton(switchView, isNightMode(), TOOLBAR); TextView title = switchContainer.findViewById(R.id.switchButtonText); title.setText(checked ? R.string.shared_string_on : R.string.shared_string_off); diff --git a/OsmAnd/src/net/osmand/plus/settings/VoiceAnnouncesFragment.java b/OsmAnd/src/net/osmand/plus/settings/VoiceAnnouncesFragment.java index 878424848a..a1b7554778 100644 --- a/OsmAnd/src/net/osmand/plus/settings/VoiceAnnouncesFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/VoiceAnnouncesFragment.java @@ -29,6 +29,7 @@ import net.osmand.plus.settings.preferences.ListPreferenceEx; import java.util.Set; +import static net.osmand.plus.UiUtilities.CompoundButtonType.TOOLBAR; import static net.osmand.plus.activities.SettingsNavigationActivity.MORE_VALUE; public class VoiceAnnouncesFragment extends BaseSettingsFragment { @@ -71,7 +72,7 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment { SwitchCompat switchView = (SwitchCompat) switchContainer.findViewById(R.id.switchWidget); switchView.setChecked(checked); - UiUtilities.setupCompoundButton(isNightMode(), getActiveProfileColor(), switchView); + UiUtilities.setupCompoundButton(switchView, isNightMode(), TOOLBAR); TextView title = switchContainer.findViewById(R.id.switchButtonText); title.setText(checked ? R.string.shared_string_on : R.string.shared_string_off); diff --git a/OsmAnd/src/net/osmand/plus/widgets/OsmandTextFieldBoxes.java b/OsmAnd/src/net/osmand/plus/widgets/OsmandTextFieldBoxes.java index d2503239d9..9eb0df286d 100644 --- a/OsmAnd/src/net/osmand/plus/widgets/OsmandTextFieldBoxes.java +++ b/OsmAnd/src/net/osmand/plus/widgets/OsmandTextFieldBoxes.java @@ -9,6 +9,8 @@ import android.util.AttributeSet; import android.view.View; import android.view.inputmethod.InputMethodManager; +import net.osmand.plus.R; + import studio.carbonylgroup.textfieldboxes.ExtendedEditText; import studio.carbonylgroup.textfieldboxes.TextFieldBoxes; @@ -88,4 +90,16 @@ public class OsmandTextFieldBoxes extends TextFieldBoxes { public ExtendedEditText getEditText() { return editText; } + + @Override + public void setError(String errorText, boolean giveFocus) { + super.setError(errorText, giveFocus); + this.findViewById(R.id.text_field_boxes_bottom).setVisibility(View.VISIBLE); + } + + @Override + public void removeError() { + super.removeError(); + this.findViewById(R.id.text_field_boxes_bottom).setVisibility(View.GONE); + } }