-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
EditPostActivity.java
3039 lines (2695 loc) · 137 KB
/
EditPostActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package org.wordpress.android.ui.posts;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.text.TextUtils;
import android.view.DragEvent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.MimeTypeMap;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.Toolbar;
import androidx.core.app.ActivityCompat.OnRequestPermissionsResultCallback;
import androidx.core.util.Consumer;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.ViewModelProvider;
import androidx.lifecycle.ViewModelProviders;
import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.snackbar.Snackbar;
import com.yalantis.ucrop.UCrop;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.jetbrains.annotations.NotNull;
import org.wordpress.android.BuildConfig;
import org.wordpress.android.R;
import org.wordpress.android.WordPress;
import org.wordpress.android.analytics.AnalyticsTracker;
import org.wordpress.android.analytics.AnalyticsTracker.Stat;
import org.wordpress.android.editor.AztecEditorFragment;
import org.wordpress.android.editor.EditorEditMediaListener;
import org.wordpress.android.editor.EditorFragmentAbstract;
import org.wordpress.android.editor.EditorFragmentAbstract.EditorDragAndDropListener;
import org.wordpress.android.editor.EditorFragmentAbstract.EditorFragmentListener;
import org.wordpress.android.editor.EditorFragmentAbstract.EditorFragmentNotAddedException;
import org.wordpress.android.editor.EditorFragmentAbstract.TrackableEvent;
import org.wordpress.android.editor.EditorFragmentActivity;
import org.wordpress.android.editor.EditorImageMetaData;
import org.wordpress.android.editor.EditorImagePreviewListener;
import org.wordpress.android.editor.EditorImageSettingsListener;
import org.wordpress.android.editor.EditorMediaUploadListener;
import org.wordpress.android.editor.EditorMediaUtils;
import org.wordpress.android.editor.GutenbergEditorFragment;
import org.wordpress.android.editor.ImageSettingsDialogFragment;
import org.wordpress.android.fluxc.Dispatcher;
import org.wordpress.android.fluxc.action.AccountAction;
import org.wordpress.android.fluxc.generated.AccountActionBuilder;
import org.wordpress.android.fluxc.generated.PostActionBuilder;
import org.wordpress.android.fluxc.generated.SiteActionBuilder;
import org.wordpress.android.fluxc.model.AccountModel;
import org.wordpress.android.fluxc.model.CauseOfOnPostChanged;
import org.wordpress.android.fluxc.model.CauseOfOnPostChanged.RemoteAutoSavePost;
import org.wordpress.android.fluxc.model.MediaModel;
import org.wordpress.android.fluxc.model.MediaModel.MediaUploadState;
import org.wordpress.android.fluxc.model.PostImmutableModel;
import org.wordpress.android.fluxc.model.PostModel;
import org.wordpress.android.fluxc.model.SiteModel;
import org.wordpress.android.fluxc.model.post.PostStatus;
import org.wordpress.android.fluxc.network.rest.wpcom.site.PrivateAtomicCookie;
import org.wordpress.android.fluxc.store.AccountStore;
import org.wordpress.android.fluxc.store.AccountStore.OnAccountChanged;
import org.wordpress.android.fluxc.store.MediaStore;
import org.wordpress.android.fluxc.store.MediaStore.MediaError;
import org.wordpress.android.fluxc.store.MediaStore.MediaErrorType;
import org.wordpress.android.fluxc.store.MediaStore.OnMediaChanged;
import org.wordpress.android.fluxc.store.MediaStore.OnMediaUploaded;
import org.wordpress.android.fluxc.store.PostStore;
import org.wordpress.android.fluxc.store.PostStore.OnPostChanged;
import org.wordpress.android.fluxc.store.PostStore.OnPostUploaded;
import org.wordpress.android.fluxc.store.PostStore.RemotePostPayload;
import org.wordpress.android.fluxc.store.QuickStartStore;
import org.wordpress.android.fluxc.store.SiteStore;
import org.wordpress.android.fluxc.store.SiteStore.FetchPrivateAtomicCookiePayload;
import org.wordpress.android.fluxc.store.SiteStore.OnPrivateAtomicCookieFetched;
import org.wordpress.android.fluxc.store.UploadStore;
import org.wordpress.android.fluxc.tools.FluxCImageLoader;
import org.wordpress.android.ui.ActivityId;
import org.wordpress.android.ui.ActivityLauncher;
import org.wordpress.android.ui.LocaleAwareActivity;
import org.wordpress.android.ui.PagePostCreationSourcesDetail;
import org.wordpress.android.ui.PrivateAtCookieRefreshProgressDialog;
import org.wordpress.android.ui.PrivateAtCookieRefreshProgressDialog.PrivateAtCookieProgressDialogOnDismissListener;
import org.wordpress.android.ui.RequestCodes;
import org.wordpress.android.ui.Shortcut;
import org.wordpress.android.ui.gif.GifPickerActivity;
import org.wordpress.android.ui.history.HistoryListItem.Revision;
import org.wordpress.android.ui.media.MediaBrowserActivity;
import org.wordpress.android.ui.media.MediaBrowserType;
import org.wordpress.android.ui.media.MediaPreviewActivity;
import org.wordpress.android.ui.media.MediaSettingsActivity;
import org.wordpress.android.ui.pages.SnackbarMessageHolder;
import org.wordpress.android.ui.photopicker.PhotoPickerActivity;
import org.wordpress.android.ui.photopicker.PhotoPickerFragment;
import org.wordpress.android.ui.photopicker.PhotoPickerFragment.PhotoPickerIcon;
import org.wordpress.android.ui.posts.EditPostRepository.UpdatePostResult;
import org.wordpress.android.ui.posts.EditPostSettingsFragment.EditPostSettingsCallback;
import org.wordpress.android.ui.posts.InsertMediaDialog.InsertMediaCallback;
import org.wordpress.android.ui.posts.PostEditorAnalyticsSession.Editor;
import org.wordpress.android.ui.posts.PostEditorAnalyticsSession.Outcome;
import org.wordpress.android.ui.posts.RemotePreviewLogicHelper.PreviewLogicOperationResult;
import org.wordpress.android.ui.posts.editor.EditorActionsProvider;
import org.wordpress.android.ui.posts.editor.EditorPhotoPicker;
import org.wordpress.android.ui.posts.editor.EditorPhotoPickerListener;
import org.wordpress.android.ui.posts.editor.EditorTracker;
import org.wordpress.android.ui.posts.editor.PostLoadingState;
import org.wordpress.android.ui.posts.editor.PrimaryEditorAction;
import org.wordpress.android.ui.posts.editor.SecondaryEditorAction;
import org.wordpress.android.ui.posts.editor.StorePostViewModel;
import org.wordpress.android.ui.posts.editor.StorePostViewModel.ActivityFinishState;
import org.wordpress.android.ui.posts.editor.StorePostViewModel.UpdateFromEditor;
import org.wordpress.android.ui.posts.editor.StorePostViewModel.UpdateFromEditor.PostFields;
import org.wordpress.android.ui.posts.editor.media.EditorMedia;
import org.wordpress.android.ui.posts.editor.media.EditorMedia.AddExistingMediaSource;
import org.wordpress.android.ui.posts.editor.media.EditorMediaListener;
import org.wordpress.android.ui.posts.reactnative.ReactNativeRequestHandler;
import org.wordpress.android.ui.posts.services.AztecImageLoader;
import org.wordpress.android.ui.posts.services.AztecVideoLoader;
import org.wordpress.android.ui.prefs.AppPrefs;
import org.wordpress.android.ui.reader.utils.ReaderUtilsWrapper;
import org.wordpress.android.ui.stockmedia.StockMediaPickerActivity;
import org.wordpress.android.ui.uploads.PostEvents;
import org.wordpress.android.ui.uploads.UploadService;
import org.wordpress.android.ui.uploads.UploadUtils;
import org.wordpress.android.ui.uploads.UploadUtilsWrapper;
import org.wordpress.android.ui.uploads.VideoOptimizer;
import org.wordpress.android.ui.utils.AuthenticationUtils;
import org.wordpress.android.ui.utils.UiHelpers;
import org.wordpress.android.util.ActivityUtils;
import org.wordpress.android.util.AniUtils;
import org.wordpress.android.util.AppLog;
import org.wordpress.android.util.AppLog.T;
import org.wordpress.android.util.AutolinkUtils;
import org.wordpress.android.util.CrashLoggingUtils;
import org.wordpress.android.util.DateTimeUtilsWrapper;
import org.wordpress.android.util.DisplayUtils;
import org.wordpress.android.util.FluxCUtils;
import org.wordpress.android.util.ListUtils;
import org.wordpress.android.util.LocaleManager;
import org.wordpress.android.util.LocaleManagerWrapper;
import org.wordpress.android.util.MediaUtils;
import org.wordpress.android.util.PermissionUtils;
import org.wordpress.android.util.ShortcutUtils;
import org.wordpress.android.util.SiteUtils;
import org.wordpress.android.util.StringUtils;
import org.wordpress.android.util.ToastUtils;
import org.wordpress.android.util.ToastUtils.Duration;
import org.wordpress.android.util.UrlUtils;
import org.wordpress.android.util.WPMediaUtils;
import org.wordpress.android.util.WPPermissionUtils;
import org.wordpress.android.util.WPUrlUtils;
import org.wordpress.android.util.analytics.AnalyticsUtils;
import org.wordpress.android.util.analytics.AnalyticsUtils.BlockEditorEnabledSource;
import org.wordpress.android.util.helpers.MediaFile;
import org.wordpress.android.util.helpers.MediaGallery;
import org.wordpress.android.util.image.ImageManager;
import org.wordpress.android.viewmodel.helpers.ToastMessageHolder;
import org.wordpress.android.widgets.AppRatingDialog;
import org.wordpress.android.widgets.WPSnackbar;
import org.wordpress.android.widgets.WPViewPager;
import org.wordpress.aztec.exceptions.DynamicLayoutGetBlockIndexOutOfBoundsException;
import org.wordpress.aztec.util.AztecLog;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.inject.Inject;
import static org.wordpress.android.analytics.AnalyticsTracker.Stat.APP_REVIEWS_EVENT_INCREMENTED_BY_PUBLISHING_POST_OR_PAGE;
import static org.wordpress.android.imageeditor.preview.PreviewImageFragment.PREVIEW_IMAGE_REDUCED_SIZE_FACTOR;
import static org.wordpress.android.ui.PagePostCreationSourcesDetail.CREATED_POST_SOURCE_DETAIL_KEY;
import static org.wordpress.android.ui.history.HistoryDetailContainerFragment.KEY_REVISION;
import kotlin.Unit;
import kotlin.jvm.functions.Function0;
public class EditPostActivity extends LocaleAwareActivity implements
EditorFragmentActivity,
EditorImageSettingsListener,
EditorImagePreviewListener,
EditorEditMediaListener,
EditorDragAndDropListener,
EditorFragmentListener,
OnRequestPermissionsResultCallback,
PhotoPickerFragment.PhotoPickerListener,
EditorPhotoPickerListener,
EditorMediaListener,
EditPostSettingsFragment.EditPostActivityHook,
BasicFragmentDialog.BasicDialogPositiveClickInterface,
BasicFragmentDialog.BasicDialogNegativeClickInterface,
PostSettingsListDialogFragment.OnPostSettingsDialogFragmentListener,
HistoryListFragment.HistoryItemClickInterface,
EditPostSettingsCallback,
PrivateAtCookieProgressDialogOnDismissListener {
public static final String EXTRA_POST_LOCAL_ID = "postModelLocalId";
public static final String EXTRA_LOAD_AUTO_SAVE_REVISION = "loadAutosaveRevision";
public static final String EXTRA_POST_REMOTE_ID = "postModelRemoteId";
public static final String EXTRA_IS_PAGE = "isPage";
public static final String EXTRA_IS_PROMO = "isPromo";
public static final String EXTRA_IS_QUICKPRESS = "isQuickPress";
public static final String EXTRA_QUICKPRESS_BLOG_ID = "quickPressBlogId";
public static final String EXTRA_UPLOAD_NOT_STARTED = "savedAsLocalDraft";
public static final String EXTRA_HAS_FAILED_MEDIA = "hasFailedMedia";
public static final String EXTRA_HAS_CHANGES = "hasChanges";
public static final String EXTRA_RESTART_EDITOR = "isSwitchingEditors";
public static final String EXTRA_INSERT_MEDIA = "insertMedia";
public static final String EXTRA_IS_NEW_POST = "isNewPost";
public static final String EXTRA_CREATION_SOURCE_DETAIL = "creationSourceDetail";
private static final String STATE_KEY_EDITOR_FRAGMENT = "editorFragment";
private static final String STATE_KEY_DROPPED_MEDIA_URIS = "stateKeyDroppedMediaUri";
private static final String STATE_KEY_POST_LOCAL_ID = "stateKeyPostModelLocalId";
private static final String STATE_KEY_POST_REMOTE_ID = "stateKeyPostModelRemoteId";
private static final String STATE_KEY_POST_LOADING_STATE = "stateKeyPostLoadingState";
private static final String STATE_KEY_IS_NEW_POST = "stateKeyIsNewPost";
private static final String STATE_KEY_IS_PHOTO_PICKER_VISIBLE = "stateKeyPhotoPickerVisible";
private static final String STATE_KEY_HTML_MODE_ON = "stateKeyHtmlModeOn";
private static final String STATE_KEY_REVISION = "stateKeyRevision";
private static final String STATE_KEY_EDITOR_SESSION_DATA = "stateKeyEditorSessionData";
private static final String STATE_KEY_GUTENBERG_IS_SHOWN = "stateKeyGutenbergIsShown";
private static final String TAG_PUBLISH_CONFIRMATION_DIALOG = "tag_publish_confirmation_dialog";
private static final String TAG_UPDATE_CONFIRMATION_DIALOG = "tag_update_confirmation_dialog";
private static final String TAG_GB_INFORMATIVE_DIALOG = "tag_gb_informative_dialog";
private static final String TAG_GB_ROLLOUT_V2_INFORMATIVE_DIALOG = "tag_gb_rollout_v2_informative_dialog";
private static final int PAGE_CONTENT = 0;
private static final int PAGE_SETTINGS = 1;
private static final int PAGE_PUBLISH_SETTINGS = 2;
private static final int PAGE_HISTORY = 3;
private AztecImageLoader mAztecImageLoader;
enum RestartEditorOptions {
NO_RESTART,
RESTART_SUPPRESS_GUTENBERG,
RESTART_DONT_SUPPRESS_GUTENBERG,
}
private RestartEditorOptions mRestartEditorOption = RestartEditorOptions.NO_RESTART;
private boolean mShowAztecEditor;
private boolean mShowGutenbergEditor;
private List<String> mPendingVideoPressInfoRequests;
private PostEditorAnalyticsSession mPostEditorAnalyticsSession;
private boolean mIsConfigChange = false;
/**
* The {@link PagerAdapter} that will provide
* fragments for each of the sections. We use a
* {@link FragmentPagerAdapter} derivative, which will keep every
* loaded fragment in memory. If this becomes too memory intensive, it
* may be best to switch to a
* {@link FragmentStatePagerAdapter}.
*/
SectionsPagerAdapter mSectionsPagerAdapter;
/**
* The {@link ViewPager} that will host the section contents.
*/
WPViewPager mViewPager;
private Revision mRevision;
private EditorFragmentAbstract mEditorFragment;
private EditPostSettingsFragment mEditPostSettingsFragment;
private EditorMediaUploadListener mEditorMediaUploadListener;
private EditorPhotoPicker mEditorPhotoPicker;
private ProgressDialog mProgressDialog;
private ProgressDialog mAddingMediaToEditorProgressDialog;
private boolean mIsNewPost;
private boolean mIsPage;
private boolean mHasSetPostContent;
private PostLoadingState mPostLoadingState = PostLoadingState.NONE;
// For opening the context menu after permissions have been granted
private View mMenuView = null;
private boolean mHtmlModeMenuStateOn = false;
@Inject Dispatcher mDispatcher;
@Inject AccountStore mAccountStore;
@Inject SiteStore mSiteStore;
@Inject PostStore mPostStore;
@Inject MediaStore mMediaStore;
@Inject UploadStore mUploadStore;
@Inject FluxCImageLoader mImageLoader;
@Inject ShortcutUtils mShortcutUtils;
@Inject QuickStartStore mQuickStartStore;
@Inject ImageManager mImageManager;
@Inject UiHelpers mUiHelpers;
@Inject RemotePreviewLogicHelper mRemotePreviewLogicHelper;
@Inject ProgressDialogHelper mProgressDialogHelper;
@Inject FeaturedImageHelper mFeaturedImageHelper;
@Inject ReactNativeRequestHandler mReactNativeRequestHandler;
@Inject EditorMedia mEditorMedia;
@Inject LocaleManagerWrapper mLocaleManagerWrapper;
@Inject EditPostRepository mEditPostRepository;
@Inject PostUtilsWrapper mPostUtils;
@Inject EditorTracker mEditorTracker;
@Inject UploadUtilsWrapper mUploadUtilsWrapper;
@Inject EditorActionsProvider mEditorActionsProvider;
@Inject DateTimeUtilsWrapper mDateTimeUtils;
@Inject ViewModelProvider.Factory mViewModelFactory;
@Inject ReaderUtilsWrapper mReaderUtilsWrapper;
@Inject protected PrivateAtomicCookie mPrivateAtomicCookie;
private StorePostViewModel mViewModel;
private SiteModel mSite;
public static boolean checkToRestart(@NonNull Intent data) {
return data.hasExtra(EditPostActivity.EXTRA_RESTART_EDITOR)
&& RestartEditorOptions.valueOf(data.getStringExtra(EditPostActivity.EXTRA_RESTART_EDITOR))
!= RestartEditorOptions.NO_RESTART;
}
private void newPostSetup() {
mIsNewPost = true;
if (mSite == null) {
showErrorAndFinish(R.string.blog_not_found);
return;
}
if (!mSite.isVisible()) {
showErrorAndFinish(R.string.error_blog_hidden);
return;
}
// Create a new post
mEditPostRepository.set(() -> {
PostModel post = mPostStore.instantiatePostModel(mSite, mIsPage, null, null);
post.setStatus(PostStatus.DRAFT.toString());
return post;
});
mEditPostRepository.savePostSnapshot();
EventBus.getDefault().postSticky(
new PostEvents.PostOpenedInEditor(mEditPostRepository.getLocalSiteId(), mEditPostRepository.getId()));
mShortcutUtils.reportShortcutUsed(Shortcut.CREATE_NEW_POST);
}
private void createPostEditorAnalyticsSessionTracker(boolean showGutenbergEditor, PostImmutableModel post,
SiteModel site, boolean isNewPost) {
if (mPostEditorAnalyticsSession == null) {
mPostEditorAnalyticsSession = new PostEditorAnalyticsSession(
showGutenbergEditor ? Editor.GUTENBERG : Editor.CLASSIC,
post, site, isNewPost);
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
((WordPress) getApplication()).component().inject(this);
mDispatcher.register(this);
mViewModel =
ViewModelProviders.of(this, mViewModelFactory).get(StorePostViewModel.class);
setContentView(R.layout.new_edit_post_activity);
if (savedInstanceState == null) {
mSite = (SiteModel) getIntent().getSerializableExtra(WordPress.SITE);
} else {
mSite = (SiteModel) savedInstanceState.getSerializable(WordPress.SITE);
}
// FIXME: Make sure to use the latest fresh info about the site we've in the DB
// set only the editor setting for now.
if (mSite != null) {
SiteModel refreshedSite = mSiteStore.getSiteByLocalId(mSite.getId());
if (refreshedSite != null) {
mSite.setMobileEditor(refreshedSite.getMobileEditor());
}
}
// Check whether to show the visual editor
PreferenceManager.setDefaultValues(this, R.xml.account_settings, false);
mShowAztecEditor = AppPrefs.isAztecEditorEnabled();
mEditorPhotoPicker = new EditorPhotoPicker(this, this, this, mShowAztecEditor);
// TODO when aztec is the only editor, remove this part and set the overlay bottom margin in xml
if (mShowAztecEditor) {
View overlay = findViewById(R.id.view_overlay);
ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) overlay.getLayoutParams();
layoutParams.bottomMargin = getResources().getDimensionPixelOffset(R.dimen.aztec_format_bar_height);
overlay.setLayoutParams(layoutParams);
}
// Set up the action bar.
Toolbar toolbar = findViewById(R.id.toolbar_main);
setSupportActionBar(toolbar);
final ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}
FragmentManager fragmentManager = getSupportFragmentManager();
Bundle extras = getIntent().getExtras();
String action = getIntent().getAction();
boolean isRestarting = !RestartEditorOptions.NO_RESTART.name().equals(extras.getString(EXTRA_RESTART_EDITOR));
if (savedInstanceState == null) {
if (!getIntent().hasExtra(EXTRA_POST_LOCAL_ID)
|| Intent.ACTION_SEND.equals(action)
|| Intent.ACTION_SEND_MULTIPLE.equals(action)
|| NEW_MEDIA_POST.equals(action)
|| getIntent().hasExtra(EXTRA_IS_QUICKPRESS)) {
if (getIntent().hasExtra(EXTRA_QUICKPRESS_BLOG_ID)) {
// QuickPress might want to use a different blog than the current blog
int localSiteId = getIntent().getIntExtra(EXTRA_QUICKPRESS_BLOG_ID, -1);
mSite = mSiteStore.getSiteByLocalId(localSiteId);
}
mIsPage = extras.getBoolean(EXTRA_IS_PAGE);
newPostSetup();
} else {
mEditPostRepository.loadPostByLocalPostId(extras.getInt(EXTRA_POST_LOCAL_ID));
// Load post from extra)s
if (mEditPostRepository.hasPost()) {
if (extras.getBoolean(EXTRA_LOAD_AUTO_SAVE_REVISION)) {
mEditPostRepository.update(postModel -> {
boolean updateTitle = !TextUtils.isEmpty(postModel.getAutoSaveTitle());
if (updateTitle) {
postModel.setTitle(postModel.getAutoSaveTitle());
}
boolean updateContent = !TextUtils.isEmpty(postModel.getAutoSaveContent());
if (updateContent) {
postModel.setContent(postModel.getAutoSaveContent());
}
boolean updateExcerpt = !TextUtils.isEmpty(postModel.getAutoSaveExcerpt());
if (updateExcerpt) {
postModel.setExcerpt(postModel.getAutoSaveExcerpt());
}
return updateTitle || updateContent || updateExcerpt;
});
mEditPostRepository.savePostSnapshot();
}
initializePostObject();
} else if (isRestarting) {
newPostSetup();
}
}
// retrieve Editor session data if switched editors
if (isRestarting && extras.getSerializable(STATE_KEY_EDITOR_SESSION_DATA) != null) {
mPostEditorAnalyticsSession =
(PostEditorAnalyticsSession) extras.getSerializable(STATE_KEY_EDITOR_SESSION_DATA);
}
} else {
mEditorMedia.setDroppedMediaUris(savedInstanceState.getParcelableArrayList(STATE_KEY_DROPPED_MEDIA_URIS));
mIsNewPost = savedInstanceState.getBoolean(STATE_KEY_IS_NEW_POST, false);
updatePostLoadingAndDialogState(PostLoadingState.fromInt(
savedInstanceState.getInt(STATE_KEY_POST_LOADING_STATE, 0)));
mRevision = savedInstanceState.getParcelable(STATE_KEY_REVISION);
mPostEditorAnalyticsSession =
(PostEditorAnalyticsSession) savedInstanceState.getSerializable(STATE_KEY_EDITOR_SESSION_DATA);
// if we have a remote id saved, let's first try that, as the local Id might have changed after FETCH_POSTS
if (savedInstanceState.containsKey(STATE_KEY_POST_REMOTE_ID)) {
mEditPostRepository.loadPostByRemotePostId(savedInstanceState.getLong(STATE_KEY_POST_REMOTE_ID), mSite);
initializePostObject();
} else if (savedInstanceState.containsKey(STATE_KEY_POST_LOCAL_ID)) {
mEditPostRepository.loadPostByLocalPostId(savedInstanceState.getInt(STATE_KEY_POST_LOCAL_ID));
initializePostObject();
}
mEditorFragment =
(EditorFragmentAbstract) fragmentManager.getFragment(savedInstanceState, STATE_KEY_EDITOR_FRAGMENT);
if (mEditorFragment instanceof EditorMediaUploadListener) {
mEditorMediaUploadListener = (EditorMediaUploadListener) mEditorFragment;
}
}
if (mSite == null) {
ToastUtils.showToast(this, R.string.blog_not_found, ToastUtils.Duration.SHORT);
finish();
return;
}
// Ensure we have a valid post
if (!mEditPostRepository.hasPost()) {
showErrorAndFinish(R.string.post_not_found);
return;
}
mEditorMedia.start(mSite, this);
startObserving();
if (mHasSetPostContent = mEditorFragment != null) {
mEditorFragment.setImageLoader(mImageLoader);
}
// Ensure that this check happens when mPost is set
if (savedInstanceState == null) {
String restartEditorOptionName = getIntent().getStringExtra(EXTRA_RESTART_EDITOR);
RestartEditorOptions restartEditorOption =
restartEditorOptionName == null ? RestartEditorOptions.RESTART_DONT_SUPPRESS_GUTENBERG
: RestartEditorOptions.valueOf(restartEditorOptionName);
mShowGutenbergEditor =
PostUtils.shouldShowGutenbergEditor(mIsNewPost, mEditPostRepository.getContent(), mSite)
&& restartEditorOption != RestartEditorOptions.RESTART_SUPPRESS_GUTENBERG;
} else {
mShowGutenbergEditor = savedInstanceState.getBoolean(STATE_KEY_GUTENBERG_IS_SHOWN);
}
// ok now we are sure to have both a valid Post and showGutenberg flag, let's start the editing session tracker
createPostEditorAnalyticsSessionTracker(mShowGutenbergEditor, mEditPostRepository.getPost(), mSite, mIsNewPost);
// Bump post created analytics only once, first time the editor is opened
if (mIsNewPost && savedInstanceState == null) {
trackEditorCreatedPost(action, getIntent());
}
if (!mIsNewPost) {
// if we are opening a Post for which an error notification exists, we need to remove it from the dashboard
// to prevent the user from tapping RETRY on a Post that is being currently edited
UploadService.cancelFinalNotification(this, mEditPostRepository.getPost());
resetUploadingMediaToFailedIfPostHasNotMediaInProgressOrQueued();
}
setTitle(SiteUtils.getSiteNameOrHomeURL(mSite));
mSectionsPagerAdapter = new SectionsPagerAdapter(fragmentManager);
// we need to make sure AT cookie is available when trying to edit post on private AT site
if (mSite.isPrivateWPComAtomic() && mPrivateAtomicCookie.isCookieRefreshRequired()) {
PrivateAtCookieRefreshProgressDialog.Companion.showIfNecessary(fragmentManager);
mDispatcher.dispatch(SiteActionBuilder.newFetchPrivateAtomicCookieAction(
new FetchPrivateAtomicCookiePayload(mSite.getSiteId())));
} else {
setupViewPager();
}
ActivityId.trackLastActivity(ActivityId.POST_EDITOR);
}
@SuppressWarnings("unused")
@Subscribe(threadMode = ThreadMode.MAIN)
public void onPrivateAtomicCookieFetched(OnPrivateAtomicCookieFetched event) {
// if the dialog is not showing by the time cookie fetched it means that it was dismissed and content was loaded
if (PrivateAtCookieRefreshProgressDialog.Companion.isShowing(getSupportFragmentManager())) {
setupViewPager();
PrivateAtCookieRefreshProgressDialog.Companion.dismissIfNecessary(getSupportFragmentManager());
}
if (event.isError()) {
AppLog.e(AppLog.T.EDITOR,
"Failed to load private AT cookie. " + event.error.type + " - " + event.error.message);
WPSnackbar.make(findViewById(R.id.editor_activity), R.string.media_accessing_failed, Snackbar.LENGTH_LONG)
.show();
}
}
@Override
public void onCookieProgressDialogCancelled() {
WPSnackbar.make(findViewById(R.id.editor_activity), R.string.media_accessing_failed, Snackbar.LENGTH_LONG)
.show();
setupViewPager();
}
private void setupViewPager() {
// Set up the ViewPager with the sections adapter.
mViewPager = findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
mViewPager.setOffscreenPageLimit(4);
mViewPager.setPagingEnabled(false);
// When swiping between different sections, select the corresponding tab. We can also use ActionBar.Tab#select()
// to do this if we have a reference to the Tab.
mViewPager.clearOnPageChangeListeners();
mViewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
invalidateOptionsMenu();
if (position == PAGE_CONTENT) {
setTitle(SiteUtils.getSiteNameOrHomeURL(mSite));
} else if (position == PAGE_SETTINGS) {
setTitle(mEditPostRepository.isPage() ? R.string.page_settings : R.string.post_settings);
mEditorPhotoPicker.hidePhotoPicker();
} else if (position == PAGE_PUBLISH_SETTINGS) {
setTitle(R.string.publish_date);
mEditorPhotoPicker.hidePhotoPicker();
} else if (position == PAGE_HISTORY) {
setTitle(R.string.history_title);
mEditorPhotoPicker.hidePhotoPicker();
}
}
});
}
private void startObserving() {
mEditorMedia.getUiState().observe(this, uiState -> {
if (uiState != null) {
updateAddingMediaToEditorProgressDialogState(uiState.getProgressDialogUiState());
if (uiState.getEditorOverlayVisibility()) {
showOverlay(false);
} else {
hideOverlay();
}
}
});
mEditorMedia.getSnackBarMessage().observe(this, event -> {
SnackbarMessageHolder messageHolder = event.getContentIfNotHandled();
if (messageHolder != null) {
WPSnackbar
.make(findViewById(R.id.editor_activity), messageHolder.getMessageRes(), Snackbar.LENGTH_SHORT)
.show();
}
});
mEditorMedia.getToastMessage().observe(this, event -> {
ToastMessageHolder contentIfNotHandled = event.getContentIfNotHandled();
if (contentIfNotHandled != null) {
contentIfNotHandled.show(this);
}
});
mViewModel.getOnSavePostTriggered().observe(this, unitEvent -> unitEvent.applyIfNotHandled(unit -> {
updateAndSavePostAsync();
return null;
}));
mViewModel.getOnFinish().observe(this, finishEvent -> finishEvent.applyIfNotHandled(activityFinishState -> {
switch (activityFinishState) {
case SAVED_ONLINE:
saveResult(true, false);
break;
case SAVED_LOCALLY:
saveResult(true, true);
break;
case CANCELLED:
saveResult(false, true);
break;
}
removePostOpenInEditorStickyEvent();
mEditorMedia.definitelyDeleteBackspaceDeletedMediaItemsAsync();
finish();
return null;
}));
mEditPostRepository.getPostChanged().observe(this, postEvent -> postEvent.applyIfNotHandled(post -> {
mViewModel.savePostToDb(this, mEditPostRepository, mSite);
return null;
}));
}
private void initializePostObject() {
if (mEditPostRepository.hasPost()) {
mEditPostRepository.savePostSnapshotWhenEditorOpened();
mEditPostRepository.replace(UploadService::updatePostWithCurrentlyCompletedUploads);
mIsPage = mEditPostRepository.isPage();
EventBus.getDefault().postSticky(new PostEvents.PostOpenedInEditor(mEditPostRepository.getLocalSiteId(),
mEditPostRepository.getId()));
mEditorMedia.purgeMediaToPostAssociationsIfNotInPostAnymoreAsync();
}
}
// this method aims at recovering the current state of media items if they're inconsistent within the PostModel.
private void resetUploadingMediaToFailedIfPostHasNotMediaInProgressOrQueued() {
boolean useAztec = AppPrefs.isAztecEditorEnabled();
if (!useAztec || UploadService.hasPendingOrInProgressMediaUploadsForPost(mEditPostRepository.getPost())) {
return;
}
mEditPostRepository.updateAsync(postModel -> {
String oldContent = postModel.getContent();
if (!AztecEditorFragment.hasMediaItemsMarkedUploading(EditPostActivity.this, oldContent)
// we need to make sure items marked failed are still failed or not as well
&& !AztecEditorFragment.hasMediaItemsMarkedFailed(EditPostActivity.this, oldContent)) {
return false;
}
String newContent = AztecEditorFragment.resetUploadingMediaToFailed(EditPostActivity.this, oldContent);
if (!TextUtils.isEmpty(oldContent) && newContent != null && oldContent.compareTo(newContent) != 0) {
postModel.setContent(newContent);
return true;
}
return false;
}, null);
}
@Override
protected void onResume() {
super.onResume();
EventBus.getDefault().register(this);
reattachUploadingMediaForAztec();
// Bump editor opened event every time the activity is resumed, to match the EDITOR_CLOSED event onPause
PostUtils.trackOpenEditorAnalytics(mEditPostRepository.getPost(), mSite);
mIsConfigChange = false;
}
private void reattachUploadingMediaForAztec() {
if (mEditorMediaUploadListener != null) {
mEditorMedia.reattachUploadingMediaForAztec(
mEditPostRepository,
mEditorFragment instanceof AztecEditorFragment,
mEditorMediaUploadListener
);
}
}
@Override
protected void onPause() {
super.onPause();
EventBus.getDefault().unregister(this);
AnalyticsTracker.track(AnalyticsTracker.Stat.EDITOR_CLOSED);
}
@Override protected void onStop() {
super.onStop();
if (mAztecImageLoader != null && isFinishing()) {
mAztecImageLoader.clearTargets();
mAztecImageLoader = null;
}
}
@Override
protected void onDestroy() {
if (!mIsConfigChange && (mRestartEditorOption == RestartEditorOptions.NO_RESTART)) {
if (mPostEditorAnalyticsSession != null) {
mPostEditorAnalyticsSession.end();
}
}
mDispatcher.unregister(this);
mEditorMedia.cancelAddMediaToEditorActions();
removePostOpenInEditorStickyEvent();
if (mEditorFragment instanceof AztecEditorFragment) {
((AztecEditorFragment) mEditorFragment).disableContentLogOnCrashes();
}
if (mReactNativeRequestHandler != null) {
mReactNativeRequestHandler.destroy();
}
super.onDestroy();
}
private void removePostOpenInEditorStickyEvent() {
PostEvents.PostOpenedInEditor stickyEvent =
EventBus.getDefault().getStickyEvent(PostEvents.PostOpenedInEditor.class);
if (stickyEvent != null) {
// "Consume" the sticky event
EventBus.getDefault().removeStickyEvent(stickyEvent);
}
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
// Saves both post objects so we can restore them in onCreate()
updateAndSavePostAsync();
outState.putInt(STATE_KEY_POST_LOCAL_ID, mEditPostRepository.getId());
if (!mEditPostRepository.isLocalDraft()) {
outState.putLong(STATE_KEY_POST_REMOTE_ID, mEditPostRepository.getRemotePostId());
}
outState.putInt(STATE_KEY_POST_LOADING_STATE, mPostLoadingState.getValue());
outState.putBoolean(STATE_KEY_IS_NEW_POST, mIsNewPost);
outState.putBoolean(STATE_KEY_IS_PHOTO_PICKER_VISIBLE, mEditorPhotoPicker.isPhotoPickerShowing());
outState.putBoolean(STATE_KEY_HTML_MODE_ON, mHtmlModeMenuStateOn);
outState.putSerializable(WordPress.SITE, mSite);
outState.putParcelable(STATE_KEY_REVISION, mRevision);
outState.putSerializable(STATE_KEY_EDITOR_SESSION_DATA, mPostEditorAnalyticsSession);
mIsConfigChange = true; // don't call sessionData.end() in onDestroy() if this is an Android config change
outState.putBoolean(STATE_KEY_GUTENBERG_IS_SHOWN, mShowGutenbergEditor);
outState.putParcelableArrayList(STATE_KEY_DROPPED_MEDIA_URIS, mEditorMedia.getDroppedMediaUris());
if (mEditorFragment != null) {
getSupportFragmentManager().putFragment(outState, STATE_KEY_EDITOR_FRAGMENT, mEditorFragment);
}
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
mHtmlModeMenuStateOn = savedInstanceState.getBoolean(STATE_KEY_HTML_MODE_ON);
if (savedInstanceState.getBoolean(STATE_KEY_IS_PHOTO_PICKER_VISIBLE, false)) {
mEditorPhotoPicker.showPhotoPicker(mSite);
}
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mEditorPhotoPicker.onOrientationChanged(newConfig.orientation);
}
private PrimaryEditorAction getPrimaryAction() {
return mEditorActionsProvider
.getPrimaryAction(mEditPostRepository.getStatus(), UploadUtils.userCanPublish(mSite));
}
private String getPrimaryActionText() {
return getString(getPrimaryAction().getTitleResource());
}
private SecondaryEditorAction getSecondaryAction() {
return mEditorActionsProvider
.getSecondaryAction(mEditPostRepository.getStatus(), UploadUtils.userCanPublish(mSite));
}
private @Nullable String getSecondaryActionText() {
@StringRes Integer titleResource = getSecondaryAction().getTitleResource();
return titleResource != null ? getString(titleResource) : null;
}
private boolean shouldSwitchToGutenbergBeVisible(
EditorFragmentAbstract editorFragment,
SiteModel site
) {
// Some guard conditions
if (!mEditPostRepository.hasPost()) {
AppLog.w(T.EDITOR, "shouldSwitchToGutenbergBeVisible got a null post parameter.");
return false;
}
if (editorFragment == null) {
AppLog.w(T.EDITOR, "shouldSwitchToGutenbergBeVisible got a null editorFragment parameter.");
return false;
}
// Check whether the content has blocks.
boolean hasBlocks = false;
boolean isEmpty = false;
try {
final String content = (String) editorFragment.getContent(mEditPostRepository.getContent());
hasBlocks = PostUtils.contentContainsGutenbergBlocks(content);
isEmpty = TextUtils.isEmpty(content);
} catch (EditorFragmentNotAddedException e) {
// legacy exception; just ignore.
}
// if content has blocks or empty, offer the switch to Gutenberg. The block editor doesn't have good
// "Classic Block" support yet so, don't offer a switch to it if content doesn't have blocks. If the post
// is empty but the user hasn't enabled "Use Gutenberg for new posts" in Site Setting,
// don't offer the switch.
return hasBlocks || (SiteUtils.isBlockEditorDefaultForNewPost(site) && isEmpty);
}
/*
* shows/hides the overlay which appears atop the editor, which effectively disables it
*/
private void showOverlay(boolean animate) {
View overlay = findViewById(R.id.view_overlay);
if (animate) {
AniUtils.fadeIn(overlay, AniUtils.Duration.MEDIUM);
} else {
overlay.setVisibility(View.VISIBLE);
}
}
private void hideOverlay() {
View overlay = findViewById(R.id.view_overlay);
overlay.setVisibility(View.GONE);
}
@Override
public void onPhotoPickerShown() {
// animate in the editor overlay
showOverlay(true);
if (mEditorFragment instanceof AztecEditorFragment) {
((AztecEditorFragment) mEditorFragment).enableMediaMode(true);
}
}
@Override
public void onPhotoPickerHidden() {
hideOverlay();
if (mEditorFragment instanceof AztecEditorFragment) {
((AztecEditorFragment) mEditorFragment).enableMediaMode(false);
}
}
/*
* called by PhotoPickerFragment when media is selected - may be a single item or a list of items
*/
@Override
public void onPhotoPickerMediaChosen(@NonNull final List<Uri> uriList) {
mEditorPhotoPicker.hidePhotoPicker();
mEditorMedia.onPhotoPickerMediaChosen(uriList);
}
/*
* called by PhotoPickerFragment when user clicks an icon to launch the camera, native
* picker, or WP media picker
*/
@Override
public void onPhotoPickerIconClicked(@NonNull PhotoPickerIcon icon, boolean allowMultipleSelection) {
mEditorPhotoPicker.hidePhotoPicker();
if (!icon.requiresUploadPermission() || WPMediaUtils.currentUserCanUploadMedia(mSite)) {
mEditorPhotoPicker.setAllowMultipleSelection(allowMultipleSelection);
switch (icon) {
case ANDROID_CAPTURE_PHOTO:
launchCamera();
break;
case ANDROID_CAPTURE_VIDEO:
launchVideoCamera();
break;
case ANDROID_CHOOSE_PHOTO_OR_VIDEO:
WPMediaUtils.launchMediaLibrary(this, allowMultipleSelection);
break;
case ANDROID_CHOOSE_PHOTO:
launchPictureLibrary();
break;
case ANDROID_CHOOSE_VIDEO:
launchVideoLibrary();
break;
case WP_MEDIA:
ActivityLauncher.viewMediaPickerForResult(this, mSite, MediaBrowserType.EDITOR_PICKER);
break;
case STOCK_MEDIA:
ActivityLauncher.showStockMediaPickerForResult(
this, mSite, RequestCodes.STOCK_MEDIA_PICKER_MULTI_SELECT);
break;
case GIF:
ActivityLauncher.showGifPickerForResult(this, mSite, RequestCodes.GIF_PICKER);
break;
}
} else {
WPSnackbar.make(findViewById(R.id.editor_activity), R.string.media_error_no_permission_upload,
Snackbar.LENGTH_SHORT).show();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.edit_post, menu);
return true;
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
boolean showMenuItems = true;
if (mViewPager != null && mViewPager.getCurrentItem() > PAGE_CONTENT) {
showMenuItems = false;
}
MenuItem secondaryAction = menu.findItem(R.id.menu_secondary_action);
MenuItem previewMenuItem = menu.findItem(R.id.menu_preview_post);
MenuItem viewHtmlModeMenuItem = menu.findItem(R.id.menu_html_mode);
MenuItem historyMenuItem = menu.findItem(R.id.menu_history);
MenuItem settingsMenuItem = menu.findItem(R.id.menu_post_settings);
if (secondaryAction != null && mEditPostRepository.hasPost()) {
secondaryAction.setVisible(showMenuItems && getSecondaryAction().isVisible());
secondaryAction.setTitle(getSecondaryActionText());
}
if (previewMenuItem != null) {
previewMenuItem.setVisible(showMenuItems);
}