Skip to content

Commit

Permalink
Merge branch 'make_members_private'
Browse files Browse the repository at this point in the history
  • Loading branch information
simonpoole committed Nov 28, 2024
2 parents 3e3989f + 39888e5 commit b78e0a4
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 46 deletions.
2 changes: 1 addition & 1 deletion src/main/java/de/blau/android/osm/Relation.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class Relation extends StyledOsmElement implements RelationInterface, Bou
*/
private static final long serialVersionUID = 1104911642016294268L;

final List<RelationMember> members;
private final List<RelationMember> members;

public static final String NAME = "relation";

Expand Down
95 changes: 50 additions & 45 deletions src/main/java/de/blau/android/osm/UndoStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,9 @@ public UndoNode(@NonNull Node originalNode, boolean inCurrentStorage, boolean in
@Override
public OsmElement restore() {
OsmElement restored = super.restore();

if (restored == null) {
return null;
}
((Node) restored).lat = lat;
((Node) restored).lon = lon;
return restored;
Expand Down Expand Up @@ -902,31 +904,32 @@ public OsmElement restore() {
return null;
}
// now we can restore with confidence
if (restored != null) {
((Way) restored).removeAllNodes();
for (Node n : nodes) {
Node wayNode = currentStorage.getNode(n.getOsmId());
boolean nodeNotNull = wayNode != null;
if (nodeNotNull || deleted) {
// only add undeleted way nodes except if we are deleted
((Way) restored).addNode(nodeNotNull ? wayNode : n);
if (nodeNotNull) {
wayNode.resetHasProblem();
}
} else {
Log.w(DEBUG_TAG, "#" + element.getOsmId() + " " + element.getDescription() + " missing node " + n.getOsmId());
restored.updateState(OsmElement.STATE_MODIFIED);
try {
apiStorage.insertElementSafe(restored);
} catch (StorageException e) {
// TODO Handle OOM
}
if (restored == null) {
return null;
}
((Way) restored).removeAllNodes();
for (Node n : nodes) {
Node wayNode = currentStorage.getNode(n.getOsmId());
boolean nodeNotNull = wayNode != null;
if (nodeNotNull || deleted) {
// only add undeleted way nodes except if we are deleted
((Way) restored).addNode(nodeNotNull ? wayNode : n);
if (nodeNotNull) {
wayNode.resetHasProblem();
}
} else {
Log.w(DEBUG_TAG, "#" + element.getOsmId() + " " + element.getDescription() + " missing node " + n.getOsmId());
restored.updateState(OsmElement.STATE_MODIFIED);
try {
apiStorage.insertElementSafe(restored);
} catch (StorageException e) {
// TODO Handle OOM
}
}
// reset the style
((Way) restored).setStyle(null);
((Way) restored).invalidateBoundingBox();
}
// reset the style
((Way) restored).setStyle(null);
((Way) restored).invalidateBoundingBox();
return restored;
}

Expand Down Expand Up @@ -979,7 +982,7 @@ public UndoRelation(@NonNull Relation originalRelation, boolean inCurrentStorage
// deep copy
members = new ArrayList<>();
if (inCurrentStorage || inApiStorage) {
for (RelationMember member : originalRelation.members) {
for (RelationMember member : originalRelation.getMembers()) {
members.add(new RelationMember(member));
}
}
Expand All @@ -988,27 +991,29 @@ public UndoRelation(@NonNull Relation originalRelation, boolean inCurrentStorage
@Override
public OsmElement restore() {
OsmElement restored = super.restore();
if (restored != null) {
((Relation) restored).members.clear();
for (RelationMember rm : members) {
OsmElement rmElement = rm.getElement();
if (rmElement instanceof StyleableFeature) {
((StyleableFeature) rmElement).setStyle(null); // style could have been generated from Relation
}
OsmElement rmStorage = currentStorage.getOsmElement(rm.getType(), rm.getRef());
Log.d(DEBUG_TAG, "rmElement " + rmElement + " rmStorage " + rmStorage);
if (rmElement == null || rmStorage != null) {
rm.setElement(rmStorage);
((Relation) restored).members.add(rm); // only add undeleted members or ones that haven't been
// downloaded
} else {
Log.e(DEBUG_TAG, rm.getType() + " #" + rmElement.getOsmId() + " member of relation #" + restored.getOsmId() + " is deleted");
restored.updateState(OsmElement.STATE_MODIFIED);
try {
apiStorage.insertElementSafe(restored);
} catch (StorageException e) {
// TODO Handle OOM
}
if (restored == null) {
return null;
}
((Relation) restored).getMembers().clear();
for (RelationMember rm : members) {
OsmElement rmElement = rm.getElement();
if (rmElement instanceof StyleableFeature) {
((StyleableFeature) rmElement).setStyle(null); // style could have been generated from Relation
}
OsmElement rmStorage = currentStorage.getOsmElement(rm.getType(), rm.getRef());
Log.d(DEBUG_TAG, "rmElement " + rmElement + " rmStorage " + rmStorage);
if (rmElement == null || rmStorage != null) {
rm.setElement(rmStorage);
((Relation) restored).getMembers().add(rm); // only add undeleted members or ones that haven't
// been
// downloaded
} else {
Log.e(DEBUG_TAG, rm.getType() + " #" + rmElement.getOsmId() + " member of relation #" + restored.getOsmId() + " is deleted");
restored.updateState(OsmElement.STATE_MODIFIED);
try {
apiStorage.insertElementSafe(restored);
} catch (StorageException e) {
// TODO Handle OOM
}
}
}
Expand Down

0 comments on commit b78e0a4

Please sign in to comment.