diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.kt index b76fcf0cc119..eec54313e76b 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.kt @@ -1414,11 +1414,11 @@ class EditPostActivity : AppCompatActivity(), EditorFragmentActivity, EditorImag val helpMenuItem = menu.findItem(R.id.menu_editor_help) if (undoItem != null) { undoItem.setEnabled(menuHasUndo) - undoItem.setVisible(!htmlModeMenuStateOn && !isGutenbergKitEditor) + undoItem.setVisible(!htmlModeMenuStateOn) } if (redoItem != null) { redoItem.setEnabled(menuHasRedo) - redoItem.setVisible(!htmlModeMenuStateOn && !isGutenbergKitEditor) + redoItem.setVisible(!htmlModeMenuStateOn) } if (secondaryAction != null && editPostRepository.hasPost()) { secondaryAction.setVisible(showMenuItems && this.secondaryAction.isVisible) @@ -2516,6 +2516,12 @@ class EditPostActivity : AppCompatActivity(), EditorFragmentActivity, EditorImag storePostViewModel.savePostWithDelay() } }) + editorFragment?.onEditorHistoryChanged(object : GutenbergView.HistoryChangeListener { + override fun onHistoryChanged(hasUndo: Boolean, hasRedo: Boolean) { + onToggleUndo(!hasUndo) + onToggleRedo(!hasRedo) + } + }) editorFragment?.onOpenMediaLibrary(object: GutenbergView.OpenMediaLibraryListener { override fun onOpenMediaLibrary(config: GutenbergView.OpenMediaLibraryConfig) { editorPhotoPicker?.allowMultipleSelection = config.multiple diff --git a/libs/editor/src/main/java/org/wordpress/android/editor/AztecEditorFragment.java b/libs/editor/src/main/java/org/wordpress/android/editor/AztecEditorFragment.java index 4860c3e7c5ed..cfff93415617 100644 --- a/libs/editor/src/main/java/org/wordpress/android/editor/AztecEditorFragment.java +++ b/libs/editor/src/main/java/org/wordpress/android/editor/AztecEditorFragment.java @@ -107,6 +107,7 @@ import org.wordpress.aztec.util.AztecLog; import org.wordpress.aztec.watchers.EndOfBufferMarkerAdder; import org.wordpress.gutenberg.GutenbergView.ContentChangeListener; +import org.wordpress.gutenberg.GutenbergView.HistoryChangeListener; import org.wordpress.gutenberg.GutenbergView.OpenMediaLibraryListener; import org.xml.sax.Attributes; @@ -711,6 +712,9 @@ public Pair getTitleAndContent(CharSequence original @Override public void onEditorContentChanged(@Nullable ContentChangeListener listener) { } + @Override public void onEditorHistoryChanged(@Nullable HistoryChangeListener listener) { + } + @Override public void onOpenMediaLibrary(@Nullable OpenMediaLibraryListener listener) { } diff --git a/libs/editor/src/main/java/org/wordpress/android/editor/EditorFragmentAbstract.java b/libs/editor/src/main/java/org/wordpress/android/editor/EditorFragmentAbstract.java index af6e04aabfa0..8962f822a2d7 100644 --- a/libs/editor/src/main/java/org/wordpress/android/editor/EditorFragmentAbstract.java +++ b/libs/editor/src/main/java/org/wordpress/android/editor/EditorFragmentAbstract.java @@ -21,6 +21,7 @@ import org.wordpress.android.util.helpers.MediaFile; import org.wordpress.android.util.helpers.MediaGallery; import org.wordpress.gutenberg.GutenbergView.ContentChangeListener; +import org.wordpress.gutenberg.GutenbergView.HistoryChangeListener; import org.wordpress.gutenberg.GutenbergView.OpenMediaLibraryListener; import java.util.ArrayList; @@ -41,6 +42,7 @@ public class EditorFragmentNotAddedException extends Exception { public abstract Pair getTitleAndContent(CharSequence originalContent) throws EditorFragmentNotAddedException; public abstract void onEditorContentChanged(ContentChangeListener listener); + public abstract void onEditorHistoryChanged(HistoryChangeListener listener); public abstract void onOpenMediaLibrary(OpenMediaLibraryListener listener); public abstract LiveData getTitleOrContentChanged(); public abstract void appendMediaFile(MediaFile mediaFile, String imageUrl, ImageLoader imageLoader); diff --git a/libs/editor/src/main/java/org/wordpress/android/editor/gutenberg/GutenbergEditorFragment.java b/libs/editor/src/main/java/org/wordpress/android/editor/gutenberg/GutenbergEditorFragment.java index aaeacc51ca47..ae279371ecdc 100644 --- a/libs/editor/src/main/java/org/wordpress/android/editor/gutenberg/GutenbergEditorFragment.java +++ b/libs/editor/src/main/java/org/wordpress/android/editor/gutenberg/GutenbergEditorFragment.java @@ -66,6 +66,7 @@ import org.wordpress.android.util.helpers.MediaGallery; import org.wordpress.aztec.IHistoryListener; import org.wordpress.gutenberg.GutenbergView.ContentChangeListener; +import org.wordpress.gutenberg.GutenbergView.HistoryChangeListener; import org.wordpress.gutenberg.GutenbergView.OpenMediaLibraryListener; import org.wordpress.mobile.ReactNativeGutenbergBridge.GutenbergBridgeJS2Parent.LogExceptionCallback; import org.wordpress.mobile.ReactNativeGutenbergBridge.GutenbergEmbedWebViewActivity; @@ -1259,6 +1260,9 @@ public void onContentInfoReceived(HashMap contentInfo) { public void onEditorContentChanged(@NonNull ContentChangeListener listener) { } + public void onEditorHistoryChanged(@NonNull HistoryChangeListener listener) { + } + public void onOpenMediaLibrary(@NonNull OpenMediaLibraryListener listener) { } diff --git a/libs/editor/src/main/java/org/wordpress/android/editor/gutenberg/GutenbergKitEditorFragment.java b/libs/editor/src/main/java/org/wordpress/android/editor/gutenberg/GutenbergKitEditorFragment.java index dbe53032e50b..080b33b40ab0 100644 --- a/libs/editor/src/main/java/org/wordpress/android/editor/gutenberg/GutenbergKitEditorFragment.java +++ b/libs/editor/src/main/java/org/wordpress/android/editor/gutenberg/GutenbergKitEditorFragment.java @@ -44,6 +44,7 @@ import org.wordpress.aztec.IHistoryListener; import org.wordpress.gutenberg.GutenbergView; import org.wordpress.gutenberg.GutenbergView.ContentChangeListener; +import org.wordpress.gutenberg.GutenbergView.HistoryChangeListener; import org.wordpress.gutenberg.GutenbergView.OpenMediaLibraryListener; import org.wordpress.gutenberg.GutenbergView.TitleAndContentCallback; import org.wordpress.gutenberg.GutenbergWebViewPool; @@ -79,6 +80,7 @@ public class GutenbergKitEditorFragment extends EditorFragmentAbstract implement private final LiveTextWatcher mTextWatcher = new LiveTextWatcher(); @Nullable private ContentChangeListener mContentChangeListener = null; + @Nullable private HistoryChangeListener mHistoryChangeListener = null; @Nullable private OpenMediaLibraryListener mOpenMediaLibraryListener = null; private boolean mEditorDidMount; @@ -135,6 +137,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa return null; }); mGutenbergView.setContentChangeListener(mContentChangeListener); + mGutenbergView.setHistoryChangeListener(mHistoryChangeListener); mGutenbergView.setOpenMediaLibraryListener(mOpenMediaLibraryListener); mGutenbergView.setEditorDidBecomeAvailable(view -> { mEditorFragmentListener.onEditorFragmentContentReady(new ArrayList<>(), false); @@ -364,6 +367,10 @@ public void onEditorContentChanged(@NonNull ContentChangeListener listener) { mContentChangeListener = listener; } + public void onEditorHistoryChanged(@NonNull HistoryChangeListener listener) { + mHistoryChangeListener = listener; + } + public void onOpenMediaLibrary(@NonNull OpenMediaLibraryListener listener) { mOpenMediaLibraryListener = listener; } @@ -462,6 +469,7 @@ public void onDestroy() { if (mGutenbergView != null) { GutenbergWebViewPool.recycleWebView(mGutenbergView); mContentChangeListener = null; + mHistoryChangeListener = null; } super.onDestroy(); }