Merge pull request #8133 from osmandapp/Manage_profile_settings

Fix profiles reorder
This commit is contained in:
max-klaus 2019-12-24 11:09:02 +03:00 committed by GitHub
commit f7b9b3decb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 9 deletions

View file

@ -52,7 +52,6 @@ public class ApplicationMode {
private static Map<String, Set<ApplicationMode>> widgetsAvailabilityMap = new LinkedHashMap<>();
private static List<ApplicationMode> defaultValues = new ArrayList<>();
private static List<ApplicationMode> customValues = new ArrayList<>();
private static List<ApplicationMode> values = new ArrayList<>();
private static List<ApplicationMode> cachedFilteredValues = new ArrayList<>();
@ -194,6 +193,9 @@ public class ApplicationMode {
private ApplicationMode reg() {
values.add(applicationMode);
defaultValues.add(applicationMode);
if (applicationMode.getOrder() == 0 && !values.isEmpty()) {
applicationMode.setOrder(values.size());
}
return applicationMode;
}
@ -213,7 +215,9 @@ public class ApplicationMode {
m.locationIconDayLost = m.parentAppMode.locationIconDayLost;
m.locationIconNightLost = m.parentAppMode.locationIconNightLost;
values.add(applicationMode);
customValues.add(applicationMode);
if (applicationMode.getOrder() == 0 && !values.isEmpty()) {
applicationMode.setOrder(values.size());
}
return applicationMode;
}
@ -677,9 +681,11 @@ public class ApplicationMode {
ApplicationModeBuilder b = createCustomMode(valueOfStringKey(mb.parent, null),
mb.userProfileName, mb.stringKey);
b.setRouteService(mb.routeService).setRoutingProfile(mb.routingProfile);
b.setRouteService(mb.routeService);
b.setRoutingProfile(mb.routingProfile);
b.icon(app, mb.iconName);
b.setColor(mb.iconColor);
b.setOrder(mb.order);
return b;
}
@ -692,6 +698,7 @@ public class ApplicationMode {
mb.stringKey = stringKey;
mb.routeService = routeService;
mb.routingProfile = routingProfile;
mb.order = order;
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
return gson.toJson(mb);
}
@ -807,7 +814,6 @@ public class ApplicationMode {
it.remove();
}
}
customValues.remove(md);
cachedFilteredValues.remove(md);
saveAppModesToSettings(app.getSettings(), md.isCustomProfile());
}

View file

@ -391,11 +391,16 @@ public class EditProfilesFragment extends BaseOsmAndFragment {
Object itemFrom = getItem(from);
Object itemTo = getItem(to);
if (itemFrom instanceof EditProfileDataObject && itemTo instanceof EditProfileDataObject) {
EditProfileDataObject profileDataObjectFrom = (EditProfileDataObject) itemFrom;
EditProfileDataObject profileDataObjectTo = (EditProfileDataObject) itemTo;
int tmp = profileDataObjectFrom.getOrder();
appModesOrders.put(profileDataObjectFrom.getStringKey(), profileDataObjectTo.getOrder());
appModesOrders.put(profileDataObjectTo.getStringKey(), tmp);
EditProfileDataObject profileFrom = (EditProfileDataObject) itemFrom;
EditProfileDataObject profileTo = (EditProfileDataObject) itemTo;
int orderFrom = profileFrom.getOrder();
int orderTo = profileTo.getOrder();
profileFrom.setOrder(orderTo);
profileTo.setOrder(orderFrom);
appModesOrders.put(profileFrom.getStringKey(), orderTo);
appModesOrders.put(profileTo.getStringKey(), orderFrom);
Collections.swap(items, from, to);
notifyItemMoved(from, to);