From f922f904430a52d250595157f7f4e7b04a7192c4 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Mon, 20 Nov 2017 16:48:31 +0200 Subject: [PATCH] Remove cache for synced items --- .../net/osmand/plus/FavouritesDbHelper.java | 24 ----------------- .../net/osmand/plus/GpxSelectionHelper.java | 10 ------- .../src/net/osmand/plus/MapMarkersHelper.java | 27 ++++++++++++++++--- .../osmand/plus/views/FavouritesLayer.java | 13 +++++---- .../src/net/osmand/plus/views/GPXLayer.java | 7 +++-- 5 files changed, 34 insertions(+), 47 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java index 77082db441..47635fa5f9 100644 --- a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java @@ -44,7 +44,6 @@ public class FavouritesDbHelper { private List cachedFavoritePoints = new ArrayList(); private List favoriteGroups = new ArrayList(); private Map flatGroups = new LinkedHashMap(); - private List 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 points = new ArrayList(); } - public void addSyncedGroup(FavoriteGroup group) { - List copyList = new ArrayList<>(syncedFavouritePoints); - copyList.addAll(group.points); - syncedFavouritePoints = copyList; - } - - public void removeSyncedGroup(FavoriteGroup group) { - List copyList = new ArrayList<>(syncedFavouritePoints); - List 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 getSyncedFavouritePoints() { - return syncedFavouritePoints; - } - public void loadFavorites() { flatGroups.clear(); favoriteGroups.clear(); diff --git a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java index f1f72fd2e4..3225081c2f 100644 --- a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java +++ b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java @@ -556,16 +556,6 @@ public class GpxSelectionHelper { private List 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) { diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 692b66c392..9e9af48145 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -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 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 markers, LatLon latLon, String name, boolean enabled, FavouritePoint favouritePoint, WptPt wptPt) { boolean exists = false; diff --git a/OsmAnd/src/net/osmand/plus/views/FavouritesLayer.java b/OsmAnd/src/net/osmand/plus/views/FavouritesLayer.java index cf1675d783..97633f3dfc 100644 --- a/OsmAnd/src/net/osmand/plus/views/FavouritesLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/FavouritesLayer.java @@ -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 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 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); } } diff --git a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java index 1a259802fb..4c4464fd2e 100644 --- a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java @@ -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 cache = new ArrayList<>(); private Map 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)); } }