Merge pull request #7622 from osmandapp/revert-7621-app_modes_editing
Revert "Change routing profile in default app modes"
This commit is contained in:
commit
09906af37e
5 changed files with 55 additions and 113 deletions
|
@ -350,11 +350,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) {
|
||||
|
@ -397,16 +392,6 @@ public class ApplicationMode {
|
|||
return defaultValues;
|
||||
}
|
||||
|
||||
public static List<ApplicationMode> getCustomValues() {
|
||||
List<ApplicationMode> customModes = new ArrayList<>();
|
||||
for (ApplicationMode mode : values) {
|
||||
if (mode.isCustomProfile()) {
|
||||
customModes.add(mode);
|
||||
}
|
||||
}
|
||||
return customModes;
|
||||
}
|
||||
|
||||
// returns modifiable ! Set<ApplicationMode> to exclude non-wanted derived
|
||||
public static Set<ApplicationMode> regWidgetVisibility(String widgetId, ApplicationMode... am) {
|
||||
HashSet<ApplicationMode> set = new HashSet<>();
|
||||
|
@ -622,7 +607,6 @@ public class ApplicationMode {
|
|||
|
||||
public static void onApplicationStart(OsmandApplication app) {
|
||||
// load for default profiles to initialize later custom modes
|
||||
initDefaultModesUpdates(app);
|
||||
initDefaultSpeed(app);
|
||||
initCustomModes(app);
|
||||
initDefaultSpeed(app);
|
||||
|
@ -656,60 +640,25 @@ public class ApplicationMode {
|
|||
|
||||
}
|
||||
|
||||
private static void initDefaultModesUpdates(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);
|
||||
|
||||
if (!Algorithms.isEmpty(defaultAppModeBeans)) {
|
||||
for (ApplicationModeBean modeBean : defaultAppModeBeans) {
|
||||
ApplicationMode applicationMode = ApplicationMode.valueOfStringKey(modeBean.stringKey, null);
|
||||
if (applicationMode != null) {
|
||||
if (!applicationMode.routingProfile.equals(modeBean.routingProfile)) {
|
||||
applicationMode.routingProfile = modeBean.routingProfile;
|
||||
}
|
||||
if (!applicationMode.routeService.equals(modeBean.routeService)) {
|
||||
applicationMode.routeService = modeBean.routeService;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void saveCustomModeToSettings(OsmandSettings settings) {
|
||||
List<ApplicationModeBean> customModes = createApplicationModeBeans(getCustomValues());
|
||||
saveModesToSettings(settings, customModes, true);
|
||||
}
|
||||
|
||||
public static void saveDefaultModeToSettings(OsmandSettings settings) {
|
||||
List<ApplicationModeBean> defaultModes = createApplicationModeBeans(defaultValues);
|
||||
saveModesToSettings(settings, defaultModes, false);
|
||||
}
|
||||
|
||||
private static List<ApplicationModeBean> createApplicationModeBeans(List<ApplicationMode> applicationModes) {
|
||||
List<ApplicationModeBean> modeBeans = new ArrayList<>();
|
||||
for (ApplicationMode mode : applicationModes) {
|
||||
private static void saveCustomModeToSettings(OsmandSettings settings){
|
||||
List<ApplicationModeBean> customModes = new ArrayList<>();
|
||||
for (ApplicationMode mode : values) {
|
||||
if (mode.parentAppMode != null) {
|
||||
ApplicationModeBean mb = new ApplicationModeBean();
|
||||
mb.userProfileName = mode.userProfileName;
|
||||
mb.iconColor = mode.iconColor;
|
||||
mb.iconName = mode.iconResName;
|
||||
mb.parent = mode.parentAppMode != null ? mode.parentAppMode.getStringKey() : null;
|
||||
mb.parent = mode.parentAppMode.getStringKey();
|
||||
mb.stringKey = mode.stringKey;
|
||||
mb.routeService = mode.routeService;
|
||||
mb.routingProfile = mode.routingProfile;
|
||||
modeBeans.add(mb);
|
||||
customModes.add(mb);
|
||||
}
|
||||
return modeBeans;
|
||||
}
|
||||
|
||||
private static void saveModesToSettings(OsmandSettings settings, List<ApplicationModeBean> modeBeans, boolean customModes) {
|
||||
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
|
||||
String profiles = gson.toJson(modeBeans);
|
||||
if (customModes) {
|
||||
String profiles = gson.toJson(customModes);
|
||||
settings.CUSTOM_APP_PROFILES.set(profiles);
|
||||
} else {
|
||||
settings.DEFAULT_APP_PROFILES.set(profiles);
|
||||
}
|
||||
}
|
||||
|
||||
public static ApplicationMode saveCustomProfile(ApplicationModeBuilder builder, OsmandApplication app) {
|
||||
|
|
|
@ -2938,9 +2938,6 @@ public class OsmandSettings {
|
|||
RateUsBottomSheetDialog.RateUsState.INITIAL_STATE, RateUsBottomSheetDialog.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();
|
||||
|
||||
|
|
|
@ -81,7 +81,9 @@ public abstract class AppModesBottomSheetDialogFragment<T extends AbstractProfil
|
|||
public void onProfilePressed(ApplicationMode item) {
|
||||
Intent intent = new Intent(getActivity(), EditProfileActivity.class);
|
||||
intent.putExtra(PROFILE_STRING_KEY, item.getStringKey());
|
||||
intent.putExtra(IS_USER_PROFILE, item.isCustomProfile());
|
||||
if (item.isCustomProfile()) {
|
||||
intent.putExtra(IS_USER_PROFILE, true);
|
||||
}
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
|
|
|
@ -285,20 +285,20 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
selectNavTypeBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
FragmentActivity activity = getActivity();
|
||||
if (activity != null) {
|
||||
if (isNew || isUserProfile) {
|
||||
hideKeyboard();
|
||||
final SelectProfileBottomSheetDialogFragment fragment = new SelectProfileBottomSheetDialogFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
if (profile.routingProfileDataObject != null) {
|
||||
bundle.putString(SELECTED_KEY, profile.routingProfileDataObject.getStringKey());
|
||||
bundle.putString(SELECTED_KEY,
|
||||
profile.routingProfileDataObject.getStringKey());
|
||||
}
|
||||
bundle.putString(DIALOG_TYPE, TYPE_NAV_PROFILE);
|
||||
|
||||
SelectProfileBottomSheetDialogFragment fragment = new SelectProfileBottomSheetDialogFragment();
|
||||
fragment.setArguments(bundle);
|
||||
activity.getSupportFragmentManager().beginTransaction()
|
||||
if (getActivity() != null) {
|
||||
getActivity().getSupportFragmentManager().beginTransaction()
|
||||
.add(fragment, "select_nav_type").commitAllowingStateLoss();
|
||||
|
||||
}
|
||||
navTypeEt.setCursorVisible(false);
|
||||
navTypeEt.setTextIsSelectable(false);
|
||||
navTypeEt.clearFocus();
|
||||
|
@ -403,13 +403,16 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
}
|
||||
});
|
||||
|
||||
if (!isNew && !isUserProfile) {
|
||||
saveButtonSV.setEnabled(false);
|
||||
saveButton.setEnabled(false);
|
||||
} else {
|
||||
saveButton.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
FragmentActivity activity = getActivity();
|
||||
if (activity != null && saveNewProfile()) {
|
||||
if (saveNewProfile()) {
|
||||
activateMode(mode);
|
||||
activity.onBackPressed();
|
||||
getActivity().onBackPressed();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -417,13 +420,13 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
saveButtonSV.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
FragmentActivity activity = getActivity();
|
||||
if (activity != null && saveNewProfile()) {
|
||||
if (saveNewProfile()) {
|
||||
activateMode(mode);
|
||||
activity.onBackPressed();
|
||||
getActivity().onBackPressed();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
final float d = getResources().getDisplayMetrics().density;
|
||||
view.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
|
||||
|
@ -516,6 +519,7 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
super.onViewCreated(view, savedInstanceState);
|
||||
if (!isUserProfile && !isNew) {
|
||||
profileNameEt.setFocusable(false);
|
||||
navTypeEt.setFocusable(false);
|
||||
}
|
||||
|
||||
if (isNew) {
|
||||
|
@ -655,34 +659,22 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
profile.parent.getStringKey() + "_" + System.currentTimeMillis();
|
||||
}
|
||||
|
||||
boolean customMode = isNew || isUserProfile;
|
||||
|
||||
ApplicationMode.ApplicationModeBuilder builder;
|
||||
if (customMode) {
|
||||
builder = ApplicationMode.createCustomMode(profile.parent, profile.userProfileTitle.trim(), customStringKey);
|
||||
} else {
|
||||
builder = ApplicationMode.changeBaseMode(mode);
|
||||
}
|
||||
builder.icon(app, profile.iconStringName);
|
||||
ApplicationMode.ApplicationModeBuilder builder = ApplicationMode
|
||||
.createCustomMode(profile.parent, profile.userProfileTitle.trim(), customStringKey)
|
||||
.icon(app, profile.iconStringName);
|
||||
|
||||
if(profile.routingProfileDataObject.getStringKey().equals(
|
||||
RoutingProfilesResources.STRAIGHT_LINE_MODE.name())) {
|
||||
builder.setRoutingProfile(RoutingProfilesResources.STRAIGHT_LINE_MODE.name());
|
||||
builder.setRouteService(RouteService.STRAIGHT);
|
||||
} else if(profile.routingProfileDataObject.getStringKey().equals(
|
||||
RoutingProfilesResources.BROUTER_MODE.name())) {
|
||||
builder.setRoutingProfile(RoutingProfilesResources.BROUTER_MODE.name());
|
||||
builder.setRouteService(RouteService.BROUTER);
|
||||
} else if (profile.routingProfileDataObject != null) {
|
||||
builder.setRoutingProfile(profile.routingProfileDataObject.getStringKey());
|
||||
builder.setRouteService(RouteService.OSMAND);
|
||||
}
|
||||
builder.setColor(profile.iconColor);
|
||||
if (customMode) {
|
||||
|
||||
mode = ApplicationMode.saveCustomProfile(builder, getMyApplication());
|
||||
} else {
|
||||
ApplicationMode.saveDefaultModeToSettings(getSettings());
|
||||
}
|
||||
if (!ApplicationMode.values(app).contains(mode)) {
|
||||
ApplicationMode.changeProfileAvailability(mode, true, getMyApplication());
|
||||
}
|
||||
|
|
|
@ -190,7 +190,9 @@ public class SettingsProfileFragment extends BaseOsmAndFragment
|
|||
if (activity instanceof SettingsProfileActivity) {
|
||||
Intent intent = new Intent(getActivity(), EditProfileActivity.class);
|
||||
intent.putExtra(PROFILE_STRING_KEY, item.getStringKey());
|
||||
intent.putExtra(IS_USER_PROFILE, item.isCustomProfile());
|
||||
if (item.isCustomProfile()) {
|
||||
intent.putExtra(IS_USER_PROFILE, true);
|
||||
}
|
||||
activity.startActivity(intent);
|
||||
} else {
|
||||
FragmentManager fragmentManager = activity.getSupportFragmentManager();
|
||||
|
|
Loading…
Reference in a new issue