Small refactoring
This commit is contained in:
parent
de543f37a6
commit
db0eee7290
3 changed files with 24 additions and 25 deletions
|
@ -302,19 +302,13 @@ public class MapMarkersHelper {
|
|||
});
|
||||
}
|
||||
|
||||
public boolean isSynced(SelectedGpxFile gpxFile) {
|
||||
List<WptPt> gpxPoints = gpxFile.getGpxFile().getPoints();
|
||||
for (WptPt wptPt : gpxPoints) {
|
||||
if (getMapMarker(wptPt) != null) {
|
||||
return true;
|
||||
}
|
||||
public MapMarkersGroup getMarkersGroup(SelectedGpxFile gpxFile) {
|
||||
if(gpxFile.getGpxFile() == null) {
|
||||
return null;
|
||||
}
|
||||
return false;
|
||||
return getMapMarkerGroupById(getMarkerGroupId(new File(gpxFile.getGpxFile().path)));
|
||||
}
|
||||
|
||||
public boolean isSynced(FavouritePoint favouritePoint) {
|
||||
return getMapMarker(favouritePoint) != null;
|
||||
}
|
||||
|
||||
public void addOrEnableGroup(@NonNull MapMarkersGroup group) {
|
||||
if (!isGroupSynced(group.getId())) {
|
||||
|
@ -479,17 +473,21 @@ public class MapMarkersHelper {
|
|||
}
|
||||
return group;
|
||||
}
|
||||
|
||||
|
||||
public MapMarkersGroup getOrCreateGroup(@NonNull File gpx) {
|
||||
MapMarkersGroup group = getMapMarkerGroupById(gpx.getAbsolutePath());
|
||||
MapMarkersGroup group = getMapMarkerGroupById(getMarkerGroupId(gpx));
|
||||
if (group == null) {
|
||||
group = new MapMarkersGroup(gpx.getAbsolutePath(),
|
||||
group = new MapMarkersGroup(getMarkerGroupId(gpx),
|
||||
AndroidUtils.trimExtension(gpx.getName()),
|
||||
MapMarkersGroup.GPX_TYPE);
|
||||
}
|
||||
return group;
|
||||
}
|
||||
|
||||
private String getMarkerGroupId(File gpx) {
|
||||
return gpx.getAbsolutePath();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public List<MapMarkersGroup> getGroupsForDisplayedGpx() {
|
||||
List<MapMarkersGroup> res = new ArrayList<>();
|
||||
|
@ -514,7 +512,7 @@ public class MapMarkersHelper {
|
|||
for (TravelArticle art : savedArticles) {
|
||||
String gpxName = travelDbHelper.getGPXName(art);
|
||||
File path = ctx.getAppPath(IndexConstants.GPX_TRAVEL_DIR + gpxName);
|
||||
LOG.debug("Article group " + path.getAbsolutePath() + " " + path.exists()) ;
|
||||
LOG.debug("Article group " + getMarkerGroupId(path) + " " + path.exists()) ;
|
||||
MapMarkersGroup group = getOrCreateGroup(path);
|
||||
if (!isGroupSynced(group.getId())) {
|
||||
group.disabled = true;
|
||||
|
@ -973,7 +971,7 @@ public class MapMarkersHelper {
|
|||
file.addPoint(wpt);
|
||||
}
|
||||
GPXUtilities.writeGpxFile(fout, file, ctx);
|
||||
return fout.getAbsolutePath();
|
||||
return getMarkerGroupId(fout);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -12,7 +12,6 @@ import android.support.annotation.ColorInt;
|
|||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
|
||||
import net.osmand.data.FavouritePoint;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.PointDescription;
|
||||
|
@ -21,6 +20,7 @@ import net.osmand.data.QuadTree;
|
|||
import net.osmand.data.RotatedTileBox;
|
||||
import net.osmand.plus.FavouritesDbHelper;
|
||||
import net.osmand.plus.MapMarkersHelper;
|
||||
import net.osmand.plus.MapMarkersHelper.MapMarker;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.base.FavoriteImageDrawable;
|
||||
|
@ -97,7 +97,8 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.
|
|||
if (contextMenuLayer.getMoveableObject() instanceof FavouritePoint) {
|
||||
FavouritePoint objectInMotion = (FavouritePoint) contextMenuLayer.getMoveableObject();
|
||||
FavoriteImageDrawable fid;
|
||||
if (mapMarkersHelper.isSynced(objectInMotion)) {
|
||||
MapMarker mapMarker = mapMarkersHelper.getMapMarker(objectInMotion);
|
||||
if (mapMarker != null) {
|
||||
fid = FavoriteImageDrawable.getOrCreateSyncedIcon(view.getContext(), objectInMotion.getColor());
|
||||
} else {
|
||||
fid = FavoriteImageDrawable.getOrCreate(view.getContext(),
|
||||
|
@ -142,8 +143,8 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.
|
|||
}
|
||||
for (FavouritePoint o : fullObjects) {
|
||||
if (o != contextMenuLayer.getMoveableObject()) {
|
||||
boolean syncedPoint = mapMarkersHelper.isSynced(o);
|
||||
drawPoint(canvas, tileBox, latLonBounds, o, syncedPoint);
|
||||
MapMarker mapMarker = mapMarkersHelper.getMapMarker(objectInMotion);
|
||||
drawPoint(canvas, tileBox, latLonBounds, o, mapMarker);
|
||||
}
|
||||
}
|
||||
this.fullObjectsLatLon = fullObjectsLatLon;
|
||||
|
@ -156,14 +157,14 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.
|
|||
|
||||
}
|
||||
|
||||
private void drawPoint(Canvas canvas, RotatedTileBox tileBox, final QuadRect latLonBounds, FavouritePoint o, boolean synced) {
|
||||
private void drawPoint(Canvas canvas, RotatedTileBox tileBox, final QuadRect latLonBounds, FavouritePoint o, MapMarker mapMarker) {
|
||||
if (o.isVisible() && o.getLatitude() >= latLonBounds.bottom && o.getLatitude() <= latLonBounds.top && o.getLongitude() >= latLonBounds.left
|
||||
&& o.getLongitude() <= latLonBounds.right ) {
|
||||
cache.add(o);
|
||||
int x = (int) tileBox.getPixXFromLatLon(o.getLatitude(), o.getLongitude());
|
||||
int y = (int) tileBox.getPixYFromLatLon(o.getLatitude(), o.getLongitude());
|
||||
FavoriteImageDrawable fid;
|
||||
if (synced) {
|
||||
if (mapMarker != null) {
|
||||
fid = FavoriteImageDrawable.getOrCreateSyncedIcon(view.getContext(), o.getColor());
|
||||
} else {
|
||||
fid = FavoriteImageDrawable.getOrCreate(view.getContext(), o.getColor(), true);
|
||||
|
|
|
@ -180,7 +180,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
|
|||
PointF pf = contextMenuLayer.getMovableCenterPoint(tileBox);
|
||||
SelectedGpxFile gpxFile = pointFileMap.get(objectInMotion);
|
||||
if (gpxFile != null) {
|
||||
drawBigPoint(canvas, objectInMotion, getFileColor(gpxFile), pf.x, pf.y, isSynced(gpxFile));
|
||||
drawBigPoint(canvas, objectInMotion, getFileColor(gpxFile), pf.x, pf.y, isSyncedWithMarkers(gpxFile));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -362,7 +362,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
|
|||
List<WptPt> fullObjects = new ArrayList<>();
|
||||
@ColorInt
|
||||
int fileColor = getFileColor(g);
|
||||
boolean synced = isSynced(g);
|
||||
boolean synced = isSyncedWithMarkers(g);
|
||||
for (WptPt o : pts) {
|
||||
if (o.lat >= latLonBounds.bottom && o.lat <= latLonBounds.top
|
||||
&& o.lon >= latLonBounds.left && o.lon <= latLonBounds.right
|
||||
|
@ -531,8 +531,8 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
|
|||
return g.getGpxFile().getPoints();
|
||||
}
|
||||
|
||||
private boolean isSynced(SelectedGpxFile g) {
|
||||
return mapMarkersHelper.isSynced(g);
|
||||
private boolean isSyncedWithMarkers(SelectedGpxFile g) {
|
||||
return mapMarkersHelper.getMarkersGroup(g) != null;
|
||||
}
|
||||
|
||||
private boolean calculateBelongs(int ex, int ey, int objx, int objy, int radius) {
|
||||
|
|
Loading…
Reference in a new issue