diff --git a/src/org/thoughtcrime/securesms/imageeditor/model/EditorFlags.java b/src/org/thoughtcrime/securesms/imageeditor/model/EditorFlags.java index 700ddaa864..5887f8540b 100644 --- a/src/org/thoughtcrime/securesms/imageeditor/model/EditorFlags.java +++ b/src/org/thoughtcrime/securesms/imageeditor/model/EditorFlags.java @@ -1,5 +1,7 @@ package org.thoughtcrime.securesms.imageeditor.model; +import android.support.annotation.NonNull; + /** * Flags for an {@link EditorElement}. *
@@ -113,4 +115,9 @@ public final class EditorFlags {
void restoreState(int flags) {
this.flags = flags;
}
+
+ public void set(@NonNull EditorFlags from) {
+ this.persistedFlags = from.persistedFlags;
+ this.flags = from.flags;
+ }
}
diff --git a/src/org/thoughtcrime/securesms/imageeditor/model/EditorModel.java b/src/org/thoughtcrime/securesms/imageeditor/model/EditorModel.java
index 1a1b6644d7..9f178c1a3b 100644
--- a/src/org/thoughtcrime/securesms/imageeditor/model/EditorModel.java
+++ b/src/org/thoughtcrime/securesms/imageeditor/model/EditorModel.java
@@ -40,8 +40,8 @@ public final class EditorModel implements Parcelable, RendererContext.Ready {
@NonNull
private Runnable invalidate = NULL_RUNNABLE;
- private final ElementStack undoStack;
- private final ElementStack redoStack;
+ private final UndoRedoStacks undoRedoStacks;
+ private final UndoRedoStacks cropUndoRedoStacks;
private EditorElementHierarchy editorElementHierarchy;
@@ -51,16 +51,16 @@ public final class EditorModel implements Parcelable, RendererContext.Ready {
public EditorModel() {
this.size = new Point(1024, 1024);
this.editorElementHierarchy = EditorElementHierarchy.create();
- this.undoStack = new ElementStack(50);
- this.redoStack = new ElementStack(50);
+ this.undoRedoStacks = new UndoRedoStacks(50);
+ this.cropUndoRedoStacks = new UndoRedoStacks(50);
}
private EditorModel(Parcel in) {
ClassLoader classLoader = getClass().getClassLoader();
this.size = new Point(in.readInt(), in.readInt());
this.editorElementHierarchy = EditorElementHierarchy.create(in.readParcelable(classLoader));
- this.undoStack = in.readParcelable(classLoader);
- this.redoStack = in.readParcelable(classLoader);
+ this.undoRedoStacks = in.readParcelable(classLoader);
+ this.cropUndoRedoStacks = in.readParcelable(classLoader);
}
public void setInvalidate(@Nullable Runnable invalidate) {
@@ -107,28 +107,35 @@ public final class EditorModel implements Parcelable, RendererContext.Ready {
}
public void pushUndoPoint() {
- if (undoStack.tryPush(editorElementHierarchy.getRoot())) {
- redoStack.clear();
+ UndoRedoStacks stacks = isCropping() ? cropUndoRedoStacks : undoRedoStacks;
+
+ if (stacks.getUndoStack().tryPush(editorElementHierarchy.getRoot())) {
+ stacks.getRedoStack().clear();
}
}
public void undo() {
- undoRedo(undoStack, redoStack);
+ boolean cropping = isCropping();
+ UndoRedoStacks stacks = cropping ? cropUndoRedoStacks : undoRedoStacks;
+
+ undoRedo(stacks.getUndoStack(), stacks.getRedoStack(), cropping);
}
public void redo() {
- undoRedo(redoStack, undoStack);
+ boolean cropping = isCropping();
+ UndoRedoStacks stacks = cropping ? cropUndoRedoStacks : undoRedoStacks;
+
+ undoRedo(stacks.getRedoStack(), stacks.getUndoStack(), cropping);
}
- private void undoRedo(@NonNull ElementStack fromStack, @NonNull ElementStack toStack) {
+ private void undoRedo(@NonNull ElementStack fromStack, @NonNull ElementStack toStack, boolean keepEditorState) {
final EditorElement popped = fromStack.pop();
-
if (popped != null) {
EditorElement oldRootElement = editorElementHierarchy.getRoot();
editorElementHierarchy = EditorElementHierarchy.create(popped);
toStack.tryPush(oldRootElement);
- restoreStateWithAnimations(oldRootElement, editorElementHierarchy.getRoot(), invalidate);
+ restoreStateWithAnimations(oldRootElement, editorElementHierarchy.getRoot(), invalidate, keepEditorState);
invalidate.run();
// re-zoom image root as the view port might be different now
@@ -136,7 +143,7 @@ public final class EditorModel implements Parcelable, RendererContext.Ready {
}
}
- private static void restoreStateWithAnimations(@NonNull EditorElement fromRootElement, @NonNull EditorElement toRootElement, @NonNull Runnable onInvalidate) {
+ private static void restoreStateWithAnimations(@NonNull EditorElement fromRootElement, @NonNull EditorElement toRootElement, @NonNull Runnable onInvalidate, boolean keepEditorState) {
Map