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

Introduce GutenbergEditPostActivity #8874

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
a49bc70
introduced EditPostBaseActivity
mzorz Dec 24, 2018
74765be
moved all static references to EditPostBaseActivity
mzorz Dec 24, 2018
13d3d75
made differentiated intent for opening EditPostActivity or upcoming G…
mzorz Dec 24, 2018
79eef32
added GutenbergEditPostActivity, first version
mzorz Dec 26, 2018
ae235ce
moved attachBaseContext to super class
mzorz Dec 26, 2018
2ccd179
expanded getNormalOrGutenbergEditPostActivityIntent parameters to bet…
mzorz Dec 27, 2018
2f8ef0e
added dedicated editPageForResultOnGutenberg launcher method for Page…
mzorz Dec 27, 2018
d008ed1
removed mShowGutenbergEditor flag, unneeded in the context of dedicat…
mzorz Dec 27, 2018
5e1c762
removed mShowAztec and Aztec references, and commented out media rela…
mzorz Dec 27, 2018
f3f4ee9
make sure to present Gutenberg for Pages editing on the same cased as…
mzorz Dec 27, 2018
85263bb
removed flags for legacy editor / modern editor decision
mzorz Dec 27, 2018
9656247
removed unused flag and initializer mIsToolbarExpanded
mzorz Dec 27, 2018
5dbdfce
fixed lint warnings
mzorz Dec 27, 2018
ea3d415
fixed lint warnings
mzorz Dec 27, 2018
fbd314b
fixed ktlint warnings
mzorz Dec 27, 2018
fd181f2
removed Gutenberg editor from EditPostActivity
mzorz Dec 28, 2018
dd4211e
removed Aztec.IHistoryListener with onUndoEnabled and onRedoEnabled i…
mzorz Dec 28, 2018
87fae7e
fixed typo
mzorz Dec 28, 2018
7ad4619
Update lint-baseline.xml snapshot
mzorz Dec 28, 2018
e30b4d6
Update lint-baseline.xml snapshot
mzorz Dec 28, 2018
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
3,192 changes: 763 additions & 2,429 deletions WordPress/lint-baseline.xml

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions WordPress/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,19 @@
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<activity
android:name=".ui.posts.GutenbergEditPostActivity"
android:theme="@style/Calypso.ActionMode.Dark"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="stateHidden|adjustResize">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".ui.posts.PostsListActivity" />

<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<!-- Workaround for old launcher icon pointing to .ui.posts.PostsActivity -->
<activity-alias
android:name=".ui.posts.PostsActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
import org.wordpress.android.ui.posts.EditPostActivity;
import org.wordpress.android.ui.posts.EditPostPreviewFragment;
import org.wordpress.android.ui.posts.EditPostSettingsFragment;
import org.wordpress.android.ui.posts.GutenbergEditPostActivity;
import org.wordpress.android.ui.posts.HistoryListFragment;
import org.wordpress.android.ui.posts.PostListFragment;
import org.wordpress.android.ui.posts.PostPreviewActivity;
Expand Down Expand Up @@ -322,6 +323,8 @@ public interface AppComponent extends AndroidInjector<WordPress> {

void inject(EditPostActivity object);

void inject(GutenbergEditPostActivity object);

void inject(EditPostSettingsFragment object);

void inject(EditPostPreviewFragment object);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
import org.wordpress.android.ui.plugins.PluginDetailActivity;
import org.wordpress.android.ui.plugins.PluginUtils;
import org.wordpress.android.ui.posts.EditPostActivity;
import org.wordpress.android.ui.posts.EditPostBaseActivity;
import org.wordpress.android.ui.posts.GutenbergEditPostActivity;
import org.wordpress.android.ui.posts.PostPreviewActivity;
import org.wordpress.android.ui.posts.PostsListActivity;
import org.wordpress.android.ui.prefs.AccountSettingsActivity;
Expand Down Expand Up @@ -571,14 +573,14 @@ public static void viewPostPreviewForResult(Activity activity, SiteModel site, P
}

Intent intent = new Intent(activity, PostPreviewActivity.class);
intent.putExtra(EditPostActivity.EXTRA_POST_LOCAL_ID, post.getId());
intent.putExtra(EditPostBaseActivity.EXTRA_POST_LOCAL_ID, post.getId());
intent.putExtra(WordPress.SITE, site);
activity.startActivityForResult(intent, RequestCodes.PREVIEW_POST);
}

public static void viewPagePreview(@NonNull Fragment fragment, @NonNull PageModel page) {
Intent intent = new Intent(fragment.getContext(), PostPreviewActivity.class);
intent.putExtra(EditPostActivity.EXTRA_POST_LOCAL_ID, page.getPageId());
intent.putExtra(EditPostBaseActivity.EXTRA_POST_LOCAL_ID, page.getPageId());
intent.putExtra(WordPress.SITE, page.getSite());
fragment.startActivity(intent);
}
Expand All @@ -588,10 +590,10 @@ public static void addNewPostForResult(Activity activity, SiteModel site, boolea
return;
}

Intent intent = new Intent(activity, EditPostActivity.class);
Intent intent = EditPostBaseActivity.getNormalOrGutenbergEditPostActivityIntent(activity, true, null);
intent.putExtra(WordPress.SITE, site);
intent.putExtra(EditPostActivity.EXTRA_IS_PAGE, false);
intent.putExtra(EditPostActivity.EXTRA_IS_PROMO, isPromo);
intent.putExtra(EditPostBaseActivity.EXTRA_IS_PAGE, false);
intent.putExtra(EditPostBaseActivity.EXTRA_IS_PROMO, isPromo);
activity.startActivityForResult(intent, RequestCodes.EDIT_POST);
}

Expand All @@ -600,27 +602,35 @@ public static void editPostOrPageForResult(Activity activity, SiteModel site, Po
return;
}

Intent intent = new Intent(activity, EditPostActivity.class);
Intent intent = EditPostBaseActivity.getNormalOrGutenbergEditPostActivityIntent(activity, false, post);
intent.putExtra(WordPress.SITE, site);
// PostModel objects can be quite large, since content field is not size restricted,
// in order to avoid issues like TransactionTooLargeException it's better to pass the id of the post.
// However, we still want to keep passing the SiteModel to avoid confusion around local & remote ids.
intent.putExtra(EditPostActivity.EXTRA_POST_LOCAL_ID, post.getId());
intent.putExtra(EditPostBaseActivity.EXTRA_POST_LOCAL_ID, post.getId());
activity.startActivityForResult(intent, RequestCodes.EDIT_POST);
}

public static void editPageForResult(@NonNull Fragment fragment, @NonNull PageModel page) {
Intent intent = new Intent(fragment.getContext(), EditPostActivity.class);
intent.putExtra(WordPress.SITE, page.getSite());
intent.putExtra(EditPostActivity.EXTRA_POST_LOCAL_ID, page.getPageId());
intent.putExtra(EditPostBaseActivity.EXTRA_POST_LOCAL_ID, page.getPageId());
fragment.startActivityForResult(intent, RequestCodes.EDIT_POST);
}

public static void editPageForResultOnGutenberg(@NonNull Fragment fragment, @NonNull PageModel page) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, having a Gutenberg-dedicated method (editPageForResultOnGutenberg) is generally fine but, only a few lines above (line 605) we're seeing a different pattern, where the method is just one and it it decides internally which editor to launch. Can we get away with using just one of the two patterns perhaps?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine for this case as otherwise we need to inject and use FluxC in ActivityLauncher just to be able to inflate the PageModel, read the content of the Post body and then only decide which Activity to launch. This, in the only case where this method is called, is already known at the time the call happens by the caller.

Intent intent = new Intent(fragment.getContext(), GutenbergEditPostActivity.class);
intent.putExtra(WordPress.SITE, page.getSite());
intent.putExtra(EditPostBaseActivity.EXTRA_POST_LOCAL_ID, page.getPageId());
fragment.startActivityForResult(intent, RequestCodes.EDIT_POST);
}

public static void addNewPageForResult(@NonNull Fragment fragment, @NonNull SiteModel site) {
Intent intent = new Intent(fragment.getContext(), EditPostActivity.class);
Intent intent = EditPostBaseActivity.getNormalOrGutenbergEditPostActivityIntent(
fragment.getContext(), true, null);
intent.putExtra(WordPress.SITE, site);
intent.putExtra(EditPostActivity.EXTRA_IS_PAGE, true);
intent.putExtra(EditPostActivity.EXTRA_IS_PROMO, false);
intent.putExtra(EditPostBaseActivity.EXTRA_IS_PAGE, true);
intent.putExtra(EditPostBaseActivity.EXTRA_IS_PROMO, false);
fragment.startActivityForResult(intent, RequestCodes.EDIT_POST);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import org.wordpress.android.fluxc.model.SiteModel;
import org.wordpress.android.fluxc.store.SiteStore;
import org.wordpress.android.fluxc.tools.FluxCImageLoader;
import org.wordpress.android.ui.posts.EditPostActivity;
import org.wordpress.android.ui.posts.EditPostBaseActivity;
import org.wordpress.android.util.LocaleManager;
import org.wordpress.android.util.SiteUtils;
import org.wordpress.android.util.ToastUtils;
Expand Down Expand Up @@ -136,12 +136,14 @@ public void onClick(DialogInterface dialog, int which) {
ToastUtils.showToast(AddQuickPressShortcutActivity.this, R.string.quickpress_add_error,
ToastUtils.Duration.LONG);
} else {
Intent shortcutIntent = new Intent(getApplicationContext(), EditPostActivity.class);
Intent shortcutIntent =
EditPostBaseActivity.getNormalOrGutenbergEditPostActivityIntent(
getApplicationContext(), true, null);
shortcutIntent.setAction(Intent.ACTION_MAIN);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
shortcutIntent.putExtra(EditPostActivity.EXTRA_QUICKPRESS_BLOG_ID, siteIds[position]);
shortcutIntent.putExtra(EditPostActivity.EXTRA_IS_QUICKPRESS, true);
shortcutIntent.putExtra(EditPostBaseActivity.EXTRA_QUICKPRESS_BLOG_ID, siteIds[position]);
shortcutIntent.putExtra(EditPostBaseActivity.EXTRA_IS_QUICKPRESS, true);

String shortcutName = quickPressShortcutName.getText().toString();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
import org.wordpress.android.ui.notifications.utils.PendingDraftsNotificationsUtils;
import org.wordpress.android.ui.posts.BasicFragmentDialog.BasicDialogNegativeClickInterface;
import org.wordpress.android.ui.posts.BasicFragmentDialog.BasicDialogPositiveClickInterface;
import org.wordpress.android.ui.posts.EditPostActivity;
import org.wordpress.android.ui.posts.EditPostBaseActivity;
import org.wordpress.android.ui.posts.PromoDialog;
import org.wordpress.android.ui.posts.PromoDialog.PromoDialogClickInterface;
import org.wordpress.android.ui.prefs.AppPrefs;
Expand Down Expand Up @@ -686,7 +686,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != Activity.RESULT_OK || data == null || isFinishing()) {
return;
}
int localId = data.getIntExtra(EditPostActivity.EXTRA_POST_LOCAL_ID, 0);
int localId = data.getIntExtra(EditPostBaseActivity.EXTRA_POST_LOCAL_ID, 0);
final SiteModel site = getSelectedSite();
final PostModel post = mPostStore.getPostByLocalPostId(localId);
if (site != null && post != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import org.wordpress.android.ui.RequestCodes
import org.wordpress.android.ui.WPWebViewActivity
import org.wordpress.android.ui.pages.PageItem.Page
import org.wordpress.android.ui.posts.BasicFragmentDialog
import org.wordpress.android.ui.posts.EditPostActivity
import org.wordpress.android.ui.posts.EditPostBaseActivity
import org.wordpress.android.ui.posts.GutenbergWarningFragmentDialog.GutenbergWarningDialogClickInterface
import org.wordpress.android.ui.posts.PostUtils
import org.wordpress.android.ui.prefs.AppPrefs
Expand Down Expand Up @@ -90,7 +90,7 @@ class PagesFragment : Fragment(), GutenbergWarningDialogClickInterface {

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (requestCode == RequestCodes.EDIT_POST && resultCode == Activity.RESULT_OK && data != null) {
val pageId = data.getLongExtra(EditPostActivity.EXTRA_POST_REMOTE_ID, -1)
val pageId = data.getLongExtra(EditPostBaseActivity.EXTRA_POST_REMOTE_ID, -1)
if (pageId != -1L) {
onPageEditFinished(pageId)
}
Expand Down Expand Up @@ -246,13 +246,17 @@ class PagesFragment : Fragment(), GutenbergWarningDialogClickInterface {
viewModel.editPage.observe(this, Observer { page ->
page?.let {
val post = postStore.getPostByLocalPostId(page.pageId)
val isGutenbergContent = PostUtils.contentContainsGutenbergBlocks(post?.content)
if (isGutenbergContent && !AppPrefs.isGutenbergWarningDialogDisabled()) {
PostUtils.showGutenbergCompatibilityWarningDialog(
getActivity(), fragmentManager, post, viewModel.site
)
if (PostUtils.shouldShowGutenbergEditor(false, post)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels to me that the check for Gutenberg editor is bleeding into this class (PagesFragment) but it'd better not. Can we leave it out, perhaps by having it inside ActivityLauncher.editPageForResult()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comment above

ActivityLauncher.editPageForResultOnGutenberg(this, page)
} else {
ActivityLauncher.editPageForResult(this, page)
val isGutenbergContent = PostUtils.contentContainsGutenbergBlocks(post?.content)
if (isGutenbergContent && !AppPrefs.isGutenbergWarningDialogDisabled()) {
PostUtils.showGutenbergCompatibilityWarningDialog(
getActivity(), fragmentManager, post, viewModel.site
)
} else {
ActivityLauncher.editPageForResult(this, page)
}
}
}
})
Expand Down
Loading