From a40f802a7a4f4c609422eef60197e2be42065e54 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Mon, 15 Mar 2021 12:23:40 +0200 Subject: [PATCH] Move markerGroups to ItineraryHelper --- .../src/net/osmand/plus/AppInitializer.java | 2 +- .../net/osmand/plus/FavouritesDbHelper.java | 9 +- .../net/osmand/plus/GpxSelectionHelper.java | 6 +- .../EditFavoriteGroupDialogFragment.java | 6 +- .../activities/FavoritesTreeFragment.java | 2 +- .../net/osmand/plus/helpers/IntentHelper.java | 4 +- .../ItineraryGroup.java} | 12 +- .../plus/itinerary/ItineraryHelper.java | 296 ++++++++++++- .../editors/WptPtEditorFragment.java | 4 +- .../editors/WptPtEditorFragmentNew.java | 4 +- ...ouritesGroupBottomSheetDialogFragment.java | 2 +- ...dTracksGroupBottomSheetDialogFragment.java | 2 +- .../plus/mapmarkers/CategoriesSubHeader.java | 8 +- .../CoordinateInputDialogFragment.java | 10 +- .../osmand/plus/mapmarkers/GroupHeader.java | 8 +- .../net/osmand/plus/mapmarkers/MapMarker.java | 5 +- .../plus/mapmarkers/MapMarkersDbHelper.java | 13 +- .../plus/mapmarkers/MapMarkersHelper.java | 393 +++--------------- ...ptCategoriesBottomSheetDialogFragment.java | 12 +- .../adapters/MapMarkersActiveAdapter.java | 6 +- .../adapters/MapMarkersGroupsAdapter.java | 35 +- .../plus/myplaces/DeletePointsTask.java | 4 +- .../EditTrackGroupDialogFragment.java | 12 +- .../plus/myplaces/TrackPointFragment.java | 15 +- .../backup/HistoryMarkersSettingsItem.java | 8 +- .../backend/backup/MarkersSettingsItem.java | 8 +- .../backend/backup/SettingsHelper.java | 31 +- .../fragments/ExportItemsBottomSheet.java | 6 +- .../fragments/ExportSettingsAdapter.java | 6 +- .../plus/views/layers/FavouritesLayer.java | 2 +- .../osmand/plus/views/layers/GPXLayer.java | 6 +- 31 files changed, 478 insertions(+), 459 deletions(-) rename OsmAnd/src/net/osmand/plus/{mapmarkers/MapMarkersGroup.java => itinerary/ItineraryGroup.java} (91%) diff --git a/OsmAnd/src/net/osmand/plus/AppInitializer.java b/OsmAnd/src/net/osmand/plus/AppInitializer.java index 7d3afbffcd..812d4bb843 100644 --- a/OsmAnd/src/net/osmand/plus/AppInitializer.java +++ b/OsmAnd/src/net/osmand/plus/AppInitializer.java @@ -685,7 +685,7 @@ public class AppInitializer implements IProgress { // restore backuped favorites to normal file restoreBackupForFavoritesFiles(); notifyEvent(InitEvents.RESTORE_BACKUPS); - app.mapMarkersHelper.syncAllGroupsAsync(); + app.itineraryHelper.syncAllGroupsAsync(); app.searchUICore.initSearchUICore(); checkLiveUpdatesAlerts(); diff --git a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java index 151737a157..c90ecccc02 100644 --- a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java @@ -17,7 +17,7 @@ import net.osmand.data.FavouritePoint; import net.osmand.data.LatLon; import net.osmand.plus.GeocodingLookupService.AddressLookupRequest; import net.osmand.plus.mapmarkers.MapMarkersHelper; -import net.osmand.plus.mapmarkers.MapMarkersGroup; +import net.osmand.plus.itinerary.ItineraryGroup; import net.osmand.plus.api.SQLiteAPI.SQLiteConnection; import net.osmand.plus.api.SQLiteAPI.SQLiteCursor; import net.osmand.util.Algorithms; @@ -272,7 +272,7 @@ public class FavouritesDbHelper { } private void runSyncWithMarkers(FavoriteGroup favGroup) { - MapMarkersGroup group = context.getMapMarkersHelper().getMarkersGroup(favGroup); + ItineraryGroup group = context.getItineraryHelper().getMarkersGroup(favGroup); if (group != null) { context.getItineraryHelper().runSynchronization(group); } @@ -280,7 +280,7 @@ public class FavouritesDbHelper { private boolean removeFromMarkers(FavoriteGroup favGroup) { MapMarkersHelper helper = context.getMapMarkersHelper(); - MapMarkersGroup group = helper.getMarkersGroup(favGroup); + ItineraryGroup group = context.getItineraryHelper().getMarkersGroup(favGroup); if (group != null) { helper.removeMarkersGroup(group); return true; @@ -289,8 +289,7 @@ public class FavouritesDbHelper { } private void addToMarkers(FavoriteGroup favGroup) { - MapMarkersHelper helper = context.getMapMarkersHelper(); - helper.addOrEnableGroup(favGroup); + context.getItineraryHelper().addOrEnableGroup(favGroup); } private File getInternalFile() { diff --git a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java index 82b101b2a1..3c95d75e9f 100644 --- a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java +++ b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java @@ -30,7 +30,7 @@ import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetType; import net.osmand.plus.helpers.GpxUiHelper.GPXInfo; import net.osmand.plus.helpers.SearchHistoryHelper; import net.osmand.plus.helpers.enums.MetricsConstants; -import net.osmand.plus.mapmarkers.MapMarkersGroup; +import net.osmand.plus.itinerary.ItineraryGroup; import net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder; import net.osmand.plus.track.GpxSplitType; import net.osmand.util.Algorithms; @@ -795,7 +795,7 @@ public class GpxSelectionHelper { boolean addToHistory) { GpxDataItem dataItem = app.getGpxDbHelper().getItem(new File(gpx.path)); if (canAddToMarkers && show && dataItem != null && dataItem.isShowAsMarkers()) { - app.getMapMarkersHelper().addOrEnableGroup(gpx); + app.getItineraryHelper().addOrEnableGroup(gpx); } return selectGpxFile(gpx, dataItem, show, notShowNavigationDialog, syncGroup, selectedByUser, addToHistory); } @@ -822,7 +822,7 @@ public class GpxSelectionHelper { } private void syncGpxWithMarkers(GPXFile gpxFile) { - MapMarkersGroup group = app.getMapMarkersHelper().getMarkersGroup(gpxFile); + ItineraryGroup group = app.getItineraryHelper().getMarkersGroup(gpxFile); if (group != null) { app.getItineraryHelper().runSynchronization(group); } diff --git a/OsmAnd/src/net/osmand/plus/activities/EditFavoriteGroupDialogFragment.java b/OsmAnd/src/net/osmand/plus/activities/EditFavoriteGroupDialogFragment.java index 001868e7b4..e625212ee7 100644 --- a/OsmAnd/src/net/osmand/plus/activities/EditFavoriteGroupDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/EditFavoriteGroupDialogFragment.java @@ -28,7 +28,7 @@ import net.osmand.AndroidUtils; import net.osmand.plus.FavouritesDbHelper; import net.osmand.plus.FavouritesDbHelper.FavoriteGroup; import net.osmand.plus.mapmarkers.MapMarkersHelper; -import net.osmand.plus.mapmarkers.MapMarkersGroup; +import net.osmand.plus.itinerary.ItineraryGroup; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; @@ -179,7 +179,7 @@ public class EditFavoriteGroupDialogFragment extends MenuBottomSheetDialogFragme final MapMarkersHelper markersHelper = app.getMapMarkersHelper(); final FavoriteGroup favGroup = this.group; - final MapMarkersGroup markersGr = markersHelper.getMarkersGroup(this.group); + final ItineraryGroup markersGr = app.getItineraryHelper().getMarkersGroup(this.group); final boolean synced = markersGr != null; BaseBottomSheetItem markersGroupItem = new SimpleBottomSheetItem.Builder() @@ -192,7 +192,7 @@ public class EditFavoriteGroupDialogFragment extends MenuBottomSheetDialogFragme if (synced) { markersHelper.removeMarkersGroup(markersGr); } else { - markersHelper.addOrEnableGroup(favGroup); + app.getItineraryHelper().addOrEnableGroup(favGroup); } dismiss(); MapActivity.launchMapActivityMoveToTop(getActivity()); diff --git a/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java b/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java index a24859fa30..98304247a4 100644 --- a/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java @@ -526,7 +526,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen for (Map.Entry> entry : favoritesSelected.entrySet()) { FavoriteGroup group = helper.getGroup(entry.getKey()); if (group != null && entry.getValue().size() == group.getPoints().size()) { - markersHelper.addOrEnableGroup(group); + getMyApplication().getItineraryHelper().addOrEnableGroup(group); } else { for (FavouritePoint fp : entry.getValue()) { points.add(new LatLon(fp.getLatitude(), fp.getLongitude())); diff --git a/OsmAnd/src/net/osmand/plus/helpers/IntentHelper.java b/OsmAnd/src/net/osmand/plus/helpers/IntentHelper.java index f02b5b0961..ba48fe6899 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/IntentHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/IntentHelper.java @@ -19,7 +19,7 @@ import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.PluginsFragment; import net.osmand.plus.dashboard.DashboardOnMap.DashboardType; import net.osmand.plus.mapmarkers.MapMarkersDialogFragment; -import net.osmand.plus.mapmarkers.MapMarkersGroup; +import net.osmand.plus.itinerary.ItineraryGroup; import net.osmand.plus.mapsource.EditMapSourceDialogFragment; import net.osmand.plus.openplacereviews.OPRConstants; import net.osmand.plus.openplacereviews.OprAuthHelper.OprAuthorizationListener; @@ -219,7 +219,7 @@ public class IntentHelper { if (intent.hasExtra(MapMarkersDialogFragment.OPEN_MAP_MARKERS_GROUPS)) { Bundle openMapMarkersGroupsExtra = intent.getBundleExtra(MapMarkersDialogFragment.OPEN_MAP_MARKERS_GROUPS); if (openMapMarkersGroupsExtra != null) { - MapMarkersDialogFragment.showInstance(mapActivity, openMapMarkersGroupsExtra.getString(MapMarkersGroup.MARKERS_SYNC_GROUP_ID)); + MapMarkersDialogFragment.showInstance(mapActivity, openMapMarkersGroupsExtra.getString(ItineraryGroup.MARKERS_SYNC_GROUP_ID)); } mapActivity.setIntent(null); } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroup.java b/OsmAnd/src/net/osmand/plus/itinerary/ItineraryGroup.java similarity index 91% rename from OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroup.java rename to OsmAnd/src/net/osmand/plus/itinerary/ItineraryGroup.java index 2a97af91c8..595315a028 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroup.java +++ b/OsmAnd/src/net/osmand/plus/itinerary/ItineraryGroup.java @@ -1,8 +1,12 @@ -package net.osmand.plus.mapmarkers; +package net.osmand.plus.itinerary; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import net.osmand.plus.mapmarkers.CategoriesSubHeader; +import net.osmand.plus.mapmarkers.GroupHeader; +import net.osmand.plus.mapmarkers.MapMarker; +import net.osmand.plus.mapmarkers.ShowHideHistoryButton; import net.osmand.plus.wikivoyage.data.TravelArticle; import net.osmand.util.Algorithms; @@ -10,7 +14,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Set; -public class MapMarkersGroup { +public class ItineraryGroup { public static final int ANY_TYPE = -1; public static final int FAVORITES_TYPE = 0; @@ -34,11 +38,11 @@ public class MapMarkersGroup { private CategoriesSubHeader categoriesSubHeader; private ShowHideHistoryButton showHideHistoryButton; - public MapMarkersGroup() { + public ItineraryGroup() { } - public MapMarkersGroup(@NonNull String id, @NonNull String name, int type) { + public ItineraryGroup(@NonNull String id, @NonNull String name, int type) { this.id = id; this.name = name; this.type = type; diff --git a/OsmAnd/src/net/osmand/plus/itinerary/ItineraryHelper.java b/OsmAnd/src/net/osmand/plus/itinerary/ItineraryHelper.java index 8e3c96a08a..f89d05c1f9 100644 --- a/OsmAnd/src/net/osmand/plus/itinerary/ItineraryHelper.java +++ b/OsmAnd/src/net/osmand/plus/itinerary/ItineraryHelper.java @@ -3,31 +3,44 @@ package net.osmand.plus.itinerary; import android.os.AsyncTask; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.WptPt; +import net.osmand.IndexConstants; import net.osmand.PlatformUtil; import net.osmand.data.FavouritePoint; import net.osmand.data.LatLon; import net.osmand.plus.FavouritesDbHelper.FavoriteGroup; +import net.osmand.plus.GPXDatabase; import net.osmand.plus.GpxSelectionHelper; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.OsmandApplication; import net.osmand.plus.mapmarkers.MapMarker; -import net.osmand.plus.mapmarkers.MapMarkersGroup; +import net.osmand.plus.mapmarkers.MapMarkersDbHelper; import net.osmand.plus.mapmarkers.MapMarkersHelper; import net.osmand.plus.mapmarkers.MapMarkersHelper.OnGroupSyncedListener; +import net.osmand.plus.wikivoyage.data.TravelArticle; +import net.osmand.plus.wikivoyage.data.TravelHelper; +import net.osmand.util.Algorithms; import org.apache.commons.logging.Log; import java.io.File; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.HashSet; +import java.util.Iterator; import java.util.List; +import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import static net.osmand.plus.mapmarkers.MapMarkersHelper.BY_DATE_ADDED_DESC; + public class ItineraryHelper { private static final Log LOG = PlatformUtil.getLog(ItineraryHelper.class); @@ -35,14 +48,150 @@ public class ItineraryHelper { private OsmandApplication app; private MapMarkersHelper markersHelper; + private MapMarkersDbHelper markersDbHelper; private ExecutorService executorService = Executors.newSingleThreadExecutor(); + private List itineraryGroups = new ArrayList<>(); private Set syncListeners = new HashSet<>(); public ItineraryHelper(@NonNull OsmandApplication app) { this.app = app; markersHelper = app.getMapMarkersHelper(); + markersDbHelper = app.getMapMarkersDbHelper(); + loadGroups(); + } + + public List getItineraryGroups() { + return itineraryGroups; + } + + public void syncAllGroupsAsync() { + for (ItineraryGroup group : itineraryGroups) { + if (group.getId() != null && group.getName() != null) { + runSynchronization(group); + } + } + } + + public void updateGroupWptCategories(@NonNull ItineraryGroup group, Set wptCategories) { + String id = group.getId(); + if (id != null) { + group.setWptCategories(wptCategories); + if (wptCategories != null) { + markersDbHelper.updateGroupCategories(id, group.getWptCategoriesString()); + } + } + } + + public void enableGroup(@NonNull ItineraryGroup gr) { + // check if group doesn't exist internally + if (!itineraryGroups.contains(gr)) { + addGroupInternally(gr); + } + if (gr.isDisabled()) { + updateGroupDisabled(gr, false); + } + runSynchronization(gr); + } + + public void updateGroups() { + for (ItineraryGroup group : itineraryGroups) { + markersHelper.updateGroup(group); + } + } + + public void updateGroupDisabled(@NonNull ItineraryGroup group, boolean disabled) { + String id = group.getId(); + if (id != null) { + markersDbHelper.updateGroupDisabled(id, disabled); + group.setDisabled(disabled); + } + } + + public List getMapMarkersFromDefaultGroups(boolean history) { + List mapMarkers = new ArrayList<>(); + for (ItineraryGroup group : itineraryGroups) { + if (group.getType() == ItineraryGroup.ANY_TYPE) { + for (MapMarker marker : group.getMarkers()) { + if (history && marker.history || !history && !marker.history) { + mapMarkers.add(marker); + } + } + } + } + return mapMarkers; + } + + private void loadGroups() { + Map groupsMap = markersDbHelper.getAllGroupsMap(); + List allMarkers = new ArrayList<>(markersHelper.getMapMarkers()); + allMarkers.addAll(markersHelper.getMapMarkersHistory()); + + Iterator> iterator = groupsMap.entrySet().iterator(); + while (iterator.hasNext()) { + ItineraryGroup group = iterator.next().getValue(); + if (group.getType() == ItineraryGroup.GPX_TYPE && !new File(group.getId()).exists()) { + markersDbHelper.removeMarkersGroup(group.getId()); + iterator.remove(); + } + } + + ItineraryGroup noGroup = null; + + for (MapMarker marker : allMarkers) { + ItineraryGroup group = groupsMap.get(marker.groupKey); + if (group == null) { + if (noGroup == null) { + noGroup = new ItineraryGroup(); + noGroup.setCreationDate(Long.MAX_VALUE); + } + noGroup.getMarkers().add(marker); + } else { + if (marker.creationDate < group.getCreationDate()) { + group.setCreationDate(marker.creationDate); + } + group.getMarkers().add(marker); + } + } + + itineraryGroups = new ArrayList<>(groupsMap.values()); + if (noGroup != null) { + markersHelper.sortMarkers(noGroup.getMarkers(), false, BY_DATE_ADDED_DESC); + addToGroupsList(noGroup); + } + + sortGroups(); + + for (ItineraryGroup group : itineraryGroups) { + markersHelper.updateGroup(group); + } + } + + public void addGroupInternally(ItineraryGroup gr) { + markersDbHelper.addGroup(gr); + markersHelper.addHistoryMarkersToGroup(gr); + addToGroupsList(gr); + } + + public void updateGpxShowAsMarkers(File file) { + GPXDatabase.GpxDataItem dataItem = app.getGpxDbHelper().getItem(file); + if (dataItem != null) { + app.getGpxDbHelper().updateShowAsMarkers(dataItem, true); + dataItem.setShowAsMarkers(true); + } + } + + public void addToGroupsList(ItineraryGroup group) { + List copyList = new ArrayList<>(itineraryGroups); + copyList.add(group); + itineraryGroups = copyList; + } + + public void removeFromGroupsList(ItineraryGroup group) { + List copyList = new ArrayList<>(itineraryGroups); + copyList.remove(group); + itineraryGroups = copyList; } public void addSyncListener(OnGroupSyncedListener listener) { @@ -53,7 +202,7 @@ public class ItineraryHelper { syncListeners.remove(listener); } - public void runSynchronization(final @NonNull MapMarkersGroup group) { + public void runSynchronization(final @NonNull ItineraryGroup group) { app.runInUIThread(new Runnable() { @Override public void run() { @@ -62,11 +211,146 @@ public class ItineraryHelper { }); } + public ItineraryGroup getMarkersGroup(GPXFile gpx) { + if (gpx == null || gpx.path == null) { + return null; + } + return getMapMarkerGroupById(getMarkerGroupId(new File(gpx.path)), ItineraryGroup.GPX_TYPE); + } + + public ItineraryGroup getMarkersGroup(FavoriteGroup favGroup) { + return getMapMarkerGroupById(getMarkerGroupId(favGroup), ItineraryGroup.FAVORITES_TYPE); + } + + public ItineraryGroup addOrEnableGpxGroup(@NonNull File file) { + updateGpxShowAsMarkers(file); + ItineraryGroup gr = getMapMarkerGroupById(getMarkerGroupId(file), ItineraryGroup.GPX_TYPE); + if (gr == null) { + gr = createGPXMarkerGroup(file); + addGroupInternally(gr); + } + enableGroup(gr); + return gr; + } + + public ItineraryGroup addOrEnableGroup(@NonNull GPXFile file) { + updateGpxShowAsMarkers(new File(file.path)); + ItineraryGroup gr = getMarkersGroup(file); + if (gr == null) { + gr = createGPXMarkerGroup(new File(file.path)); + addGroupInternally(gr); + } + enableGroup(gr); + return gr; + } + + public ItineraryGroup addOrEnableGroup(@NonNull FavoriteGroup group) { + ItineraryGroup gr = getMarkersGroup(group); + if (gr == null) { + gr = createFavMarkerGroup(group); + addGroupInternally(gr); + } + enableGroup(gr); + return gr; + } + + private ItineraryGroup createGPXMarkerGroup(File fl) { + return new ItineraryGroup(getMarkerGroupId(fl), + Algorithms.getFileNameWithoutExtension(fl.getName()), + ItineraryGroup.GPX_TYPE); + } + + private ItineraryGroup createFavMarkerGroup(FavoriteGroup favGroup) { + return new ItineraryGroup(favGroup.getName(), favGroup.getName(), ItineraryGroup.FAVORITES_TYPE); + } + + private String getMarkerGroupId(File gpx) { + return gpx.getAbsolutePath(); + } + + private String getMarkerGroupId(FavoriteGroup group) { + return group.getName(); + } + + + public void removeMarkerFromGroup(MapMarker marker) { + if (marker != null) { + ItineraryGroup itineraryGroup = getMapMarkerGroupById(marker.groupKey, marker.getType()); + if (itineraryGroup != null) { + itineraryGroup.getMarkers().remove(marker); + markersHelper.updateGroup(itineraryGroup); + } + } + } + + public void sortGroups() { + if (itineraryGroups.size() > 0) { + Collections.sort(itineraryGroups, new Comparator() { + @Override + public int compare(ItineraryGroup group1, ItineraryGroup group2) { + long t1 = group1.getCreationDate(); + long t2 = group2.getCreationDate(); + return (t1 > t2) ? -1 : ((t1 == t2) ? 0 : 1); + } + }); + } + } + + @Nullable + public ItineraryGroup getMapMarkerGroupById(String id, int type) { + for (ItineraryGroup group : itineraryGroups) { + if ((id == null && group.getId() == null) + || (group.getId() != null && group.getId().equals(id))) { + if (type == ItineraryGroup.ANY_TYPE || type == group.getType()) { + return group; + } + } + } + return null; + } + + @NonNull + public List getGroupsForDisplayedGpx() { + List res = new ArrayList<>(); + List selectedGpxFiles = app.getSelectedGpxHelper().getSelectedGPXFiles(); + for (SelectedGpxFile selected : selectedGpxFiles) { + ItineraryGroup search = getMarkersGroup(selected.getGpxFile()); + if (search == null && selected.getGpxFile() != null && selected.getGpxFile().path != null) { + ItineraryGroup group = createGPXMarkerGroup(new File(selected.getGpxFile().path)); + group.setDisabled(true); + markersHelper.createHeadersInGroup(group); + res.add(group); + } + } + return res; + } + + @NonNull + public List getGroupsForSavedArticlesTravelBook() { + List res = new ArrayList<>(); + TravelHelper travelHelper = app.getTravelHelper(); + if (travelHelper.isAnyTravelBookPresent()) { + List savedArticles = travelHelper.getBookmarksHelper().getSavedArticles(); + for (TravelArticle art : savedArticles) { + String gpxName = travelHelper.getGPXName(art); + File path = app.getAppPath(IndexConstants.GPX_TRAVEL_DIR + gpxName); + ItineraryGroup search = getMapMarkerGroupById(getMarkerGroupId(path), ItineraryGroup.GPX_TYPE); + if (search == null) { + ItineraryGroup group = createGPXMarkerGroup(path); + group.setDisabled(true); + markersHelper.createHeadersInGroup(group); + res.add(group); + } + } + } + return res; + } + private class SyncGroupTask extends AsyncTask { - private MapMarkersGroup group; + private ItineraryGroup group; - SyncGroupTask(MapMarkersGroup group) { + SyncGroupTask(ItineraryGroup group) { this.group = group; } @@ -93,7 +377,7 @@ public class ItineraryHelper { // TODO extract method from Asynctask to Helper directly private void runGroupSynchronization() { List groupMarkers = new ArrayList<>(group.getMarkers()); - if (group.getType() == MapMarkersGroup.FAVORITES_TYPE) { + if (group.getType() == ItineraryGroup.FAVORITES_TYPE) { FavoriteGroup favGroup = app.getFavorites().getGroup(group.getName()); if (favGroup == null) { return; @@ -107,7 +391,7 @@ public class ItineraryHelper { for (FavouritePoint fp : points) { markersHelper.addNewMarkerIfNeeded(group, groupMarkers, new LatLon(fp.getLatitude(), fp.getLongitude()), fp.getName(), fp, null); } - } else if (group.getType() == MapMarkersGroup.GPX_TYPE) { + } else if (group.getType() == ItineraryGroup.GPX_TYPE) { GpxSelectionHelper gpxHelper = app.getSelectedGpxHelper(); File file = new File(group.getId()); if (!file.exists()) { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragment.java index e1c1ac3d61..713b13a177 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragment.java @@ -24,7 +24,7 @@ import net.osmand.plus.activities.SavingTrackHelper; import net.osmand.plus.base.PointImageDrawable; import net.osmand.plus.mapcontextmenu.MapContextMenu; import net.osmand.plus.mapcontextmenu.editors.WptPtEditor.OnDismissListener; -import net.osmand.plus.mapmarkers.MapMarkersGroup; +import net.osmand.plus.itinerary.ItineraryGroup; import net.osmand.plus.track.SaveGpxAsyncTask; import net.osmand.plus.track.SaveGpxAsyncTask.SaveGpxListener; import net.osmand.util.Algorithms; @@ -219,7 +219,7 @@ public class WptPtEditorFragment extends PointEditorFragment { private void syncGpx(GPXFile gpxFile) { OsmandApplication app = getMyApplication(); if (app != null) { - MapMarkersGroup group = app.getMapMarkersHelper().getMarkersGroup(gpxFile); + ItineraryGroup group = app.getItineraryHelper().getMarkersGroup(gpxFile); if (group != null) { app.getItineraryHelper().runSynchronization(group); } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragmentNew.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragmentNew.java index afb86d2e5c..0e583392ba 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragmentNew.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragmentNew.java @@ -28,7 +28,7 @@ import net.osmand.plus.activities.SavingTrackHelper; import net.osmand.plus.base.PointImageDrawable; import net.osmand.plus.mapcontextmenu.MapContextMenu; import net.osmand.plus.mapcontextmenu.editors.WptPtEditor.OnDismissListener; -import net.osmand.plus.mapmarkers.MapMarkersGroup; +import net.osmand.plus.itinerary.ItineraryGroup; import net.osmand.plus.track.SaveGpxAsyncTask; import net.osmand.plus.track.SaveGpxAsyncTask.SaveGpxListener; import net.osmand.util.Algorithms; @@ -235,7 +235,7 @@ public class WptPtEditorFragmentNew extends PointEditorFragmentNew { private void syncGpx(GPXFile gpxFile) { OsmandApplication app = getMyApplication(); if (app != null) { - MapMarkersGroup group = app.getMapMarkersHelper().getMarkersGroup(gpxFile); + ItineraryGroup group = app.getItineraryHelper().getMarkersGroup(gpxFile); if (group != null) { app.getItineraryHelper().runSynchronization(group); } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/AddFavouritesGroupBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/AddFavouritesGroupBottomSheetDialogFragment.java index 0e6b31f4f4..52f85bf0e7 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/AddFavouritesGroupBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/AddFavouritesGroupBottomSheetDialogFragment.java @@ -56,7 +56,7 @@ public class AddFavouritesGroupBottomSheetDialogFragment extends AddGroupBottomS if (!group.isVisible()) { favouritesDbHelper.editFavouriteGroup(group, group.getName(), group.getColor(), true); } - getMyApplication().getMapMarkersHelper().addOrEnableGroup(group); + getMyApplication().getItineraryHelper().addOrEnableGroup(group); dismiss(); } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/AddTracksGroupBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/AddTracksGroupBottomSheetDialogFragment.java index b01548be00..32dfd58172 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/AddTracksGroupBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/AddTracksGroupBottomSheetDialogFragment.java @@ -108,7 +108,7 @@ public class AddTracksGroupBottomSheetDialogFragment extends AddGroupBottomSheet GPXFile res = GPXUtilities.loadGPXFile(gpx); selectionHelper.selectGpxFile(res, true, false, false, false, false); } - app.getMapMarkersHelper().addOrEnableGpxGroup(gpx); + app.getItineraryHelper().addOrEnableGpxGroup(gpx); } } dismiss(); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CategoriesSubHeader.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CategoriesSubHeader.java index aef2f28afd..52ea71617b 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/CategoriesSubHeader.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CategoriesSubHeader.java @@ -2,13 +2,15 @@ package net.osmand.plus.mapmarkers; import androidx.annotation.DrawableRes; +import net.osmand.plus.itinerary.ItineraryGroup; + public class CategoriesSubHeader { @DrawableRes private int iconRes; - private MapMarkersGroup group; + private ItineraryGroup group; - public CategoriesSubHeader(int iconRes, MapMarkersGroup group) { + public CategoriesSubHeader(int iconRes, ItineraryGroup group) { this.iconRes = iconRes; this.group = group; } @@ -18,7 +20,7 @@ public class CategoriesSubHeader { return iconRes; } - public MapMarkersGroup getGroup() { + public ItineraryGroup getGroup() { return group; } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java index 31e477fbf1..138109f126 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java @@ -71,6 +71,8 @@ import net.osmand.plus.Version; import net.osmand.plus.activities.SavingTrackHelper; import net.osmand.plus.activities.TrackActivity; import net.osmand.plus.helpers.AndroidUiHelper; +import net.osmand.plus.itinerary.ItineraryGroup; +import net.osmand.plus.itinerary.ItineraryHelper; import net.osmand.plus.mapmarkers.CoordinateInputBottomSheetDialogFragment.CoordinateInputFormatChangeListener; import net.osmand.plus.mapmarkers.CoordinateInputFormats.DDM; import net.osmand.plus.mapmarkers.CoordinateInputFormats.DMS; @@ -168,10 +170,10 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm } private void syncGpx(GPXFile gpxFile) { - MapMarkersHelper helper = getMyApplication().getMapMarkersHelper(); - MapMarkersGroup group = helper.getMarkersGroup(gpxFile); + ItineraryHelper helper = getMyApplication().getItineraryHelper(); + ItineraryGroup group = helper.getMarkersGroup(gpxFile); if (group != null) { - getMyApplication().getItineraryHelper().runSynchronization(group); + helper.runSynchronization(group); } } @@ -1089,7 +1091,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm public void saveGpx(final String fileName) { new SaveGpxAsyncTask(app, getGpx(),fileName, false).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); hasUnsavedChanges = false; - app.getMapMarkersHelper().addOrEnableGroup(getGpx()); + app.getItineraryHelper().addOrEnableGroup(getGpx()); if (listener != null) { listener.onPointsSaved(); } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/GroupHeader.java b/OsmAnd/src/net/osmand/plus/mapmarkers/GroupHeader.java index c5c97a1c2e..c760b08dee 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/GroupHeader.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/GroupHeader.java @@ -2,13 +2,15 @@ package net.osmand.plus.mapmarkers; import androidx.annotation.DrawableRes; +import net.osmand.plus.itinerary.ItineraryGroup; + public class GroupHeader { @DrawableRes private int iconRes; - private MapMarkersGroup group; + private ItineraryGroup group; - public GroupHeader(int iconRes, MapMarkersGroup group) { + public GroupHeader(int iconRes, ItineraryGroup group) { this.iconRes = iconRes; this.group = group; } @@ -18,7 +20,7 @@ public class GroupHeader { return iconRes; } - public MapMarkersGroup getGroup() { + public ItineraryGroup getGroup() { return group; } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarker.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarker.java index 498c36f93c..e1f2c413f1 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarker.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarker.java @@ -11,6 +11,7 @@ import net.osmand.data.LatLon; import net.osmand.data.LocationPoint; import net.osmand.data.PointDescription; import net.osmand.plus.R; +import net.osmand.plus.itinerary.ItineraryGroup; import net.osmand.util.Algorithms; import static net.osmand.data.PointDescription.POINT_TYPE_MAP_MARKER; @@ -46,8 +47,8 @@ public class MapMarker implements LocationPoint { public int getType() { return favouritePoint == null ? - (wptPt == null ? MapMarkersGroup.ANY_TYPE : MapMarkersGroup.GPX_TYPE) : - MapMarkersGroup.FAVORITES_TYPE; + (wptPt == null ? ItineraryGroup.ANY_TYPE : ItineraryGroup.GPX_TYPE) : + ItineraryGroup.FAVORITES_TYPE; } public PointDescription getPointDescription(Context ctx) { diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java index 0b2ba5ab0c..4fe3debbb5 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java @@ -8,6 +8,7 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.api.SQLiteAPI.SQLiteConnection; import net.osmand.plus.api.SQLiteAPI.SQLiteCursor; import net.osmand.plus.helpers.SearchHistoryHelper; +import net.osmand.plus.itinerary.ItineraryGroup; import net.osmand.util.Algorithms; import java.util.ArrayList; @@ -161,7 +162,7 @@ public class MapMarkersDbHelper { } } - public void addGroup(MapMarkersGroup group) { + public void addGroup(ItineraryGroup group) { SQLiteConnection db = openConnection(false); if (db != null) { try { @@ -173,15 +174,15 @@ public class MapMarkersDbHelper { } } - public Map getAllGroupsMap() { - Map res = new LinkedHashMap<>(); + public Map getAllGroupsMap() { + Map res = new LinkedHashMap<>(); SQLiteConnection db = openConnection(true); if (db != null) { try { SQLiteCursor query = db.rawQuery(GROUPS_TABLE_SELECT, null); if (query != null && query.moveToFirst()) { do { - MapMarkersGroup group = readGroup(query); + ItineraryGroup group = readGroup(query); res.put(group.getId(), group); } while (query.moveToNext()); } @@ -195,14 +196,14 @@ public class MapMarkersDbHelper { return res; } - private MapMarkersGroup readGroup(SQLiteCursor query) { + private ItineraryGroup readGroup(SQLiteCursor query) { String id = query.getString(0); String name = query.getString(1); int type = query.getInt(2); boolean disabled = query.getInt(3) == 1; String categories = query.getString(4); - MapMarkersGroup res = new MapMarkersGroup(id, name, type); + ItineraryGroup res = new ItineraryGroup(id, name, type); res.setDisabled(disabled); res.setWptCategories(categories == null ? null : Algorithms.decodeStringSet(categories)); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHelper.java index b8bcddbc5c..1f2233b7c0 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHelper.java @@ -14,16 +14,12 @@ import net.osmand.PlatformUtil; import net.osmand.data.FavouritePoint; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; -import net.osmand.plus.FavouritesDbHelper.FavoriteGroup; -import net.osmand.plus.GPXDatabase; import net.osmand.plus.GeocodingLookupService; import net.osmand.plus.GeocodingLookupService.AddressLookupRequest; -import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.Version; -import net.osmand.plus.wikivoyage.data.TravelArticle; -import net.osmand.plus.wikivoyage.data.TravelHelper; +import net.osmand.plus.itinerary.ItineraryGroup; import net.osmand.util.Algorithms; import net.osmand.util.MapUtils; @@ -41,8 +37,6 @@ import java.util.Date; import java.util.Iterator; import java.util.List; import java.util.Locale; -import java.util.Map; -import java.util.Set; import java.util.TimeZone; import static net.osmand.GPXUtilities.GPX_TIME_FORMAT; @@ -69,12 +63,11 @@ public class MapMarkersHelper { public @interface MapMarkersSortByDef { } - private OsmandApplication ctx; + private OsmandApplication app; private MapMarkersDbHelper markersDbHelper; private List mapMarkers = new ArrayList<>(); private List mapMarkersHistory = new ArrayList<>(); - private List mapMarkersGroups = new ArrayList<>(); private List listeners = new ArrayList<>(); @@ -88,29 +81,24 @@ public class MapMarkersHelper { return mapMarkersHistory; } - public List getMapMarkersGroups() { - return mapMarkersGroups; - } - public boolean isStartFromMyLocation() { - return ctx.getSettings().ROUTE_MAP_MARKERS_START_MY_LOC.get(); + return app.getSettings().ROUTE_MAP_MARKERS_START_MY_LOC.get(); } public void setStartFromMyLocation(boolean startFromMyLocation) { - ctx.getSettings().ROUTE_MAP_MARKERS_START_MY_LOC.set(startFromMyLocation); + app.getSettings().ROUTE_MAP_MARKERS_START_MY_LOC.set(startFromMyLocation); } public MarkersPlanRouteContext getPlanRouteContext() { return planRouteContext; } - public MapMarkersHelper(OsmandApplication ctx) { - this.ctx = ctx; - markersDbHelper = ctx.getMapMarkersDbHelper(); - planRouteContext = new MarkersPlanRouteContext(ctx); + public MapMarkersHelper(OsmandApplication app) { + this.app = app; + markersDbHelper = app.getMapMarkersDbHelper(); + planRouteContext = new MarkersPlanRouteContext(app); markersDbHelper.removeDisabledGroups(); loadMarkers(); - loadGroups(); } private void loadMarkers() { @@ -124,63 +112,11 @@ public class MapMarkersHelper { sortMarkers(markersHistory, true, BY_DATE_ADDED_DESC); addToMapMarkersHistoryList(markersHistory); - if (!ctx.isApplicationInitializing()) { + if (!app.isApplicationInitializing()) { lookupAddressAll(); } } - private void loadGroups() { - Map groupsMap = markersDbHelper.getAllGroupsMap(); - List allMarkers = new ArrayList<>(mapMarkers); - allMarkers.addAll(mapMarkersHistory); - - Iterator> iterator = groupsMap.entrySet().iterator(); - while (iterator.hasNext()) { - MapMarkersGroup group = iterator.next().getValue(); - if (group.getType() == MapMarkersGroup.GPX_TYPE && !new File(group.getId()).exists()) { - markersDbHelper.removeMarkersGroup(group.getId()); - iterator.remove(); - } - } - - MapMarkersGroup noGroup = null; - - for (MapMarker marker : allMarkers) { - MapMarkersGroup group = groupsMap.get(marker.groupKey); - if (group == null) { - if (noGroup == null) { - noGroup = new MapMarkersGroup(); - noGroup.setCreationDate(Long.MAX_VALUE); - } - noGroup.getMarkers().add(marker); - } else { - if (marker.creationDate < group.getCreationDate()) { - group.setCreationDate(marker.creationDate); - } - group.getMarkers().add(marker); - } - } - - mapMarkersGroups = new ArrayList<>(groupsMap.values()); - if (noGroup != null) { - sortMarkers(noGroup.getMarkers(), false, BY_DATE_ADDED_DESC); - addToGroupsList(noGroup); - } - - sortGroups(); - - for (MapMarkersGroup group : mapMarkersGroups) { - updateGroup(group); - } - } - - public void syncAllGroupsAsync() { - for (MapMarkersGroup gr : mapMarkersGroups) { - if (gr.getId() != null && gr.getName() != null) { - ctx.getItineraryHelper().runSynchronization(gr); - } - } - } public void lookupAddressAll() { for (MapMarker mapMarker : mapMarkers) { @@ -192,7 +128,7 @@ public class MapMarkersHelper { } private void lookupAddress(final MapMarker mapMarker) { - if (mapMarker != null && mapMarker.getOriginalPointDescription().isSearchingAddress(ctx)) { + if (mapMarker != null && mapMarker.getOriginalPointDescription().isSearchingAddress(app)) { cancelPointAddressRequests(mapMarker.point); AddressLookupRequest lookupRequest = new AddressLookupRequest(mapMarker.point, new GeocodingLookupService.OnAddressLookupResult() { @@ -200,7 +136,7 @@ public class MapMarkersHelper { public void geocodingDone(String address) { PointDescription pointDescription = mapMarker.getOriginalPointDescription(); if (Algorithms.isEmpty(address)) { - pointDescription.setName(PointDescription.getAddressNotFoundStr(ctx)); + pointDescription.setName(PointDescription.getAddressNotFoundStr(app)); } else { pointDescription.setName(address); } @@ -208,7 +144,7 @@ public class MapMarkersHelper { refreshMarker(mapMarker); } }, null); - ctx.getGeocodingLookupService().lookupAddress(lookupRequest); + app.getGeocodingLookupService().lookupAddress(lookupRequest); } } @@ -225,7 +161,7 @@ public class MapMarkersHelper { private void cancelPointAddressRequests(LatLon latLon) { if (latLon != null) { - ctx.getGeocodingLookupService().cancel(latLon); + app.getGeocodingLookupService().cancel(latLon); } } @@ -254,7 +190,7 @@ public class MapMarkersHelper { reorderActiveMarkersIfNeeded(); } - private void sortMarkers(List markers, final boolean visited, final @MapMarkersSortByDef int sortByMode) { + public void sortMarkers(List markers, final boolean visited, final @MapMarkersSortByDef int sortByMode) { sortMarkers(markers, visited, sortByMode, null); } @@ -286,83 +222,15 @@ public class MapMarkersHelper { return sortByMode == BY_DISTANCE_DESC ? 1 : -1; } } else { - String n1 = mapMarker1.getName(ctx); - String n2 = mapMarker2.getName(ctx); + String n1 = mapMarker1.getName(app); + String n2 = mapMarker2.getName(app); return n1.compareToIgnoreCase(n2); } } }); } - public MapMarkersGroup getMarkersGroup(GPXFile gpx) { - if (gpx == null || gpx.path == null) { - return null; - } - return getMapMarkerGroupById(getMarkerGroupId(new File(gpx.path)), MapMarkersGroup.GPX_TYPE); - } - - public MapMarkersGroup getMarkersGroup(FavoriteGroup favGroup) { - return getMapMarkerGroupById(getMarkerGroupId(favGroup), MapMarkersGroup.FAVORITES_TYPE); - } - - public MapMarkersGroup addOrEnableGpxGroup(@NonNull File file) { - updateGpxShowAsMarkers(file); - MapMarkersGroup gr = getMapMarkerGroupById(getMarkerGroupId(file), MapMarkersGroup.GPX_TYPE); - if (gr == null) { - gr = createGPXMarkerGroup(file); - addGroupInternally(gr); - } - enableGroup(gr); - return gr; - } - - public MapMarkersGroup addOrEnableGroup(@NonNull GPXFile file) { - updateGpxShowAsMarkers(new File(file.path)); - MapMarkersGroup gr = getMarkersGroup(file); - if (gr == null) { - gr = createGPXMarkerGroup(new File(file.path)); - addGroupInternally(gr); - } - enableGroup(gr); - return gr; - } - - public MapMarkersGroup addOrEnableGroup(@NonNull FavoriteGroup group) { - MapMarkersGroup gr = getMarkersGroup(group); - if (gr == null) { - gr = createFavMarkerGroup(group); - addGroupInternally(gr); - } - enableGroup(gr); - return gr; - } - - public void enableGroup(@NonNull MapMarkersGroup gr) { - // check if group doesn't exist internally - if (!mapMarkersGroups.contains(gr)) { - addGroupInternally(gr); - } - if (gr.isDisabled()) { - updateGroupDisabled(gr, false); - } - ctx.getItineraryHelper().runSynchronization(gr); - } - - private void addGroupInternally(MapMarkersGroup gr) { - markersDbHelper.addGroup(gr); - addHistoryMarkersToGroup(gr); - addToGroupsList(gr); - } - - private void updateGpxShowAsMarkers(File file) { - GPXDatabase.GpxDataItem dataItem = ctx.getGpxDbHelper().getItem(file); - if (dataItem != null) { - ctx.getGpxDbHelper().updateShowAsMarkers(dataItem, true); - dataItem.setShowAsMarkers(true); - } - } - - private void addHistoryMarkersToGroup(@NonNull MapMarkersGroup group) { + public void addHistoryMarkersToGroup(@NonNull ItineraryGroup group) { List historyMarkers = new ArrayList<>(mapMarkersHistory); for (MapMarker m : historyMarkers) { if (m.groupKey != null && group.getId() != null && m.groupKey.equals(group.getId())) { @@ -371,33 +239,15 @@ public class MapMarkersHelper { } } - public void removeMarkersGroup(MapMarkersGroup group) { + public void removeMarkersGroup(ItineraryGroup group) { if (group != null) { markersDbHelper.removeMarkersGroup(group.getId()); removeGroupActiveMarkers(group, false); - removeFromGroupsList(group); + app.getItineraryHelper().removeFromGroupsList(group); } } - public void updateGroupDisabled(@NonNull MapMarkersGroup group, boolean disabled) { - String id = group.getId(); - if (id != null) { - markersDbHelper.updateGroupDisabled(id, disabled); - group.setDisabled(disabled); - } - } - - public void updateGroupWptCategories(@NonNull MapMarkersGroup group, Set wptCategories) { - String id = group.getId(); - if (id != null) { - group.setWptCategories(wptCategories); - if (wptCategories != null) { - markersDbHelper.updateGroupCategories(id, group.getWptCategoriesString()); - } - } - } - - public void removeGroupActiveMarkers(MapMarkersGroup group, boolean updateGroup) { + public void removeGroupActiveMarkers(ItineraryGroup group, boolean updateGroup) { if (group != null) { markersDbHelper.removeActiveMarkersFromGroup(group.getId()); removeFromMapMarkersList(group.getActiveMarkers()); @@ -410,27 +260,21 @@ public class MapMarkersHelper { } } - public void updateGroups() { - for (MapMarkersGroup group : mapMarkersGroups) { - updateGroup(group); - } - } - - public void updateGroup(MapMarkersGroup mapMarkersGroup) { - if (mapMarkersGroup.getId() == null || mapMarkersGroup.getName() == null) { + public void updateGroup(ItineraryGroup itineraryGroup) { + if (itineraryGroup.getId() == null || itineraryGroup.getName() == null) { return; } - createHeadersInGroup(mapMarkersGroup); - int historyMarkersCount = mapMarkersGroup.getHistoryMarkers().size(); - ShowHideHistoryButton showHideHistoryButton = mapMarkersGroup.getShowHideHistoryButton(); + createHeadersInGroup(itineraryGroup); + int historyMarkersCount = itineraryGroup.getHistoryMarkers().size(); + ShowHideHistoryButton showHideHistoryButton = itineraryGroup.getShowHideHistoryButton(); if (showHideHistoryButton != null) { if (historyMarkersCount == 0) { - mapMarkersGroup.setShowHideHistoryButton(null); + itineraryGroup.setShowHideHistoryButton(null); } } else if (historyMarkersCount > 0) { showHideHistoryButton = new ShowHideHistoryButton(); showHideHistoryButton.showHistory = false; - mapMarkersGroup.setShowHideHistoryButton(showHideHistoryButton); + itineraryGroup.setShowHideHistoryButton(showHideHistoryButton); } } @@ -442,30 +286,30 @@ public class MapMarkersHelper { private void addMarkerToGroup(MapMarker marker) { if (marker != null) { - MapMarkersGroup mapMarkersGroup = getMapMarkerGroupById(marker.groupKey, marker.getType()); - if (mapMarkersGroup != null) { - mapMarkersGroup.getMarkers().add(marker); - updateGroup(mapMarkersGroup); - if (mapMarkersGroup.getName() == null) { - sortMarkers(mapMarkersGroup.getMarkers(), false, BY_DATE_ADDED_DESC); + ItineraryGroup itineraryGroup = app.getItineraryHelper().getMapMarkerGroupById(marker.groupKey, marker.getType()); + if (itineraryGroup != null) { + itineraryGroup.getMarkers().add(marker); + updateGroup(itineraryGroup); + if (itineraryGroup.getName() == null) { + sortMarkers(itineraryGroup.getMarkers(), false, BY_DATE_ADDED_DESC); } } else { - mapMarkersGroup = new MapMarkersGroup(marker.groupKey, marker.groupName, MapMarkersGroup.ANY_TYPE); - mapMarkersGroup.setCreationDate(Long.MAX_VALUE); - mapMarkersGroup.getMarkers().add(marker); - addToGroupsList(mapMarkersGroup); - sortGroups(); - updateGroup(mapMarkersGroup); + itineraryGroup = new ItineraryGroup(marker.groupKey, marker.groupName, ItineraryGroup.ANY_TYPE); + itineraryGroup.setCreationDate(Long.MAX_VALUE); + itineraryGroup.getMarkers().add(marker); + app.getItineraryHelper().addToGroupsList(itineraryGroup); + app.getItineraryHelper().sortGroups(); + updateGroup(itineraryGroup); } } } - private void createHeadersInGroup(@NonNull MapMarkersGroup group) { + public void createHeadersInGroup(@NonNull ItineraryGroup group) { int type = group.getType(); int headerIconId = 0; int subHeaderIconId = 0; if (type != -1) { - headerIconId = type == MapMarkersGroup.FAVORITES_TYPE + headerIconId = type == ItineraryGroup.FAVORITES_TYPE ? R.drawable.ic_action_favorite : R.drawable.ic_action_polygom_dark; subHeaderIconId = R.drawable.ic_action_filter; } @@ -476,97 +320,6 @@ public class MapMarkersHelper { group.setCategoriesSubHeader(categoriesSubHeader); } - private void removeMarkerFromGroup(MapMarker marker) { - if (marker != null) { - MapMarkersGroup mapMarkersGroup = getMapMarkerGroupById(marker.groupKey, marker.getType()); - if (mapMarkersGroup != null) { - mapMarkersGroup.getMarkers().remove(marker); - updateGroup(mapMarkersGroup); - } - } - } - - private void sortGroups() { - if (mapMarkersGroups.size() > 0) { - Collections.sort(mapMarkersGroups, new Comparator() { - @Override - public int compare(MapMarkersGroup group1, MapMarkersGroup group2) { - long t1 = group1.getCreationDate(); - long t2 = group2.getCreationDate(); - return (t1 > t2) ? -1 : ((t1 == t2) ? 0 : 1); - } - }); - } - } - - @Nullable - public MapMarkersGroup getMapMarkerGroupById(String id, int type) { - for (MapMarkersGroup group : mapMarkersGroups) { - if ((id == null && group.getId() == null) - || (group.getId() != null && group.getId().equals(id))) { - if (type == MapMarkersGroup.ANY_TYPE || type == group.getType()) { - return group; - } - } - } - return null; - } - - private MapMarkersGroup createGPXMarkerGroup(File fl) { - return new MapMarkersGroup(getMarkerGroupId(fl), - Algorithms.getFileNameWithoutExtension(fl.getName()), - MapMarkersGroup.GPX_TYPE); - } - - private MapMarkersGroup createFavMarkerGroup(FavoriteGroup favGroup) { - return new MapMarkersGroup(favGroup.getName(), favGroup.getName(), MapMarkersGroup.FAVORITES_TYPE); - } - - private String getMarkerGroupId(File gpx) { - return gpx.getAbsolutePath(); - } - - private String getMarkerGroupId(FavoriteGroup group) { - return group.getName(); - } - - @NonNull - public List getGroupsForDisplayedGpx() { - List res = new ArrayList<>(); - List selectedGpxFiles = ctx.getSelectedGpxHelper().getSelectedGPXFiles(); - for (SelectedGpxFile selected : selectedGpxFiles) { - MapMarkersGroup search = getMarkersGroup(selected.getGpxFile()); - if (search == null && selected.getGpxFile() != null && selected.getGpxFile().path != null) { - MapMarkersGroup group = createGPXMarkerGroup(new File(selected.getGpxFile().path)); - group.setDisabled(true); - createHeadersInGroup(group); - res.add(group); - } - } - return res; - } - - @NonNull - public List getGroupsForSavedArticlesTravelBook() { - List res = new ArrayList<>(); - TravelHelper travelHelper = ctx.getTravelHelper(); - if (travelHelper.isAnyTravelBookPresent()) { - List savedArticles = travelHelper.getBookmarksHelper().getSavedArticles(); - for (TravelArticle art : savedArticles) { - String gpxName = travelHelper.getGPXName(art); - File path = ctx.getAppPath(IndexConstants.GPX_TRAVEL_DIR + gpxName); - MapMarkersGroup search = getMapMarkerGroupById(getMarkerGroupId(path), MapMarkersGroup.GPX_TYPE); - if (search == null) { - MapMarkersGroup group = createGPXMarkerGroup(path); - group.setDisabled(true); - createHeadersInGroup(group); - res.add(group); - } - } - } - return res; - } - @Nullable public MapMarker getMapMarker(WptPt wptPt) { for (MapMarker marker : getMarkers()) { @@ -599,7 +352,7 @@ public class MapMarkersHelper { private List getMarkers() { List res = new ArrayList<>(mapMarkers); - if (ctx.getSettings().KEEP_PASSED_MARKERS_ON_MAP.get()) { + if (app.getSettings().KEEP_PASSED_MARKERS_ON_MAP.get()) { res.addAll(mapMarkersHistory); } return res; @@ -618,7 +371,7 @@ public class MapMarkersHelper { return null; } - public void addNewMarkerIfNeeded(@NonNull MapMarkersGroup group, + public void addNewMarkerIfNeeded(@NonNull ItineraryGroup group, @NonNull List groupMarkers, @NonNull LatLon latLon, @NonNull String name, @@ -720,7 +473,7 @@ public class MapMarkersHelper { addToMapMarkersList(markers); reorderActiveMarkersIfNeeded(); sortMarkers(mapMarkersHistory, true, BY_DATE_ADDED_DESC); - updateGroups(); + app.getItineraryHelper().updateGroups(); refresh(); } } @@ -737,7 +490,7 @@ public class MapMarkersHelper { } else { removeFromMapMarkersList(marker); } - removeMarkerFromGroup(marker); + app.getItineraryHelper().removeMarkerFromGroup(marker); if (refresh) { refresh(); } @@ -834,7 +587,7 @@ public class MapMarkersHelper { addToMapMarkersHistoryList(mapMarkers); mapMarkers = new ArrayList<>(); sortMarkers(mapMarkersHistory, true, BY_DATE_ADDED_DESC); - updateGroups(); + app.getItineraryHelper().updateGroups(); refresh(); } @@ -855,18 +608,18 @@ public class MapMarkersHelper { public void addMapMarkers(@NonNull List points, @NonNull List historyNames, - @Nullable MapMarkersGroup group) { + @Nullable ItineraryGroup group) { addMarkers(points, historyNames, group, null, null, null); } private void addMarkers(@NonNull List points, @NonNull List historyNames, - @Nullable MapMarkersGroup group, + @Nullable ItineraryGroup group, @Nullable List favouritePoints, @Nullable List wptPts, @Nullable List mapObjNames) { if (points.size() > 0) { - ctx.getSettings().SHOW_MAP_MARKERS.set(true); + app.getSettings().SHOW_MAP_MARKERS.set(true); int colorIndex = -1; List addedMarkers = new ArrayList<>(); for (int i = 0; i < points.size(); i++) { @@ -882,7 +635,7 @@ public class MapMarkersHelper { pointDescription = historyName; } if (pointDescription.isLocation() && Algorithms.isEmpty(pointDescription.getName())) { - pointDescription.setName(PointDescription.getSearchAddressStr(ctx)); + pointDescription.setName(PointDescription.getSearchAddressStr(app)); } if (colorIndex == -1) { if (mapMarkers.size() > 0) { @@ -896,7 +649,7 @@ public class MapMarkersHelper { MapMarker marker = new MapMarker(point, pointDescription, colorIndex, false, 0); if (group != null) { - marker.id = group.getId() + marker.getName(ctx) + MapUtils.createShortLinkString(marker.point.getLatitude(), marker.point.getLongitude(), 15); + marker.id = group.getId() + marker.getName(app) + MapUtils.createShortLinkString(marker.point.getLatitude(), marker.point.getLongitude(), 15); if (markersDbHelper.getMarker(marker.id) != null) { continue; } @@ -963,7 +716,7 @@ public class MapMarkersHelper { } private void refreshMarker(final MapMarker marker) { - ctx.runInUIThread(new Runnable() { + app.runInUIThread(new Runnable() { @Override public void run() { for (MapMarkerChangedListener l : listeners) { @@ -974,7 +727,7 @@ public class MapMarkersHelper { } private void refresh() { - ctx.runInUIThread(new Runnable() { + app.runInUIThread(new Runnable() { @Override public void run() { for (MapMarkerChangedListener l : listeners) { @@ -984,28 +737,14 @@ public class MapMarkersHelper { }); } - public List getMapMarkersFromDefaultGroups(boolean history) { - List mapMarkers = new ArrayList<>(); - for (MapMarkersGroup group : mapMarkersGroups) { - if (group.getType() == MapMarkersGroup.ANY_TYPE) { - for (MapMarker marker : group.getMarkers()) { - if (history && marker.history || !history && !marker.history) { - mapMarkers.add(marker); - } - } - } - } - return mapMarkers; - } - public String saveMarkersToFile(String fileName) { GPXFile gpxFile = generateGpx(); String dirName = IndexConstants.GPX_INDEX_DIR + IndexConstants.MAP_MARKERS_INDEX_DIR; - File dir = ctx.getAppPath(dirName); + File dir = app.getAppPath(dirName); if (!dir.exists()) { dir.mkdirs(); } - String uniqueFileName = FileUtils.createUniqueFileName(ctx, fileName, dirName, IndexConstants.GPX_FILE_EXT); + String uniqueFileName = FileUtils.createUniqueFileName(app, fileName, dirName, IndexConstants.GPX_FILE_EXT); File fout = new File(dir, uniqueFileName + IndexConstants.GPX_FILE_EXT); GPXUtilities.writeGpxFile(fout, gpxFile); @@ -1020,13 +759,13 @@ public class MapMarkersHelper { SimpleDateFormat format = new SimpleDateFormat(GPX_TIME_FORMAT, Locale.US); format.setTimeZone(TimeZone.getTimeZone("UTC")); - GPXFile gpxFile = new GPXFile(Version.getFullVersion(ctx)); + GPXFile gpxFile = new GPXFile(Version.getFullVersion(app)); for (MapMarker marker : markers) { WptPt wpt = new WptPt(); wpt.lat = marker.getLatitude(); wpt.lon = marker.getLongitude(); wpt.name = marker.getOnlyName(); - wpt.setColor(ContextCompat.getColor(ctx, MapMarker.getColorId(marker.colorIndex))); + wpt.setColor(ContextCompat.getColor(app, MapMarker.getColorId(marker.colorIndex))); if (completeBackup) { if (marker.creationDate != 0) { wpt.getExtensionsToWrite().put(CREATION_DATE, format.format(new Date(marker.creationDate))); @@ -1047,7 +786,7 @@ public class MapMarkersHelper { List mapMarkers = new ArrayList<>(); for (WptPt point : gpxFile.getPoints()) { LatLon latLon = new LatLon(point.lat, point.lon); - int colorIndex = MapMarker.getColorIndex(ctx, point.getColor()); + int colorIndex = MapMarker.getColorIndex(app, point.getColor()); PointDescription name = new PointDescription(PointDescription.POINT_TYPE_LOCATION, point.name); MapMarker marker = new MapMarker(latLon, name, colorIndex, false, 0); @@ -1138,22 +877,6 @@ public class MapMarkersHelper { mapMarkersHistory = copyList; } - // accessors to markers groups: - - private void addToGroupsList(MapMarkersGroup group) { - List copyList = new ArrayList<>(mapMarkersGroups); - copyList.add(group); - mapMarkersGroups = copyList; - } - - private void removeFromGroupsList(MapMarkersGroup group) { - List copyList = new ArrayList<>(mapMarkersGroups); - copyList.remove(group); - mapMarkersGroups = copyList; - } - - // --------------------------------------------------------------------------------------------- - // classes and interfaces: public interface MapMarkerChangedListener { diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/SelectWptCategoriesBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/SelectWptCategoriesBottomSheetDialogFragment.java index 1f86a94a1d..2cabb6f804 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/SelectWptCategoriesBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/SelectWptCategoriesBottomSheetDialogFragment.java @@ -20,6 +20,8 @@ import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton; import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.ShortDescriptionItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; +import net.osmand.plus.itinerary.ItineraryGroup; +import net.osmand.plus.itinerary.ItineraryHelper; import java.io.File; import java.util.ArrayList; @@ -136,18 +138,18 @@ public class SelectWptCategoriesBottomSheetDialogFragment extends MenuBottomShee private void updateAddOrEnableGroupWptCategories() { OsmandApplication app = getMyApplication(); GpxSelectionHelper gpxSelectionHelper = app.getSelectedGpxHelper(); - MapMarkersHelper mapMarkersHelper = app.getMapMarkersHelper(); + ItineraryHelper helper = app.getItineraryHelper(); SelectedGpxFile selectedGpxFile = gpxSelectionHelper.getSelectedFileByPath(gpxFile.path); if (selectedGpxFile == null) { gpxSelectionHelper.selectGpxFile(gpxFile, true, false, false, false, false); } - MapMarkersGroup group = mapMarkersHelper.getMarkersGroup(gpxFile); + ItineraryGroup group = helper.getMarkersGroup(gpxFile); if (group == null) { - group = mapMarkersHelper.addOrEnableGroup(gpxFile); + group = helper.addOrEnableGroup(gpxFile); } - mapMarkersHelper.updateGroupWptCategories(group, selectedCategories); - app.getItineraryHelper().runSynchronization(group); + helper.updateGroupWptCategories(group, selectedCategories); + helper.runSynchronization(group); } private boolean isAllChecked() { diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java index 2fa206d08f..4dfe175720 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java @@ -14,7 +14,7 @@ import com.google.android.material.snackbar.Snackbar; import net.osmand.data.LatLon; import net.osmand.plus.mapmarkers.MapMarker; -import net.osmand.plus.mapmarkers.MapMarkersGroup; +import net.osmand.plus.itinerary.ItineraryGroup; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; @@ -214,8 +214,8 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter(); - MapMarkersHelper helper = app.getMapMarkersHelper(); + ItineraryHelper helper = app.getItineraryHelper(); helper.updateGroups(); - List groups = new ArrayList<>(helper.getMapMarkersGroups()); + List groups = new ArrayList<>(helper.getItineraryGroups()); groups.addAll(helper.getGroupsForDisplayedGpx()); groups.addAll(helper.getGroupsForSavedArticlesTravelBook()); for (int i = 0; i < groups.size(); i++) { - MapMarkersGroup group = groups.get(i); + ItineraryGroup group = groups.get(i); if (!group.isVisible()) { continue; } @@ -176,7 +177,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter categories = group.getWptCategories(); if (categories != null && !categories.isEmpty()) { diff --git a/OsmAnd/src/net/osmand/plus/myplaces/DeletePointsTask.java b/OsmAnd/src/net/osmand/plus/myplaces/DeletePointsTask.java index c9d9d4c423..c7179f1091 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/DeletePointsTask.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/DeletePointsTask.java @@ -8,7 +8,7 @@ import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType; import net.osmand.plus.OsmandApplication; import net.osmand.plus.activities.SavingTrackHelper; -import net.osmand.plus.mapmarkers.MapMarkersGroup; +import net.osmand.plus.itinerary.ItineraryGroup; import java.io.File; import java.lang.ref.WeakReference; @@ -64,7 +64,7 @@ public class DeletePointsTask extends AsyncTask { } private void syncGpx(GPXFile gpxFile) { - MapMarkersGroup group = app.getMapMarkersHelper().getMarkersGroup(gpxFile); + ItineraryGroup group = app.getItineraryHelper().getMarkersGroup(gpxFile); if (group != null) { app.getItineraryHelper().runSynchronization(group); } diff --git a/OsmAnd/src/net/osmand/plus/myplaces/EditTrackGroupDialogFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/EditTrackGroupDialogFragment.java index b3ff9b91bd..352e7ecc3b 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/EditTrackGroupDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/EditTrackGroupDialogFragment.java @@ -49,7 +49,7 @@ import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.FontCache; -import net.osmand.plus.mapmarkers.MapMarkersGroup; +import net.osmand.plus.itinerary.ItineraryGroup; import net.osmand.plus.mapmarkers.MapMarkersHelper; import net.osmand.plus.measurementtool.OptionsDividerItem; import net.osmand.plus.myplaces.DeletePointsTask.OnPointsDeleteListener; @@ -192,7 +192,7 @@ public class EditTrackGroupDialogFragment extends MenuBottomSheetDialogFragment } private BaseBottomSheetItem createCopyToMarkersItem(final GPXFile gpxFile) { - MapMarkersGroup markersGroup = mapMarkersHelper.getMarkersGroup(gpxFile); + ItineraryGroup markersGroup = app.getItineraryHelper().getMarkersGroup(gpxFile); final boolean synced = markersGroup != null && (Algorithms.isEmpty(markersGroup.getWptCategories()) || markersGroup.getWptCategories().contains(group.getName())); @@ -216,10 +216,10 @@ public class EditTrackGroupDialogFragment extends MenuBottomSheetDialogFragment selectedGpxHelper.selectGpxFile(gpxFile, true, false, false, false, false); } boolean groupCreated = false; - MapMarkersGroup markersGroup = mapMarkersHelper.getMarkersGroup(gpxFile); + ItineraryGroup markersGroup = app.getItineraryHelper().getMarkersGroup(gpxFile); if (markersGroup == null) { groupCreated = true; - markersGroup = mapMarkersHelper.addOrEnableGroup(gpxFile); + markersGroup = app.getItineraryHelper().addOrEnableGroup(gpxFile); } Set categories = markersGroup.getWptCategories(); Set selectedCategories = new HashSet<>(); @@ -234,7 +234,7 @@ public class EditTrackGroupDialogFragment extends MenuBottomSheetDialogFragment if (Algorithms.isEmpty(selectedCategories)) { mapMarkersHelper.removeMarkersGroup(markersGroup); } else { - mapMarkersHelper.updateGroupWptCategories(markersGroup, selectedCategories); + app.getItineraryHelper().updateGroupWptCategories(markersGroup, selectedCategories); if (!groupCreated) { app.getItineraryHelper().runSynchronization(markersGroup); } @@ -524,7 +524,7 @@ public class EditTrackGroupDialogFragment extends MenuBottomSheetDialogFragment } private void syncGpx(GPXFile gpxFile) { - MapMarkersGroup group = app.getMapMarkersHelper().getMarkersGroup(gpxFile); + ItineraryGroup group = app.getItineraryHelper().getMarkersGroup(gpxFile); if (group != null) { app.getItineraryHelper().runSynchronization(group); } diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java index 59be8cc533..2641fe986f 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java @@ -63,7 +63,7 @@ import net.osmand.plus.base.OsmandExpandableListFragment; import net.osmand.plus.base.PointImageDrawable; import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.mapmarkers.CoordinateInputDialogFragment; -import net.osmand.plus.mapmarkers.MapMarkersGroup; +import net.osmand.plus.itinerary.ItineraryGroup; import net.osmand.plus.mapmarkers.MapMarkersHelper; import net.osmand.plus.myplaces.DeletePointsTask.OnPointsDeleteListener; import net.osmand.plus.myplaces.TrackBitmapDrawer.TrackBitmapDrawerListener; @@ -399,8 +399,7 @@ public class TrackPointFragment extends OsmandExpandableListFragment implements createMenuItem(menu, SHARE_ID, R.string.shared_string_share, R.drawable.ic_action_gshare_dark, MenuItem.SHOW_AS_ACTION_NEVER, true); GPXFile gpxFile = getGpx(); if (gpxFile != null && gpxFile.path != null) { - final MapMarkersHelper markersHelper = app.getMapMarkersHelper(); - final boolean synced = markersHelper.getMarkersGroup(getGpx()) != null; + final boolean synced = app.getItineraryHelper().getMarkersGroup(getGpx()) != null; createMenuItem(menu, SELECT_MAP_MARKERS_ID, synced ? R.string.remove_from_map_markers : R.string.shared_string_add_to_map_markers, R.drawable.ic_action_flag, MenuItem.SHOW_AS_ACTION_NEVER); } @@ -501,15 +500,15 @@ public class TrackPointFragment extends OsmandExpandableListFragment implements return; } final GPXFile gpxFile = getGpx(); - MapMarkersGroup markersSearch = markersHelper.getMarkersGroup(gpxFile); - final MapMarkersGroup markersGr; + ItineraryGroup markersSearch = app.getItineraryHelper().getMarkersGroup(gpxFile); + final ItineraryGroup markersGr; final boolean markersRemoved; if (markersSearch != null) { markersGr = markersSearch; markersHelper.removeMarkersGroup(markersGr); markersRemoved = true; } else if (gpxFile != null) { - markersGr = markersHelper.addOrEnableGroup(gpxFile); + markersGr = app.getItineraryHelper().addOrEnableGroup(gpxFile); markersRemoved = false; } else { markersRemoved = false; @@ -535,10 +534,10 @@ public class TrackPointFragment extends OsmandExpandableListFragment implements if (trackActivity != null) { if (markersRemoved) { if (gpxFile != null) { - markersHelper.addOrEnableGroup(gpxFile); + app.getItineraryHelper().addOrEnableGroup(gpxFile); } } else { - MapMarkersGroup group = markersHelper.getMarkersGroup(gpxFile); + ItineraryGroup group = app.getItineraryHelper().getMarkersGroup(gpxFile); if (group != null) { markersHelper.removeMarkersGroup(group); } diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/HistoryMarkersSettingsItem.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/HistoryMarkersSettingsItem.java index ba0c3d7dc0..9cbb536177 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/HistoryMarkersSettingsItem.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/HistoryMarkersSettingsItem.java @@ -12,7 +12,7 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.mapmarkers.MapMarker; import net.osmand.plus.mapmarkers.MapMarkersDbHelper; -import net.osmand.plus.mapmarkers.MapMarkersGroup; +import net.osmand.plus.itinerary.ItineraryGroup; import net.osmand.plus.mapmarkers.MapMarkersHelper; import net.osmand.plus.settings.backend.ExportSettingsType; import net.osmand.util.Algorithms; @@ -46,7 +46,7 @@ public class HistoryMarkersSettingsItem extends CollectionSettingsItem(markersHelper.getMapMarkersFromDefaultGroups(true)); + existingItems = new ArrayList<>(app.getItineraryHelper().getMapMarkersFromDefaultGroups(true)); } @NonNull @@ -122,10 +122,10 @@ public class HistoryMarkersSettingsItem extends CollectionSettingsItem { protected void init() { super.init(); markersHelper = app.getMapMarkersHelper(); - existingItems = new ArrayList<>(markersHelper.getMapMarkersFromDefaultGroups(false)); + existingItems = new ArrayList<>(app.getItineraryHelper().getMapMarkersFromDefaultGroups(false)); } @NonNull @@ -122,10 +122,10 @@ public class MarkersSettingsItem extends CollectionSettingsItem { } } - public MapMarkersGroup getMarkersGroup() { + public ItineraryGroup getMarkersGroup() { String name = app.getString(R.string.map_markers); String groupId = ExportSettingsType.ACTIVE_MARKERS.name(); - MapMarkersGroup markersGroup = new MapMarkersGroup(groupId, name, MapMarkersGroup.ANY_TYPE); + ItineraryGroup markersGroup = new ItineraryGroup(groupId, name, ItineraryGroup.ANY_TYPE); markersGroup.setMarkers(items); return markersGroup; } diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java index 4204fded0b..0e3b9612cc 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java @@ -30,11 +30,10 @@ import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo; import net.osmand.plus.helpers.FileNameTranslationHelper; import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.helpers.GpxUiHelper.GPXInfo; -import net.osmand.plus.helpers.LocaleHelper; import net.osmand.plus.helpers.SearchHistoryHelper; import net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry; import net.osmand.plus.mapmarkers.MapMarker; -import net.osmand.plus.mapmarkers.MapMarkersGroup; +import net.osmand.plus.itinerary.ItineraryGroup; import net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine; import net.osmand.plus.osmedit.OpenstreetmapPoint; import net.osmand.plus.osmedit.OsmEditingPlugin; @@ -606,19 +605,19 @@ public class SettingsHelper { myPlacesItems.put(ExportSettingsType.MULTIMEDIA_NOTES, files); } } - List mapMarkers = app.getMapMarkersHelper().getMapMarkersFromDefaultGroups(false); + List mapMarkers = app.getItineraryHelper().getMapMarkersFromDefaultGroups(false); if (!mapMarkers.isEmpty()) { String name = app.getString(R.string.map_markers); String groupId = ExportSettingsType.ACTIVE_MARKERS.name(); - MapMarkersGroup markersGroup = new MapMarkersGroup(groupId, name, MapMarkersGroup.ANY_TYPE); + ItineraryGroup markersGroup = new ItineraryGroup(groupId, name, ItineraryGroup.ANY_TYPE); markersGroup.setMarkers(mapMarkers); myPlacesItems.put(ExportSettingsType.ACTIVE_MARKERS, Collections.singletonList(markersGroup)); } - List markersHistory = app.getMapMarkersHelper().getMapMarkersFromDefaultGroups(true); + List markersHistory = app.getItineraryHelper().getMapMarkersFromDefaultGroups(true); if (!markersHistory.isEmpty()) { String name = app.getString(R.string.shared_string_history); String groupId = ExportSettingsType.HISTORY_MARKERS.name(); - MapMarkersGroup markersGroup = new MapMarkersGroup(groupId, name, MapMarkersGroup.ANY_TYPE); + ItineraryGroup markersGroup = new ItineraryGroup(groupId, name, ItineraryGroup.ANY_TYPE); markersGroup.setMarkers(markersHistory); myPlacesItems.put(ExportSettingsType.HISTORY_MARKERS, Collections.singletonList(markersGroup)); } @@ -721,8 +720,8 @@ public class SettingsHelper { List favoriteGroups = new ArrayList<>(); List osmNotesPointList = new ArrayList<>(); List osmEditsPointList = new ArrayList<>(); - List markersGroups = new ArrayList<>(); - List markersHistoryGroups = new ArrayList<>(); + List markersGroups = new ArrayList<>(); + List markersHistoryGroups = new ArrayList<>(); List historyEntries = new ArrayList<>(); List onlineRoutingEngines = new ArrayList<>(); @@ -756,12 +755,12 @@ public class SettingsHelper { osmEditsPointList.add((OpenstreetmapPoint) object); } else if (object instanceof FavoriteGroup) { favoriteGroups.add((FavoriteGroup) object); - } else if (object instanceof MapMarkersGroup) { - MapMarkersGroup markersGroup = (MapMarkersGroup) object; + } else if (object instanceof ItineraryGroup) { + ItineraryGroup markersGroup = (ItineraryGroup) object; if (ExportSettingsType.ACTIVE_MARKERS.name().equals(markersGroup.getId())) { - markersGroups.add((MapMarkersGroup) object); + markersGroups.add((ItineraryGroup) object); } else if (ExportSettingsType.HISTORY_MARKERS.name().equals(markersGroup.getId())) { - markersHistoryGroups.add((MapMarkersGroup) object); + markersHistoryGroups.add((ItineraryGroup) object); } } else if (object instanceof HistoryEntry) { historyEntries.add((HistoryEntry) object); @@ -813,7 +812,7 @@ public class SettingsHelper { } if (!markersGroups.isEmpty()) { List mapMarkers = new ArrayList<>(); - for (MapMarkersGroup group : markersGroups) { + for (ItineraryGroup group : markersGroups) { mapMarkers.addAll(group.getMarkers()); } MarkersSettingsItem baseItem = getBaseItem(SettingsItemType.ACTIVE_MARKERS, MarkersSettingsItem.class, settingsItems); @@ -821,7 +820,7 @@ public class SettingsHelper { } if (!markersHistoryGroups.isEmpty()) { List mapMarkers = new ArrayList<>(); - for (MapMarkersGroup group : markersHistoryGroups) { + for (ItineraryGroup group : markersHistoryGroups) { mapMarkers.addAll(group.getMarkers()); } HistoryMarkersSettingsItem baseItem = getBaseItem(SettingsItemType.HISTORY_MARKERS, HistoryMarkersSettingsItem.class, settingsItems); @@ -911,8 +910,8 @@ public class SettingsHelper { List notesPointList = new ArrayList<>(); List editsPointList = new ArrayList<>(); List favoriteGroups = new ArrayList<>(); - List markersGroups = new ArrayList<>(); - List markersHistoryGroups = new ArrayList<>(); + List markersGroups = new ArrayList<>(); + List markersHistoryGroups = new ArrayList<>(); List historyEntries = new ArrayList<>(); List onlineRoutingEngines = new ArrayList<>(); diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/ExportItemsBottomSheet.java b/OsmAnd/src/net/osmand/plus/settings/fragments/ExportItemsBottomSheet.java index 59c7327975..5bfed7996f 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/ExportItemsBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/ExportItemsBottomSheet.java @@ -32,7 +32,7 @@ import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo; import net.osmand.plus.helpers.FileNameTranslationHelper; import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry; -import net.osmand.plus.mapmarkers.MapMarkersGroup; +import net.osmand.plus.itinerary.ItineraryGroup; import net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine; import net.osmand.plus.osmedit.OpenstreetmapPoint; import net.osmand.plus.osmedit.OsmEditingPlugin; @@ -355,8 +355,8 @@ public class ExportItemsBottomSheet extends MenuBottomSheetDialogFragment { GlobalSettingsItem globalSettingsItem = (GlobalSettingsItem) object; builder.setTitle(globalSettingsItem.getPublicName(app)); builder.setIcon(uiUtilities.getIcon(R.drawable.ic_action_settings, activeColorRes)); - } else if (object instanceof MapMarkersGroup) { - MapMarkersGroup markersGroup = (MapMarkersGroup) object; + } else if (object instanceof ItineraryGroup) { + ItineraryGroup markersGroup = (ItineraryGroup) object; if (ExportSettingsType.ACTIVE_MARKERS.name().equals(markersGroup.getId())) { builder.setTitle(getString(R.string.map_markers)); builder.setIcon(uiUtilities.getIcon(R.drawable.ic_action_flag, activeColorRes)); diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/ExportSettingsAdapter.java b/OsmAnd/src/net/osmand/plus/settings/fragments/ExportSettingsAdapter.java index 94816dbc1c..634d317b05 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/ExportSettingsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/ExportSettingsAdapter.java @@ -18,7 +18,7 @@ import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.OsmandBaseExpandableListAdapter; import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.FontCache; -import net.osmand.plus.mapmarkers.MapMarkersGroup; +import net.osmand.plus.itinerary.ItineraryGroup; import net.osmand.plus.settings.backend.ExportSettingsCategory; import net.osmand.plus.settings.backend.ExportSettingsType; import net.osmand.plus.settings.backend.backup.FileSettingsItem; @@ -318,8 +318,8 @@ public class ExportSettingsAdapter extends OsmandBaseExpandableListAdapter { itemsSize += ((FileSettingsItem) object).getSize(); } else if (object instanceof File) { itemsSize += ((File) object).length(); - } else if (object instanceof MapMarkersGroup) { - int selectedMarkers = ((MapMarkersGroup) object).getMarkers().size(); + } else if (object instanceof ItineraryGroup) { + int selectedMarkers = ((ItineraryGroup) object).getMarkers().size(); String itemsDescr = app.getString(R.string.shared_string_items); return app.getString(R.string.ltr_or_rtl_combine_via_colon, itemsDescr, selectedMarkers); } diff --git a/OsmAnd/src/net/osmand/plus/views/layers/FavouritesLayer.java b/OsmAnd/src/net/osmand/plus/views/layers/FavouritesLayer.java index d011e1dc8b..c2c00bcfe5 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/FavouritesLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/FavouritesLayer.java @@ -106,7 +106,7 @@ public class FavouritesLayer extends OsmandMapLayer implements IContextMenuProvi List smallObjectsLatLon = new ArrayList<>(); for (FavoriteGroup group : favouritesDbHelper.getFavoriteGroups()) { List> fullObjects = new ArrayList<>(); - boolean synced = mapMarkersHelper.getMarkersGroup(group) != null; + boolean synced = view.getApplication().getItineraryHelper().getMarkersGroup(group) != null; for (FavouritePoint favoritePoint : group.getPoints()) { double lat = favoritePoint.getLatitude(); double lon = favoritePoint.getLongitude(); diff --git a/OsmAnd/src/net/osmand/plus/views/layers/GPXLayer.java b/OsmAnd/src/net/osmand/plus/views/layers/GPXLayer.java index dfc2cbf426..b2a79dafb7 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/GPXLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/GPXLayer.java @@ -47,7 +47,7 @@ import net.osmand.plus.base.PointImageDrawable; import net.osmand.plus.mapcontextmenu.controllers.SelectedGpxMenuController.SelectedGpxPoint; import net.osmand.plus.mapcontextmenu.other.TrackChartPoints; import net.osmand.plus.mapmarkers.MapMarker; -import net.osmand.plus.mapmarkers.MapMarkersGroup; +import net.osmand.plus.itinerary.ItineraryGroup; import net.osmand.plus.mapmarkers.MapMarkersHelper; import net.osmand.plus.render.OsmandRenderer; import net.osmand.plus.render.OsmandRenderer.RenderingContext; @@ -512,7 +512,7 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM for (SelectedGpxFile g : selectedGPXFiles) { List> fullObjects = new ArrayList<>(); int fileColor = getFileColor(g); - boolean synced = mapMarkersHelper.getMarkersGroup(g.getGpxFile()) != null; + boolean synced = view.getApplication().getItineraryHelper().getMarkersGroup(g.getGpxFile()) != null; for (WptPt wpt : getListStarPoints(g)) { if (wpt.lat >= latLonBounds.bottom && wpt.lat <= latLonBounds.top && wpt.lon >= latLonBounds.left && wpt.lon <= latLonBounds.right @@ -1077,7 +1077,7 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM } private void syncGpx(GPXFile gpxFile) { - MapMarkersGroup group = view.getApplication().getMapMarkersHelper().getMarkersGroup(gpxFile); + ItineraryGroup group = view.getApplication().getItineraryHelper().getMarkersGroup(gpxFile); if (group != null) { view.getApplication().getItineraryHelper().runSynchronization(group); }