Remove cache for synced items
This commit is contained in:
parent
28aa11786d
commit
f922f90443
5 changed files with 34 additions and 47 deletions
|
@ -44,7 +44,6 @@ public class FavouritesDbHelper {
|
|||
private List<FavouritePoint> cachedFavoritePoints = new ArrayList<FavouritePoint>();
|
||||
private List<FavoriteGroup> favoriteGroups = new ArrayList<FavouritesDbHelper.FavoriteGroup>();
|
||||
private Map<String, FavoriteGroup> flatGroups = new LinkedHashMap<String, FavouritesDbHelper.FavoriteGroup>();
|
||||
private List<FavouritePoint> syncedFavouritePoints = new ArrayList<>();
|
||||
private final OsmandApplication context;
|
||||
protected static final String HIDDEN = "HIDDEN";
|
||||
private static final String DELIMETER = "__";
|
||||
|
@ -61,29 +60,6 @@ public class FavouritesDbHelper {
|
|||
public List<FavouritePoint> points = new ArrayList<FavouritePoint>();
|
||||
}
|
||||
|
||||
public void addSyncedGroup(FavoriteGroup group) {
|
||||
List<FavouritePoint> copyList = new ArrayList<>(syncedFavouritePoints);
|
||||
copyList.addAll(group.points);
|
||||
syncedFavouritePoints = copyList;
|
||||
}
|
||||
|
||||
public void removeSyncedGroup(FavoriteGroup group) {
|
||||
List<FavouritePoint> copyList = new ArrayList<>(syncedFavouritePoints);
|
||||
List<FavouritePoint> pointsToRemove = new ArrayList<>();
|
||||
for (int i = 0; i < copyList.size(); i++) {
|
||||
FavouritePoint point = copyList.get(i);
|
||||
if (point.getCategory().equals(group.name)) {
|
||||
pointsToRemove.add(point);
|
||||
}
|
||||
}
|
||||
copyList.removeAll(pointsToRemove);
|
||||
syncedFavouritePoints = copyList;
|
||||
}
|
||||
|
||||
public List<FavouritePoint> getSyncedFavouritePoints() {
|
||||
return syncedFavouritePoints;
|
||||
}
|
||||
|
||||
public void loadFavorites() {
|
||||
flatGroups.clear();
|
||||
favoriteGroups.clear();
|
||||
|
|
|
@ -556,16 +556,6 @@ public class GpxSelectionHelper {
|
|||
|
||||
private List<GpxDisplayGroup> displayGroups;
|
||||
|
||||
private boolean synced;
|
||||
|
||||
public void setSynced(boolean synced) {
|
||||
this.synced = synced;
|
||||
}
|
||||
|
||||
public boolean isSynced() {
|
||||
return synced;
|
||||
}
|
||||
|
||||
public void setGpxFile(GPXFile gpxFile) {
|
||||
this.gpxFile = gpxFile;
|
||||
if (gpxFile.tracks.size() > 0) {
|
||||
|
|
|
@ -514,7 +514,6 @@ public class MapMarkersHelper {
|
|||
if (!favGroup.visible) {
|
||||
removeActiveMarkersFromSyncGroup(group.getId());
|
||||
removeActiveMarkersFromGroup(group.getId());
|
||||
favouritesDbHelper.removeSyncedGroup(favGroup);
|
||||
return;
|
||||
}
|
||||
if (group.getColor() == -1) {
|
||||
|
@ -524,8 +523,6 @@ public class MapMarkersHelper {
|
|||
for (FavouritePoint fp : favGroup.points) {
|
||||
addNewMarkerIfNeeded(group, dbMarkers, new LatLon(fp.getLatitude(), fp.getLongitude()), fp.getName(), enabled, fp, null);
|
||||
}
|
||||
favouritesDbHelper.removeSyncedGroup(favGroup);
|
||||
favouritesDbHelper.addSyncedGroup(favGroup);
|
||||
|
||||
removeOldMarkersIfNeeded(dbMarkers);
|
||||
} else if (group.getType() == MarkersSyncGroup.GPX_TYPE) {
|
||||
|
@ -549,7 +546,6 @@ public class MapMarkersHelper {
|
|||
group.setColor(pt.getColor(defColor));
|
||||
addNewMarkerIfNeeded(group, dbMarkers, new LatLon(pt.lat, pt.lon), pt.name, enabled, null, pt);
|
||||
}
|
||||
selectedGpxFile.setSynced(true);
|
||||
|
||||
removeOldMarkersIfNeeded(dbMarkers);
|
||||
}
|
||||
|
@ -568,6 +564,29 @@ public class MapMarkersHelper {
|
|||
}
|
||||
}
|
||||
|
||||
public boolean isSynced(SelectedGpxFile gpxFile) {
|
||||
GPXFile gpx = gpxFile.getGpxFile();
|
||||
List<WptPt> gpxPoints = gpx.getPoints();
|
||||
for (WptPt wptPt : gpxPoints) {
|
||||
for (MapMarker marker : mapMarkers) {
|
||||
if (marker.id.equals(gpx.path + wptPt.name)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isSynced(FavouritePoint favouritePoint) {
|
||||
FavoriteGroup group = favouritesDbHelper.getGroup(favouritePoint);
|
||||
for (MapMarker marker : mapMarkers) {
|
||||
if (marker.id.equals(favouritePoint.getName() + group.name)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void addNewMarkerIfNeeded(MarkersSyncGroup group, List<MapMarker> markers, LatLon latLon, String name, boolean enabled, FavouritePoint favouritePoint, WptPt wptPt) {
|
||||
boolean exists = false;
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ import net.osmand.data.QuadRect;
|
|||
import net.osmand.data.QuadTree;
|
||||
import net.osmand.data.RotatedTileBox;
|
||||
import net.osmand.plus.FavouritesDbHelper;
|
||||
import net.osmand.plus.MapMarkersHelper;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.base.FavoriteImageDrawable;
|
||||
|
@ -37,6 +38,7 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.
|
|||
protected OsmandMapTileView view;
|
||||
private Paint paint;
|
||||
private FavouritesDbHelper favorites;
|
||||
private MapMarkersHelper mapMarkersHelper;
|
||||
protected List<FavouritePoint> cache = new ArrayList<>();
|
||||
private MapTextLayer textLayer;
|
||||
private Paint paintIcon;
|
||||
|
@ -55,10 +57,6 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.
|
|||
return favorites.getFavouritePoints();
|
||||
}
|
||||
|
||||
protected List<? extends FavouritePoint> getSyncedPoints() {
|
||||
return favorites.getSyncedFavouritePoints();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initLayer(OsmandMapTileView view) {
|
||||
this.view = view;
|
||||
|
@ -68,6 +66,7 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.
|
|||
paint.setDither(true);
|
||||
settings = view.getApplication().getSettings();
|
||||
favorites = view.getApplication().getFavorites();
|
||||
mapMarkersHelper = view.getApplication().getMapMarkersHelper();
|
||||
textLayer = view.getLayerByClass(MapTextLayer.class);
|
||||
paintIcon = new Paint();
|
||||
pointSmall = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_white_shield_small);
|
||||
|
@ -98,7 +97,7 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.
|
|||
if (contextMenuLayer.getMoveableObject() instanceof FavouritePoint) {
|
||||
FavouritePoint objectInMotion = (FavouritePoint) contextMenuLayer.getMoveableObject();
|
||||
FavoriteImageDrawable fid;
|
||||
if (getSyncedPoints().contains(objectInMotion)) {
|
||||
if (mapMarkersHelper.isSynced(objectInMotion)) {
|
||||
fid = FavoriteImageDrawable.getOrCreateSyncedIcon(view.getContext(), objectInMotion.getColor());
|
||||
} else {
|
||||
fid = FavoriteImageDrawable.getOrCreate(view.getContext(),
|
||||
|
@ -143,7 +142,7 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.
|
|||
}
|
||||
for (FavouritePoint o : fullObjects) {
|
||||
if (o != contextMenuLayer.getMoveableObject()) {
|
||||
boolean syncedPoint = getSyncedPoints().contains(o);
|
||||
boolean syncedPoint = mapMarkersHelper.isSynced(o);
|
||||
drawPoint(canvas, tileBox, latLonBounds, o, syncedPoint);
|
||||
}
|
||||
}
|
||||
|
@ -184,7 +183,7 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.
|
|||
int ex = (int) point.x;
|
||||
int ey = (int) point.y;
|
||||
for (FavouritePoint n : getPoints()) {
|
||||
if (!getSyncedPoints().contains(n)) {
|
||||
if (!mapMarkersHelper.isSynced(n)) {
|
||||
getFavFromPoint(tb, res, r, ex, ey, n);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ import net.osmand.plus.GpxSelectionHelper;
|
|||
import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup;
|
||||
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
|
||||
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
|
||||
import net.osmand.plus.MapMarkersHelper;
|
||||
import net.osmand.plus.MapMarkersHelper.MarkersSyncGroup;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings.CommonPreference;
|
||||
|
@ -80,6 +81,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
|
|||
|
||||
|
||||
private GpxSelectionHelper selectedGpxHelper;
|
||||
private MapMarkersHelper mapMarkersHelper;
|
||||
private Paint paintBmp;
|
||||
private List<WptPt> cache = new ArrayList<>();
|
||||
private Map<WptPt, SelectedGpxFile> pointFileMap = new HashMap<>();
|
||||
|
@ -108,6 +110,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
|
|||
public void initLayer(OsmandMapTileView view) {
|
||||
this.view = view;
|
||||
selectedGpxHelper = view.getApplication().getSelectedGpxHelper();
|
||||
mapMarkersHelper = view.getApplication().getMapMarkersHelper();
|
||||
osmandRenderer = view.getApplication().getResourceManager().getRenderer().getRenderer();
|
||||
initUI();
|
||||
}
|
||||
|
@ -526,7 +529,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
|
|||
}
|
||||
|
||||
private boolean isSynced(SelectedGpxFile g) {
|
||||
return g.isSynced();
|
||||
return mapMarkersHelper.isSynced(g);
|
||||
}
|
||||
|
||||
private boolean calculateBelongs(int ex, int ey, int objx, int objy, int radius) {
|
||||
|
@ -655,7 +658,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
|
|||
private void syncGpx(GPXFile gpxFile) {
|
||||
File gpx = new File(gpxFile.path);
|
||||
if (gpx.exists()) {
|
||||
view.getApplication().getMapMarkersHelper().syncGroupAsync(new MarkersSyncGroup(gpx.getAbsolutePath(),
|
||||
mapMarkersHelper.syncGroupAsync(new MarkersSyncGroup(gpx.getAbsolutePath(),
|
||||
AndroidUtils.trimExtension(gpx.getName()), MarkersSyncGroup.GPX_TYPE));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue