Fix manage profiles

This commit is contained in:
Nazar-Kutz 2020-01-06 13:18:41 +02:00
parent c0ed1d1eca
commit 04497938f0
14 changed files with 100 additions and 48 deletions

View file

@ -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">
<studio.carbonylgroup.textfieldboxes.ExtendedEditText

View file

@ -791,6 +791,7 @@ public class ApplicationMode {
if (mode != null) {
mode.iconResName = builder.applicationMode.iconResName;
mode.iconRes = builder.applicationMode.iconRes;
mode.iconMapRes = builder.applicationMode.iconMapRes;
mode.userProfileName = builder.applicationMode.userProfileName;
mode.parentAppMode = builder.applicationMode.parentAppMode;
mode.routingProfile = builder.applicationMode.routingProfile;

View file

@ -52,6 +52,12 @@ public class UiUtilities {
STROKED
}
public enum CompoundButtonType {
GLOBAL,
PROFILE_DEPENDENT,
TOOLBAR
}
public UiUtilities(OsmandApplication app) {
this.app = app;
}
@ -335,23 +341,48 @@ public class UiUtilities {
DrawableCompat.setTintList(DrawableCompat.wrap(drawable), csl);
}
public static void setupCompoundButton(OsmandApplication app, CompoundButton compoundButton, boolean nightMode, boolean profileDependent) {
if (compoundButton == null) {
return;
}
int activeColor = profileDependent ?
app.getSettings().APPLICATION_MODE.get().getIconColorInfo().getColor(nightMode) :
nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light;
setupCompoundButton(nightMode, ContextCompat.getColor(app, activeColor), compoundButton);
}
public static void setupCompoundButton(boolean nightMode, @ColorInt int activeColor, CompoundButton compoundButton) {
if (compoundButton == null) {
return;
}
Context ctx = compoundButton.getContext();
if (compoundButton == null) {
return;
}
Context ctx = compoundButton.getContext();
int inactiveColorPrimary = ContextCompat.getColor(ctx, nightMode ? R.color.icon_color_default_dark : R.color.icon_color_secondary_light);
int inactiveColorSecondary = getColorWithAlpha(inactiveColorPrimary, 0.45f);
setupCompoundButton(compoundButton, activeColor, inactiveColorPrimary, inactiveColorSecondary);
}
public static void setupCompoundButton(CompoundButton compoundButton, boolean nightMode, CompoundButtonType type) {
if (compoundButton == null) {
return;
}
OsmandApplication app = (OsmandApplication) compoundButton.getContext().getApplicationContext();
@ColorInt int activeColor = -1;
@ColorInt int inactiveColorPrimary = ContextCompat.getColor(app, nightMode ? R.color.icon_color_default_dark : R.color.icon_color_secondary_light);
@ColorInt int inactiveColorSecondary = getColorWithAlpha(inactiveColorPrimary, 0.45f);
switch (type) {
case GLOBAL:
activeColor = ContextCompat.getColor(app, nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light);
break;
case PROFILE_DEPENDENT:
ApplicationMode appMode = app.getSettings().getApplicationMode();
activeColor = ContextCompat.getColor(app, appMode.getIconColorInfo().getColor(nightMode));
break;
case TOOLBAR:
activeColor = ContextCompat.getColor(app, nightMode ? R.color.text_color_tab_active_dark : R.color.text_color_tab_active_light);
inactiveColorPrimary = activeColor;
inactiveColorSecondary = UiUtilities.getColorWithAlpha(Color.BLACK, 0.25f);
break;
}
setupCompoundButton(compoundButton, activeColor, inactiveColorPrimary, inactiveColorSecondary);
}
public static void setupCompoundButton(CompoundButton compoundButton,
@ColorInt int activeColor,
@ColorInt int inactiveColorPrimary,
@ColorInt int inactiveColorSecondary) {
if (compoundButton == null) {
return;
}
int[][] states = new int[][] {
new int[] {-android.R.attr.state_checked},
new int[] {android.R.attr.state_checked}

View file

@ -39,6 +39,8 @@ import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import static net.osmand.plus.UiUtilities.CompoundButtonType.PROFILE_DEPENDENT;
public class SelectMapStyleBottomSheetDialogFragment extends MenuBottomSheetDialogFragment {
public static final String TAG = SelectMapStyleBottomSheetDialogFragment.class.getSimpleName();
@ -210,7 +212,7 @@ public class SelectMapStyleBottomSheetDialogFragment extends MenuBottomSheetDial
RadioButton rb = (RadioButton) view.findViewById(R.id.compound_button);
rb.setChecked(selected);
UiUtilities.setupCompoundButton(getMyApplication(), rb, nightMode, true);
UiUtilities.setupCompoundButton(rb, nightMode, PROFILE_DEPENDENT);
counter++;
}

View file

@ -73,7 +73,6 @@ import net.osmand.PlatformUtil;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.GPXDatabase.GpxDataItem;
import net.osmand.plus.GpxDbHelper;
import net.osmand.plus.GpxDbHelper.GpxDataItemCallback;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.OsmAndConstants;
@ -121,6 +120,7 @@ import static net.osmand.plus.OsmAndFormatter.METERS_IN_KILOMETER;
import static net.osmand.plus.OsmAndFormatter.METERS_IN_ONE_MILE;
import static net.osmand.plus.OsmAndFormatter.METERS_IN_ONE_NAUTICALMILE;
import static net.osmand.plus.OsmAndFormatter.YARDS_IN_ONE_METER;
import static net.osmand.plus.UiUtilities.CompoundButtonType.PROFILE_DEPENDENT;
import static net.osmand.plus.dialogs.ConfigureMapMenu.CURRENT_TRACK_COLOR_ATTR;
import static net.osmand.plus.dialogs.ConfigureMapMenu.CURRENT_TRACK_WIDTH_ATTR;
import static net.osmand.plus.download.DownloadActivity.formatKb;
@ -561,7 +561,7 @@ public class GpxUiHelper {
item.setSelected(isChecked);
}
});
UiUtilities.setupCompoundButton(app, ch, nightMode, true);
UiUtilities.setupCompoundButton(ch, nightMode, PROFILE_DEPENDENT);
} else {
final SwitchCompat ch = ((SwitchCompat) v.findViewById(R.id.toggle_item));
ch.setVisibility(View.VISIBLE);
@ -574,7 +574,7 @@ public class GpxUiHelper {
item.setSelected(isChecked);
}
});
UiUtilities.setupCompoundButton(app, ch, nightMode, true);
UiUtilities.setupCompoundButton(ch, nightMode, PROFILE_DEPENDENT);
}
v.findViewById(R.id.check_item).setVisibility(View.VISIBLE);
}

View file

@ -41,6 +41,8 @@ import net.osmand.plus.helpers.AndroidUiHelper;
import java.util.LinkedList;
import static net.osmand.plus.UiUtilities.CompoundButtonType.PROFILE_DEPENDENT;
public class DirectionIndicationDialogFragment extends BaseOsmAndDialogFragment {
public final static String TAG = "DirectionIndicationDialogFragment";
@ -152,7 +154,7 @@ public class DirectionIndicationDialogFragment extends BaseOsmAndDialogFragment
updateSelection(true);
}
});
UiUtilities.setupCompoundButton(getMyApplication(), distanceIndicationToggle, nightMode, true);
UiUtilities.setupCompoundButton(distanceIndicationToggle, nightMode, PROFILE_DEPENDENT);
mainView.findViewById(R.id.top_bar_row).setOnClickListener(new View.OnClickListener() {
@Override
@ -180,7 +182,7 @@ public class DirectionIndicationDialogFragment extends BaseOsmAndDialogFragment
updateChecked(settings.SHOW_ARROWS_TO_FIRST_MARKERS, showArrowsToggle);
}
});
UiUtilities.setupCompoundButton(getMyApplication(), showArrowsToggle, nightMode, true);
UiUtilities.setupCompoundButton(showArrowsToggle, nightMode, PROFILE_DEPENDENT);
final CompoundButton showLinesToggle = (CompoundButton) mainView.findViewById(R.id.show_guide_line_switch);
showLinesToggle.setChecked(settings.SHOW_LINES_TO_FIRST_MARKERS.get());
@ -190,7 +192,7 @@ public class DirectionIndicationDialogFragment extends BaseOsmAndDialogFragment
updateChecked(settings.SHOW_LINES_TO_FIRST_MARKERS, showLinesToggle);
}
});
UiUtilities.setupCompoundButton(getMyApplication(), showLinesToggle, nightMode, true);
UiUtilities.setupCompoundButton(showLinesToggle, nightMode, PROFILE_DEPENDENT);
final CompoundButton oneTapActiveToggle = (CompoundButton) mainView.findViewById(R.id.one_tap_active_switch);
oneTapActiveToggle.setChecked(settings.SELECT_MARKER_ON_SINGLE_TAP.get());
@ -200,7 +202,7 @@ public class DirectionIndicationDialogFragment extends BaseOsmAndDialogFragment
updateChecked(settings.SELECT_MARKER_ON_SINGLE_TAP, oneTapActiveToggle);
}
});
UiUtilities.setupCompoundButton(getMyApplication(), oneTapActiveToggle, nightMode, true);
UiUtilities.setupCompoundButton(oneTapActiveToggle, nightMode, PROFILE_DEPENDENT);
final CompoundButton keepPassedToggle = (CompoundButton) mainView.findViewById(R.id.keep_passed_switch);
keepPassedToggle.setChecked(settings.KEEP_PASSED_MARKERS_ON_MAP.get());
@ -210,7 +212,7 @@ public class DirectionIndicationDialogFragment extends BaseOsmAndDialogFragment
updateChecked(settings.KEEP_PASSED_MARKERS_ON_MAP, keepPassedToggle);
}
});
UiUtilities.setupCompoundButton(getMyApplication(), keepPassedToggle, nightMode, true);
UiUtilities.setupCompoundButton(keepPassedToggle, nightMode, PROFILE_DEPENDENT);
return mainView;
}
@ -387,7 +389,7 @@ public class DirectionIndicationDialogFragment extends BaseOsmAndDialogFragment
private void updateMarkerModeRow(int rowId, int radioButtonId, boolean checked, boolean active) {
RadioButton rb = (RadioButton) mainView.findViewById(radioButtonId);
rb.setChecked(checked);
UiUtilities.setupCompoundButton(getMyApplication(), rb, isNightMode(usedOnMap), true);
UiUtilities.setupCompoundButton(rb, isNightMode(usedOnMap), PROFILE_DEPENDENT);
mainView.findViewById(rowId).setEnabled(active);
}

View file

@ -45,6 +45,8 @@ import java.util.List;
import gnu.trove.list.array.TIntArrayList;
import static net.osmand.plus.UiUtilities.CompoundButtonType.PROFILE_DEPENDENT;
public class OsmandMonitoringPlugin extends OsmandPlugin {
public static final String ID = "osmand.monitoring";
public final static String OSMAND_SAVE_SERVICE_ACTION = "OSMAND_SAVE_SERVICE_ACTION";
@ -544,7 +546,7 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
}
});
UiUtilities.setupCompoundButton(app, cb, nightMode, true);
UiUtilities.setupCompoundButton(cb, nightMode, PROFILE_DEPENDENT);
ll.addView(cb);
}
@ -572,7 +574,7 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
app.getSelectedGpxHelper().selectGpxFile(app.getSavingTrackHelper().getCurrentGpx(), isChecked, false);
}
});
UiUtilities.setupCompoundButton(app, cb, nightMode, true);
UiUtilities.setupCompoundButton(cb, nightMode, PROFILE_DEPENDENT);
ll.addView(cb);
}

View file

@ -55,6 +55,7 @@ import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_D
import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_UPDATE_MAP;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.OVERLAY_MAP;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.UNDERLAY_MAP;
import static net.osmand.plus.UiUtilities.CompoundButtonType.PROFILE_DEPENDENT;
public class OsmandRasterMapsPlugin extends OsmandPlugin {
public static final String ID = "osmand.rastermaps";
@ -503,7 +504,7 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin {
final AppCompatCheckBox elliptic = (AppCompatCheckBox) view.findViewById(R.id.EllipticMercator);
elliptic.setTextColor(textColorPrimary);
elliptic.setPadding(dp8, 0, 0, 0);
UiUtilities.setupCompoundButton(app, elliptic, nightMode, true);
UiUtilities.setupCompoundButton(elliptic, nightMode, PROFILE_DEPENDENT);
updateTileSourceEditView(ts, name, urlToLoad, minZoom, maxZoom, expire, elliptic);
final ArrayList<String> templates = new ArrayList<>(entriesMap.keySet());

View file

@ -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);

View file

@ -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))

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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);
}
}