From eefe1a00ac229ee39c10ab3becaa33eeb0e520db Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Wed, 21 Apr 2021 15:07:18 +0300 Subject: [PATCH] Revert "Create ItineraryHelper" This reverts commit 7218e7d4 --- .../src/net/osmand/plus/AppInitializer.java | 2 - .../net/osmand/plus/FavouritesDbHelper.java | 5 +- .../net/osmand/plus/GpxSelectionHelper.java | 6 +- .../net/osmand/plus/OsmandApplication.java | 10 -- .../plus/itinerary/ItineraryHelper.java | 152 ------------------ .../editors/WptPtEditorFragment.java | 8 +- .../editors/WptPtEditorFragmentNew.java | 8 +- .../CoordinateInputDialogFragment.java | 2 +- .../mapmarkers/MapMarkersDialogFragment.java | 4 +- .../plus/mapmarkers/MapMarkersHelper.java | 135 ++++++++++++++-- ...ptCategoriesBottomSheetDialogFragment.java | 2 +- .../adapters/MapMarkersGroupsAdapter.java | 2 +- .../plus/myplaces/DeletePointsTask.java | 6 +- .../EditTrackGroupDialogFragment.java | 7 +- .../osmand/plus/views/layers/GPXLayer.java | 2 +- 15 files changed, 156 insertions(+), 195 deletions(-) delete mode 100644 OsmAnd/src/net/osmand/plus/itinerary/ItineraryHelper.java diff --git a/OsmAnd/src/net/osmand/plus/AppInitializer.java b/OsmAnd/src/net/osmand/plus/AppInitializer.java index cfcdc737b2..07bb9084e8 100644 --- a/OsmAnd/src/net/osmand/plus/AppInitializer.java +++ b/OsmAnd/src/net/osmand/plus/AppInitializer.java @@ -40,7 +40,6 @@ import net.osmand.plus.helpers.DayNightHelper; import net.osmand.plus.helpers.LockHelper; import net.osmand.plus.helpers.WaypointHelper; import net.osmand.plus.inapp.InAppPurchaseHelperImpl; -import net.osmand.plus.itinerary.ItineraryHelper; import net.osmand.plus.liveupdates.LiveUpdatesHelper; import net.osmand.plus.mapmarkers.MapMarkersDbHelper; import net.osmand.plus.mapmarkers.MapMarkersHelper; @@ -473,7 +472,6 @@ public class AppInitializer implements IProgress { app.osmOAuthHelper = startupInit(new OsmOAuthHelper(app), OsmOAuthHelper.class); app.oprAuthHelper = startupInit(new OprAuthHelper(app), OprAuthHelper.class); app.onlineRoutingHelper = startupInit(new OnlineRoutingHelper(app), OnlineRoutingHelper.class); - app.itineraryHelper = startupInit(new ItineraryHelper(app), ItineraryHelper.class); app.backupHelper = startupInit(new BackupHelper(app), BackupHelper.class); initOpeningHoursParser(); diff --git a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java index ca52169e10..42cf1c0d2e 100644 --- a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java @@ -280,9 +280,10 @@ public class FavouritesDbHelper { } private void runSyncWithMarkers(FavoriteGroup favGroup) { - MapMarkersGroup group = context.getMapMarkersHelper().getMarkersGroup(favGroup); + MapMarkersHelper helper = context.getMapMarkersHelper(); + MapMarkersGroup group = helper.getMarkersGroup(favGroup); if (group != null) { - context.getItineraryHelper().runSynchronization(group); + helper.runSynchronization(group); } } diff --git a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java index 77bcb5e0e7..0eba1b2b1a 100644 --- a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java +++ b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java @@ -31,6 +31,7 @@ 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.mapmarkers.MapMarkersHelper; import net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder; import net.osmand.plus.track.GpxSplitType; import net.osmand.util.Algorithms; @@ -824,9 +825,10 @@ public class GpxSelectionHelper { } private void syncGpxWithMarkers(GPXFile gpxFile) { - MapMarkersGroup group = app.getMapMarkersHelper().getMarkersGroup(gpxFile); + MapMarkersHelper mapMarkersHelper = app.getMapMarkersHelper(); + MapMarkersGroup group = mapMarkersHelper.getMarkersGroup(gpxFile); if (group != null) { - app.getItineraryHelper().runSynchronization(group); + mapMarkersHelper.runSynchronization(group); } } diff --git a/OsmAnd/src/net/osmand/plus/OsmandApplication.java b/OsmAnd/src/net/osmand/plus/OsmandApplication.java index ddbbd7087e..e6e6539bcb 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandApplication.java +++ b/OsmAnd/src/net/osmand/plus/OsmandApplication.java @@ -67,7 +67,6 @@ import net.osmand.plus.helpers.WaypointHelper; import net.osmand.plus.helpers.enums.DrivingRegion; import net.osmand.plus.helpers.enums.MetricsConstants; import net.osmand.plus.inapp.InAppPurchaseHelper; -import net.osmand.plus.itinerary.ItineraryHelper; import net.osmand.plus.mapmarkers.MapMarkersDbHelper; import net.osmand.plus.mapmarkers.MapMarkersHelper; import net.osmand.plus.measurementtool.MeasurementEditingContext; @@ -169,7 +168,6 @@ public class OsmandApplication extends MultiDexApplication { OprAuthHelper oprAuthHelper; MeasurementEditingContext measurementEditingContext; OnlineRoutingHelper onlineRoutingHelper; - ItineraryHelper itineraryHelper; BackupHelper backupHelper; private Map customRoutingConfigs = new ConcurrentHashMap<>(); @@ -472,14 +470,6 @@ public class OsmandApplication extends MultiDexApplication { return onlineRoutingHelper; } - public ItineraryHelper getItineraryHelper() { - return itineraryHelper; - } - - public BackupHelper getBackupHelper() { - return backupHelper; - } - public TransportRoutingHelper getTransportRoutingHelper() { return transportRoutingHelper; } diff --git a/OsmAnd/src/net/osmand/plus/itinerary/ItineraryHelper.java b/OsmAnd/src/net/osmand/plus/itinerary/ItineraryHelper.java deleted file mode 100644 index 8e3c96a08a..0000000000 --- a/OsmAnd/src/net/osmand/plus/itinerary/ItineraryHelper.java +++ /dev/null @@ -1,152 +0,0 @@ -package net.osmand.plus.itinerary; - -import android.os.AsyncTask; - -import androidx.annotation.NonNull; - -import net.osmand.GPXUtilities.GPXFile; -import net.osmand.GPXUtilities.WptPt; -import net.osmand.PlatformUtil; -import net.osmand.data.FavouritePoint; -import net.osmand.data.LatLon; -import net.osmand.plus.FavouritesDbHelper.FavoriteGroup; -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.MapMarkersHelper; -import net.osmand.plus.mapmarkers.MapMarkersHelper.OnGroupSyncedListener; - -import org.apache.commons.logging.Log; - -import java.io.File; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -public class ItineraryHelper { - - private static final Log LOG = PlatformUtil.getLog(ItineraryHelper.class); - - private OsmandApplication app; - - private MapMarkersHelper markersHelper; - - private ExecutorService executorService = Executors.newSingleThreadExecutor(); - - private Set syncListeners = new HashSet<>(); - - public ItineraryHelper(@NonNull OsmandApplication app) { - this.app = app; - markersHelper = app.getMapMarkersHelper(); - } - - public void addSyncListener(OnGroupSyncedListener listener) { - syncListeners.add(listener); - } - - public void removeSyncListener(OnGroupSyncedListener listener) { - syncListeners.remove(listener); - } - - public void runSynchronization(final @NonNull MapMarkersGroup group) { - app.runInUIThread(new Runnable() { - @Override - public void run() { - new SyncGroupTask(group).executeOnExecutor(executorService); - } - }); - } - - private class SyncGroupTask extends AsyncTask { - - private MapMarkersGroup group; - - SyncGroupTask(MapMarkersGroup group) { - this.group = group; - } - - @Override - protected void onPreExecute() { - if (!syncListeners.isEmpty()) { - app.runInUIThread(new Runnable() { - @Override - public void run() { - for (OnGroupSyncedListener listener : syncListeners) { - listener.onSyncStarted(); - } - } - }); - } - } - - @Override - protected Void doInBackground(Void... voids) { - runGroupSynchronization(); - return null; - } - - // TODO extract method from Asynctask to Helper directly - private void runGroupSynchronization() { - List groupMarkers = new ArrayList<>(group.getMarkers()); - if (group.getType() == MapMarkersGroup.FAVORITES_TYPE) { - FavoriteGroup favGroup = app.getFavorites().getGroup(group.getName()); - if (favGroup == null) { - return; - } - group.setVisible(favGroup.isVisible()); - if (!group.isVisible() || group.isDisabled()) { - markersHelper.removeGroupActiveMarkers(group, true); - return; - } - List points = new ArrayList<>(favGroup.getPoints()); - 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) { - GpxSelectionHelper gpxHelper = app.getSelectedGpxHelper(); - File file = new File(group.getId()); - if (!file.exists()) { - return; - } - - String gpxPath = group.getId(); - SelectedGpxFile selectedGpxFile = gpxHelper.getSelectedFileByPath(gpxPath); - GPXFile gpx = selectedGpxFile == null ? null : selectedGpxFile.getGpxFile(); - group.setVisible(gpx != null || group.isVisibleUntilRestart()); - if (gpx == null || group.isDisabled()) { - markersHelper.removeGroupActiveMarkers(group, true); - return; - } - - boolean addAll = group.getWptCategories() == null || group.getWptCategories().isEmpty(); - List gpxPoints = new ArrayList<>(gpx.getPoints()); - for (WptPt pt : gpxPoints) { - if (addAll || group.getWptCategories().contains(pt.category) - || (pt.category == null && group.getWptCategories().contains(""))) { - markersHelper.addNewMarkerIfNeeded(group, groupMarkers, new LatLon(pt.lat, pt.lon), pt.name, null, pt); - } - } - } - markersHelper.removeOldMarkersIfPresent(groupMarkers); - } - - @Override - protected void onPostExecute(Void aVoid) { - if (!syncListeners.isEmpty()) { - app.runInUIThread(new Runnable() { - @Override - public void run() { - for (OnGroupSyncedListener listener : syncListeners) { - listener.onSyncDone(); - } - } - }); - } - } - } -} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragment.java index e1c1ac3d61..2d0654301b 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragment.java @@ -17,6 +17,8 @@ import net.osmand.GPXUtilities.WptPt; import net.osmand.data.LatLon; import net.osmand.data.WptLocationPoint; import net.osmand.plus.GpxSelectionHelper; +import net.osmand.plus.mapmarkers.MapMarkersHelper; +import net.osmand.plus.mapmarkers.MapMarkersGroup; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; @@ -24,7 +26,6 @@ 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.track.SaveGpxAsyncTask; import net.osmand.plus.track.SaveGpxAsyncTask.SaveGpxListener; import net.osmand.util.Algorithms; @@ -219,9 +220,10 @@ public class WptPtEditorFragment extends PointEditorFragment { private void syncGpx(GPXFile gpxFile) { OsmandApplication app = getMyApplication(); if (app != null) { - MapMarkersGroup group = app.getMapMarkersHelper().getMarkersGroup(gpxFile); + MapMarkersHelper helper = app.getMapMarkersHelper(); + MapMarkersGroup group = helper.getMarkersGroup(gpxFile); if (group != null) { - app.getItineraryHelper().runSynchronization(group); + helper.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 4dea53b0bd..7ecd61565f 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragmentNew.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragmentNew.java @@ -20,6 +20,8 @@ import net.osmand.data.FavouritePoint.BackgroundType; import net.osmand.data.LatLon; import net.osmand.data.WptLocationPoint; import net.osmand.plus.GpxSelectionHelper; +import net.osmand.plus.mapmarkers.MapMarkersHelper; +import net.osmand.plus.mapmarkers.MapMarkersGroup; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; @@ -29,7 +31,6 @@ 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.track.SaveGpxAsyncTask; import net.osmand.plus.track.SaveGpxAsyncTask.SaveGpxListener; import net.osmand.util.Algorithms; @@ -237,9 +238,10 @@ public class WptPtEditorFragmentNew extends PointEditorFragmentNew { private void syncGpx(GPXFile gpxFile) { OsmandApplication app = getMyApplication(); if (app != null) { - MapMarkersGroup group = app.getMapMarkersHelper().getMarkersGroup(gpxFile); + MapMarkersHelper helper = app.getMapMarkersHelper(); + MapMarkersGroup group = helper.getMarkersGroup(gpxFile); if (group != null) { - app.getItineraryHelper().runSynchronization(group); + helper.runSynchronization(group); } } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java index 31e477fbf1..96d6f9a8f4 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java @@ -171,7 +171,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm MapMarkersHelper helper = getMyApplication().getMapMarkersHelper(); MapMarkersGroup group = helper.getMarkersGroup(gpxFile); if (group != null) { - getMyApplication().getItineraryHelper().runSynchronization(group); + helper.runSynchronization(group); } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java index ad453d5fe5..f0b226dd1e 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java @@ -218,13 +218,13 @@ public class MapMarkersDialogFragment extends DialogFragment implements OnGroupS @Override public void onResume() { super.onResume(); - getMyApplication().getItineraryHelper().addSyncListener(this); + getMyApplication().getMapMarkersHelper().addSyncListener(this); } @Override public void onPause() { super.onPause(); - getMyApplication().getItineraryHelper().removeSyncListener(this); + getMyApplication().getMapMarkersHelper().removeSyncListener(this); } @Override diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHelper.java index b8bcddbc5c..51911e8779 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHelper.java @@ -1,5 +1,7 @@ package net.osmand.plus.mapmarkers; +import android.os.AsyncTask; + import androidx.annotation.IntDef; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -18,6 +20,7 @@ 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; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; @@ -38,12 +41,15 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Date; +import java.util.HashSet; 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 java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import static net.osmand.GPXUtilities.GPX_TIME_FORMAT; import static net.osmand.data.PointDescription.POINT_TYPE_MAP_MARKER; @@ -72,11 +78,14 @@ public class MapMarkersHelper { private OsmandApplication ctx; private MapMarkersDbHelper markersDbHelper; + private ExecutorService executorService = Executors.newSingleThreadExecutor(); + private List mapMarkers = new ArrayList<>(); private List mapMarkersHistory = new ArrayList<>(); private List mapMarkersGroups = new ArrayList<>(); private List listeners = new ArrayList<>(); + private Set syncListeners = new HashSet<>(); private MarkersPlanRouteContext planRouteContext; @@ -177,7 +186,7 @@ public class MapMarkersHelper { public void syncAllGroupsAsync() { for (MapMarkersGroup gr : mapMarkersGroups) { if (gr.getId() != null && gr.getName() != null) { - ctx.getItineraryHelper().runSynchronization(gr); + runSynchronization(gr); } } } @@ -294,6 +303,15 @@ public class MapMarkersHelper { }); } + public void runSynchronization(final @NonNull MapMarkersGroup group) { + ctx.runInUIThread(new Runnable() { + @Override + public void run() { + new SyncGroupTask(group).executeOnExecutor(executorService); + } + }); + } + public MapMarkersGroup getMarkersGroup(GPXFile gpx) { if (gpx == null || gpx.path == null) { return null; @@ -345,7 +363,7 @@ public class MapMarkersHelper { if (gr.isDisabled()) { updateGroupDisabled(gr, false); } - ctx.getItineraryHelper().runSynchronization(gr); + runSynchronization(gr); } private void addGroupInternally(MapMarkersGroup gr) { @@ -397,7 +415,7 @@ public class MapMarkersHelper { } } - public void removeGroupActiveMarkers(MapMarkersGroup group, boolean updateGroup) { + private void removeGroupActiveMarkers(MapMarkersGroup group, boolean updateGroup) { if (group != null) { markersDbHelper.removeActiveMarkersFromGroup(group.getId()); removeFromMapMarkersList(group.getActiveMarkers()); @@ -618,12 +636,12 @@ public class MapMarkersHelper { return null; } - public void addNewMarkerIfNeeded(@NonNull MapMarkersGroup group, - @NonNull List groupMarkers, - @NonNull LatLon latLon, - @NonNull String name, - @Nullable FavouritePoint favouritePoint, - @Nullable WptPt wptPt) { + private void addNewMarkerIfNeeded(@NonNull MapMarkersGroup group, + @NonNull List groupMarkers, + @NonNull LatLon latLon, + @NonNull String name, + @Nullable FavouritePoint favouritePoint, + @Nullable WptPt wptPt) { boolean exists = false; Iterator iterator = groupMarkers.iterator(); @@ -653,7 +671,7 @@ public class MapMarkersHelper { } } - public void removeOldMarkersIfPresent(List markers) { + private void removeOldMarkersIfPresent(List markers) { if (!markers.isEmpty()) { boolean needRefresh = false; for (MapMarker marker : markers) { @@ -952,6 +970,14 @@ public class MapMarkersHelper { } } + public void addSyncListener(OnGroupSyncedListener listener) { + syncListeners.add(listener); + } + + public void removeSyncListener(OnGroupSyncedListener listener) { + syncListeners.remove(listener); + } + public void addListener(MapMarkerChangedListener l) { if (!listeners.contains(l)) { listeners.add(l); @@ -1168,4 +1194,93 @@ public class MapMarkersHelper { void onSyncDone(); } + + private class SyncGroupTask extends AsyncTask { + + private MapMarkersGroup group; + + SyncGroupTask(MapMarkersGroup group) { + this.group = group; + } + + @Override + protected void onPreExecute() { + if (!syncListeners.isEmpty()) { + ctx.runInUIThread(new Runnable() { + @Override + public void run() { + for (OnGroupSyncedListener listener : syncListeners) { + listener.onSyncStarted(); + } + } + }); + } + } + + @Override + protected Void doInBackground(Void... voids) { + runGroupSynchronization(); + return null; + } + + // TODO extract method from Asynctask to Helper directly + private void runGroupSynchronization() { + List groupMarkers = new ArrayList<>(group.getMarkers()); + if (group.getType() == MapMarkersGroup.FAVORITES_TYPE) { + FavoriteGroup favGroup = ctx.getFavorites().getGroup(group.getName()); + if (favGroup == null) { + return; + } + group.setVisible(favGroup.isVisible()); + if (!group.isVisible() || group.isDisabled()) { + removeGroupActiveMarkers(group, true); + return; + } + List points = new ArrayList<>(favGroup.getPoints()); + for (FavouritePoint fp : points) { + addNewMarkerIfNeeded(group, groupMarkers, new LatLon(fp.getLatitude(), fp.getLongitude()), fp.getName(), fp, null); + } + } else if (group.getType() == MapMarkersGroup.GPX_TYPE) { + GpxSelectionHelper gpxHelper = ctx.getSelectedGpxHelper(); + File file = new File(group.getId()); + if (!file.exists()) { + return; + } + + String gpxPath = group.getId(); + SelectedGpxFile selectedGpxFile = gpxHelper.getSelectedFileByPath(gpxPath); + GPXFile gpx = selectedGpxFile == null ? null : selectedGpxFile.getGpxFile(); + group.setVisible(gpx != null || group.isVisibleUntilRestart()); + if (gpx == null || group.isDisabled()) { + removeGroupActiveMarkers(group, true); + return; + } + + boolean addAll = group.getWptCategories() == null || group.getWptCategories().isEmpty(); + List gpxPoints = new ArrayList<>(gpx.getPoints()); + for (WptPt pt : gpxPoints) { + if (addAll || group.getWptCategories().contains(pt.category) + || (pt.category == null && group.getWptCategories().contains(""))) { + addNewMarkerIfNeeded(group, groupMarkers, new LatLon(pt.lat, pt.lon), pt.name, null, pt); + } + } + } + + removeOldMarkersIfPresent(groupMarkers); + } + + @Override + protected void onPostExecute(Void aVoid) { + if (!syncListeners.isEmpty()) { + ctx.runInUIThread(new Runnable() { + @Override + public void run() { + for (OnGroupSyncedListener listener : syncListeners) { + listener.onSyncDone(); + } + } + }); + } + } + } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/SelectWptCategoriesBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/SelectWptCategoriesBottomSheetDialogFragment.java index 1f86a94a1d..08db4d40fc 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/SelectWptCategoriesBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/SelectWptCategoriesBottomSheetDialogFragment.java @@ -147,7 +147,7 @@ public class SelectWptCategoriesBottomSheetDialogFragment extends MenuBottomShee group = mapMarkersHelper.addOrEnableGroup(gpxFile); } mapMarkersHelper.updateGroupWptCategories(group, selectedCategories); - app.getItineraryHelper().runSynchronization(group); + mapMarkersHelper.runSynchronization(group); } private boolean isAllChecked() { diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java index 4992ee88be..fb74956b16 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java @@ -478,7 +478,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter { } private void syncGpx(GPXFile gpxFile) { - MapMarkersGroup group = app.getMapMarkersHelper().getMarkersGroup(gpxFile); + MapMarkersHelper helper = app.getMapMarkersHelper(); + MapMarkersGroup group = helper.getMarkersGroup(gpxFile); if (group != null) { - app.getItineraryHelper().runSynchronization(group); + helper.runSynchronization(group); } } diff --git a/OsmAnd/src/net/osmand/plus/myplaces/EditTrackGroupDialogFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/EditTrackGroupDialogFragment.java index b3ff9b91bd..674ee76042 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/EditTrackGroupDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/EditTrackGroupDialogFragment.java @@ -236,7 +236,7 @@ public class EditTrackGroupDialogFragment extends MenuBottomSheetDialogFragment } else { mapMarkersHelper.updateGroupWptCategories(markersGroup, selectedCategories); if (!groupCreated) { - app.getItineraryHelper().runSynchronization(markersGroup); + mapMarkersHelper.runSynchronization(markersGroup); } } } @@ -524,9 +524,10 @@ public class EditTrackGroupDialogFragment extends MenuBottomSheetDialogFragment } private void syncGpx(GPXFile gpxFile) { - MapMarkersGroup group = app.getMapMarkersHelper().getMarkersGroup(gpxFile); + MapMarkersHelper markersHelper = app.getMapMarkersHelper(); + MapMarkersGroup group = markersHelper.getMarkersGroup(gpxFile); if (group != null) { - app.getItineraryHelper().runSynchronization(group); + markersHelper.runSynchronization(group); } } } diff --git a/OsmAnd/src/net/osmand/plus/views/layers/GPXLayer.java b/OsmAnd/src/net/osmand/plus/views/layers/GPXLayer.java index 99d4d41c81..b26940ff7b 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/GPXLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/GPXLayer.java @@ -1229,7 +1229,7 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM private void syncGpx(GPXFile gpxFile) { MapMarkersGroup group = view.getApplication().getMapMarkersHelper().getMarkersGroup(gpxFile); if (group != null) { - view.getApplication().getItineraryHelper().runSynchronization(group); + mapMarkersHelper.runSynchronization(group); } }