Run group synchronization in background
This commit is contained in:
parent
4efaccc61c
commit
1d11026f56
1 changed files with 60 additions and 38 deletions
|
@ -1,6 +1,7 @@
|
|||
package net.osmand.plus;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
|
@ -27,6 +28,8 @@ import java.util.LinkedHashMap;
|
|||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import static net.osmand.data.PointDescription.POINT_TYPE_MAP_MARKER;
|
||||
|
||||
|
@ -41,6 +44,7 @@ public class MapMarkersHelper {
|
|||
private OsmandApplication ctx;
|
||||
private MapMarkersDbHelper markersDbHelper;
|
||||
private boolean startFromMyLocation;
|
||||
private ExecutorService executorService = Executors.newSingleThreadExecutor();
|
||||
|
||||
private MarkersPlanRouteContext planRouteContext;
|
||||
|
||||
|
@ -455,17 +459,33 @@ public class MapMarkersHelper {
|
|||
if (!isGroupSynced(group.getId())) {
|
||||
return;
|
||||
}
|
||||
SyncGroupTask syncGroupTask = new SyncGroupTask(group, enabled);
|
||||
syncGroupTask.executeOnExecutor(executorService);
|
||||
}
|
||||
|
||||
private class SyncGroupTask extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
private MarkersSyncGroup group;
|
||||
private boolean enabled;
|
||||
|
||||
SyncGroupTask(MarkersSyncGroup group, boolean enabled) {
|
||||
this.group = group;
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... voids) {
|
||||
List<MapMarker> dbMarkers = markersDbHelper.getMarkersFromGroup(group);
|
||||
|
||||
if (group.getType() == MarkersSyncGroup.FAVORITES_TYPE) {
|
||||
FavoriteGroup favGroup = ctx.getFavorites().getGroup(group.getName());
|
||||
if (favGroup == null) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
if (!favGroup.visible) {
|
||||
removeActiveMarkersFromSyncGroup(group.getId());
|
||||
removeActiveMarkersFromGroup(group.getId());
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
if (group.getColor() == -1) {
|
||||
group.setColor(favGroup.color);
|
||||
|
@ -480,7 +500,7 @@ public class MapMarkersHelper {
|
|||
GpxSelectionHelper gpxHelper = ctx.getSelectedGpxHelper();
|
||||
File file = new File(group.getId());
|
||||
if (!file.exists()) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
SelectedGpxFile selectedGpxFile = gpxHelper.getSelectedFileByPath(group.getId());
|
||||
|
@ -488,7 +508,7 @@ public class MapMarkersHelper {
|
|||
if (gpx == null) {
|
||||
removeActiveMarkersFromSyncGroup(group.getId());
|
||||
removeActiveMarkersFromGroup(group.getId());
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
List<WptPt> gpxPoints = new LinkedList<>(gpx.getPoints());
|
||||
|
@ -500,6 +520,8 @@ public class MapMarkersHelper {
|
|||
|
||||
removeOldMarkersIfNeeded(dbMarkers);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void addNewMarkerIfNeeded(MarkersSyncGroup group, List<MapMarker> markers, LatLon latLon, String name, boolean enabled) {
|
||||
|
|
Loading…
Reference in a new issue