Save app mode params in osmand settings
This commit is contained in:
parent
6a5cd8ded2
commit
366c6657b7
6 changed files with 200 additions and 333 deletions
|
@ -214,22 +214,15 @@ public class ApplicationMode {
|
|||
values.add(applicationMode);
|
||||
defaultValues.add(applicationMode);
|
||||
if (applicationMode.getOrder() == 0 && !values.isEmpty()) {
|
||||
applicationMode.setOrder(values.size());
|
||||
applicationMode.order = values.size();
|
||||
}
|
||||
return applicationMode;
|
||||
}
|
||||
|
||||
private ApplicationMode customReg() {
|
||||
ApplicationMode m = applicationMode;
|
||||
m.defaultSpeed = m.parentAppMode.defaultSpeed;
|
||||
m.minDistanceForTurn = m.parentAppMode.minDistanceForTurn;
|
||||
m.arrivalDistance = m.parentAppMode.arrivalDistance;
|
||||
m.offRouteDistance = m.parentAppMode.offRouteDistance;
|
||||
m.navigationIcon = m.parentAppMode.navigationIcon;
|
||||
m.locationIcon = m.parentAppMode.locationIcon;
|
||||
values.add(applicationMode);
|
||||
if (applicationMode.getOrder() == 0 && !values.isEmpty()) {
|
||||
applicationMode.setOrder(values.size());
|
||||
applicationMode.order = values.size();
|
||||
}
|
||||
return applicationMode;
|
||||
}
|
||||
|
@ -343,12 +336,6 @@ public class ApplicationMode {
|
|||
return create(parent, -1, stringKey).userProfileTitle(userProfileTitle);
|
||||
}
|
||||
|
||||
public static ApplicationModeBuilder changeBaseMode(ApplicationMode applicationMode) {
|
||||
ApplicationModeBuilder builder = new ApplicationModeBuilder();
|
||||
builder.applicationMode = applicationMode;
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static List<ApplicationMode> values(OsmandApplication app) {
|
||||
if (customizationListener == null) {
|
||||
customizationListener = new OsmAndAppCustomization.OsmAndAppCustomizationListener() {
|
||||
|
@ -539,6 +526,48 @@ public class ApplicationMode {
|
|||
return defaultSpeed;
|
||||
}
|
||||
|
||||
public void setIconResName(OsmandApplication app, String iconResName) {
|
||||
updateAppModeIcon(app, iconResName, this);
|
||||
app.getSettings().ICON_RES_NAME.setModeValue(this, iconResName);
|
||||
}
|
||||
|
||||
public void setIconColor(OsmandApplication app, ProfileIconColors iconColor) {
|
||||
this.iconColor = iconColor;
|
||||
app.getSettings().ICON_COLOR.setModeValue(this, iconColor);
|
||||
}
|
||||
|
||||
public void setUserProfileName(OsmandApplication app, String userProfileName) {
|
||||
this.userProfileName = userProfileName;
|
||||
app.getSettings().USER_PROFILE_NAME.setModeValue(this, userProfileName);
|
||||
}
|
||||
|
||||
public void setParentAppMode(OsmandApplication app, ApplicationMode parentAppMode) {
|
||||
if (isCustomProfile()) {
|
||||
this.parentAppMode = parentAppMode;
|
||||
app.getSettings().PARENT_APP_MODE.setModeValue(this, parentAppMode.getStringKey());
|
||||
}
|
||||
}
|
||||
|
||||
public void setRoutingProfile(OsmandApplication app, String routingProfile) {
|
||||
this.routingProfile = routingProfile;
|
||||
app.getSettings().ROUTING_PROFILE.setModeValue(this, routingProfile);
|
||||
}
|
||||
|
||||
public void setRouteService(OsmandApplication app, RouteService routeService) {
|
||||
this.routeService = routeService;
|
||||
app.getSettings().ROUTE_SERVICE.setModeValue(this, routeService);
|
||||
}
|
||||
|
||||
public void setNavigationIcon(OsmandApplication app, NavigationIcon navigationIcon) {
|
||||
this.navigationIcon = navigationIcon;
|
||||
app.getSettings().NAVIGATION_ICON.setModeValue(this, navigationIcon);
|
||||
}
|
||||
|
||||
public void setLocationIcon(OsmandApplication app, LocationIcon locationIcon) {
|
||||
this.locationIcon = locationIcon;
|
||||
app.getSettings().LOCATION_ICON.setModeValue(this, locationIcon);
|
||||
}
|
||||
|
||||
public void setDefaultSpeed(OsmandApplication app, float defaultSpeed) {
|
||||
this.defaultSpeed = defaultSpeed;
|
||||
app.getSettings().DEFAULT_SPEED.setModeValue(this, defaultSpeed);
|
||||
|
@ -592,30 +621,35 @@ public class ApplicationMode {
|
|||
return order;
|
||||
}
|
||||
|
||||
public void setOrder(int order) {
|
||||
public void setOrder(OsmandApplication app, int order) {
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
public static void onApplicationStart(OsmandApplication app) {
|
||||
// load for default profiles to initialize later custom modes
|
||||
initDefaultModesParams(app);
|
||||
initDefaultSpeed(app);
|
||||
initCustomModes(app);
|
||||
initDefaultSpeed(app);
|
||||
initModesParams(app);
|
||||
initRegVisibility();
|
||||
reorderAppModes();
|
||||
reorderAppModes(app);
|
||||
}
|
||||
|
||||
private static void initDefaultSpeed(OsmandApplication app) {
|
||||
for (ApplicationMode m : values) {
|
||||
float spd = app.getSettings().DEFAULT_SPEED.getModeValue(m);
|
||||
if (spd > 0) {
|
||||
m.defaultSpeed = spd;
|
||||
}
|
||||
private static void initModesParams(OsmandApplication app) {
|
||||
OsmandSettings settings = app.getSettings();
|
||||
for (ApplicationMode mode : allPossibleValues()) {
|
||||
mode.defaultSpeed = settings.DEFAULT_SPEED.getModeValue(mode);
|
||||
updateAppModeIcon(app, settings.ICON_RES_NAME.getModeValue(mode), mode);
|
||||
mode.iconColor = settings.ICON_COLOR.getModeValue(mode);
|
||||
mode.minDistanceForTurn = settings.MIN_DISTANCE_FOR_TURN.getModeValue(mode);
|
||||
mode.arrivalDistance = settings.ARRIVAL_DISTANCE.getModeValue(mode);
|
||||
mode.offRouteDistance = settings.OFF_ROUTE_DISTANCE.getModeValue(mode);
|
||||
mode.navigationIcon = settings.NAVIGATION_ICON.getModeValue(mode);
|
||||
mode.locationIcon = settings.LOCATION_ICON.getModeValue(mode);
|
||||
// mode.order = settings.APP_MODE_ORDER.getModeValue(mode);
|
||||
}
|
||||
}
|
||||
|
||||
public static void reorderAppModes() {
|
||||
public static void reorderAppModes(OsmandApplication app) {
|
||||
Comparator<ApplicationMode> comparator = new Comparator<ApplicationMode>() {
|
||||
@Override
|
||||
public int compare(ApplicationMode mode1, ApplicationMode mode2) {
|
||||
|
@ -625,12 +659,12 @@ public class ApplicationMode {
|
|||
Collections.sort(values, comparator);
|
||||
Collections.sort(defaultValues, comparator);
|
||||
Collections.sort(cachedFilteredValues, comparator);
|
||||
updateAppModesOrder();
|
||||
updateAppModesOrder(app);
|
||||
}
|
||||
|
||||
private static void updateAppModesOrder() {
|
||||
private static void updateAppModesOrder(OsmandApplication app) {
|
||||
for (int i = 0; i < values.size(); i++) {
|
||||
values.get(i).setOrder(i);
|
||||
values.get(i).setOrder(app, i);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -667,78 +701,68 @@ public class ApplicationMode {
|
|||
}
|
||||
|
||||
private static void initDefaultModesParams(OsmandApplication app) {
|
||||
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
|
||||
Type t = new TypeToken<ArrayList<ApplicationModeBean>>() {
|
||||
}.getType();
|
||||
List<ApplicationModeBean> defaultAppModeBeans = gson.fromJson(app.getSettings().DEFAULT_APP_PROFILES.get(), t);
|
||||
OsmandSettings settings = app.getSettings();
|
||||
if (settings.DEFAULT_APP_PROFILES.isSet()) {
|
||||
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
|
||||
Type t = new TypeToken<ArrayList<ApplicationModeBean>>() {
|
||||
}.getType();
|
||||
List<ApplicationModeBean> defaultAppModeBeans = gson.fromJson(settings.DEFAULT_APP_PROFILES.get(), t);
|
||||
|
||||
if (!Algorithms.isEmpty(defaultAppModeBeans)) {
|
||||
for (ApplicationModeBean modeBean : defaultAppModeBeans) {
|
||||
ApplicationMode applicationMode = ApplicationMode.valueOfStringKey(modeBean.stringKey, null);
|
||||
if (applicationMode != null) {
|
||||
applicationMode.userProfileName = modeBean.userProfileName;
|
||||
applicationMode.iconResName = modeBean.iconName;
|
||||
applicationMode.iconColor = modeBean.iconColor;
|
||||
applicationMode.routingProfile = modeBean.routingProfile;
|
||||
applicationMode.routeService = modeBean.routeService;
|
||||
if (modeBean.locIcon != null) {
|
||||
applicationMode.locationIcon = modeBean.locIcon;
|
||||
if (!Algorithms.isEmpty(defaultAppModeBeans)) {
|
||||
for (ApplicationModeBean modeBean : defaultAppModeBeans) {
|
||||
ApplicationMode mode = ApplicationMode.valueOfStringKey(modeBean.stringKey, null);
|
||||
if (mode != null) {
|
||||
settings.ICON_RES_NAME.setModeValue(mode, modeBean.iconName);
|
||||
settings.ICON_COLOR.setModeValue(mode, modeBean.iconColor);
|
||||
settings.USER_PROFILE_NAME.setModeValue(mode, modeBean.userProfileName);
|
||||
settings.ROUTING_PROFILE.setModeValue(mode, modeBean.routingProfile);
|
||||
settings.ROUTE_SERVICE.setModeValue(mode, modeBean.routeService);
|
||||
// settings.APP_MODE_ORDER.setModeValue(mode, modeBean.order);
|
||||
if (modeBean.locIcon != null) {
|
||||
settings.LOCATION_ICON.setModeValue(mode, modeBean.locIcon);
|
||||
}
|
||||
if (modeBean.navIcon != null) {
|
||||
settings.NAVIGATION_ICON.setModeValue(mode, modeBean.navIcon);
|
||||
}
|
||||
}
|
||||
if (modeBean.navIcon != null) {
|
||||
applicationMode.navigationIcon = modeBean.navIcon;
|
||||
}
|
||||
applicationMode.order = modeBean.order;
|
||||
}
|
||||
}
|
||||
settings.DEFAULT_APP_PROFILES.resetToDefault();
|
||||
}
|
||||
}
|
||||
|
||||
private static void initCustomModes(OsmandApplication app) {
|
||||
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
|
||||
Type t = new TypeToken<ArrayList<ApplicationModeBean>>() {
|
||||
}.getType();
|
||||
List<ApplicationModeBean> customProfiles = gson.fromJson(app.getSettings().CUSTOM_APP_PROFILES.get(), t);
|
||||
|
||||
if (!Algorithms.isEmpty(customProfiles)) {
|
||||
for (ApplicationModeBean m : customProfiles) {
|
||||
ApplicationMode parentMode = valueOfStringKey(m.parent, CAR);
|
||||
createCustomMode(parentMode, m.userProfileName, m.stringKey)
|
||||
.setRouteService(m.routeService)
|
||||
.setRoutingProfile(m.routingProfile)
|
||||
.icon(app, m.iconName)
|
||||
.setColor(m.iconColor)
|
||||
.locationIcon(m.locIcon)
|
||||
.navigationIcon(m.navIcon)
|
||||
.setOrder(m.order)
|
||||
.customReg();
|
||||
OsmandSettings settings = app.getSettings();
|
||||
if (settings.CUSTOM_APP_PROFILES.isSet()) {
|
||||
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
|
||||
Type t = new TypeToken<ArrayList<ApplicationModeBean>>() {
|
||||
}.getType();
|
||||
List<ApplicationModeBean> customProfiles = gson.fromJson(app.getSettings().CUSTOM_APP_PROFILES.get(), t);
|
||||
List<String> customModesKeys = new ArrayList<>();
|
||||
if (!Algorithms.isEmpty(customProfiles)) {
|
||||
for (ApplicationModeBean m : customProfiles) {
|
||||
customModesKeys.add(m.stringKey);
|
||||
ApplicationMode parentMode = valueOfStringKey(m.parent, CAR);
|
||||
createCustomMode(parentMode, m.userProfileName, m.stringKey)
|
||||
.setRouteService(m.routeService)
|
||||
.setRoutingProfile(m.routingProfile)
|
||||
.icon(app, m.iconName)
|
||||
.setColor(m.iconColor)
|
||||
.locationIcon(m.locIcon)
|
||||
.navigationIcon(m.navIcon)
|
||||
.setOrder(m.order)
|
||||
.customReg();
|
||||
}
|
||||
}
|
||||
settings.CUSTOM_APP_MODES_KEYS.set(gson.toJson(customModesKeys));
|
||||
settings.CUSTOM_APP_PROFILES.resetToDefault();
|
||||
}
|
||||
}
|
||||
|
||||
public static void saveAppModesToSettings(OsmandApplication app) {
|
||||
private static void saveAppModesToSettings(OsmandSettings settings) {
|
||||
List<ApplicationModeBean> modeBeans = createApplicationModeBeans(getCustomValues());
|
||||
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
|
||||
|
||||
List<ApplicationModeBean> defaultModeBeans = createApplicationModeBeans(defaultValues);
|
||||
List<ApplicationModeBean> customModeBeans = createApplicationModeBeans(getCustomValues());
|
||||
|
||||
String defaultProfiles = gson.toJson(defaultModeBeans);
|
||||
String customProfiles = gson.toJson(customModeBeans);
|
||||
|
||||
app.getSettings().DEFAULT_APP_PROFILES.set(defaultProfiles);
|
||||
app.getSettings().CUSTOM_APP_PROFILES.set(customProfiles);
|
||||
}
|
||||
|
||||
private static void saveAppModesToSettings(OsmandSettings settings, boolean saveCustomModes) {
|
||||
List<ApplicationMode> appModes = saveCustomModes ? getCustomValues() : defaultValues;
|
||||
List<ApplicationModeBean> modeBeans = createApplicationModeBeans(appModes);
|
||||
|
||||
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
|
||||
String profiles = gson.toJson(modeBeans);
|
||||
if (saveCustomModes) {
|
||||
settings.CUSTOM_APP_PROFILES.set(profiles);
|
||||
} else {
|
||||
settings.DEFAULT_APP_PROFILES.set(profiles);
|
||||
}
|
||||
settings.CUSTOM_APP_PROFILES.set(gson.toJson(modeBeans));
|
||||
}
|
||||
|
||||
private static List<ApplicationModeBean> createApplicationModeBeans(List<ApplicationMode> applicationModes) {
|
||||
|
@ -762,36 +786,23 @@ public class ApplicationMode {
|
|||
|
||||
public static ApplicationMode saveProfile(ApplicationModeBuilder builder, OsmandApplication app) {
|
||||
ApplicationMode mode = ApplicationMode.valueOfStringKey(builder.applicationMode.stringKey, null);
|
||||
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;
|
||||
mode.routeService = builder.applicationMode.routeService;
|
||||
mode.iconColor = builder.applicationMode.iconColor;
|
||||
mode.locationIcon = builder.applicationMode.locationIcon;
|
||||
mode.navigationIcon = builder.applicationMode.navigationIcon;
|
||||
mode.order = builder.applicationMode.order;
|
||||
} else {
|
||||
if (mode == null) {
|
||||
mode = builder.customReg();
|
||||
initRegVisibility();
|
||||
}
|
||||
saveAppModesToSettings(app.getSettings(), mode.isCustomProfile());
|
||||
return mode;
|
||||
}
|
||||
|
||||
public static void deleteCustomMode(ApplicationMode md, OsmandApplication app) {
|
||||
Iterator<ApplicationMode> it = values.iterator();
|
||||
while (it.hasNext()) {
|
||||
ApplicationMode m = it.next();
|
||||
if (m == md) {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
cachedFilteredValues.remove(md);
|
||||
saveAppModesToSettings(app.getSettings(), md.isCustomProfile());
|
||||
mode.setIconResName(app, builder.applicationMode.iconResName);
|
||||
mode.setUserProfileName(app, builder.applicationMode.userProfileName);
|
||||
mode.setParentAppMode(app, builder.applicationMode.parentAppMode);
|
||||
mode.setRoutingProfile(app, builder.applicationMode.routingProfile);
|
||||
mode.setRouteService(app, builder.applicationMode.routeService);
|
||||
mode.setIconColor(app, builder.applicationMode.iconColor);
|
||||
mode.setLocationIcon(app, builder.applicationMode.locationIcon);
|
||||
mode.setNavigationIcon(app, builder.applicationMode.navigationIcon);
|
||||
mode.setOrder(app, builder.applicationMode.order);
|
||||
|
||||
saveAppModesToSettings(app.getSettings());
|
||||
return mode;
|
||||
}
|
||||
|
||||
public static void deleteCustomModes(List<ApplicationMode> modes, OsmandApplication app) {
|
||||
|
@ -802,171 +813,33 @@ public class ApplicationMode {
|
|||
it.remove();
|
||||
}
|
||||
}
|
||||
OsmandSettings settings = app.getSettings();
|
||||
if (modes.contains(settings.APPLICATION_MODE.get())) {
|
||||
settings.APPLICATION_MODE.resetToDefault();
|
||||
}
|
||||
cachedFilteredValues.removeAll(modes);
|
||||
saveAppModesToSettings(app.getSettings(), true);
|
||||
saveAppModesToSettings(app.getSettings());
|
||||
}
|
||||
|
||||
public static boolean changeProfileAvailability(ApplicationMode mode, boolean isSelected, OsmandApplication app) {
|
||||
Set<ApplicationMode> selectedModes = new LinkedHashSet<>(ApplicationMode.values(app));
|
||||
StringBuilder vls = new StringBuilder(ApplicationMode.DEFAULT.getStringKey() + ",");
|
||||
if (allPossibleValues().contains(mode)) {
|
||||
OsmandSettings settings = app.getSettings();
|
||||
if (isSelected) {
|
||||
selectedModes.add(mode);
|
||||
} else {
|
||||
selectedModes.remove(mode);
|
||||
if (app.getSettings().APPLICATION_MODE.get() == mode) {
|
||||
app.getSettings().APPLICATION_MODE.set(ApplicationMode.DEFAULT);
|
||||
if (settings.APPLICATION_MODE.get() == mode) {
|
||||
settings.APPLICATION_MODE.resetToDefault();
|
||||
}
|
||||
}
|
||||
for (ApplicationMode m : selectedModes) {
|
||||
vls.append(m.getStringKey()).append(",");
|
||||
}
|
||||
app.getSettings().AVAILABLE_APP_MODES.set(vls.toString());
|
||||
settings.AVAILABLE_APP_MODES.set(vls.toString());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public enum ProfileIconColors {
|
||||
DEFAULT(R.string.rendering_value_default_name, R.color.profile_icon_color_blue_light_default, R.color.profile_icon_color_blue_dark_default),
|
||||
PURPLE(R.string.rendering_value_purple_name, R.color.profile_icon_color_purple_light, R.color.profile_icon_color_purple_dark),
|
||||
GREEN(R.string.rendering_value_green_name, R.color.profile_icon_color_green_light, R.color.profile_icon_color_green_dark),
|
||||
BLUE(R.string.rendering_value_blue_name, R.color.profile_icon_color_blue_light, R.color.profile_icon_color_blue_dark),
|
||||
RED(R.string.rendering_value_red_name, R.color.profile_icon_color_red_light, R.color.profile_icon_color_red_dark),
|
||||
DARK_YELLOW(R.string.rendering_value_darkyellow_name, R.color.profile_icon_color_yellow_light, R.color.profile_icon_color_yellow_dark),
|
||||
MAGENTA(R.string.shared_string_color_magenta, R.color.profile_icon_color_magenta_light, R.color.profile_icon_color_magenta_dark);
|
||||
|
||||
@StringRes
|
||||
private int name;
|
||||
@ColorRes
|
||||
private int dayColor;
|
||||
@ColorRes
|
||||
private int nightColor;
|
||||
|
||||
ProfileIconColors(@StringRes int name, @ColorRes int dayColor, @ColorRes int nightColor) {
|
||||
this.name = name;
|
||||
this.dayColor = dayColor;
|
||||
this.nightColor = nightColor;
|
||||
}
|
||||
|
||||
public int getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getColor(boolean nightMode) {
|
||||
return nightMode ? nightColor : dayColor;
|
||||
}
|
||||
}
|
||||
|
||||
public enum ProfileIcons {
|
||||
DEFAULT(R.drawable.ic_world_globe_dark, R.string.app_mode_default, "ic_world_globe_dark"),
|
||||
CAR(R.drawable.ic_action_car_dark, R.string.app_mode_car, "ic_action_car_dark"),
|
||||
TAXI(R.drawable.ic_action_taxi, R.string.app_mode_taxi, "ic_action_taxi"),
|
||||
TRUCK(R.drawable.ic_action_truck_dark, R.string.app_mode_truck, "ic_action_truck_dark"),
|
||||
SHUTTLE_BUS(R.drawable.ic_action_shuttle_bus, R.string.app_mode_shuttle_bus, "ic_action_shuttle_bus"),
|
||||
BUS(R.drawable.ic_action_bus_dark, R.string.app_mode_bus, "ic_action_bus_dark"),
|
||||
SUBWAY(R.drawable.ic_action_subway, R.string.app_mode_subway, "ic_action_subway"),
|
||||
MOTORCYCLE(R.drawable.ic_action_motorcycle_dark, R.string.app_mode_motorcycle, "ic_action_motorcycle_dark"),
|
||||
BICYCLE(R.drawable.ic_action_bicycle_dark, R.string.app_mode_bicycle, "ic_action_bicycle_dark"),
|
||||
HORSE(R.drawable.ic_action_horse, R.string.app_mode_horse, "ic_action_horse"),
|
||||
PEDESTRIAN(R.drawable.ic_action_pedestrian_dark, R.string.app_mode_pedestrian, "ic_action_pedestrian_dark"),
|
||||
TREKKING(R.drawable.ic_action_trekking_dark, R.string.app_mode_hiking, "ic_action_trekking_dark"),
|
||||
SKIING(R.drawable.ic_action_skiing, R.string.app_mode_skiing, "ic_action_skiing"),
|
||||
SAIL_BOAT(R.drawable.ic_action_sail_boat_dark, R.string.app_mode_boat, "ic_action_sail_boat_dark"),
|
||||
AIRCRAFT(R.drawable.ic_action_aircraft, R.string.app_mode_aircraft, "ic_action_aircraft"),
|
||||
HELICOPTER(R.drawable.ic_action_helicopter, R.string.app_mode_helicopter, "ic_action_helicopter"),
|
||||
TRANSPORTER(R.drawable.ic_action_personal_transporter, R.string.app_mode_personal_transporter, "ic_action_personal_transporter"),
|
||||
MONOWHEEL(R.drawable.ic_action_monowheel, R.string.app_mode_monowheel, "ic_action_monowheel"),
|
||||
SCOOTER(R.drawable.ic_action_scooter, R.string.app_mode_scooter, "ic_action_scooter"),
|
||||
UFO(R.drawable.ic_action_ufo, R.string.app_mode_ufo, "ic_action_ufo"),
|
||||
OFFROAD(R.drawable.ic_action_offroad, R.string.app_mode_offroad, "ic_action_offroad"),
|
||||
CAMPERVAN(R.drawable.ic_action_campervan, R.string.app_mode_campervan, "ic_action_campervan"),
|
||||
CAMPER(R.drawable.ic_action_camper, R.string.app_mode_camper, "ic_action_camper"),
|
||||
PICKUP_TRUCK(R.drawable.ic_action_pickup_truck, R.string.app_mode_pickup_truck, "ic_action_pickup_truck"),
|
||||
WAGON(R.drawable.ic_action_wagon, R.string.app_mode_wagon, "ic_action_wagon"),
|
||||
UTV(R.drawable.ic_action_utv, R.string.app_mode_utv, "ic_action_utv"),
|
||||
OSM(R.drawable.ic_action_openstreetmap_logo, R.string.app_mode_osm, "ic_action_openstreetmap_logo");
|
||||
|
||||
@DrawableRes
|
||||
private int resId;
|
||||
@StringRes
|
||||
private int titleId;
|
||||
private String resStringId;
|
||||
|
||||
ProfileIcons(@DrawableRes int resId, @StringRes int titleId, @NonNull String resStringId) {
|
||||
this.resId = resId;
|
||||
this.titleId = titleId;
|
||||
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 DEFAULT.getResStringId();
|
||||
}
|
||||
}
|
||||
|
||||
public enum LocationIcon {
|
||||
DEFAULT(R.drawable.map_location_default, R.drawable.map_location_default_view_angle),
|
||||
CAR(R.drawable.map_location_car, R.drawable.map_location_car_view_angle),
|
||||
BICYCLE(R.drawable.map_location_bicycle, R.drawable.map_location_bicycle_view_angle);
|
||||
|
||||
LocationIcon(@DrawableRes int iconId, @DrawableRes int headingIconId) {
|
||||
this.iconId = iconId;
|
||||
this.headingIconId = headingIconId;
|
||||
}
|
||||
|
||||
@DrawableRes
|
||||
private final int iconId;
|
||||
@DrawableRes
|
||||
private final int headingIconId;
|
||||
|
||||
public int getIconId() {
|
||||
return iconId;
|
||||
}
|
||||
|
||||
public int getHeadingIconId() {
|
||||
return headingIconId;
|
||||
}
|
||||
}
|
||||
|
||||
public enum NavigationIcon {
|
||||
DEFAULT(R.drawable.map_navigation_default),
|
||||
NAUTICAL(R.drawable.map_navigation_nautical),
|
||||
CAR(R.drawable.map_navigation_car);
|
||||
|
||||
NavigationIcon(@DrawableRes int iconId) {
|
||||
this.iconId = iconId;
|
||||
}
|
||||
|
||||
@DrawableRes
|
||||
private final int iconId;
|
||||
|
||||
public int getIconId() {
|
||||
return iconId;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1240,11 +1240,7 @@ public class OsmandSettings {
|
|||
|
||||
public final OsmandPreference<String> LAST_FAV_CATEGORY_ENTERED = new StringPreference("last_fav_category", "").makeGlobal();
|
||||
|
||||
|
||||
public final OsmandPreference<ApplicationMode> DEFAULT_APPLICATION_MODE = new CommonPreference<ApplicationMode>("default_application_mode_string", ApplicationMode.DEFAULT) {
|
||||
{
|
||||
makeGlobal();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ApplicationMode getValue(Object prefs, ApplicationMode defaultValue) {
|
||||
|
@ -1292,12 +1288,9 @@ public class OsmandSettings {
|
|||
public ApplicationMode parseString(String s) {
|
||||
return appModeFromString(s);
|
||||
}
|
||||
};
|
||||
}.makeGlobal();
|
||||
|
||||
public final OsmandPreference<ApplicationMode> LAST_ROUTE_APPLICATION_MODE = new CommonPreference<ApplicationMode>("last_route_application_mode_backup_string", ApplicationMode.DEFAULT) {
|
||||
{
|
||||
makeGlobal();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ApplicationMode getValue(Object prefs, ApplicationMode defaultValue) {
|
||||
|
@ -1340,7 +1333,7 @@ public class OsmandSettings {
|
|||
public ApplicationMode parseString(String s) {
|
||||
return appModeFromString(s);
|
||||
}
|
||||
};
|
||||
}.makeGlobal();
|
||||
|
||||
public final OsmandPreference<Boolean> FIRST_MAP_IS_DOWNLOADED = new BooleanPreference(
|
||||
"first_map_is_downloaded", false);
|
||||
|
@ -1355,8 +1348,6 @@ public class OsmandSettings {
|
|||
return super.setValue(prefs, val);
|
||||
}
|
||||
|
||||
;
|
||||
|
||||
protected DrivingRegion getDefaultValue() {
|
||||
Locale df = Locale.getDefault();
|
||||
if (df == null) {
|
||||
|
@ -1441,9 +1432,6 @@ public class OsmandSettings {
|
|||
return SpeedConstants.MILES_PER_HOUR;
|
||||
}
|
||||
}
|
||||
|
||||
;
|
||||
|
||||
}.makeProfile();
|
||||
|
||||
|
||||
|
@ -1461,9 +1449,6 @@ public class OsmandSettings {
|
|||
public final OsmandPreference<Float> SPEECH_RATE =
|
||||
new FloatPreference("speech_rate", 1f).makeProfile();
|
||||
|
||||
public final OsmandPreference<Float> ARRIVAL_DISTANCE_FACTOR =
|
||||
new FloatPreference("arrival_distance_factor", 1f).makeProfile();
|
||||
|
||||
public final OsmandPreference<Float> SPEED_LIMIT_EXCEED =
|
||||
new FloatPreference("speed_limit_exceed", 5f).makeProfile();
|
||||
|
||||
|
@ -1502,6 +1487,8 @@ public class OsmandSettings {
|
|||
|
||||
public final CommonPreference<String> USER_PROFILE_NAME = new StringPreference("user_profile_name", "").makeProfile().cache();
|
||||
|
||||
public final CommonPreference<String> PARENT_APP_MODE = new StringPreference("parent_app_mode", null).makeProfile().cache();
|
||||
|
||||
public final CommonPreference<String> ROUTING_PROFILE = new StringPreference("routing_profile", "").makeProfile().cache();
|
||||
|
||||
{
|
||||
|
@ -1532,6 +1519,8 @@ public class OsmandSettings {
|
|||
MIN_DISTANCE_FOR_TURN.setModeDefaultValue(ApplicationMode.SKI, 15);
|
||||
}
|
||||
|
||||
public final OsmandPreference<Float> ARRIVAL_DISTANCE_FACTOR = new FloatPreference("arrival_distance_factor", 1f).makeProfile().cache();
|
||||
|
||||
public final CommonPreference<Integer> ARRIVAL_DISTANCE = new IntPreference("arrival_distance", 90).makeProfile().cache();
|
||||
|
||||
{
|
||||
|
@ -1571,7 +1560,7 @@ public class OsmandSettings {
|
|||
LOCATION_ICON.setModeDefaultValue(ApplicationMode.SKI, LocationIcon.BICYCLE);
|
||||
}
|
||||
|
||||
public final CommonPreference<Integer> APP_MODE_ORDER = new IntPreference("app_mode_order", 0).makeProfile().cache();
|
||||
// public final CommonPreference<Integer> APP_MODE_ORDER = new IntPreference("app_mode_order", 0).makeProfile().cache();
|
||||
|
||||
public final OsmandPreference<Float> SWITCH_MAP_DIRECTION_TO_COMPASS =
|
||||
new FloatPreference("speed_for_map_to_direction_of_movement", 0f).makeProfile();
|
||||
|
@ -1728,8 +1717,6 @@ public class OsmandSettings {
|
|||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
;
|
||||
}.makeGlobal().cache();
|
||||
|
||||
public final CommonPreference<Boolean> SNAP_TO_ROAD = new BooleanPreference("snap_to_road", false).makeProfile().cache();
|
||||
|
@ -3402,6 +3389,8 @@ public class OsmandSettings {
|
|||
public final CommonPreference<String> CUSTOM_APP_PROFILES =
|
||||
new StringPreference("custom_app_profiles", "").makeGlobal().cache();
|
||||
|
||||
public final CommonPreference<String> CUSTOM_APP_MODES_KEYS =
|
||||
new StringPreference("custom_app_modes_keys", "").makeGlobal().cache();
|
||||
|
||||
public enum DayNightMode {
|
||||
AUTO(R.string.daynight_mode_auto, R.drawable.ic_action_map_sunset),
|
||||
|
|
|
@ -23,7 +23,6 @@ import android.widget.TextView;
|
|||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.UiUtilities;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
|
@ -150,7 +149,6 @@ public class EditProfilesFragment extends BaseOsmAndFragment {
|
|||
MapActivity mapActivity = (MapActivity) getActivity();
|
||||
if (mapActivity != null) {
|
||||
OsmandApplication app = mapActivity.getMyApplication();
|
||||
OsmandSettings settings = app.getSettings();
|
||||
|
||||
if (!deletedModesKeys.isEmpty()) {
|
||||
List<ApplicationMode> deletedModes = new ArrayList<>();
|
||||
|
@ -161,9 +159,6 @@ public class EditProfilesFragment extends BaseOsmAndFragment {
|
|||
}
|
||||
}
|
||||
ApplicationMode.deleteCustomModes(deletedModes, app);
|
||||
if (deletedModes.contains(settings.APPLICATION_MODE.get())) {
|
||||
settings.APPLICATION_MODE.resetToDefault();
|
||||
}
|
||||
}
|
||||
for (ApplicationMode mode : ApplicationMode.allPossibleValues()) {
|
||||
String modeKey = mode.getStringKey();
|
||||
|
@ -171,10 +166,9 @@ public class EditProfilesFragment extends BaseOsmAndFragment {
|
|||
if (order == null) {
|
||||
order = mode.getOrder();
|
||||
}
|
||||
mode.setOrder(order);
|
||||
mode.setOrder(app, order);
|
||||
}
|
||||
ApplicationMode.reorderAppModes();
|
||||
ApplicationMode.saveAppModesToSettings(app);
|
||||
ApplicationMode.reorderAppModes(app);
|
||||
mapActivity.onBackPressed();
|
||||
}
|
||||
}
|
||||
|
@ -273,7 +267,7 @@ public class EditProfilesFragment extends BaseOsmAndFragment {
|
|||
private boolean deleted;
|
||||
private boolean customProfile;
|
||||
|
||||
EditProfileDataObject(String stringKey, String name, String descr, int iconRes, boolean isSelected, boolean customProfile, boolean deleted, ApplicationMode.ProfileIconColors iconColor, int order) {
|
||||
EditProfileDataObject(String stringKey, String name, String descr, int iconRes, boolean isSelected, boolean customProfile, boolean deleted, ProfileIconColors iconColor, int order) {
|
||||
super(name, descr, stringKey, iconRes, isSelected, iconColor);
|
||||
this.customProfile = customProfile;
|
||||
this.deleted = deleted;
|
||||
|
|
|
@ -49,6 +49,7 @@ import net.osmand.plus.skimapsplugin.SkiMapsPlugin;
|
|||
import org.apache.commons.logging.Log;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static net.osmand.plus.UiUtilities.CompoundButtonType.TOOLBAR;
|
||||
|
@ -413,8 +414,7 @@ public class ConfigureProfileFragment extends BaseSettingsFragment implements Co
|
|||
public void onClick(DialogInterface dialog, int which) {
|
||||
OsmandApplication app = getMyApplication();
|
||||
if (app != null) {
|
||||
ApplicationMode.deleteCustomMode(ApplicationMode.valueOfStringKey(profile.getStringKey(), ApplicationMode.DEFAULT), app);
|
||||
app.getSettings().APPLICATION_MODE.set(ApplicationMode.DEFAULT);
|
||||
ApplicationMode.deleteCustomModes(Collections.singletonList(profile), app);
|
||||
}
|
||||
|
||||
if (getActivity() != null) {
|
||||
|
|
|
@ -138,18 +138,14 @@ public class NavigationFragment extends BaseSettingsFragment {
|
|||
}
|
||||
navigationType.setSummary(selectedRoutingProfileDataObject.getName());
|
||||
navigationType.setIcon(getContentIcon(selectedRoutingProfileDataObject.getIconRes()));
|
||||
ApplicationMode.ApplicationModeBuilder builder = ApplicationMode.changeBaseMode(getSelectedAppMode());
|
||||
if (profileKey.equals(RoutingProfilesResources.STRAIGHT_LINE_MODE.name())) {
|
||||
builder.setRouteService(RouteProvider.RouteService.STRAIGHT);
|
||||
} else if (profileKey.equals(RoutingProfilesResources.BROUTER_MODE.name())) {
|
||||
builder.setRouteService(RouteProvider.RouteService.BROUTER);
|
||||
} else {
|
||||
builder.setRoutingProfile(profileKey);
|
||||
}
|
||||
|
||||
ApplicationMode mode = ApplicationMode.saveProfile(builder, app);
|
||||
if (!ApplicationMode.values(app).contains(mode)) {
|
||||
ApplicationMode.changeProfileAvailability(mode, true, app);
|
||||
ApplicationMode appMode = getSelectedAppMode();
|
||||
if (profileKey.equals(RoutingProfilesResources.STRAIGHT_LINE_MODE.name())) {
|
||||
appMode.setRouteService(app, RouteProvider.RouteService.STRAIGHT);
|
||||
} else if (profileKey.equals(RoutingProfilesResources.BROUTER_MODE.name())) {
|
||||
appMode.setRouteService(app, RouteProvider.RouteService.BROUTER);
|
||||
} else {
|
||||
appMode.setRoutingProfile(app, profileKey);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -49,6 +49,7 @@ import net.osmand.util.Algorithms;
|
|||
import org.apache.commons.logging.Log;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_SETTINGS_ID;
|
||||
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.DIALOG_TYPE;
|
||||
|
@ -280,12 +281,12 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
|
|||
changedProfile.name = savedInstanceState.getString(PROFILE_NAME_KEY);
|
||||
changedProfile.stringKey = savedInstanceState.getString(PROFILE_STRINGKEY_KEY);
|
||||
changedProfile.iconRes = savedInstanceState.getInt(PROFILE_ICON_RES_KEY);
|
||||
changedProfile.color = (ApplicationMode.ProfileIconColors) savedInstanceState.getSerializable(PROFILE_COLOR_KEY);
|
||||
changedProfile.color = (ProfileIconColors) savedInstanceState.getSerializable(PROFILE_COLOR_KEY);
|
||||
String parentStringKey = savedInstanceState.getString(PROFILE_PARENT_KEY);
|
||||
changedProfile.parent = ApplicationMode.valueOfStringKey(parentStringKey, null);
|
||||
isBaseProfileImported = savedInstanceState.getBoolean(IS_BASE_PROFILE_IMPORTED);
|
||||
changedProfile.locationIcon = (ApplicationMode.LocationIcon) savedInstanceState.getSerializable(PROFILE_LOCATION_ICON_KEY);
|
||||
changedProfile.navigationIcon = (ApplicationMode.NavigationIcon) savedInstanceState.getSerializable(PROFILE_NAVIGATION_ICON_KEY);
|
||||
changedProfile.locationIcon = (LocationIcon) savedInstanceState.getSerializable(PROFILE_LOCATION_ICON_KEY);
|
||||
changedProfile.navigationIcon = (NavigationIcon) savedInstanceState.getSerializable(PROFILE_NAVIGATION_ICON_KEY);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -372,7 +373,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
|
|||
} else if (COLOR_ITEMS.equals(preference.getKey())) {
|
||||
colorItems = (FlowLayout) holder.findViewById(R.id.color_items);
|
||||
colorItems.removeAllViews();
|
||||
for (ApplicationMode.ProfileIconColors color : ApplicationMode.ProfileIconColors.values()) {
|
||||
for (ProfileIconColors color : ProfileIconColors.values()) {
|
||||
View colorItem = createColorItemView(color, colorItems);
|
||||
colorItems.addView(colorItem, new FlowLayout.LayoutParams(0, 0));
|
||||
|
||||
|
@ -381,7 +382,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
|
|||
} else if (ICON_ITEMS.equals(preference.getKey())) {
|
||||
iconItems = (FlowLayout) holder.findViewById(R.id.color_items);
|
||||
iconItems.removeAllViews();
|
||||
ArrayList<Integer> icons = ApplicationMode.ProfileIcons.getIcons();
|
||||
ArrayList<Integer> icons = ProfileIcons.getIcons();
|
||||
for (int iconRes : icons) {
|
||||
View iconItem = createIconItemView(iconRes, iconItems);
|
||||
iconItems.addView(iconItem, new FlowLayout.LayoutParams(0, 0));
|
||||
|
@ -390,7 +391,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
|
|||
} else if (LOCATION_ICON_ITEMS.equals(preference.getKey())) {
|
||||
locationIconItems = (FlowLayout) holder.findViewById(R.id.color_items);
|
||||
locationIconItems.removeAllViews();
|
||||
for (ApplicationMode.LocationIcon locationIcon : ApplicationMode.LocationIcon.values()) {
|
||||
for (LocationIcon locationIcon : LocationIcon.values()) {
|
||||
View iconItemView = createLocationIconView(locationIcon, locationIconItems);
|
||||
locationIconItems.addView(iconItemView, new FlowLayout.LayoutParams(0, 0));
|
||||
}
|
||||
|
@ -398,7 +399,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
|
|||
} else if (NAV_ICON_ITEMS.equals(preference.getKey())) {
|
||||
navIconItems = (FlowLayout) holder.findViewById(R.id.color_items);
|
||||
navIconItems.removeAllViews();
|
||||
for (ApplicationMode.NavigationIcon navigationIcon : ApplicationMode.NavigationIcon.values()) {
|
||||
for (NavigationIcon navigationIcon : NavigationIcon.values()) {
|
||||
View iconItemView = createNavigationIconView(navigationIcon, navIconItems);
|
||||
navIconItems.addView(iconItemView, new FlowLayout.LayoutParams(0, 0));
|
||||
}
|
||||
|
@ -406,7 +407,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
|
|||
}
|
||||
}
|
||||
|
||||
private View createColorItemView(final ApplicationMode.ProfileIconColors colorRes, ViewGroup rootView) {
|
||||
private View createColorItemView(final ProfileIconColors colorRes, ViewGroup rootView) {
|
||||
FrameLayout colorItemView = (FrameLayout) UiUtilities.getInflater(getContext(), isNightMode())
|
||||
.inflate(R.layout.preference_circle_item, rootView, false);
|
||||
ImageView coloredCircle = colorItemView.findViewById(R.id.backgroundCircle);
|
||||
|
@ -439,7 +440,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
|
|||
return colorItemView;
|
||||
}
|
||||
|
||||
private void updateColorSelector(ApplicationMode.ProfileIconColors color) {
|
||||
private void updateColorSelector(ProfileIconColors color) {
|
||||
View colorItem = colorItems.findViewWithTag(changedProfile.color);
|
||||
colorItem.findViewById(R.id.outlineCircle).setVisibility(View.GONE);
|
||||
colorItem.findViewById(R.id.checkMark).setVisibility(View.GONE);
|
||||
|
@ -499,7 +500,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
|
|||
updateProfileButton();
|
||||
}
|
||||
|
||||
private View createLocationIconView(final ApplicationMode.LocationIcon locationIcon, ViewGroup rootView) {
|
||||
private View createLocationIconView(final LocationIcon locationIcon, ViewGroup rootView) {
|
||||
FrameLayout locationIconView = (FrameLayout) UiUtilities.getInflater(getContext(), isNightMode())
|
||||
.inflate(R.layout.preference_select_icon_button, rootView, false);
|
||||
int changedProfileColor = ContextCompat.getColor(app, changedProfile.color.getColor(
|
||||
|
@ -533,7 +534,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
|
|||
return locationIconView;
|
||||
}
|
||||
|
||||
private void updateLocationIconSelector(ApplicationMode.LocationIcon locationIcon) {
|
||||
private void updateLocationIconSelector(LocationIcon locationIcon) {
|
||||
View viewWithTag = locationIconItems.findViewWithTag(changedProfile.locationIcon);
|
||||
viewWithTag.findViewById(R.id.outlineRect).setVisibility(View.GONE);
|
||||
viewWithTag = locationIconItems.findViewWithTag(locationIcon);
|
||||
|
@ -541,7 +542,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
|
|||
changedProfile.locationIcon = locationIcon;
|
||||
}
|
||||
|
||||
private View createNavigationIconView(final ApplicationMode.NavigationIcon navigationIcon, ViewGroup rootView) {
|
||||
private View createNavigationIconView(final NavigationIcon navigationIcon, ViewGroup rootView) {
|
||||
FrameLayout navigationIconView = (FrameLayout) UiUtilities.getInflater(getContext(), isNightMode())
|
||||
.inflate(R.layout.preference_select_icon_button, rootView, false);
|
||||
LayerDrawable navigationIconDrawable = (LayerDrawable) app.getResources().getDrawable(navigationIcon.getIconId());
|
||||
|
@ -579,7 +580,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
|
|||
return navigationIconView;
|
||||
}
|
||||
|
||||
private void updateNavigationIconSelector(ApplicationMode.NavigationIcon navigationIcon) {
|
||||
private void updateNavigationIconSelector(NavigationIcon navigationIcon) {
|
||||
View viewWithTag = navIconItems.findViewWithTag(changedProfile.navigationIcon);
|
||||
viewWithTag.findViewById(R.id.outlineRect).setVisibility(View.GONE);
|
||||
viewWithTag = navIconItems.findViewWithTag(navigationIcon);
|
||||
|
@ -652,21 +653,33 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
ApplicationMode mode = ApplicationMode.valueOfStringKey(changedProfile.stringKey, null);
|
||||
if (mode != null && !isNew) {
|
||||
mode.setParentAppMode(app, changedProfile.parent);
|
||||
mode.setUserProfileName(app, changedProfile.name.trim());
|
||||
mode.setIconResName(app, ProfileIcons.getResStringByResId(changedProfile.iconRes));
|
||||
mode.setRouteService(app, changedProfile.routeService);
|
||||
mode.setRoutingProfile(app, changedProfile.routingProfile);
|
||||
mode.setIconColor(app, changedProfile.color);
|
||||
mode.setLocationIcon(app, changedProfile.locationIcon);
|
||||
mode.setNavigationIcon(app, changedProfile.navigationIcon);
|
||||
} else {
|
||||
ApplicationMode.ApplicationModeBuilder builder = ApplicationMode
|
||||
.createCustomMode(changedProfile.parent, changedProfile.name.trim(), changedProfile.stringKey)
|
||||
.icon(app, ProfileIcons.getResStringByResId(changedProfile.iconRes))
|
||||
.setRouteService(changedProfile.routeService)
|
||||
.setRoutingProfile(changedProfile.routingProfile)
|
||||
.setColor(changedProfile.color)
|
||||
.locationIcon(changedProfile.locationIcon)
|
||||
.navigationIcon(changedProfile.navigationIcon);
|
||||
|
||||
ApplicationMode.ApplicationModeBuilder builder = ApplicationMode
|
||||
.createCustomMode(changedProfile.parent, changedProfile.name.trim(), changedProfile.stringKey)
|
||||
.icon(app, ApplicationMode.ProfileIcons.getResStringByResId(changedProfile.iconRes))
|
||||
.setRouteService(changedProfile.routeService)
|
||||
.setRoutingProfile(changedProfile.routingProfile)
|
||||
.setColor(changedProfile.color)
|
||||
.locationIcon(changedProfile.locationIcon)
|
||||
.navigationIcon(changedProfile.navigationIcon);
|
||||
|
||||
ApplicationMode mode = ApplicationMode.saveProfile(builder, getMyApplication());
|
||||
if (!ApplicationMode.values(app).contains(mode)) {
|
||||
ApplicationMode.changeProfileAvailability(mode, true, getMyApplication());
|
||||
mode = ApplicationMode.saveProfile(builder, app);
|
||||
}
|
||||
|
||||
if (isNew) {
|
||||
if (!ApplicationMode.values(app).contains(mode)) {
|
||||
ApplicationMode.changeProfileAvailability(mode, true, app);
|
||||
}
|
||||
app.getSettings().copyPreferencesFromProfile(changedProfile.parent, mode);
|
||||
}
|
||||
return true;
|
||||
|
@ -719,8 +732,10 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
|
|||
|
||||
private void deleteImportedProfile() {
|
||||
if (isBaseProfileImported) {
|
||||
ApplicationMode.deleteCustomMode(ApplicationMode.valueOfStringKey(
|
||||
changedProfile.parent.getStringKey(), ApplicationMode.DEFAULT), app);
|
||||
ApplicationMode appMode = ApplicationMode.valueOfStringKey(changedProfile.parent.getStringKey(), null);
|
||||
if (appMode != null) {
|
||||
ApplicationMode.deleteCustomModes(Collections.singletonList(appMode), app);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -748,12 +763,12 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
|
|||
String stringKey;
|
||||
ApplicationMode parent = null;
|
||||
String name;
|
||||
ApplicationMode.ProfileIconColors color;
|
||||
ProfileIconColors color;
|
||||
int iconRes;
|
||||
String routingProfile;
|
||||
RouteProvider.RouteService routeService;
|
||||
ApplicationMode.NavigationIcon navigationIcon;
|
||||
ApplicationMode.LocationIcon locationIcon;
|
||||
NavigationIcon navigationIcon;
|
||||
LocationIcon locationIcon;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
|
|
Loading…
Reference in a new issue