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

Prevent annotation changes from invalidating unrelated drag actions #1159

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public T create(S options) {
T t = options.build(currentId, this);
annotations.put(t.getId(), t);
currentId++;
updateSource();
internalUpdateSource();
return t;
}

Expand All @@ -150,7 +150,7 @@ public List<T> create(List<S> optionsList) {
annotations.put(annotation.getId(), annotation);
currentId++;
}
updateSource();
internalUpdateSource();
return annotationList;
}

Expand All @@ -162,7 +162,8 @@ public List<T> create(List<S> optionsList) {
@UiThread
public void delete(T annotation) {
annotations.remove(annotation.getId());
updateSource();
draggableAnnotationController.onAnnotationUpdated(annotation);
internalUpdateSource();
}

/**
Expand All @@ -174,8 +175,9 @@ public void delete(T annotation) {
public void delete(List<T> annotationList) {
for (T annotation : annotationList) {
annotations.remove(annotation.getId());
draggableAnnotationController.onAnnotationUpdated(annotation);
}
updateSource();
internalUpdateSource();
}

/**
Expand All @@ -196,7 +198,8 @@ public void deleteAll() {
public void update(T annotation) {
if (annotations.containsValue(annotation)) {
annotations.put(annotation.getId(), annotation);
updateSource();
draggableAnnotationController.onAnnotationUpdated(annotation);
internalUpdateSource();
} else {
Logger.e(TAG, "Can't update annotation: "
+ annotation.toString()
Expand All @@ -213,12 +216,13 @@ public void update(T annotation) {
public void update(List<T> annotationList) {
for (T annotation : annotationList) {
annotations.put(annotation.getId(), annotation);
draggableAnnotationController.onAnnotationUpdated(annotation);
}
updateSource();
internalUpdateSource();
}

/**
* Trigger an update to the underlying source
* Trigger an update to the underlying source. Invalidates active drags.
*/
public void updateSource() {
draggableAnnotationController.onSourceUpdated();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ void removeAnnotationManager(AnnotationManager annotationManager) {
}
}

void onAnnotationUpdated(Annotation annotation) {
if (annotation == draggedAnnotation) {
stopDragging(draggedAnnotation, draggedAnnotationManager);
}
}

void onSourceUpdated() {
stopDragging(draggedAnnotation, draggedAnnotationManager);
}
Expand Down