diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt index 3be419b757ef..d73245c20f19 100644 --- a/RELEASE-NOTES.txt +++ b/RELEASE-NOTES.txt @@ -4,9 +4,12 @@ ----- -25.6 +25.6.1 ----- +* [*] Fix experimental editor crash when changing the device orienation. [#21658] +25.6 +----- 25.5 ----- 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 4f16e13cdeec..f656af6b8dac 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 @@ -1973,7 +1973,25 @@ class EditPostActivity : LocaleAwareActivity(), EditorFragmentActivity, EditorIm } override fun initializeEditorFragment() { - if (editorFragment is AztecEditorFragment) { + if (editorFragment is GutenbergKitEditorFragment) { + editorFragment?.onEditorContentChanged(object : GutenbergView.ContentChangeListener { + override fun onContentChanged(title: String, content: String) { + storePostViewModel.savePostWithDelay() + } + }) + editorFragment?.onOpenMediaLibrary(object: GutenbergView.OpenMediaLibraryListener { + override fun onOpenMediaLibrary(config: GutenbergView.OpenMediaLibraryConfig) { + editorPhotoPicker?.allowMultipleSelection = config.multiple + val mediaType = mapAllowedTypesToMediaBrowserType(config.allowedTypes, config.multiple) + val initialSelection = when (val value = config.value) { + is GutenbergView.Value.Single -> listOf(value.value) + is GutenbergView.Value.Multiple -> value.toList() + else -> emptyList() + } + openMediaLibrary(mediaType, initialSelection) + } + }) + } else if (editorFragment is AztecEditorFragment) { val aztecEditorFragment = editorFragment as AztecEditorFragment aztecEditorFragment.setEditorImageSettingsListener(this@EditPostActivity) aztecEditorFragment.setMediaToolbarButtonClickListener(editorPhotoPicker) @@ -2508,25 +2526,8 @@ class EditPostActivity : LocaleAwareActivity(), EditorFragmentActivity, EditorIm PAGE_CONTENT -> { editorFragment = fragment as EditorFragmentAbstract editorFragment?.setImageLoader(imageLoader) - if (isGutenbergKitEditor) { - editorFragment?.onEditorContentChanged(object : GutenbergView.ContentChangeListener { - override fun onContentChanged(title: String, content: String) { - storePostViewModel.savePostWithDelay() - } - }) - editorFragment?.onOpenMediaLibrary(object: GutenbergView.OpenMediaLibraryListener { - override fun onOpenMediaLibrary(config: GutenbergView.OpenMediaLibraryConfig) { - editorPhotoPicker?.allowMultipleSelection = config.multiple - val mediaType = mapAllowedTypesToMediaBrowserType(config.allowedTypes, config.multiple) - val initialSelection = when (val value = config.value) { - is GutenbergView.Value.Single -> listOf(value.value) - is GutenbergView.Value.Multiple -> value.toList() - else -> emptyList() - } - openMediaLibrary(mediaType, initialSelection) - } - }) - } else { + // Refactor GutenbergKit to rely upon this observer rather than its custom implementation + if (editorFragment !is GutenbergKitEditorFragment) { editorFragment?.titleOrContentChanged?.observe(this@EditPostActivity) { _: Editable? -> storePostViewModel.savePostWithDelay() } 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..4157786a2be2 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 @@ -27,6 +27,7 @@ import org.wordpress.android.editor.BuildConfig; import org.wordpress.android.editor.EditorEditMediaListener; import org.wordpress.android.editor.EditorFragmentAbstract; +import org.wordpress.android.editor.EditorFragmentActivity; import org.wordpress.android.editor.EditorImagePreviewListener; import org.wordpress.android.editor.EditorMediaUploadListener; import org.wordpress.android.editor.EditorThemeUpdateListener; @@ -125,6 +126,11 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa mSettings = (Map) getArguments().getSerializable(ARG_GUTENBERG_KIT_SETTINGS); } + // request dependency injection. Do this after setting min/max dimensions + if (getActivity() instanceof EditorFragmentActivity) { + ((EditorFragmentActivity) getActivity()).initializeEditorFragment(); + } + mGutenbergView = GutenbergWebViewPool.getPreloadedWebView(requireContext()); mGutenbergView.setLayoutParams(new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT,