Create ItineraryHelper
This commit is contained in:
parent
eb5d46d441
commit
7218e7d4b5
15 changed files with 198 additions and 162 deletions
|
@ -39,6 +39,7 @@ 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;
|
||||||
|
@ -471,6 +472,7 @@ 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);
|
||||||
|
|
||||||
initOpeningHoursParser();
|
initOpeningHoursParser();
|
||||||
}
|
}
|
||||||
|
|
|
@ -272,10 +272,9 @@ public class FavouritesDbHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void runSyncWithMarkers(FavoriteGroup favGroup) {
|
private void runSyncWithMarkers(FavoriteGroup favGroup) {
|
||||||
MapMarkersHelper helper = context.getMapMarkersHelper();
|
MapMarkersGroup group = context.getMapMarkersHelper().getMarkersGroup(favGroup);
|
||||||
MapMarkersGroup group = helper.getMarkersGroup(favGroup);
|
|
||||||
if (group != null) {
|
if (group != null) {
|
||||||
helper.runSynchronization(group);
|
context.getItineraryHelper().runSynchronization(group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,6 @@ 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;
|
||||||
|
@ -823,10 +822,9 @@ public class GpxSelectionHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void syncGpxWithMarkers(GPXFile gpxFile) {
|
private void syncGpxWithMarkers(GPXFile gpxFile) {
|
||||||
MapMarkersHelper mapMarkersHelper = app.getMapMarkersHelper();
|
MapMarkersGroup group = app.getMapMarkersHelper().getMarkersGroup(gpxFile);
|
||||||
MapMarkersGroup group = mapMarkersHelper.getMarkersGroup(gpxFile);
|
|
||||||
if (group != null) {
|
if (group != null) {
|
||||||
mapMarkersHelper.runSynchronization(group);
|
app.getItineraryHelper().runSynchronization(group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,13 @@ import android.view.View;
|
||||||
import android.view.accessibility.AccessibilityManager;
|
import android.view.accessibility.AccessibilityManager;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
import androidx.appcompat.app.AppCompatDelegate;
|
||||||
|
import androidx.multidex.MultiDex;
|
||||||
|
import androidx.multidex.MultiDexApplication;
|
||||||
|
|
||||||
import net.osmand.AndroidUtils;
|
import net.osmand.AndroidUtils;
|
||||||
import net.osmand.FileUtils;
|
import net.osmand.FileUtils;
|
||||||
import net.osmand.IndexConstants;
|
import net.osmand.IndexConstants;
|
||||||
|
@ -59,6 +66,7 @@ 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;
|
||||||
|
@ -99,12 +107,6 @@ import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import androidx.appcompat.app.AlertDialog;
|
|
||||||
import androidx.appcompat.app.AppCompatDelegate;
|
|
||||||
import androidx.multidex.MultiDex;
|
|
||||||
import androidx.multidex.MultiDexApplication;
|
|
||||||
import btools.routingapp.BRouterServiceConnection;
|
import btools.routingapp.BRouterServiceConnection;
|
||||||
import btools.routingapp.IBRouterService;
|
import btools.routingapp.IBRouterService;
|
||||||
|
|
||||||
|
@ -166,6 +168,7 @@ public class OsmandApplication extends MultiDexApplication {
|
||||||
OprAuthHelper oprAuthHelper;
|
OprAuthHelper oprAuthHelper;
|
||||||
MeasurementEditingContext measurementEditingContext;
|
MeasurementEditingContext measurementEditingContext;
|
||||||
OnlineRoutingHelper onlineRoutingHelper;
|
OnlineRoutingHelper onlineRoutingHelper;
|
||||||
|
ItineraryHelper itineraryHelper;
|
||||||
|
|
||||||
private Map<String, Builder> customRoutingConfigs = new ConcurrentHashMap<>();
|
private Map<String, Builder> customRoutingConfigs = new ConcurrentHashMap<>();
|
||||||
private File externalStorageDirectory;
|
private File externalStorageDirectory;
|
||||||
|
@ -467,6 +470,10 @@ public class OsmandApplication extends MultiDexApplication {
|
||||||
return onlineRoutingHelper;
|
return onlineRoutingHelper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ItineraryHelper getItineraryHelper() {
|
||||||
|
return itineraryHelper;
|
||||||
|
}
|
||||||
|
|
||||||
public TransportRoutingHelper getTransportRoutingHelper() {
|
public TransportRoutingHelper getTransportRoutingHelper() {
|
||||||
return transportRoutingHelper;
|
return transportRoutingHelper;
|
||||||
}
|
}
|
||||||
|
|
152
OsmAnd/src/net/osmand/plus/itinerary/ItineraryHelper.java
Normal file
152
OsmAnd/src/net/osmand/plus/itinerary/ItineraryHelper.java
Normal file
|
@ -0,0 +1,152 @@
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -17,8 +17,6 @@ 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;
|
||||||
|
@ -26,6 +24,7 @@ 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;
|
||||||
|
@ -220,10 +219,9 @@ 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) {
|
||||||
MapMarkersHelper helper = app.getMapMarkersHelper();
|
MapMarkersGroup group = app.getMapMarkersHelper().getMarkersGroup(gpxFile);
|
||||||
MapMarkersGroup group = helper.getMarkersGroup(gpxFile);
|
|
||||||
if (group != null) {
|
if (group != null) {
|
||||||
helper.runSynchronization(group);
|
app.getItineraryHelper().runSynchronization(group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,8 +20,6 @@ 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.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.UiUtilities;
|
import net.osmand.plus.UiUtilities;
|
||||||
|
@ -30,6 +28,7 @@ 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;
|
||||||
|
@ -236,10 +235,9 @@ 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) {
|
||||||
MapMarkersHelper helper = app.getMapMarkersHelper();
|
MapMarkersGroup group = app.getMapMarkersHelper().getMarkersGroup(gpxFile);
|
||||||
MapMarkersGroup group = helper.getMarkersGroup(gpxFile);
|
|
||||||
if (group != null) {
|
if (group != null) {
|
||||||
helper.runSynchronization(group);
|
app.getItineraryHelper().runSynchronization(group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
||||||
helper.runSynchronization(group);
|
getMyApplication().getItineraryHelper().runSynchronization(group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -218,13 +218,13 @@ public class MapMarkersDialogFragment extends DialogFragment implements OnGroupS
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
getMyApplication().getMapMarkersHelper().addSyncListener(this);
|
getMyApplication().getItineraryHelper().addSyncListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
getMyApplication().getMapMarkersHelper().removeSyncListener(this);
|
getMyApplication().getItineraryHelper().removeSyncListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
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;
|
||||||
|
@ -20,7 +18,6 @@ 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;
|
||||||
|
@ -41,15 +38,12 @@ 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;
|
||||||
|
@ -78,14 +72,11 @@ 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;
|
||||||
|
|
||||||
|
@ -186,7 +177,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) {
|
||||||
runSynchronization(gr);
|
ctx.getItineraryHelper().runSynchronization(gr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -303,15 +294,6 @@ 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;
|
||||||
|
@ -363,7 +345,7 @@ public class MapMarkersHelper {
|
||||||
if (gr.isDisabled()) {
|
if (gr.isDisabled()) {
|
||||||
updateGroupDisabled(gr, false);
|
updateGroupDisabled(gr, false);
|
||||||
}
|
}
|
||||||
runSynchronization(gr);
|
ctx.getItineraryHelper().runSynchronization(gr);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addGroupInternally(MapMarkersGroup gr) {
|
private void addGroupInternally(MapMarkersGroup gr) {
|
||||||
|
@ -415,7 +397,7 @@ public class MapMarkersHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeGroupActiveMarkers(MapMarkersGroup group, boolean updateGroup) {
|
public 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());
|
||||||
|
@ -636,7 +618,7 @@ public class MapMarkersHelper {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addNewMarkerIfNeeded(@NonNull MapMarkersGroup group,
|
public 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,
|
||||||
|
@ -671,7 +653,7 @@ public class MapMarkersHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeOldMarkersIfPresent(List<MapMarker> markers) {
|
public 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) {
|
||||||
|
@ -970,14 +952,6 @@ 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);
|
||||||
|
@ -1194,93 +1168,4 @@ 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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -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);
|
||||||
mapMarkersHelper.runSynchronization(group);
|
app.getItineraryHelper().runSynchronization(group);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isAllChecked() {
|
private boolean isAllChecked() {
|
||||||
|
|
|
@ -478,7 +478,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
|
||||||
if(!disabled) {
|
if(!disabled) {
|
||||||
mapMarkersHelper.enableGroup(group);
|
mapMarkersHelper.enableGroup(group);
|
||||||
} else {
|
} else {
|
||||||
mapMarkersHelper.runSynchronization(group);
|
app.getItineraryHelper().runSynchronization(group);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (disabled) {
|
if (disabled) {
|
||||||
|
|
|
@ -9,7 +9,6 @@ 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;
|
||||||
|
@ -65,10 +64,9 @@ public class DeletePointsTask extends AsyncTask<Void, Void, Void> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void syncGpx(GPXFile gpxFile) {
|
private void syncGpx(GPXFile gpxFile) {
|
||||||
MapMarkersHelper helper = app.getMapMarkersHelper();
|
MapMarkersGroup group = app.getMapMarkersHelper().getMarkersGroup(gpxFile);
|
||||||
MapMarkersGroup group = helper.getMarkersGroup(gpxFile);
|
|
||||||
if (group != null) {
|
if (group != null) {
|
||||||
helper.runSynchronization(group);
|
app.getItineraryHelper().runSynchronization(group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -236,7 +236,7 @@ public class EditTrackGroupDialogFragment extends MenuBottomSheetDialogFragment
|
||||||
} else {
|
} else {
|
||||||
mapMarkersHelper.updateGroupWptCategories(markersGroup, selectedCategories);
|
mapMarkersHelper.updateGroupWptCategories(markersGroup, selectedCategories);
|
||||||
if (!groupCreated) {
|
if (!groupCreated) {
|
||||||
mapMarkersHelper.runSynchronization(markersGroup);
|
app.getItineraryHelper().runSynchronization(markersGroup);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -524,10 +524,9 @@ public class EditTrackGroupDialogFragment extends MenuBottomSheetDialogFragment
|
||||||
}
|
}
|
||||||
|
|
||||||
private void syncGpx(GPXFile gpxFile) {
|
private void syncGpx(GPXFile gpxFile) {
|
||||||
MapMarkersHelper markersHelper = app.getMapMarkersHelper();
|
MapMarkersGroup group = app.getMapMarkersHelper().getMarkersGroup(gpxFile);
|
||||||
MapMarkersGroup group = markersHelper.getMarkersGroup(gpxFile);
|
|
||||||
if (group != null) {
|
if (group != null) {
|
||||||
markersHelper.runSynchronization(group);
|
app.getItineraryHelper().runSynchronization(group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1079,7 +1079,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) {
|
||||||
mapMarkersHelper.runSynchronization(group);
|
view.getApplication().getItineraryHelper().runSynchronization(group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue