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

feat: GutenbergKit history navigation #21570

Merged
merged 6 commits into from
Jan 9, 2025
Merged
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 @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ google-play-services-auth = '20.4.1'
google-services = '4.4.2'
gravatar = '2.2.0'
greenrobot-eventbus = '3.3.1'
gutenberg-kit = 'v0.0.3'
gutenberg-kit = '55-a490cd3d2d70ad4bba501655f83fdc42b404d502'
gutenberg-mobile = 'v1.121.0'
indexos-media-for-mobile = '43a9026f0973a2f0a74fa813132f6a16f7499c3a'
jackson-databind = '2.12.7.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -711,6 +712,9 @@ public Pair<CharSequence, CharSequence> getTitleAndContent(CharSequence original
@Override public void onEditorContentChanged(@Nullable ContentChangeListener listener) {
}

@Override public void onEditorHistoryChanged(@Nullable HistoryChangeListener listener) {
}

@Override public void onOpenMediaLibrary(@Nullable OpenMediaLibraryListener listener) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -41,6 +42,7 @@ public class EditorFragmentNotAddedException extends Exception {
public abstract Pair<CharSequence, CharSequence> 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<Editable> getTitleOrContentChanged();
public abstract void appendMediaFile(MediaFile mediaFile, String imageUrl, ImageLoader imageLoader);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1259,6 +1260,9 @@ public void onContentInfoReceived(HashMap<String, Object> contentInfo) {
public void onEditorContentChanged(@NonNull ContentChangeListener listener) {
}

public void onEditorHistoryChanged(@NonNull HistoryChangeListener listener) {
}

public void onOpenMediaLibrary(@NonNull OpenMediaLibraryListener listener) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -462,6 +469,7 @@ public void onDestroy() {
if (mGutenbergView != null) {
GutenbergWebViewPool.recycleWebView(mGutenbergView);
mContentChangeListener = null;
mHistoryChangeListener = null;
}
super.onDestroy();
}
Expand Down Expand Up @@ -521,11 +529,11 @@ public void showEditorHelp() {
}

@Override public void onUndoPressed() {
// Currently unsupported
mGutenbergView.undo();
}

@Override public void onRedoPressed() {
// Currently unsupported
mGutenbergView.redo();
}

@Override
Expand Down
Loading