use of net.osmand.plus.myplaces.FavoriteGroup in project Osmand by osmandapp.
the class FavoritesSettingsItem method apply.
@Override
public void apply() {
List<FavoriteGroup> newItems = getNewItems();
if (personalGroup != null) {
duplicateItems.add(personalGroup);
}
if (!newItems.isEmpty() || !duplicateItems.isEmpty()) {
appliedItems = new ArrayList<>(newItems);
for (FavoriteGroup duplicate : duplicateItems) {
boolean isPersonal = duplicate.isPersonal();
boolean replace = shouldReplace || isPersonal;
if (replace) {
FavoriteGroup existingGroup = favoritesHelper.getGroup(duplicate.getName());
if (existingGroup != null) {
List<FavouritePoint> favouritePoints = new ArrayList<>(existingGroup.getPoints());
for (FavouritePoint favouritePoint : favouritePoints) {
favoritesHelper.deleteFavourite(favouritePoint, false);
}
}
}
if (!isPersonal) {
appliedItems.add(shouldReplace ? duplicate : renameItem(duplicate));
} else {
for (FavouritePoint item : duplicate.getPoints()) {
if (item.getSpecialPointType() == FavouritePoint.SpecialPointType.PARKING) {
ParkingPositionPlugin plugin = OsmandPlugin.getPlugin(ParkingPositionPlugin.class);
if (plugin != null) {
plugin.clearParkingPosition();
boolean isTimeRestricted = item.getTimestamp() > 0;
plugin.setParkingType(isTimeRestricted);
plugin.setParkingTime(isTimeRestricted ? item.getTimestamp() : 0);
plugin.setParkingStartTime(item.getCreationDate());
plugin.setParkingPosition(item.getLatitude(), item.getLongitude());
plugin.addOrRemoveParkingEvent(item.getCalendarEvent());
if (item.getCalendarEvent()) {
plugin.addCalendarEvent(app);
}
}
}
}
}
}
List<FavouritePoint> favourites = getPointsFromGroups(appliedItems);
for (FavouritePoint favourite : favourites) {
favoritesHelper.addFavourite(favourite, false, false);
}
favoritesHelper.sortAll();
favoritesHelper.saveCurrentPointsIntoFile();
favoritesHelper.loadFavorites();
}
}
use of net.osmand.plus.myplaces.FavoriteGroup in project Osmand by osmandapp.
the class FavoritesSettingsItem method renameItem.
@NonNull
@Override
public FavoriteGroup renameItem(@NonNull FavoriteGroup item) {
int number = 0;
while (true) {
number++;
String name = item.getName() + " (" + number + ")";
FavoriteGroup renamedItem = new FavoriteGroup(name, item.getPoints(), item.getColor(), item.isVisible());
if (!isDuplicate(renamedItem)) {
for (FavouritePoint point : renamedItem.getPoints()) {
point.setCategory(renamedItem.getName());
}
return renamedItem;
}
}
}
use of net.osmand.plus.myplaces.FavoriteGroup in project Osmand by osmandapp.
the class FavouritePointMenuBuilder method buildGroupFavouritesView.
private void buildGroupFavouritesView(View view) {
FavoriteGroup favoriteGroup = app.getFavoritesHelper().getGroup(fav);
List<FavouritePoint> groupFavourites = favoriteGroup.getPoints();
if (groupFavourites.size() > 0) {
int color = favoriteGroup.getColor() == 0 ? view.getResources().getColor(R.color.color_favorite) : favoriteGroup.getColor();
int disabledColor = ColorUtilities.getSecondaryTextColorId(!light);
color = favoriteGroup.isVisible() ? (color | 0xff000000) : view.getResources().getColor(disabledColor);
String name = view.getContext().getString(R.string.context_menu_points_of_group);
buildRow(view, app.getUIUtilities().getPaintedIcon(R.drawable.ic_action_folder, color), null, name, 0, null, true, getCollapsableFavouritesView(view.getContext(), true, favoriteGroup, fav), false, 0, false, null, false);
}
}
use of net.osmand.plus.myplaces.FavoriteGroup in project Osmand by osmandapp.
the class FavoritePointEditorFragment method getPointColor.
@ColorInt
@Override
public int getPointColor() {
FavouritePoint favorite = getFavorite();
int color = favorite != null ? this.color : 0;
FavoriteGroup group = getGroup();
if (group != null && color == 0) {
color = group.getColor();
}
if (color == 0) {
color = defaultColor;
}
return color;
}
use of net.osmand.plus.myplaces.FavoriteGroup in project Osmand by osmandapp.
the class FavoritePointEditorFragment method setCategory.
@Override
public void setCategory(String name, int color) {
FavouritesHelper helper = getHelper();
Context ctx = getContext();
if (helper != null && ctx != null) {
FavoriteGroup group = helper.getGroup(FavoriteGroup.convertDisplayNameToGroupIdName(ctx, name));
this.group = group;
super.setCategory(name, group != null ? group.getColor() : 0);
}
}
Aggregations