Add profile appearance draft with save changing

This commit is contained in:
Dima-1 2019-12-18 22:15:24 +02:00
parent 185ec7fe55
commit 0f5448795c
11 changed files with 224 additions and 148 deletions

View file

@ -239,7 +239,7 @@
android:tint="@color/settings_divider"/> android:tint="@color/settings_divider"/>
<net.osmand.plus.widgets.OsmandTextFieldBoxes <net.osmand.plus.widgets.OsmandTextFieldBoxes
android:id="@+id/navigation_type_otfb" android:id="@+id/master_profile_otfb"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="60dp" android:layout_height="60dp"
app:primaryColor="@color/active_color_primary_dark" app:primaryColor="@color/active_color_primary_dark"
@ -247,7 +247,7 @@
app:labelText="@string/nav_type_hint"> app:labelText="@string/nav_type_hint">
<studio.carbonylgroup.textfieldboxes.ExtendedEditText <studio.carbonylgroup.textfieldboxes.ExtendedEditText
android:id="@+id/navigation_type_et" android:id="@+id/master_profile_et"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:focusable="false" android:focusable="false"

View file

@ -25,15 +25,15 @@
android:tint="@color/settings_divider"/> android:tint="@color/settings_divider"/>
<net.osmand.plus.widgets.OsmandTextFieldBoxes <net.osmand.plus.widgets.OsmandTextFieldBoxes
android:id="@+id/navigation_type_otfb" android:id="@+id/master_profile_otfb"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="60dp" android:layout_height="60dp"
app:primaryColor="@color/active_color_primary_dark" app:primaryColor="@color/active_color_primary_dark"
app:secondaryColor="?android:textColorSecondary" app:secondaryColor="?android:textColorSecondary"
app:labelText="@string/nav_type_hint"> app:labelText="@string/master_profile">
<studio.carbonylgroup.textfieldboxes.ExtendedEditText <studio.carbonylgroup.textfieldboxes.ExtendedEditText
android:id="@+id/navigation_type_et" android:id="@+id/master_profile_et"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:focusable="false" android:focusable="false"

View file

@ -11,6 +11,8 @@
Thx - Hardy Thx - Hardy
--> -->
<string name="select_navigation_icon">Select navigation icon</string>
<string name="select_map_icon">Select map icon</string>
<string name="delete_profiles_descr">After you tap Apply, deleted profiles will be lost completely.</string> <string name="delete_profiles_descr">After you tap Apply, deleted profiles will be lost completely.</string>
<string name="master_profile">Master profile</string> <string name="master_profile">Master profile</string>
<string name="select_color">Select color</string> <string name="select_color">Select color</string>

View file

@ -52,12 +52,12 @@
<PreferenceCategory <PreferenceCategory
android:key="select_map_icon" android:key="select_map_icon"
android:layout="@layout/preference_category_with_descr" android:layout="@layout/preference_category_with_descr"
android:title="@string/map_during_navigation" /> android:title="@string/select_map_icon" />
<Preference <Preference
android:key="map_icon_items" android:key="map_icon_items"
android:layout="@layout/preference_with_descr" android:layout="@layout/preference_with_descr"
android:title="@string/map_during_navigation" android:title="@string/select_map_icon"
android:selectable="false"/> android:selectable="false"/>
<Preference <Preference
@ -67,12 +67,12 @@
<PreferenceCategory <PreferenceCategory
android:key="select_nav_icon" android:key="select_nav_icon"
android:layout="@layout/preference_category_with_descr" android:layout="@layout/preference_category_with_descr"
android:title="@string/map_during_navigation" /> android:title="@string/select_navigation_icon" />
<Preference <Preference
android:key="nav_icon_items" android:key="nav_icon_items"
android:layout="@layout/preference_with_descr" android:layout="@layout/preference_with_descr"
android:title="@string/map_during_navigation" android:title="@string/select_navigation_icon"
android:selectable="false"/> android:selectable="false"/>
</PreferenceScreen> </PreferenceScreen>

View file

@ -3,6 +3,7 @@ package net.osmand.plus;
import android.content.Context; import android.content.Context;
import android.support.annotation.ColorRes; import android.support.annotation.ColorRes;
import android.support.annotation.DrawableRes; import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.support.annotation.StringRes; import android.support.annotation.StringRes;
import com.google.gson.Gson; import com.google.gson.Gson;
@ -862,4 +863,79 @@ public class ApplicationMode {
return nightMode ? nightColor : dayColor; return nightMode ? nightColor : dayColor;
} }
} }
public enum ProfileIcons {
CAR(R.drawable.ic_action_car_dark, R.string.app_mode_car, "ic_action_car_dark", false),
TAXI(R.drawable.ic_action_taxi, R.string.app_mode_taxi, "ic_action_taxi", false),
TRUCK(R.drawable.ic_action_truck_dark, R.string.app_mode_truck, "ic_action_truck_dark", false),
SHUTTLE_BUS(R.drawable.ic_action_shuttle_bus, R.string.app_mode_shuttle_bus, "ic_action_shuttle_bus", false),
BUS(R.drawable.ic_action_bus_dark, R.string.app_mode_bus, "ic_action_bus_dark", false),
SUBWAY(R.drawable.ic_action_subway, R.string.app_mode_subway, "ic_action_subway", false),
MOTORCYCLE(R.drawable.ic_action_motorcycle_dark, R.string.app_mode_motorcycle, "ic_action_motorcycle_dark", false),
BICYCLE(R.drawable.ic_action_bicycle_dark, R.string.app_mode_bicycle, "ic_action_bicycle_dark", false),
HORSE(R.drawable.ic_action_horse, R.string.app_mode_horse, "ic_action_horse", false),
PEDESTRIAN(R.drawable.ic_action_pedestrian_dark, R.string.app_mode_pedestrian, "ic_action_pedestrian_dark", false),
TREKKING(R.drawable.ic_action_trekking_dark, R.string.app_mode_hiking, "ic_action_trekking_dark", false),
SKIING(R.drawable.ic_action_skiing, R.string.app_mode_skiing, "ic_action_skiing", false),
SAIL_BOAT(R.drawable.ic_action_sail_boat_dark, R.string.app_mode_boat, "ic_action_sail_boat_dark", false),
AIRCRAFT(R.drawable.ic_action_aircraft, R.string.app_mode_aircraft, "ic_action_aircraft", false),
HELICOPTER(R.drawable.ic_action_helicopter, R.string.app_mode_helicopter, "ic_action_helicopter", false),
TRANSPORTER(R.drawable.ic_action_personal_transporter, R.string.app_mode_personal_transporter, "ic_action_personal_transporter", false),
MONOWHEEL(R.drawable.ic_action_monowheel, R.string.app_mode_monowheel, "ic_action_monowheel", false),
SCOOTER(R.drawable.ic_action_scooter, R.string.app_mode_scooter, "ic_action_scooter", false),
UFO(R.drawable.ic_action_ufo, R.string.app_mode_ufo, "ic_action_ufo", false),
OFFROAD(R.drawable.ic_action_offroad, R.string.app_mode_offroad, "ic_action_offroad", false),
CAMPERVAN(R.drawable.ic_action_campervan, R.string.app_mode_campervan, "ic_action_campervan", false),
CAMPER(R.drawable.ic_action_camper, R.string.app_mode_camper, "ic_action_camper", false),
PICKUP_TRUCK(R.drawable.ic_action_pickup_truck, R.string.app_mode_pickup_truck, "ic_action_pickup_truck", false),
WAGON(R.drawable.ic_action_wagon, R.string.app_mode_wagon, "ic_action_wagon", false),
UTV(R.drawable.ic_action_utv, R.string.app_mode_utv, "ic_action_utv", false);
@DrawableRes
private int resId;
@StringRes
private int titleId;
private String resStringId;
private boolean isSelected;
ProfileIcons(@DrawableRes int resId, @StringRes int titleId, @NonNull String resStringId, boolean isSelected) {
this.resId = resId;
this.titleId = titleId;
this.isSelected = isSelected;
this.resStringId = resStringId;
}
public static ArrayList<Integer> getIcons() {
ArrayList<Integer> list = new ArrayList<>();
for (ProfileIcons pi : values()) {
list.add(pi.resId);
}
return list;
}
public int getResId() {
return resId;
}
public int getTitleId() {
return titleId;
}
public String getResStringId() {
return resStringId;
}
public static String getResStringByResId(int resId) {
for (ProfileIcons pi : values()) {
if (pi.resId == resId) {
return pi.resStringId;
}
}
return CAR.getResStringId();
}
public boolean isSelected() {
return isSelected;
}
}
} }

View file

@ -133,6 +133,7 @@ import net.osmand.plus.search.QuickSearchDialogFragment.QuickSearchType;
import net.osmand.plus.settings.BaseSettingsFragment; import net.osmand.plus.settings.BaseSettingsFragment;
import net.osmand.plus.settings.BaseSettingsFragment.SettingsScreenType; import net.osmand.plus.settings.BaseSettingsFragment.SettingsScreenType;
import net.osmand.plus.settings.DataStorageFragment; import net.osmand.plus.settings.DataStorageFragment;
import net.osmand.plus.settings.ProfileAppearanceFragment;
import net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint; import net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint;
import net.osmand.plus.views.AnimateDraggingMapThread; import net.osmand.plus.views.AnimateDraggingMapThread;
import net.osmand.plus.views.MapControlsLayer; import net.osmand.plus.views.MapControlsLayer;
@ -676,6 +677,12 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
return; return;
} }
} }
ProfileAppearanceFragment profileAppearanceFragment = getProfileAppearanceFragment();
if (profileAppearanceFragment != null) {
if (profileAppearanceFragment.isProfileAppearanceChanged(this)) {
return;
}
}
if (mapContextMenu.isVisible() && mapContextMenu.isClosable()) { if (mapContextMenu.isVisible() && mapContextMenu.isClosable()) {
if (mapContextMenu.getCurrentMenuState() != MenuState.HEADER_ONLY && !isLandscapeLayout()) { if (mapContextMenu.getCurrentMenuState() != MenuState.HEADER_ONLY && !isLandscapeLayout()) {
mapContextMenu.openMenuHeaderOnly(); mapContextMenu.openMenuHeaderOnly();
@ -2400,6 +2407,10 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
return getFragment(EditProfileFragment.TAG); return getFragment(EditProfileFragment.TAG);
} }
public ProfileAppearanceFragment getProfileAppearanceFragment() {
return getFragment(ProfileAppearanceFragment.TAG);
}
public QuickActionListFragment getQuickActionListFragment() { public QuickActionListFragment getQuickActionListFragment() {
return getFragment(QuickActionListFragment.TAG); return getFragment(QuickActionListFragment.TAG);
} }

View file

@ -164,8 +164,8 @@ public class EditProfileFragment extends BaseOsmAndFragment {
selectColorBtn = view.findViewById(R.id.select_icon_color_button); selectColorBtn = view.findViewById(R.id.select_icon_color_button);
profileNameEt = view.findViewById(R.id.profile_name_et); profileNameEt = view.findViewById(R.id.profile_name_et);
profileNameTextBox = view.findViewById(R.id.profile_name_otfb); profileNameTextBox = view.findViewById(R.id.profile_name_otfb);
navTypeEt = view.findViewById(R.id.navigation_type_et); navTypeEt = view.findViewById(R.id.master_profile_et);
navTypeTextBox = view.findViewById(R.id.navigation_type_otfb); navTypeTextBox = view.findViewById(R.id.master_profile_otfb);
selectNavTypeBtn = view.findViewById(R.id.select_nav_type_btn); selectNavTypeBtn = view.findViewById(R.id.select_nav_type_btn);
cancelBtn = view.findViewById(R.id.cancel_button); cancelBtn = view.findViewById(R.id.cancel_button);
saveButton = view.findViewById(R.id.save_profile_btn); saveButton = view.findViewById(R.id.save_profile_btn);

View file

@ -11,6 +11,7 @@ import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.MenuBottomSheetDialogFragment;
@ -46,7 +47,6 @@ public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialo
private final List<ProfileDataObject> profiles = new ArrayList<>(); private final List<ProfileDataObject> profiles = new ArrayList<>();
private List<IconResWithDescr> icons;
private String selectedItemKey; private String selectedItemKey;
private String selectedIconRes; private String selectedIconRes;
@ -64,7 +64,6 @@ public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialo
profiles.addAll(SettingsProfileFragment.getBaseProfiles(app)); profiles.addAll(SettingsProfileFragment.getBaseProfiles(app));
} else if (type.equals(TYPE_ICON)) { } else if (type.equals(TYPE_ICON)) {
selectedIconRes = args.getString(SELECTED_ICON, ""); selectedIconRes = args.getString(SELECTED_ICON, "");
icons = getProfileIcons();
} else { } else {
LOG.error("Check intent data!"); LOG.error("Check intent data!");
dismiss(); dismiss();
@ -178,10 +177,10 @@ public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialo
} }
} else if (type.equals(TYPE_ICON)) { } else if (type.equals(TYPE_ICON)) {
items.add(new TitleItem(getString(R.string.select_icon_profile_dialog_title))); items.add(new TitleItem(getString(R.string.select_icon_profile_dialog_title)));
for (final IconResWithDescr icon : icons) { for (final ApplicationMode.ProfileIcons icon : ApplicationMode.ProfileIcons.values()) {
Drawable drawableIcon; Drawable drawableIcon;
boolean isSelected = icon.resStringId.equals(selectedIconRes); boolean isSelected = icon.getResStringId().equals(selectedIconRes);
int iconRes = icon.resId; int iconRes = icon.getResId();
if (isSelected) { if (isSelected) {
drawableIcon = getMyApplication().getUIUtilities() drawableIcon = getMyApplication().getUIUtilities()
.getIcon(iconRes, nightMode .getIcon(iconRes, nightMode
@ -193,11 +192,11 @@ public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialo
} }
items.add(new BottomSheetItemWithCompoundButton.Builder() items.add(new BottomSheetItemWithCompoundButton.Builder()
.setChecked(icon.resStringId.equals(selectedIconRes)) .setChecked(icon.getResStringId().equals(selectedIconRes))
.setButtonTintList(isSelected .setButtonTintList(isSelected
? ColorStateList.valueOf(getResolvedColor(getActiveColorId())) ? ColorStateList.valueOf(getResolvedColor(getActiveColorId()))
: null) : null)
.setTitle(getMyApplication().getString(icon.titleId)) .setTitle(getMyApplication().getString(icon.getTitleId()))
.setIcon(drawableIcon) .setIcon(drawableIcon)
.setLayoutId(R.layout.bottom_sheet_item_with_radio_btn) .setLayoutId(R.layout.bottom_sheet_item_with_radio_btn)
.setOnClickListener(new OnClickListener() { .setOnClickListener(new OnClickListener() {
@ -207,7 +206,7 @@ public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialo
getListener(); getListener();
} }
if (listener != null) { if (listener != null) {
listener.onSelectedType(icon.resId, icon.resStringId); listener.onSelectedType(icon.getResId(), icon.getResStringId());
} }
dismiss(); dismiss();
} }
@ -218,7 +217,6 @@ public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialo
} }
} }
private void getListener() { private void getListener() {
FragmentActivity activity = getActivity(); FragmentActivity activity = getActivity();
if (activity != null) { if (activity != null) {
@ -226,7 +224,7 @@ public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialo
EditProfileFragment editProfileFragment = (EditProfileFragment) fragmentManager.findFragmentByTag(EditProfileFragment.TAG); EditProfileFragment editProfileFragment = (EditProfileFragment) fragmentManager.findFragmentByTag(EditProfileFragment.TAG);
SettingsProfileFragment settingsProfileFragment = (SettingsProfileFragment) fragmentManager.findFragmentByTag(SettingsProfileFragment.class.getName()); SettingsProfileFragment settingsProfileFragment = (SettingsProfileFragment) fragmentManager.findFragmentByTag(SettingsProfileFragment.class.getName());
NavigationFragment navigationFragment = (NavigationFragment) fragmentManager.findFragmentByTag(NavigationFragment.class.getName()); NavigationFragment navigationFragment = (NavigationFragment) fragmentManager.findFragmentByTag(NavigationFragment.class.getName());
ProfileAppearanceFragment profileAppearanceFragment = (ProfileAppearanceFragment) fragmentManager.findFragmentByTag(ProfileAppearanceFragment.class.getName()); ProfileAppearanceFragment profileAppearanceFragment = (ProfileAppearanceFragment) fragmentManager.findFragmentByTag(ProfileAppearanceFragment.TAG);
if (editProfileFragment != null) { if (editProfileFragment != null) {
switch (type) { switch (type) {
@ -251,52 +249,7 @@ public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialo
} }
} }
private List<IconResWithDescr> getProfileIcons() {
List<IconResWithDescr> icons = new ArrayList<>();
icons.add(new IconResWithDescr(R.drawable.ic_action_car_dark, R.string.app_mode_car, "ic_action_car_dark", false));
icons.add(new IconResWithDescr(R.drawable.ic_action_taxi, R.string.app_mode_taxi, "ic_action_taxi", false));
icons.add(new IconResWithDescr(R.drawable.ic_action_truck_dark, R.string.app_mode_truck, "ic_action_truck_dark", false));
icons.add(new IconResWithDescr(R.drawable.ic_action_shuttle_bus, R.string.app_mode_shuttle_bus, "ic_action_shuttle_bus", false));
icons.add(new IconResWithDescr(R.drawable.ic_action_bus_dark, R.string.app_mode_bus, "ic_action_bus_dark",false));
icons.add(new IconResWithDescr(R.drawable.ic_action_subway, R.string.app_mode_subway, "ic_action_subway", false));
icons.add(new IconResWithDescr(R.drawable.ic_action_motorcycle_dark, R.string.app_mode_motorcycle, "ic_action_motorcycle_dark", false));
icons.add(new IconResWithDescr(R.drawable.ic_action_bicycle_dark, R.string.app_mode_bicycle, "ic_action_bicycle_dark", false));
icons.add(new IconResWithDescr(R.drawable.ic_action_horse, R.string.app_mode_horse, "ic_action_horse", false));
icons.add(new IconResWithDescr(R.drawable.ic_action_pedestrian_dark, R.string.app_mode_pedestrian,"ic_action_pedestrian_dark", false));
icons.add(new IconResWithDescr(R.drawable.ic_action_trekking_dark, R.string.app_mode_hiking, "ic_action_trekking_dark", false));
icons.add(new IconResWithDescr(R.drawable.ic_action_skiing, R.string.app_mode_skiing, "ic_action_skiing", false));
icons.add(new IconResWithDescr(R.drawable.ic_action_sail_boat_dark, R.string.app_mode_boat, "ic_action_sail_boat_dark", false));
icons.add(new IconResWithDescr(R.drawable.ic_action_aircraft, R.string.app_mode_aircraft, "ic_action_aircraft", false));
icons.add(new IconResWithDescr(R.drawable.ic_action_helicopter, R.string.app_mode_helicopter, "ic_action_helicopter", false));
icons.add(new IconResWithDescr(R.drawable.ic_action_personal_transporter, R.string.app_mode_personal_transporter, "ic_action_personal_transporter", false));
icons.add(new IconResWithDescr(R.drawable.ic_action_monowheel, R.string.app_mode_monowheel, "ic_action_monowheel", false));
icons.add(new IconResWithDescr(R.drawable.ic_action_scooter, R.string.app_mode_scooter, "ic_action_scooter", false));
icons.add(new IconResWithDescr(R.drawable.ic_action_ufo, R.string.app_mode_ufo, "ic_action_ufo", false));
icons.add(new IconResWithDescr(R.drawable.ic_action_offroad, R.string.app_mode_offroad, "ic_action_offroad", false));
icons.add(new IconResWithDescr(R.drawable.ic_action_campervan, R.string.app_mode_campervan, "ic_action_campervan", false));
icons.add(new IconResWithDescr(R.drawable.ic_action_camper, R.string.app_mode_camper, "ic_action_camper", false));
icons.add(new IconResWithDescr(R.drawable.ic_action_pickup_truck, R.string.app_mode_pickup_truck, "ic_action_pickup_truck", false));
icons.add(new IconResWithDescr(R.drawable.ic_action_wagon, R.string.app_mode_wagon, "ic_action_wagon", false));
icons.add(new IconResWithDescr(R.drawable.ic_action_utv, R.string.app_mode_utv, "ic_action_utv", false));
return icons;
}
public interface SelectProfileListener { public interface SelectProfileListener {
void onSelectedType(int pos, String stringRes); void onSelectedType(int pos, String stringRes);
} }
private class IconResWithDescr {
private int resId;
private int titleId;
private String resStringId;
private boolean isSelected;
public IconResWithDescr(int resId, int titleId, String resStringId, boolean isSelected) {
this.resId = resId;
this.titleId = titleId;
this.isSelected = isSelected;
this.resStringId = resStringId;
}
}
} }

View file

@ -98,7 +98,7 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
TURN_SCREEN_ON(TurnScreenOnFragment.class.getName(), true, R.xml.turn_screen_on, R.layout.profile_preference_toolbar_with_switch), TURN_SCREEN_ON(TurnScreenOnFragment.class.getName(), true, R.xml.turn_screen_on, R.layout.profile_preference_toolbar_with_switch),
DATA_STORAGE(DataStorageFragment.class.getName(), false, R.xml.data_storage, R.layout.global_preference_toolbar), DATA_STORAGE(DataStorageFragment.class.getName(), false, R.xml.data_storage, R.layout.global_preference_toolbar),
DIALOGS_AND_NOTIFICATIONS_SETTINGS(DialogsAndNotificationsSettingsFragment.class.getName(), false, R.xml.dialogs_and_notifications_preferences, R.layout.global_preferences_toolbar_with_switch), DIALOGS_AND_NOTIFICATIONS_SETTINGS(DialogsAndNotificationsSettingsFragment.class.getName(), false, R.xml.dialogs_and_notifications_preferences, R.layout.global_preferences_toolbar_with_switch),
PROFILE_APPEARANCE(ProfileAppearanceFragment.class.getName(), true, R.xml.profile_appearance, R.layout.profile_preference_toolbar); PROFILE_APPEARANCE(ProfileAppearanceFragment.TAG, true, R.xml.profile_appearance, R.layout.profile_preference_toolbar);
public final String fragmentName; public final String fragmentName;
public final boolean profileDependent; public final boolean profileDependent;

View file

@ -245,9 +245,14 @@ public class ConfigureProfileFragment extends BaseSettingsFragment {
if (ctx == null) { if (ctx == null) {
return; return;
} }
Preference configureMap = findPreference(PROFILE_APPEARANCE); Preference configureMap = findPreference(PROFILE_APPEARANCE);
configureMap.setIcon(getContentIcon(getSelectedAppMode().getIconRes())); if (!getSelectedAppMode().equals(ApplicationMode.DEFAULT)) {
configureMap.setFragment(ProfileAppearanceFragment.class.getName()); configureMap.setIcon(getContentIcon(getSelectedAppMode().getIconRes()));
configureMap.setFragment(ProfileAppearanceFragment.TAG);
} else {
configureMap.setVisible(false);
}
} }
private void setupExportProfilePref() { private void setupExportProfilePref() {

View file

@ -3,12 +3,12 @@ package net.osmand.plus.settings;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.graphics.drawable.GradientDrawable; import android.graphics.drawable.GradientDrawable;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.support.v7.preference.Preference; import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceCategory;
import android.support.v7.preference.PreferenceViewHolder; import android.support.v7.preference.PreferenceViewHolder;
import android.text.Editable; import android.text.Editable;
import android.text.TextWatcher; import android.text.TextWatcher;
@ -23,11 +23,12 @@ import android.widget.ImageView;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.plus.ApplicationMode; import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.UiUtilities; import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment; import net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment;
import net.osmand.plus.profiles.SettingsProfileFragment; import net.osmand.plus.profiles.SettingsProfileFragment;
import net.osmand.plus.routing.RouteProvider;
import net.osmand.plus.widgets.FlowLayout; import net.osmand.plus.widgets.FlowLayout;
import net.osmand.plus.widgets.OsmandTextFieldBoxes; import net.osmand.plus.widgets.OsmandTextFieldBoxes;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -40,12 +41,16 @@ import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.TY
public class ProfileAppearanceFragment extends BaseSettingsFragment { public class ProfileAppearanceFragment extends BaseSettingsFragment {
public static final String TAG = ProfileAppearanceFragment.class.getName();
private static final String MASTER_PROFILE = "master_profile"; private static final String MASTER_PROFILE = "master_profile";
private static final String PROFILE_NAME = "profile_name"; private static final String PROFILE_NAME = "profile_name";
private static final String SELECT_COLOR = "select_color"; private static final String SELECT_COLOR = "select_color";
private static final String SELECT_ICON = "select_icon"; private static final String SELECT_ICON = "select_icon";
private static final String COLOR_ITEMS = "color_items"; private static final String COLOR_ITEMS = "color_items";
private static final String ICON_ITEMS = "icon_items"; private static final String ICON_ITEMS = "icon_items";
private static final String SELECT_MAP_ICON = "select_map_icon";
private static final String SELECT_NAV_ICON = "select_nav_icon";
public static final String PROFILE_NAME_KEY = "profile_name_key"; public static final String PROFILE_NAME_KEY = "profile_name_key";
public static final String PROFILE_ICON_RES_KEY = "profile_icon_res_key"; public static final String PROFILE_ICON_RES_KEY = "profile_icon_res_key";
public static final String PROFILE_COLOR_KEY = "profile_color_key"; public static final String PROFILE_COLOR_KEY = "profile_color_key";
@ -54,8 +59,6 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
private EditText baseProfileName; private EditText baseProfileName;
private ApplicationProfileObject profile; private ApplicationProfileObject profile;
private ApplicationProfileObject changedProfile; private ApplicationProfileObject changedProfile;
private Button cancelButton;
private Button saveButton;
private EditText profileName; private EditText profileName;
private FlowLayout colorItems; private FlowLayout colorItems;
private FlowLayout iconItems; private FlowLayout iconItems;
@ -68,24 +71,30 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
restoreState(savedInstanceState); restoreState(savedInstanceState);
} else { } else {
profile = new ApplicationProfileObject(); profile = new ApplicationProfileObject();
profile.stringKey = getSelectedAppMode().getStringKey();
profile.parent = getSelectedAppMode().getParent(); profile.parent = getSelectedAppMode().getParent();
profile.name = getSelectedAppMode().toHumanString(getContext()); profile.name = getSelectedAppMode().toHumanString(getContext());
profile.color = getSelectedAppMode().getIconColorInfo(); profile.color = getSelectedAppMode().getIconColorInfo();
profile.iconRes = getSelectedAppMode().getIconRes(); profile.iconRes = getSelectedAppMode().getIconRes();
profile.routingProfile = getSelectedAppMode().getRoutingProfile();
profile.routeService = getSelectedAppMode().getRouteService();
changedProfile = new ApplicationProfileObject(); changedProfile = new ApplicationProfileObject();
changedProfile.stringKey = profile.stringKey;
changedProfile.parent = profile.parent; changedProfile.parent = profile.parent;
changedProfile.name = profile.name; changedProfile.name = profile.name;
changedProfile.color = profile.color; changedProfile.color = profile.color;
changedProfile.iconRes = profile.iconRes; changedProfile.iconRes = profile.iconRes;
changedProfile.routingProfile = profile.routingProfile;
changedProfile.routeService = profile.routeService;
} }
} }
@Override @Override
protected void setupPreferences() { protected void setupPreferences() {
PreferenceCategory selectColor = (PreferenceCategory) findPreference(SELECT_COLOR); findPreference(SELECT_COLOR).setIconSpaceReserved(false);
selectColor.setIconSpaceReserved(false); findPreference(SELECT_ICON).setIconSpaceReserved(false);
PreferenceCategory selectIcon = (PreferenceCategory) findPreference(SELECT_ICON); findPreference(SELECT_MAP_ICON).setIconSpaceReserved(false);
selectIcon.setIconSpaceReserved(false); findPreference(SELECT_NAV_ICON).setIconSpaceReserved(false);
} }
@SuppressLint("InlinedApi") @SuppressLint("InlinedApi")
@ -96,9 +105,9 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
FrameLayout frameLayout = view.findViewById(android.R.id.list_container); FrameLayout frameLayout = view.findViewById(android.R.id.list_container);
View inflatedLayout = UiUtilities.getInflater(getContext(), isNightMode()) View inflatedLayout = UiUtilities.getInflater(getContext(), isNightMode())
.inflate(R.layout.preference_cancel_save_button, frameLayout, false); .inflate(R.layout.preference_cancel_save_button, frameLayout, false);
(frameLayout).addView(inflatedLayout); frameLayout.addView(inflatedLayout);
cancelButton=inflatedLayout.findViewById(R.id.cancel_button); Button cancelButton = inflatedLayout.findViewById(R.id.cancel_button);
saveButton=inflatedLayout.findViewById(R.id.save_profile_btn); Button saveButton = inflatedLayout.findViewById(R.id.save_profile_btn);
cancelButton.setOnClickListener(new View.OnClickListener() { cancelButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -111,10 +120,10 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if (getActivity() != null) { if (getActivity() != null) {
if (profile.equals(changedProfile)) { if (isChanged()) {
saveNewProfile();
profile = changedProfile;
getActivity().onBackPressed(); getActivity().onBackPressed();
} else {
} }
} }
} }
@ -123,6 +132,10 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
return view; return view;
} }
private boolean isChanged() {
return !profile.equals(changedProfile);
}
@Override @Override
protected void createToolbar(LayoutInflater inflater, View view) { protected void createToolbar(LayoutInflater inflater, View view) {
super.createToolbar(inflater, view); super.createToolbar(inflater, view);
@ -149,9 +162,8 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
changedProfile.color = (ApplicationMode.ProfileIconColors) savedInstanceState.getSerializable(PROFILE_COLOR_KEY); changedProfile.color = (ApplicationMode.ProfileIconColors) savedInstanceState.getSerializable(PROFILE_COLOR_KEY);
String stringKey = savedInstanceState.getString(PROFILE_PARENT_KEY); String stringKey = savedInstanceState.getString(PROFILE_PARENT_KEY);
changedProfile.parent = ApplicationMode.valueOfStringKey(stringKey, null); changedProfile.parent = ApplicationMode.valueOfStringKey(stringKey, null);
OsmandApplication app = getMyApplication();
if (changedProfile.parent == null) { if (changedProfile.parent == null) {
changedProfile.parent = app.getSettings().getApplicationMode(); changedProfile.parent = settings.getApplicationMode();
} }
} }
@ -163,8 +175,8 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
} }
View profileButton = view.findViewById(R.id.profile_button); View profileButton = view.findViewById(R.id.profile_button);
if (profileButton != null) { if (profileButton != null) {
int iconColor = ContextCompat.getColor(getContext(), changedProfile.color.getColor(isNightMode())); int iconColor = ContextCompat.getColor(app, changedProfile.color.getColor(isNightMode()));
AndroidUtils.setBackground(profileButton, UiUtilities.tintDrawable(ContextCompat.getDrawable(getContext(), AndroidUtils.setBackground(profileButton, UiUtilities.tintDrawable(ContextCompat.getDrawable(app,
R.drawable.circle_background_light), UiUtilities.getColorWithAlpha(iconColor, 0.1f))); R.drawable.circle_background_light), UiUtilities.getColorWithAlpha(iconColor, 0.1f)));
ImageView profileIcon = view.findViewById(R.id.profile_icon); ImageView profileIcon = view.findViewById(R.id.profile_icon);
if (profileIcon != null) { if (profileIcon != null) {
@ -200,11 +212,11 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
} }
}); });
} else if (MASTER_PROFILE.equals(preference.getKey())) { } else if (MASTER_PROFILE.equals(preference.getKey())) {
baseProfileName = (EditText) holder.findViewById(R.id.navigation_type_et); baseProfileName = (EditText) holder.findViewById(R.id.master_profile_et);
baseProfileName.setText(changedProfile.parent != null baseProfileName.setText(changedProfile.parent != null
? changedProfile.parent.toHumanString(getContext()) ? changedProfile.parent.toHumanString(getContext())
: getSelectedAppMode().toHumanString(getContext())); : getSelectedAppMode().toHumanString(getContext()));
OsmandTextFieldBoxes baseProfileNameHint = (OsmandTextFieldBoxes) holder.findViewById(R.id.navigation_type_otfb); OsmandTextFieldBoxes baseProfileNameHint = (OsmandTextFieldBoxes) holder.findViewById(R.id.master_profile_otfb);
baseProfileNameHint.setLabelText(getString(R.string.master_profile)); baseProfileNameHint.setLabelText(getString(R.string.master_profile));
FrameLayout selectNavTypeBtn = (FrameLayout) holder.findViewById(R.id.select_nav_type_btn); FrameLayout selectNavTypeBtn = (FrameLayout) holder.findViewById(R.id.select_nav_type_btn);
selectNavTypeBtn.setOnClickListener(new View.OnClickListener() { selectNavTypeBtn.setOnClickListener(new View.OnClickListener() {
@ -230,14 +242,14 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
colorItems = (FlowLayout) holder.findViewById(R.id.color_items); colorItems = (FlowLayout) holder.findViewById(R.id.color_items);
colorItems.removeAllViews(); colorItems.removeAllViews();
for (ApplicationMode.ProfileIconColors color : ApplicationMode.ProfileIconColors.values()) { for (ApplicationMode.ProfileIconColors color : ApplicationMode.ProfileIconColors.values()) {
View view = createColorView(color); View view = createColorItemView(color);
colorItems.addView(view, new FlowLayout.LayoutParams(0, 0)); colorItems.addView(view, new FlowLayout.LayoutParams(0, 0));
ImageView outlineCircle = view.findViewById(R.id.outlineCircle); ImageView outlineCircle = view.findViewById(R.id.outlineCircle);
ImageView checkMark = view.findViewById(R.id.checkMark); ImageView checkMark = view.findViewById(R.id.checkMark);
GradientDrawable gradientDrawable = (GradientDrawable) ContextCompat.getDrawable(getContext(), R.drawable.circle_contour_bg_light); GradientDrawable gradientDrawable = (GradientDrawable) ContextCompat.getDrawable(app, R.drawable.circle_contour_bg_light);
if (gradientDrawable != null) { if (gradientDrawable != null) {
gradientDrawable.setStroke(AndroidUtils.dpToPx(getContext(), 2), gradientDrawable.setStroke(AndroidUtils.dpToPx(app, 2),
UiUtilities.getColorWithAlpha(ContextCompat.getColor(getContext(), color.getColor(isNightMode())), 0.3f)); UiUtilities.getColorWithAlpha(ContextCompat.getColor(app, color.getColor(isNightMode())), 0.3f));
outlineCircle.setImageDrawable(gradientDrawable); outlineCircle.setImageDrawable(gradientDrawable);
} }
checkMark.setVisibility(View.GONE); checkMark.setVisibility(View.GONE);
@ -247,34 +259,9 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
} else if (ICON_ITEMS.equals(preference.getKey())) { } else if (ICON_ITEMS.equals(preference.getKey())) {
iconItems = (FlowLayout) holder.findViewById(R.id.color_items); iconItems = (FlowLayout) holder.findViewById(R.id.color_items);
iconItems.removeAllViews(); iconItems.removeAllViews();
ArrayList<Integer> icons = new ArrayList<>(); ArrayList<Integer> icons = ApplicationMode.ProfileIcons.getIcons();
icons.add(R.drawable.ic_action_car_dark);
icons.add(R.drawable.ic_action_taxi);
icons.add(R.drawable.ic_action_truck_dark);
icons.add(R.drawable.ic_action_shuttle_bus);
icons.add(R.drawable.ic_action_bus_dark);
icons.add(R.drawable.ic_action_subway);
icons.add(R.drawable.ic_action_motorcycle_dark);
icons.add(R.drawable.ic_action_bicycle_dark);
icons.add(R.drawable.ic_action_horse);
icons.add(R.drawable.ic_action_pedestrian_dark);
icons.add(R.drawable.ic_action_trekking_dark);
icons.add(R.drawable.ic_action_skiing);
icons.add(R.drawable.ic_action_sail_boat_dark);
icons.add(R.drawable.ic_action_aircraft);
icons.add(R.drawable.ic_action_helicopter);
icons.add(R.drawable.ic_action_personal_transporter);
icons.add(R.drawable.ic_action_monowheel);
icons.add(R.drawable.ic_action_scooter);
icons.add(R.drawable.ic_action_ufo);
icons.add(R.drawable.ic_action_offroad);
icons.add(R.drawable.ic_action_campervan);
icons.add(R.drawable.ic_action_camper);
icons.add(R.drawable.ic_action_pickup_truck);
icons.add(R.drawable.ic_action_wagon);
icons.add(R.drawable.ic_action_utv);
for (int iconRes : icons) { for (int iconRes : icons) {
View view = createIconView(iconRes); View view = createIconItemView(iconRes);
iconItems.addView(view, new FlowLayout.LayoutParams(0, 0)); iconItems.addView(view, new FlowLayout.LayoutParams(0, 0));
ImageView outlineCircle = view.findViewById(R.id.outlineCircle); ImageView outlineCircle = view.findViewById(R.id.outlineCircle);
outlineCircle.setVisibility(View.GONE); outlineCircle.setVisibility(View.GONE);
@ -283,12 +270,12 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
} }
} }
private View createColorView(final ApplicationMode.ProfileIconColors colorRes) { private View createColorItemView(final ApplicationMode.ProfileIconColors colorRes) {
FrameLayout colorView = (FrameLayout) UiUtilities.getInflater(getContext(), isNightMode()) FrameLayout colorView = (FrameLayout) UiUtilities.getInflater(getContext(), isNightMode())
.inflate(R.layout.preference_circle_item, null, false); .inflate(R.layout.preference_circle_item, null, false);
ImageView coloredCircle = colorView.findViewById(R.id.bckgroundCircle); ImageView coloredCircle = colorView.findViewById(R.id.bckgroundCircle);
coloredCircle.setImageDrawable(getPaintedIcon(R.drawable.circle_background_light, coloredCircle.setImageDrawable(getPaintedIcon(R.drawable.circle_background_light,
ContextCompat.getColor(getContext(), colorRes.getColor(isNightMode())))); ContextCompat.getColor(app, colorRes.getColor(isNightMode()))));
coloredCircle.setOnClickListener(new View.OnClickListener() { coloredCircle.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -315,14 +302,14 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
updateProfileButton(); updateProfileButton();
} }
private View createIconView(final int iconRes) { private View createIconItemView(final int iconRes) {
FrameLayout iconView = (FrameLayout) UiUtilities.getInflater(getContext(), isNightMode()) FrameLayout iconView = (FrameLayout) UiUtilities.getInflater(getContext(), isNightMode())
.inflate(R.layout.preference_circle_item, null, false); .inflate(R.layout.preference_circle_item, null, false);
ImageView checkMark = iconView.findViewById(R.id.checkMark); ImageView checkMark = iconView.findViewById(R.id.checkMark);
checkMark.setImageDrawable(app.getUIUtilities().getIcon(iconRes, R.color.icon_color_default_light)); checkMark.setImageDrawable(app.getUIUtilities().getIcon(iconRes, R.color.icon_color_default_light));
ImageView coloredCircle = iconView.findViewById(R.id.bckgroundCircle); ImageView coloredCircle = iconView.findViewById(R.id.bckgroundCircle);
coloredCircle.setImageDrawable(getPaintedIcon(R.drawable.circle_background_light, coloredCircle.setImageDrawable(getPaintedIcon(R.drawable.circle_background_light,
UiUtilities.getColorWithAlpha(ContextCompat.getColor(getContext(), R.color.icon_color_default_light), 0.1f))); UiUtilities.getColorWithAlpha(ContextCompat.getColor(app, R.color.icon_color_default_light), 0.1f)));
coloredCircle.setOnClickListener(new View.OnClickListener() { coloredCircle.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -343,22 +330,22 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
checkMark.setImageDrawable(app.getUIUtilities().getIcon(changedProfile.iconRes, R.color.icon_color_default_light)); checkMark.setImageDrawable(app.getUIUtilities().getIcon(changedProfile.iconRes, R.color.icon_color_default_light));
ImageView coloredCircle = view.findViewById(R.id.bckgroundCircle); ImageView coloredCircle = view.findViewById(R.id.bckgroundCircle);
coloredCircle.setImageDrawable(getPaintedIcon(R.drawable.circle_background_light, coloredCircle.setImageDrawable(getPaintedIcon(R.drawable.circle_background_light,
UiUtilities.getColorWithAlpha(ContextCompat.getColor(getContext(), R.color.icon_color_default_light), 0.1f))); UiUtilities.getColorWithAlpha(ContextCompat.getColor(app, R.color.icon_color_default_light), 0.1f)));
changedProfile.iconRes = iconRes; changedProfile.iconRes = iconRes;
updateProfileButton(); updateProfileButton();
} }
private void setIconNewColor(int iconRes) { private void setIconNewColor(int iconRes) {
int changedProfileColor = ContextCompat.getColor(getContext(), changedProfile.color.getColor( int changedProfileColor = ContextCompat.getColor(app, changedProfile.color.getColor(
app.getDaynightHelper().isNightModeForMapControls())); app.getDaynightHelper().isNightModeForMapControls()));
View view = iconItems.findViewWithTag(iconRes); View view = iconItems.findViewWithTag(iconRes);
ImageView coloredCircle = view.findViewById(R.id.bckgroundCircle); ImageView coloredCircle = view.findViewById(R.id.bckgroundCircle);
coloredCircle.setImageDrawable(getPaintedIcon(R.drawable.circle_background_light, coloredCircle.setImageDrawable(getPaintedIcon(R.drawable.circle_background_light,
UiUtilities.getColorWithAlpha(ContextCompat.getColor(getContext(), changedProfile.color.getColor(isNightMode())), 0.1f))); UiUtilities.getColorWithAlpha(ContextCompat.getColor(app, changedProfile.color.getColor(isNightMode())), 0.1f)));
ImageView outlineCircle = view.findViewById(R.id.outlineCircle); ImageView outlineCircle = view.findViewById(R.id.outlineCircle);
GradientDrawable gradientDrawable = (GradientDrawable) ContextCompat.getDrawable(getContext(), R.drawable.circle_contour_bg_light); GradientDrawable gradientDrawable = (GradientDrawable) ContextCompat.getDrawable(app, R.drawable.circle_contour_bg_light);
if (gradientDrawable != null) { if (gradientDrawable != null) {
gradientDrawable.setStroke(AndroidUtils.dpToPx(getContext(), 2), changedProfileColor); gradientDrawable.setStroke(AndroidUtils.dpToPx(app, 2), changedProfileColor);
} }
outlineCircle.setImageDrawable(gradientDrawable); outlineCircle.setImageDrawable(gradientDrawable);
outlineCircle.setVisibility(View.VISIBLE); outlineCircle.setVisibility(View.VISIBLE);
@ -392,7 +379,6 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
} }
void updateParentProfile(int pos) { void updateParentProfile(int pos) {
String key = SettingsProfileFragment.getBaseProfiles(getMyApplication()).get(pos).getStringKey(); String key = SettingsProfileFragment.getBaseProfiles(getMyApplication()).get(pos).getStringKey();
setupBaseProfileView(key); setupBaseProfileView(key);
changedProfile.parent = ApplicationMode.valueOfStringKey(key, ApplicationMode.DEFAULT); changedProfile.parent = ApplicationMode.valueOfStringKey(key, ApplicationMode.DEFAULT);
@ -406,8 +392,8 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
} }
} }
/* private boolean saveNewProfile() { private boolean saveNewProfile() {
boolean isNew = true; boolean isNew = false;
if (changedProfile.name.isEmpty() if (changedProfile.name.isEmpty()
|| changedProfile.name.replace(" ", "").length() < 1 || changedProfile.name.replace(" ", "").length() < 1
|| profileName.getText().toString().replace(" ", "").length() < 1) { || profileName.getText().toString().replace(" ", "").length() < 1) {
@ -444,26 +430,16 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
ApplicationMode.ApplicationModeBuilder builder = ApplicationMode ApplicationMode.ApplicationModeBuilder builder = ApplicationMode
.createCustomMode(changedProfile.parent, changedProfile.name.trim(), customStringKey) .createCustomMode(changedProfile.parent, changedProfile.name.trim(), customStringKey)
.icon(app, profile.iconStringName); .icon(app, ApplicationMode.ProfileIcons.getResStringByResId(changedProfile.iconRes))
.setRouteService(changedProfile.routeService)
if(profile.routingProfileDataObject.getStringKey().equals( .setRoutingProfile(changedProfile.routingProfile)
EditProfileFragment.RoutingProfilesResources.STRAIGHT_LINE_MODE.name())) { .setColor(changedProfile.color);
builder.setRouteService(RouteProvider.RouteService.STRAIGHT); ApplicationMode mode = ApplicationMode.saveProfile(builder, getMyApplication());
} else if(profile.routingProfileDataObject.getStringKey().equals(
EditProfileFragment.RoutingProfilesResources.BROUTER_MODE.name())) {
builder.setRouteService(RouteProvider.RouteService.BROUTER);
} else if (profile.routingProfileDataObject != null) {
builder.setRoutingProfile(profile.routingProfileDataObject.getStringKey());
}
builder.setColor(changedProfile.color);
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());
} }
return true; return true;
}*/ }
private void showSaveWarningDialog(String title, String message, Activity activity) { private void showSaveWarningDialog(String title, String message, Activity activity) {
AlertDialog.Builder bld = new AlertDialog.Builder(activity); AlertDialog.Builder bld = new AlertDialog.Builder(activity);
@ -473,10 +449,63 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
bld.show(); bld.show();
} }
public boolean isProfileAppearanceChanged(final MapActivity mapActivity) {
if (isChanged()) {
AlertDialog.Builder dismissDialog = new AlertDialog.Builder(mapActivity);
dismissDialog.setTitle(R.string.shared_string_dismiss);
dismissDialog.setMessage(R.string.exit_without_saving);
dismissDialog.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
changedProfile = profile;
mapActivity.onBackPressed();
}
});
dismissDialog.setNegativeButton(R.string.shared_string_cancel, null);
dismissDialog.show();
return true;
} else {
return false;
}
}
class ApplicationProfileObject { class ApplicationProfileObject {
String stringKey;
ApplicationMode parent = null; ApplicationMode parent = null;
String name; String name;
ApplicationMode.ProfileIconColors color; ApplicationMode.ProfileIconColors color;
int iconRes; int iconRes;
String routingProfile;
RouteProvider.RouteService routeService;
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ApplicationProfileObject that = (ApplicationProfileObject) o;
if (iconRes != that.iconRes) return false;
if (stringKey != null ? !stringKey.equals(that.stringKey) : that.stringKey != null)
return false;
if (parent != null ? !parent.equals(that.parent) : that.parent != null) return false;
if (name != null ? !name.equals(that.name) : that.name != null) return false;
if (color != that.color) return false;
if (routingProfile != null ? !routingProfile.equals(that.routingProfile) : that.routingProfile != null)
return false;
return routeService == that.routeService;
}
@Override
public int hashCode() {
int result = stringKey != null ? stringKey.hashCode() : 0;
result = 31 * result + (parent != null ? parent.hashCode() : 0);
result = 31 * result + (name != null ? name.hashCode() : 0);
result = 31 * result + (color != null ? color.hashCode() : 0);
result = 31 * result + iconRes;
result = 31 * result + (routingProfile != null ? routingProfile.hashCode() : 0);
result = 31 * result + (routeService != null ? routeService.hashCode() : 0);
return result;
}
} }
} }