diff --git a/android/Gutenberg/src/main/java/org/wordpress/gutenberg/GutenbergView.kt b/android/Gutenberg/src/main/java/org/wordpress/gutenberg/GutenbergView.kt index ebb765c..62f3c59 100644 --- a/android/Gutenberg/src/main/java/org/wordpress/gutenberg/GutenbergView.kt +++ b/android/Gutenberg/src/main/java/org/wordpress/gutenberg/GutenbergView.kt @@ -53,6 +53,7 @@ class GutenbergView : WebView { private var onFileChooserRequested: ((Intent, Int) -> Unit)? = null private var contentChangeListener: ContentChangeListener? = null + private var historyChangeListener: HistoryChangeListener? = null private var openMediaLibraryListener: OpenMediaLibraryListener? = null private var editorDidBecomeAvailableListener: EditorAvailableListener? = null @@ -60,6 +61,10 @@ class GutenbergView : WebView { contentChangeListener = listener } + fun setHistoryChangeListener(listener: HistoryChangeListener) { + historyChangeListener = listener + } + fun setOpenMediaLibraryListener(listener: OpenMediaLibraryListener) { openMediaLibraryListener = listener } @@ -263,6 +268,10 @@ class GutenbergView : WebView { fun onContentChanged(title: String, content: String) } + interface HistoryChangeListener { + fun onHistoryChanged(hasUndo: Boolean, hasRedo: Boolean) + } + sealed class Value { data class Single(val value: Int): Value() data class Multiple(val values: IntArray): Value() { @@ -329,6 +338,11 @@ class GutenbergView : WebView { }, false) } + @JavascriptInterface + fun onEditorHistoryChanged(hasUndo: Boolean, hasRedo: Boolean) { + historyChangeListener?.onHistoryChanged(hasUndo, hasRedo) + } + @JavascriptInterface fun onBlocksChanged(isEmpty: Boolean) { if(isEmpty) { @@ -400,6 +414,7 @@ class GutenbergView : WebView { clearConfig() this.stopLoading() contentChangeListener = null + historyChangeListener = null editorDidBecomeAvailable = null filePathCallback = null onFileChooserRequested = null