Add app context to ApplicationMode
This commit is contained in:
parent
0ebbb2fd4e
commit
52c1ce3b4c
7 changed files with 477 additions and 581 deletions
File diff suppressed because it is too large
Load diff
|
@ -430,9 +430,7 @@ public class OsmandSettings {
|
|||
|
||||
public void copyProfilePreferences(ApplicationMode modeFrom, ApplicationMode modeTo, List<OsmandPreference> profilePreferences) {
|
||||
for (OsmandPreference pref : profilePreferences) {
|
||||
if (pref instanceof CommonPreference
|
||||
&& !((CommonPreference) pref).global
|
||||
&& !USER_PROFILE_NAME.getId().equals(pref.getId())) {
|
||||
if (prefCanBeCopiedOrReset(pref)) {
|
||||
CommonPreference profilePref = (CommonPreference) pref;
|
||||
if (PARENT_APP_MODE.getId().equals(pref.getId())) {
|
||||
if (modeTo.isCustomProfile()) {
|
||||
|
@ -447,30 +445,23 @@ public class OsmandSettings {
|
|||
}
|
||||
}
|
||||
|
||||
public boolean resetPreferencesForProfile(ApplicationMode mode) {
|
||||
boolean prefsCleared = settingsAPI.edit(getProfilePreferences(mode)).clear().commit();
|
||||
if (prefsCleared) {
|
||||
for (OsmandPreference pref : registeredPreferences.values()) {
|
||||
if (pref instanceof CommonPreference) {
|
||||
CommonPreference commonPreference = (CommonPreference) pref;
|
||||
if (commonPreference.cache && !commonPreference.global) {
|
||||
commonPreference.cachedValue = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return prefsCleared;
|
||||
public void resetPreferencesForProfile(ApplicationMode mode) {
|
||||
resetProfilePreferences(mode, new ArrayList<OsmandPreference>(registeredPreferences.values()));
|
||||
}
|
||||
|
||||
public void resetProfilePreferences(ApplicationMode mode, List<OsmandPreference> profilePreferences) {
|
||||
for (OsmandPreference pref : profilePreferences) {
|
||||
if (pref instanceof CommonPreference && !((CommonPreference) pref).global) {
|
||||
if (prefCanBeCopiedOrReset(pref)) {
|
||||
pref.resetModeToDefault(mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean prefCanBeCopiedOrReset(OsmandPreference pref) {
|
||||
return pref instanceof CommonPreference && !((CommonPreference) pref).global
|
||||
&& !USER_PROFILE_NAME.getId().equals(pref.getId()) && !APP_MODE_ORDER.getId().equals(pref.getId());
|
||||
}
|
||||
|
||||
public ApplicationMode LAST_ROUTING_APPLICATION_MODE = null;
|
||||
|
||||
// this value string is synchronized with settings_pref.xml preference name
|
||||
|
@ -1548,7 +1539,7 @@ public class OsmandSettings {
|
|||
LOCATION_ICON.setModeDefaultValue(ApplicationMode.SKI, LocationIcon.BICYCLE);
|
||||
}
|
||||
|
||||
public final CommonPreference<String> APP_MODES_ORDERS = new StringPreference("app_modes_orders", "").makeGlobal().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();
|
||||
|
@ -3371,12 +3362,6 @@ public class OsmandSettings {
|
|||
RateUsBottomSheetDialogFragment.RateUsState.INITIAL_STATE, RateUsBottomSheetDialogFragment.RateUsState.values())
|
||||
.makeGlobal();
|
||||
|
||||
public final CommonPreference<String> DEFAULT_APP_PROFILES =
|
||||
new StringPreference("default_app_profiles", "").makeGlobal().cache();
|
||||
|
||||
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();
|
||||
|
||||
|
|
|
@ -437,7 +437,7 @@ public class SettingsHelper {
|
|||
|
||||
void readFromJson(@NonNull OsmandApplication app, @NonNull JSONObject json) throws JSONException {
|
||||
String appModeJson = json.getString("appMode");
|
||||
builder = ApplicationMode.fromJson(app, appModeJson);
|
||||
builder = ApplicationMode.fromJson(appModeJson);
|
||||
ApplicationMode appMode = builder.getApplicationMode();
|
||||
if (!appMode.isCustomProfile()) {
|
||||
appMode = ApplicationMode.valueOfStringKey(appMode.getStringKey(), appMode);
|
||||
|
|
|
@ -783,7 +783,7 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
|
|||
builder.setPositiveButton(R.string.shared_string_ok, new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
mode.setDefaultSpeed(app, defaultValue[0] / ratio[0]);
|
||||
mode.setDefaultSpeed(defaultValue[0] / ratio[0]);
|
||||
if (!defaultSpeedOnly) {
|
||||
settings.MIN_SPEED.setModeValue(mode, minValue[0] / ratio[0]);
|
||||
settings.MAX_SPEED.setModeValue(mode, maxValue[0] / ratio[0]);
|
||||
|
@ -798,7 +798,7 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
|
|||
builder.setNeutralButton(R.string.shared_string_revert, new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
mode.resetDefaultSpeed(app);
|
||||
mode.resetDefaultSpeed();
|
||||
if (!defaultSpeedOnly) {
|
||||
settings.MIN_SPEED.setModeValue(mode,0f);
|
||||
settings.MAX_SPEED.setModeValue(mode,0f);
|
||||
|
|
|
@ -156,7 +156,6 @@ public class ConfigureProfileFragment extends BaseSettingsFragment implements Co
|
|||
if (appMode != null) {
|
||||
ApplicationMode selectedAppMode = getSelectedAppMode();
|
||||
app.getSettings().copyPreferencesFromProfile(appMode, selectedAppMode);
|
||||
ApplicationMode.initModeParams(app, selectedAppMode);
|
||||
updateToolbar();
|
||||
updateAllSettings();
|
||||
}
|
||||
|
@ -165,15 +164,12 @@ public class ConfigureProfileFragment extends BaseSettingsFragment implements Co
|
|||
@Override
|
||||
public void resetAppModePrefs(ApplicationMode appMode) {
|
||||
if (appMode != null) {
|
||||
boolean prefsRestored = app.getSettings().resetPreferencesForProfile(appMode);
|
||||
if (prefsRestored) {
|
||||
app.getSettings().resetPreferencesForProfile(appMode);
|
||||
app.showToastMessage(R.string.profile_prefs_reset_successful);
|
||||
ApplicationMode.initModeParams(app, appMode);
|
||||
updateToolbar();
|
||||
updateAllSettings();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private RecyclerView.ItemDecoration createDividerItemDecoration() {
|
||||
final Drawable dividerLight = new ColorDrawable(ContextCompat.getColor(app, R.color.list_background_color_light));
|
||||
|
|
|
@ -148,8 +148,8 @@ public class NavigationFragment extends BaseSettingsFragment {
|
|||
} else {
|
||||
routeService = RouteProvider.RouteService.OSMAND;
|
||||
}
|
||||
appMode.setRouteService(app, routeService);
|
||||
appMode.setRoutingProfile(app, profileKey);
|
||||
appMode.setRouteService(routeService);
|
||||
appMode.setRoutingProfile(profileKey);
|
||||
}
|
||||
|
||||
public static Map<String, RoutingProfileDataObject> getRoutingProfiles(OsmandApplication context) {
|
||||
|
|
|
@ -655,13 +655,15 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
|
|||
}
|
||||
if (isNew) {
|
||||
ApplicationMode.ApplicationModeBuilder builder = ApplicationMode
|
||||
.createCustomMode(changedProfile.parent, changedProfile.name.trim(), changedProfile.stringKey)
|
||||
.icon(app, ProfileIcons.getResStringByResId(changedProfile.iconRes))
|
||||
.setRouteService(changedProfile.routeService)
|
||||
.createCustomMode(changedProfile.parent, changedProfile.stringKey)
|
||||
.setIconResName(ProfileIcons.getResStringByResId(changedProfile.iconRes))
|
||||
.setUserProfileName(changedProfile.name.trim())
|
||||
.setRoutingProfile(changedProfile.routingProfile)
|
||||
.setColor(changedProfile.color)
|
||||
.locationIcon(changedProfile.locationIcon)
|
||||
.navigationIcon(changedProfile.navigationIcon);
|
||||
.setRouteService(changedProfile.routeService)
|
||||
.setIconColor(changedProfile.color)
|
||||
.setLocationIcon(changedProfile.locationIcon)
|
||||
.setNavigationIcon(changedProfile.navigationIcon)
|
||||
.setOrder(ApplicationMode.allPossibleValues().size());
|
||||
|
||||
app.getSettings().copyPreferencesFromProfile(changedProfile.parent, builder.getApplicationMode());
|
||||
ApplicationMode mode = ApplicationMode.saveProfile(builder, app);
|
||||
|
@ -669,15 +671,15 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
|
|||
ApplicationMode.changeProfileAvailability(mode, true, app);
|
||||
}
|
||||
} else {
|
||||
ApplicationMode mode = ApplicationMode.valueOfStringKey(changedProfile.stringKey, null);
|
||||
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);
|
||||
ApplicationMode mode = getSelectedAppMode();
|
||||
mode.setParentAppMode(changedProfile.parent);
|
||||
mode.setIconResName(ProfileIcons.getResStringByResId(changedProfile.iconRes));
|
||||
mode.setUserProfileName(changedProfile.name.trim());
|
||||
mode.setRoutingProfile(changedProfile.routingProfile);
|
||||
mode.setRouteService(changedProfile.routeService);
|
||||
mode.setIconColor(changedProfile.color);
|
||||
mode.setLocationIcon(changedProfile.locationIcon);
|
||||
mode.setNavigationIcon(changedProfile.navigationIcon);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
Loading…
Reference in a new issue