Revert "Create ItineraryHelper"

This reverts commit 7218e7d4
This commit is contained in:
Vitaliy 2021-04-21 15:07:18 +03:00
parent cb18d45e43
commit eefe1a00ac
15 changed files with 156 additions and 195 deletions

View file

@ -40,7 +40,6 @@ import net.osmand.plus.helpers.DayNightHelper;
import net.osmand.plus.helpers.LockHelper; import net.osmand.plus.helpers.LockHelper;
import net.osmand.plus.helpers.WaypointHelper; import net.osmand.plus.helpers.WaypointHelper;
import net.osmand.plus.inapp.InAppPurchaseHelperImpl; import net.osmand.plus.inapp.InAppPurchaseHelperImpl;
import net.osmand.plus.itinerary.ItineraryHelper;
import net.osmand.plus.liveupdates.LiveUpdatesHelper; import net.osmand.plus.liveupdates.LiveUpdatesHelper;
import net.osmand.plus.mapmarkers.MapMarkersDbHelper; import net.osmand.plus.mapmarkers.MapMarkersDbHelper;
import net.osmand.plus.mapmarkers.MapMarkersHelper; import net.osmand.plus.mapmarkers.MapMarkersHelper;
@ -473,7 +472,6 @@ public class AppInitializer implements IProgress {
app.osmOAuthHelper = startupInit(new OsmOAuthHelper(app), OsmOAuthHelper.class); app.osmOAuthHelper = startupInit(new OsmOAuthHelper(app), OsmOAuthHelper.class);
app.oprAuthHelper = startupInit(new OprAuthHelper(app), OprAuthHelper.class); app.oprAuthHelper = startupInit(new OprAuthHelper(app), OprAuthHelper.class);
app.onlineRoutingHelper = startupInit(new OnlineRoutingHelper(app), OnlineRoutingHelper.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); app.backupHelper = startupInit(new BackupHelper(app), BackupHelper.class);
initOpeningHoursParser(); initOpeningHoursParser();

View file

@ -280,9 +280,10 @@ public class FavouritesDbHelper {
} }
private void runSyncWithMarkers(FavoriteGroup favGroup) { private void runSyncWithMarkers(FavoriteGroup favGroup) {
MapMarkersGroup group = context.getMapMarkersHelper().getMarkersGroup(favGroup); MapMarkersHelper helper = context.getMapMarkersHelper();
MapMarkersGroup group = helper.getMarkersGroup(favGroup);
if (group != null) { if (group != null) {
context.getItineraryHelper().runSynchronization(group); helper.runSynchronization(group);
} }
} }

View file

@ -31,6 +31,7 @@ import net.osmand.plus.helpers.GpxUiHelper.GPXInfo;
import net.osmand.plus.helpers.SearchHistoryHelper; import net.osmand.plus.helpers.SearchHistoryHelper;
import net.osmand.plus.helpers.enums.MetricsConstants; import net.osmand.plus.helpers.enums.MetricsConstants;
import net.osmand.plus.mapmarkers.MapMarkersGroup; import net.osmand.plus.mapmarkers.MapMarkersGroup;
import net.osmand.plus.mapmarkers.MapMarkersHelper;
import net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder; import net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder;
import net.osmand.plus.track.GpxSplitType; import net.osmand.plus.track.GpxSplitType;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -824,9 +825,10 @@ public class GpxSelectionHelper {
} }
private void syncGpxWithMarkers(GPXFile gpxFile) { private void syncGpxWithMarkers(GPXFile gpxFile) {
MapMarkersGroup group = app.getMapMarkersHelper().getMarkersGroup(gpxFile); MapMarkersHelper mapMarkersHelper = app.getMapMarkersHelper();
MapMarkersGroup group = mapMarkersHelper.getMarkersGroup(gpxFile);
if (group != null) { if (group != null) {
app.getItineraryHelper().runSynchronization(group); mapMarkersHelper.runSynchronization(group);
} }
} }

View file

@ -67,7 +67,6 @@ import net.osmand.plus.helpers.WaypointHelper;
import net.osmand.plus.helpers.enums.DrivingRegion; import net.osmand.plus.helpers.enums.DrivingRegion;
import net.osmand.plus.helpers.enums.MetricsConstants; import net.osmand.plus.helpers.enums.MetricsConstants;
import net.osmand.plus.inapp.InAppPurchaseHelper; import net.osmand.plus.inapp.InAppPurchaseHelper;
import net.osmand.plus.itinerary.ItineraryHelper;
import net.osmand.plus.mapmarkers.MapMarkersDbHelper; import net.osmand.plus.mapmarkers.MapMarkersDbHelper;
import net.osmand.plus.mapmarkers.MapMarkersHelper; import net.osmand.plus.mapmarkers.MapMarkersHelper;
import net.osmand.plus.measurementtool.MeasurementEditingContext; import net.osmand.plus.measurementtool.MeasurementEditingContext;
@ -169,7 +168,6 @@ public class OsmandApplication extends MultiDexApplication {
OprAuthHelper oprAuthHelper; OprAuthHelper oprAuthHelper;
MeasurementEditingContext measurementEditingContext; MeasurementEditingContext measurementEditingContext;
OnlineRoutingHelper onlineRoutingHelper; OnlineRoutingHelper onlineRoutingHelper;
ItineraryHelper itineraryHelper;
BackupHelper backupHelper; BackupHelper backupHelper;
private Map<String, Builder> customRoutingConfigs = new ConcurrentHashMap<>(); private Map<String, Builder> customRoutingConfigs = new ConcurrentHashMap<>();
@ -472,14 +470,6 @@ public class OsmandApplication extends MultiDexApplication {
return onlineRoutingHelper; return onlineRoutingHelper;
} }
public ItineraryHelper getItineraryHelper() {
return itineraryHelper;
}
public BackupHelper getBackupHelper() {
return backupHelper;
}
public TransportRoutingHelper getTransportRoutingHelper() { public TransportRoutingHelper getTransportRoutingHelper() {
return transportRoutingHelper; return transportRoutingHelper;
} }

View file

@ -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<OnGroupSyncedListener> 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<Void, Void, Void> {
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<MapMarker> 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<FavouritePoint> 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<WptPt> 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();
}
}
});
}
}
}
}

View file

@ -17,6 +17,8 @@ import net.osmand.GPXUtilities.WptPt;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.WptLocationPoint; import net.osmand.data.WptLocationPoint;
import net.osmand.plus.GpxSelectionHelper; 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.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; 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.base.PointImageDrawable;
import net.osmand.plus.mapcontextmenu.MapContextMenu; import net.osmand.plus.mapcontextmenu.MapContextMenu;
import net.osmand.plus.mapcontextmenu.editors.WptPtEditor.OnDismissListener; 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;
import net.osmand.plus.track.SaveGpxAsyncTask.SaveGpxListener; import net.osmand.plus.track.SaveGpxAsyncTask.SaveGpxListener;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -219,9 +220,10 @@ public class WptPtEditorFragment extends PointEditorFragment {
private void syncGpx(GPXFile gpxFile) { private void syncGpx(GPXFile gpxFile) {
OsmandApplication app = getMyApplication(); OsmandApplication app = getMyApplication();
if (app != null) { if (app != null) {
MapMarkersGroup group = app.getMapMarkersHelper().getMarkersGroup(gpxFile); MapMarkersHelper helper = app.getMapMarkersHelper();
MapMarkersGroup group = helper.getMarkersGroup(gpxFile);
if (group != null) { if (group != null) {
app.getItineraryHelper().runSynchronization(group); helper.runSynchronization(group);
} }
} }
} }

View file

@ -20,6 +20,8 @@ import net.osmand.data.FavouritePoint.BackgroundType;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.WptLocationPoint; import net.osmand.data.WptLocationPoint;
import net.osmand.plus.GpxSelectionHelper; 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.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; 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.base.PointImageDrawable;
import net.osmand.plus.mapcontextmenu.MapContextMenu; import net.osmand.plus.mapcontextmenu.MapContextMenu;
import net.osmand.plus.mapcontextmenu.editors.WptPtEditor.OnDismissListener; 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;
import net.osmand.plus.track.SaveGpxAsyncTask.SaveGpxListener; import net.osmand.plus.track.SaveGpxAsyncTask.SaveGpxListener;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -237,9 +238,10 @@ public class WptPtEditorFragmentNew extends PointEditorFragmentNew {
private void syncGpx(GPXFile gpxFile) { private void syncGpx(GPXFile gpxFile) {
OsmandApplication app = getMyApplication(); OsmandApplication app = getMyApplication();
if (app != null) { if (app != null) {
MapMarkersGroup group = app.getMapMarkersHelper().getMarkersGroup(gpxFile); MapMarkersHelper helper = app.getMapMarkersHelper();
MapMarkersGroup group = helper.getMarkersGroup(gpxFile);
if (group != null) { if (group != null) {
app.getItineraryHelper().runSynchronization(group); helper.runSynchronization(group);
} }
} }
} }

View file

@ -171,7 +171,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
MapMarkersHelper helper = getMyApplication().getMapMarkersHelper(); MapMarkersHelper helper = getMyApplication().getMapMarkersHelper();
MapMarkersGroup group = helper.getMarkersGroup(gpxFile); MapMarkersGroup group = helper.getMarkersGroup(gpxFile);
if (group != null) { if (group != null) {
getMyApplication().getItineraryHelper().runSynchronization(group); helper.runSynchronization(group);
} }
} }

View file

@ -218,13 +218,13 @@ public class MapMarkersDialogFragment extends DialogFragment implements OnGroupS
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
getMyApplication().getItineraryHelper().addSyncListener(this); getMyApplication().getMapMarkersHelper().addSyncListener(this);
} }
@Override @Override
public void onPause() { public void onPause() {
super.onPause(); super.onPause();
getMyApplication().getItineraryHelper().removeSyncListener(this); getMyApplication().getMapMarkersHelper().removeSyncListener(this);
} }
@Override @Override

View file

@ -1,5 +1,7 @@
package net.osmand.plus.mapmarkers; package net.osmand.plus.mapmarkers;
import android.os.AsyncTask;
import androidx.annotation.IntDef; import androidx.annotation.IntDef;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
@ -18,6 +20,7 @@ import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
import net.osmand.plus.GPXDatabase; import net.osmand.plus.GPXDatabase;
import net.osmand.plus.GeocodingLookupService; import net.osmand.plus.GeocodingLookupService;
import net.osmand.plus.GeocodingLookupService.AddressLookupRequest; import net.osmand.plus.GeocodingLookupService.AddressLookupRequest;
import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
@ -38,12 +41,15 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.Date; import java.util.Date;
import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.TimeZone; 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.GPXUtilities.GPX_TIME_FORMAT;
import static net.osmand.data.PointDescription.POINT_TYPE_MAP_MARKER; import static net.osmand.data.PointDescription.POINT_TYPE_MAP_MARKER;
@ -72,11 +78,14 @@ public class MapMarkersHelper {
private OsmandApplication ctx; private OsmandApplication ctx;
private MapMarkersDbHelper markersDbHelper; private MapMarkersDbHelper markersDbHelper;
private ExecutorService executorService = Executors.newSingleThreadExecutor();
private List<MapMarker> mapMarkers = new ArrayList<>(); private List<MapMarker> mapMarkers = new ArrayList<>();
private List<MapMarker> mapMarkersHistory = new ArrayList<>(); private List<MapMarker> mapMarkersHistory = new ArrayList<>();
private List<MapMarkersGroup> mapMarkersGroups = new ArrayList<>(); private List<MapMarkersGroup> mapMarkersGroups = new ArrayList<>();
private List<MapMarkerChangedListener> listeners = new ArrayList<>(); private List<MapMarkerChangedListener> listeners = new ArrayList<>();
private Set<OnGroupSyncedListener> syncListeners = new HashSet<>();
private MarkersPlanRouteContext planRouteContext; private MarkersPlanRouteContext planRouteContext;
@ -177,7 +186,7 @@ public class MapMarkersHelper {
public void syncAllGroupsAsync() { public void syncAllGroupsAsync() {
for (MapMarkersGroup gr : mapMarkersGroups) { for (MapMarkersGroup gr : mapMarkersGroups) {
if (gr.getId() != null && gr.getName() != null) { 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) { public MapMarkersGroup getMarkersGroup(GPXFile gpx) {
if (gpx == null || gpx.path == null) { if (gpx == null || gpx.path == null) {
return null; return null;
@ -345,7 +363,7 @@ public class MapMarkersHelper {
if (gr.isDisabled()) { if (gr.isDisabled()) {
updateGroupDisabled(gr, false); updateGroupDisabled(gr, false);
} }
ctx.getItineraryHelper().runSynchronization(gr); runSynchronization(gr);
} }
private void addGroupInternally(MapMarkersGroup 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) { if (group != null) {
markersDbHelper.removeActiveMarkersFromGroup(group.getId()); markersDbHelper.removeActiveMarkersFromGroup(group.getId());
removeFromMapMarkersList(group.getActiveMarkers()); removeFromMapMarkersList(group.getActiveMarkers());
@ -618,7 +636,7 @@ public class MapMarkersHelper {
return null; return null;
} }
public void addNewMarkerIfNeeded(@NonNull MapMarkersGroup group, private void addNewMarkerIfNeeded(@NonNull MapMarkersGroup group,
@NonNull List<MapMarker> groupMarkers, @NonNull List<MapMarker> groupMarkers,
@NonNull LatLon latLon, @NonNull LatLon latLon,
@NonNull String name, @NonNull String name,
@ -653,7 +671,7 @@ public class MapMarkersHelper {
} }
} }
public void removeOldMarkersIfPresent(List<MapMarker> markers) { private void removeOldMarkersIfPresent(List<MapMarker> markers) {
if (!markers.isEmpty()) { if (!markers.isEmpty()) {
boolean needRefresh = false; boolean needRefresh = false;
for (MapMarker marker : markers) { 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) { public void addListener(MapMarkerChangedListener l) {
if (!listeners.contains(l)) { if (!listeners.contains(l)) {
listeners.add(l); listeners.add(l);
@ -1168,4 +1194,93 @@ public class MapMarkersHelper {
void onSyncDone(); void onSyncDone();
} }
private class SyncGroupTask extends AsyncTask<Void, Void, Void> {
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<MapMarker> 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<FavouritePoint> 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<WptPt> 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();
}
}
});
}
}
}
} }

View file

@ -147,7 +147,7 @@ public class SelectWptCategoriesBottomSheetDialogFragment extends MenuBottomShee
group = mapMarkersHelper.addOrEnableGroup(gpxFile); group = mapMarkersHelper.addOrEnableGroup(gpxFile);
} }
mapMarkersHelper.updateGroupWptCategories(group, selectedCategories); mapMarkersHelper.updateGroupWptCategories(group, selectedCategories);
app.getItineraryHelper().runSynchronization(group); mapMarkersHelper.runSynchronization(group);
} }
private boolean isAllChecked() { private boolean isAllChecked() {

View file

@ -478,7 +478,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
if(!disabled) { if(!disabled) {
mapMarkersHelper.enableGroup(group); mapMarkersHelper.enableGroup(group);
} else { } else {
app.getItineraryHelper().runSynchronization(group); mapMarkersHelper.runSynchronization(group);
} }
if (disabled) { if (disabled) {

View file

@ -9,6 +9,7 @@ import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.activities.SavingTrackHelper; import net.osmand.plus.activities.SavingTrackHelper;
import net.osmand.plus.mapmarkers.MapMarkersGroup; import net.osmand.plus.mapmarkers.MapMarkersGroup;
import net.osmand.plus.mapmarkers.MapMarkersHelper;
import java.io.File; import java.io.File;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
@ -64,9 +65,10 @@ public class DeletePointsTask extends AsyncTask<Void, Void, Void> {
} }
private void syncGpx(GPXFile gpxFile) { private void syncGpx(GPXFile gpxFile) {
MapMarkersGroup group = app.getMapMarkersHelper().getMarkersGroup(gpxFile); MapMarkersHelper helper = app.getMapMarkersHelper();
MapMarkersGroup group = helper.getMarkersGroup(gpxFile);
if (group != null) { if (group != null) {
app.getItineraryHelper().runSynchronization(group); helper.runSynchronization(group);
} }
} }

View file

@ -236,7 +236,7 @@ public class EditTrackGroupDialogFragment extends MenuBottomSheetDialogFragment
} else { } else {
mapMarkersHelper.updateGroupWptCategories(markersGroup, selectedCategories); mapMarkersHelper.updateGroupWptCategories(markersGroup, selectedCategories);
if (!groupCreated) { if (!groupCreated) {
app.getItineraryHelper().runSynchronization(markersGroup); mapMarkersHelper.runSynchronization(markersGroup);
} }
} }
} }
@ -524,9 +524,10 @@ public class EditTrackGroupDialogFragment extends MenuBottomSheetDialogFragment
} }
private void syncGpx(GPXFile gpxFile) { private void syncGpx(GPXFile gpxFile) {
MapMarkersGroup group = app.getMapMarkersHelper().getMarkersGroup(gpxFile); MapMarkersHelper markersHelper = app.getMapMarkersHelper();
MapMarkersGroup group = markersHelper.getMarkersGroup(gpxFile);
if (group != null) { if (group != null) {
app.getItineraryHelper().runSynchronization(group); markersHelper.runSynchronization(group);
} }
} }
} }

View file

@ -1229,7 +1229,7 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
private void syncGpx(GPXFile gpxFile) { private void syncGpx(GPXFile gpxFile) {
MapMarkersGroup group = view.getApplication().getMapMarkersHelper().getMarkersGroup(gpxFile); MapMarkersGroup group = view.getApplication().getMapMarkersHelper().getMarkersGroup(gpxFile);
if (group != null) { if (group != null) {
view.getApplication().getItineraryHelper().runSynchronization(group); mapMarkersHelper.runSynchronization(group);
} }
} }