Skip to content

Commit

Permalink
Merge branch 'only_overwrite_changes_if_they_differ_from_original_state'
Browse files Browse the repository at this point in the history
  • Loading branch information
simonpoole committed Jun 25, 2024
2 parents 01301cf + c980c9c commit 6955c26
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ public int getPosition() {
/**
* Set the position of the member in the Relation
*
* @param postiion the position to set
* @param postion the position to set
*/
public void setPosition(int postiion) {
this.position = postiion;
public void setPosition(int postion) {
this.position = postion;
}

@Override
Expand Down Expand Up @@ -135,7 +135,7 @@ public int hashCode() {
* @throws IOException if writing fails
*/
private void writeObject(java.io.ObjectOutputStream out) throws IOException {
super.setElement(null); // don't save the actual relation ref
super.setElement(null); // don't save the actual object
out.defaultWriteObject();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
public class PropertyEditorData implements Serializable {
private static final long serialVersionUID = 5L;

private static final String DEBUG_TAG = PropertyEditorData.class.getSimpleName().substring(0, Math.min(23, PropertyEditorData.class.getSimpleName().length()));
private static final String DEBUG_TAG = PropertyEditorData.class.getSimpleName().substring(0,
Math.min(23, PropertyEditorData.class.getSimpleName().length()));

public final long osmId;
public final String type;
Expand Down Expand Up @@ -100,9 +101,12 @@ static MultiHashMap<Long, RelationMemberPosition> getParentMap(@NonNull OsmEleme
* @return the List
*/
static <T extends List<RelationMemberDescription>> T getRelationMemberDescriptions(@NonNull Relation relation, @NonNull T members) {
int position = 0;
for (RelationMember rm : relation.getMembers()) {
RelationMemberDescription newRm = new RelationMemberDescription(rm);
newRm.setPosition(position);
members.add(newRm);
position++;
}
return members;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,18 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
public void onDataUpdate() {
Log.d(DEBUG_TAG, "onDataUpdate");
Relation r = (Relation) propertyEditorListener.getElement();
List<MemberEntry> tempEntries = new ArrayList<>();
List<MemberEntry> currentEntries = new ArrayList<>();
final ArrayList<RelationMemberDescription> currentMembers = PropertyEditorData.getRelationMemberDescriptions(r, new ArrayList<>());
getMemberEntries(currentMembers, tempEntries);
setIcons(tempEntries);
if (!tempEntries.equals(membersInternal)) {
getMemberEntries(currentMembers, currentEntries);
setIcons(currentEntries);
// relations can be very large and this might cause issues on the stack
List<RelationMemberDescription> origMembers = savingHelper.load(getContext(), Long.toString(id) + FILENAME_ORIG_MEMBERS, true);
// only update our copy if the relation members have actually changed from the original state
if (!currentMembers.equals(origMembers) && !currentEntries.equals(membersInternal)) {
Log.d(DEBUG_TAG, "onDataUpdate current members have changed");
ScreenMessage.toastTopInfo(getContext(), R.string.toast_updating_members);
membersInternal.clear();
membersInternal.addAll(tempEntries);
membersInternal.addAll(currentEntries);
adapter.notifyDataSetChanged();
savingHelper.save(getContext(), Long.toString(id) + FILENAME_ORIG_MEMBERS, currentMembers, true);
}
Expand Down

0 comments on commit 6955c26

Please sign in to comment.