Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make members private #2726

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading