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

Editor: Prevents the editor from hanging on Share text and Reblog actions #15697

Merged
merged 5 commits into from
Dec 13, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

18.9
-----
* [*] Block editor: Fixed an issue causing the editor to load indefinitely when sharing text from other apps or reblogging a post [https://github.com/wordpress-mobile/WordPress-Android/pull/15697]
antonis marked this conversation as resolved.
Show resolved Hide resolved
* [**] Block editor: Fix undo/redo functionality in links when applying text format. [https://github.com/wordpress-mobile/gutenberg-mobile/pull/4290]
* [*] Block editor: Preformatted block: Fix an issue where the background color is not showing up for standard themes. [https://github.com/wordpress-mobile/gutenberg-mobile/pull/4292]
* [**] Block editor: Update Gallery Block to default to the new format and auto-convert old galleries to the new format. [https://github.com/wordpress-mobile/gutenberg-mobile/pull/4315]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,32 @@ private void newPostSetup() {
mShortcutUtils.reportShortcutUsed(Shortcut.CREATE_NEW_POST);
}

private void newPostFromShareAction() {
Intent intent = getIntent();
final String title = intent.getStringExtra(Intent.EXTRA_SUBJECT);
final String text = intent.getStringExtra(Intent.EXTRA_TEXT);
String content = migrateToGutenbergEditor(AutolinkUtils.autoCreateLinks(text));

newPostSetup(title, content);
}

private void newReblogPostSetup() {
Intent intent = getIntent();
final String title = intent.getStringExtra(EXTRA_REBLOG_POST_TITLE);
final String quote = intent.getStringExtra(EXTRA_REBLOG_POST_QUOTE);
final String citation = intent.getStringExtra(EXTRA_REBLOG_POST_CITATION);
final String image = intent.getStringExtra(EXTRA_REBLOG_POST_IMAGE);
String content = mReblogUtils.reblogContent(image, quote, title, citation);

newPostSetup(title, content);
}

private void newPageFromLayoutPickerSetup(String title, String layoutSlug) {
String content = mSiteStore.getBlockLayoutContent(mSite, layoutSlug);
newPostSetup(title, content);
}

private void newPostSetup(String title, String content) {
mIsNewPost = true;

if (mSite == null) {
Expand All @@ -459,7 +484,6 @@ private void newPageFromLayoutPickerSetup(String title, String layoutSlug) {
showErrorAndFinish(R.string.error_blog_hidden);
return;
}
String content = mSiteStore.getBlockLayoutContent(mSite, layoutSlug);
// Create a new post
mEditPostRepository.set(() -> {
PostModel post = mPostStore.instantiatePostModel(mSite, mIsPage, title, content,
Expand Down Expand Up @@ -552,6 +576,10 @@ protected void onCreate(Bundle savedInstanceState) {
if (mIsPage && !TextUtils.isEmpty(extras.getString(EXTRA_PAGE_TITLE))) {
newPageFromLayoutPickerSetup(extras.getString(EXTRA_PAGE_TITLE),
extras.getString(EXTRA_PAGE_TEMPLATE));
} else if (Intent.ACTION_SEND.equals(action)) {
newPostFromShareAction();
} else if (ACTION_REBLOG.equals(action)) {
newReblogPostSetup();
} else {
newPostSetup();
}
Expand Down Expand Up @@ -2357,13 +2385,11 @@ private void fillContentEditorFields() {
// Special actions - these only make sense for empty posts that are going to be populated now
if (TextUtils.isEmpty(mEditPostRepository.getContent())) {
String action = getIntent().getAction();
if (Intent.ACTION_SEND.equals(action) || Intent.ACTION_SEND_MULTIPLE.equals(action)) {
if (Intent.ACTION_SEND_MULTIPLE.equals(action)) {
setPostContentFromShareAction();
} else if (NEW_MEDIA_POST.equals(action)) {
mEditorMedia.addExistingMediaToEditorAsync(AddExistingMediaSource.WP_MEDIA_LIBRARY,
getIntent().getLongArrayExtra(NEW_MEDIA_POST_EXTRA_IDS));
} else if (ACTION_REBLOG.equals(action)) {
setPostContentFromReblogAction();
}
}

Expand Down Expand Up @@ -2494,33 +2520,6 @@ private void setFeaturedImageId(final long mediaId, final boolean imagePicked, f
}
}

/**
* Sets the content of the reblogged post
*/
private void setPostContentFromReblogAction() {
Intent intent = getIntent();
final String title = intent.getStringExtra(EXTRA_REBLOG_POST_TITLE);
final String quote = intent.getStringExtra(EXTRA_REBLOG_POST_QUOTE);
final String citation = intent.getStringExtra(EXTRA_REBLOG_POST_CITATION);
final String image = intent.getStringExtra(EXTRA_REBLOG_POST_IMAGE);
if (title != null && quote != null) {
mHasSetPostContent = true;
mEditPostRepository.updateAsync(postModel -> {
postModel.setTitle(title);
String content = mReblogUtils.reblogContent(image, quote, title, citation, mShowGutenbergEditor);
postModel.setContent(content);
mEditPostRepository.updatePublishDateIfShouldBePublishedImmediately(postModel);
return true;
}, (postModel, result) -> {
if (result == UpdatePostResult.Updated.INSTANCE) {
mEditorFragment.setTitle(postModel.getTitle());
mEditorFragment.setContent(postModel.getContent());
}
return null;
});
}
}

/**
* Sets the page content
*/
Expand Down