Search in sources :

Example 1 with FavoriteGroup

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();
    }
}
Also used : ParkingPositionPlugin(net.osmand.plus.plugins.parking.ParkingPositionPlugin) FavouritePoint(net.osmand.data.FavouritePoint) FavoriteGroup(net.osmand.plus.myplaces.FavoriteGroup) ArrayList(java.util.ArrayList)

Example 2 with FavoriteGroup

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;
        }
    }
}
Also used : FavouritePoint(net.osmand.data.FavouritePoint) FavoriteGroup(net.osmand.plus.myplaces.FavoriteGroup) FavouritePoint(net.osmand.data.FavouritePoint) NonNull(androidx.annotation.NonNull)

Example 3 with FavoriteGroup

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);
    }
}
Also used : FavouritePoint(net.osmand.data.FavouritePoint) FavoriteGroup(net.osmand.plus.myplaces.FavoriteGroup) FavouritePoint(net.osmand.data.FavouritePoint)

Example 4 with FavoriteGroup

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;
}
Also used : FavouritePoint(net.osmand.data.FavouritePoint) FavoriteGroup(net.osmand.plus.myplaces.FavoriteGroup) FavouritePoint(net.osmand.data.FavouritePoint) ColorInt(androidx.annotation.ColorInt)

Example 5 with FavoriteGroup

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);
    }
}
Also used : Context(android.content.Context) FavouritesHelper(net.osmand.plus.myplaces.FavouritesHelper) FavoriteGroup(net.osmand.plus.myplaces.FavoriteGroup)

Aggregations

FavoriteGroup (net.osmand.plus.myplaces.FavoriteGroup)29 FavouritePoint (net.osmand.data.FavouritePoint)15 ArrayList (java.util.ArrayList)10 FavouritesHelper (net.osmand.plus.myplaces.FavouritesHelper)9 HistoryEntry (net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry)8 MapMarkersGroup (net.osmand.plus.mapmarkers.MapMarkersGroup)7 PoiUIFilter (net.osmand.plus.poi.PoiUIFilter)7 File (java.io.File)6 MapMarker (net.osmand.plus.mapmarkers.MapMarker)6 QuickAction (net.osmand.plus.quickaction.QuickAction)6 NonNull (androidx.annotation.NonNull)5 ITileSource (net.osmand.map.ITileSource)5 MapActivity (net.osmand.plus.activities.MapActivity)5 AvoidRoadInfo (net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo)5 OnlineRoutingEngine (net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine)5 OpenstreetmapPoint (net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint)5 OsmNotesPoint (net.osmand.plus.plugins.osmedit.data.OsmNotesPoint)5 Context (android.content.Context)4 View (android.view.View)4 List (java.util.List)4