Skip to content

Commit 2467f23

Browse files
committed
Squashed 'libs/editor/' changes from ce4343d..6647346
6647346 Merge pull request #267 from wordpress-mobile/issue/261-image-settings-nav 8b0ee06 Added featured image to state of image settings dialog, which is checked when attempting to exit without saving 47b7874 Error handling for retrieving featured image from JSON meta data e963027 Merge branch 'develop' into issue/261-image-settings-nav ca9c4ed Merge pull request #266 from wordpress-mobile/sync-featured-wpandroid fd6901d Merge branch 'develop' into sync-featured-wpandroid 156dbf0 Make travis use the latest platform-tools 021b485 Fixed onMediaUploadSucceeded implementation in the example activity c3b2934 Updated travis build tools to 23.0.2 888b271 Update gradle and build tools versions for example app 6917b66 Merge branch 'feature/visual-editor' into feature/editor-featured-images 8507915 Merge branch 'develop' into feature/visual-editor 91effe7 Removed unused 'Include image in post content' checkbox from image settings 3192b38 Updating gradle plugin to 1.5.0 and support/build tools to latest for sub projects 92683c0 Show a 'Changes saved' toast when saving and exiting the image settings dialog f5c2f13 Fixed a capitalization issue when setting the alignment spinner value 396ffcd Return to the editor when the back button is pressed within the image settings fragment d5d4c91 Fixed a capitalization issue with image alignment meta values 9fd836c Show a confirmation dialog when closing the image settings fragment with unsaved changes ec7e853 Use a callback instead of a getter to notify the host activity when the featured image changes 13b5f5a Add the remote media id to image tags when inserting from media gallery 04f9cf9 Hide the featured image checkbox if feature images aren't supported b8c8ba2 Updated Editor example project with changes to onMediaUploadProgress b3031d6 Fixed a crash issue in the image settings dialog fragment b44742e Converted featured id handling methods to be part of EditorFragmentAbstract 9d4facf Added support for getting and setting the featured image id to the editor fragments 10cc6f0 Don't clear all class data in ZSSEditor.markImageUploadDone 0a6722b Add the remote image ID to the image tag when an image upload completes 6d1c12d Added support for setting/unsetting an image as featured to the image settings dialog 2c1c98e Modified onMediaTapped to pass the image meta data as a JSONObject 477e0c9 Merge pull request #262 from wordpress-mobile/issue/233-media-sharing 7e6ee2d Fixed a potential NPE in getTitle() and getContent() 10cdca9 Queue media insertions that arrive before the DOM has loaded, and execute them later e69588f Fixed a broken test and an issue with the editor demo activity 862972f Implemented missing method in EditorFragmentAbstractTest 580c259 Added some empty string checking when retrieving failed media ids from the ZSSEditor 06c3f3a Adjusted the pattern used by the ZSSEditor to find images that are uploading 383840a Disable editor format bar buttons when post/page contains failed uploads 4ac4dfb Updated EditorFragment to handle exiting the editor with media uploads in progress more gracefully 8c34a40 Added a 'delete' flag to onMediaUploadCancelClicked 49a69f5 Fixed a bug where the media upload progress bar wouldn't display due to a localization issue 32b2696 Visual editor lib version bump bda0e0f Updated image settings dialog to always clear the custom ActionBar view 438916b Merge commit '7b6a9d464896683ba4aef6f4dccc9021641e5d71' into develop 14f89b2 Updating build tools to 23.0.1 f378f6e Merge branch 'release/4.4' into develop de1085d use default AppCompat theme on EditLink and AddCategory dialog 7bae170 set targetSdkVersion to 23 and clean up lib dependencies 1624a01 migrate from mavenCentral to jcenter (which is now the default for Android Studio) f55a91e upgrade subtrees to latest android tools e0a098f update to gradle plugin 1.3.1 and gradle 2.6 62e18f1 Merge branch 'develop' into feature/update-to-gradle-2.4 d2e000e upgrade to gradle 2.5 and gradle plugin 1.3.0 git-subtree-dir: libs/editor git-subtree-split: 664734643e6728e2dca9859bdf5e5b940db92491
1 parent 7b6a9d4 commit 2467f23

File tree

17 files changed

+334
-71
lines changed

17 files changed

+334
-71
lines changed

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ android:
55
components:
66
- extra-android-m2repository
77
- extra-android-support
8-
- build-tools-23.0.1
8+
- platform-tools
9+
- tools
10+
- build-tools-23.0.2
911
- android-23
1012

1113
env:

WordPressEditor/build.gradle

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ buildscript {
33
jcenter()
44
}
55
dependencies {
6-
classpath 'com.android.tools.build:gradle:1.3.1'
6+
classpath 'com.android.tools.build:gradle:1.5.0'
77
}
88
}
99

@@ -20,11 +20,11 @@ android {
2020
publishNonDefault true
2121

2222
compileSdkVersion 23
23-
buildToolsVersion "23.0.1"
23+
buildToolsVersion "23.0.2"
2424

2525
defaultConfig {
26-
versionCode 3
27-
versionName "0.3"
26+
versionCode 4
27+
versionName "0.4"
2828
minSdkVersion 14
2929
targetSdkVersion 23
3030
}
@@ -46,8 +46,8 @@ android {
4646
}
4747

4848
dependencies {
49-
compile 'com.android.support:appcompat-v7:23.0.1'
50-
compile 'com.android.support:support-v4:23.0.1'
49+
compile 'com.android.support:appcompat-v7:23.1.1'
50+
compile 'com.android.support:support-v4:23.1.1'
5151
compile 'org.wordpress:analytics:1.0.0'
5252
compile 'org.wordpress:utils:1.6.0'
5353

WordPressEditor/src/androidTest/java/org.wordpress.android.editor/MockEditorActivity.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,12 @@ public void onMediaRetryClicked(String mediaId) {
5252
}
5353

5454
@Override
55-
public void onMediaUploadCancelClicked(String mediaId) {
55+
public void onMediaUploadCancelClicked(String mediaId, boolean delete) {
56+
57+
}
58+
59+
@Override
60+
public void onFeaturedImageChanged(int mediaId) {
5661

5762
}
5863

WordPressEditor/src/main/java/org/wordpress/android/editor/EditorFragment.java

Lines changed: 87 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@
3030

3131
import com.android.volley.toolbox.ImageLoader;
3232

33+
import org.json.JSONObject;
3334
import org.wordpress.android.util.AppLog;
3435
import org.wordpress.android.util.AppLog.T;
36+
import org.wordpress.android.util.JSONUtils;
3537
import org.wordpress.android.util.StringUtils;
3638
import org.wordpress.android.util.ToastUtils;
3739
import org.wordpress.android.util.helpers.MediaFile;
@@ -40,8 +42,10 @@
4042
import java.util.ArrayList;
4143
import java.util.HashMap;
4244
import java.util.HashSet;
45+
import java.util.Locale;
4346
import java.util.Map;
4447
import java.util.Set;
48+
import java.util.concurrent.ConcurrentHashMap;
4549
import java.util.concurrent.CountDownLatch;
4650
import java.util.concurrent.TimeUnit;
4751

@@ -77,11 +81,14 @@ public class EditorFragment extends EditorFragmentAbstract implements View.OnCli
7781
private String mTitlePlaceholder = "";
7882
private String mContentPlaceholder = "";
7983

84+
private boolean mDomHasLoaded = false;
8085
private boolean mIsKeyboardOpen = false;
8186
private boolean mEditorWasPaused = false;
8287
private boolean mHideActionBarOnSoftKeyboardUp = false;
8388

89+
private ConcurrentHashMap<String, MediaFile> mWaitingMediaFiles;
8490
private Set<String> mUploadingMediaIds;
91+
private Set<String> mFailedMediaIds;
8592

8693
private String mJavaScriptResult = "";
8794

@@ -118,7 +125,9 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
118125
mHideActionBarOnSoftKeyboardUp = true;
119126
}
120127

128+
mWaitingMediaFiles = new ConcurrentHashMap<>();
121129
mUploadingMediaIds = new HashSet<>();
130+
mFailedMediaIds = new HashSet<>();
122131

123132
// -- WebView configuration
124133

@@ -206,6 +215,10 @@ public void onResume() {
206215

207216
@Override
208217
public void onDetach() {
218+
// Soft cancel (delete flag off) all media uploads currently in progress
219+
for (String mediaId : mUploadingMediaIds) {
220+
mEditorFragmentListener.onMediaUploadCancelClicked(mediaId, false);
221+
}
209222
super.onDetach();
210223
}
211224

@@ -529,13 +542,28 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
529542
}
530543

531544
final String imageMeta = extras.getString("imageMeta");
545+
final int imageRemoteId = extras.getInt("imageRemoteId");
546+
final boolean isFeaturedImage = extras.getBoolean("isFeatured");
532547

533548
mWebView.post(new Runnable() {
534549
@Override
535550
public void run() {
536551
mWebView.execJavaScriptFromString("ZSSEditor.updateCurrentImageMeta('" + imageMeta + "');");
537552
}
538553
});
554+
555+
if (imageRemoteId != 0) {
556+
if (isFeaturedImage) {
557+
mFeaturedImageId = imageRemoteId;
558+
mEditorFragmentListener.onFeaturedImageChanged(mFeaturedImageId);
559+
} else {
560+
// If this image was unset as featured, clear the featured image id
561+
if (mFeaturedImageId == imageRemoteId) {
562+
mFeaturedImageId = 0;
563+
mEditorFragmentListener.onFeaturedImageChanged(mFeaturedImageId);
564+
}
565+
}
566+
}
539567
}
540568
}
541569

@@ -595,7 +623,7 @@ public CharSequence getTitle() {
595623
return "";
596624
}
597625

598-
if (mSourceView.getVisibility() == View.VISIBLE) {
626+
if (mSourceView != null && mSourceView.getVisibility() == View.VISIBLE) {
599627
mTitle = mSourceViewTitle.getText().toString();
600628
return StringUtils.notNullStr(mTitle);
601629
}
@@ -634,7 +662,7 @@ public CharSequence getContent() {
634662
return "";
635663
}
636664

637-
if (mSourceView.getVisibility() == View.VISIBLE) {
665+
if (mSourceView != null && mSourceView.getVisibility() == View.VISIBLE) {
638666
mContentHtml = mSourceViewContent.getText().toString();
639667
return StringUtils.notNullStr(mContentHtml);
640668
}
@@ -665,11 +693,19 @@ public void run() {
665693

666694
@Override
667695
public void appendMediaFile(final MediaFile mediaFile, final String mediaUrl, ImageLoader imageLoader) {
696+
if (!mDomHasLoaded) {
697+
// If the DOM hasn't loaded yet, we won't be able to add media to the ZSSEditor
698+
// Place them in a queue to be handled when the DOM loaded callback is received
699+
mWaitingMediaFiles.put(mediaUrl, mediaFile);
700+
return;
701+
}
702+
668703
mWebView.post(new Runnable() {
669704
@Override
670705
public void run() {
671706
if (URLUtil.isNetworkUrl(mediaUrl)) {
672-
mWebView.execJavaScriptFromString("ZSSEditor.insertImage('" + mediaUrl + "');");
707+
String mediaId = mediaFile.getMediaId();
708+
mWebView.execJavaScriptFromString("ZSSEditor.insertImage('" + mediaUrl + "', '" + mediaId + "');");
673709
} else {
674710
String id = mediaFile.getMediaId();
675711
mWebView.execJavaScriptFromString("ZSSEditor.insertLocalImage(" + id + ", '" + mediaUrl + "');");
@@ -685,6 +721,11 @@ public void appendGallery(MediaGallery mediaGallery) {
685721
// TODO
686722
}
687723

724+
@Override
725+
public boolean hasFailedMediaUploads() {
726+
return (mFailedMediaIds.size() > 0);
727+
}
728+
688729
@Override
689730
public Spanned getSpannedContent() {
690731
return null;
@@ -701,12 +742,12 @@ public void setContentPlaceholder(CharSequence placeholderText) {
701742
}
702743

703744
@Override
704-
public void onMediaUploadSucceeded(final String mediaId, final String remoteUrl) {
745+
public void onMediaUploadSucceeded(final String mediaId, final String remoteId, final String remoteUrl) {
705746
mWebView.post(new Runnable() {
706747
@Override
707748
public void run() {
708749
mWebView.execJavaScriptFromString("ZSSEditor.replaceLocalImageWithRemoteImage(" + mediaId + ", '" +
709-
remoteUrl + "');");
750+
remoteId + "', '" + remoteUrl + "');");
710751
mUploadingMediaIds.remove(mediaId);
711752
}
712753
});
@@ -717,7 +758,7 @@ public void onMediaUploadProgress(final String mediaId, final float progress) {
717758
mWebView.post(new Runnable() {
718759
@Override
719760
public void run() {
720-
String progressString = String.format("%.1f", progress);
761+
String progressString = String.format(Locale.US, "%.1f", progress);
721762
mWebView.execJavaScriptFromString("ZSSEditor.setProgressOnImage(" + mediaId + ", " +
722763
progressString + ");");
723764
}
@@ -730,6 +771,7 @@ public void onMediaUploadFailed(final String mediaId) {
730771
@Override
731772
public void run() {
732773
mWebView.execJavaScriptFromString("ZSSEditor.markImageUploadFailed(" + mediaId + ");");
774+
mFailedMediaIds.add(mediaId);
733775
mUploadingMediaIds.remove(mediaId);
734776
}
735777
});
@@ -738,6 +780,8 @@ public void run() {
738780
public void onDomLoaded() {
739781
mWebView.post(new Runnable() {
740782
public void run() {
783+
mDomHasLoaded = true;
784+
741785
mWebView.execJavaScriptFromString("ZSSEditor.getField('zss_field_content').setMultiline('true');");
742786

743787
// Set title and content placeholder text
@@ -748,6 +792,14 @@ public void run() {
748792

749793
// Load title and content into ZSSEditor
750794
updateVisualEditorFields();
795+
796+
// If there are images that are still in progress (because the editor exited before they completed),
797+
// set them to failed, so the user can restart them (otherwise they will stay stuck in 'uploading' mode)
798+
mWebView.execJavaScriptFromString("ZSSEditor.markAllUploadingImagesAsFailed();");
799+
800+
// Update the list of failed media uploads
801+
mWebView.execJavaScriptFromString("ZSSEditor.getFailedImages();");
802+
751803
hideActionBarIfNeeded();
752804

753805
// Reset all format bar buttons (in case they remained active through activity re-creation)
@@ -756,6 +808,18 @@ public void run() {
756808
for (ToggleButton button : mTagToggleButtonMap.values()) {
757809
button.setChecked(false);
758810
}
811+
812+
// Add any media files that were placed in a queue due to the DOM not having loaded yet
813+
if (mWaitingMediaFiles.size() > 0) {
814+
// Image insertion will only work if the content field is in focus
815+
// (for a new post, no field is in focus until user action)
816+
mWebView.execJavaScriptFromString("ZSSEditor.getField('zss_field_content').focus();");
817+
818+
for (Map.Entry<String, MediaFile> entry : mWaitingMediaFiles.entrySet()) {
819+
appendMediaFile(entry.getValue(), entry.getKey(), null);
820+
}
821+
mWaitingMediaFiles.clear();
822+
}
759823
}
760824
});
761825
}
@@ -793,15 +857,15 @@ public void run() {
793857
});
794858
}
795859

796-
public void onMediaTapped(final String mediaId, String url, final String meta, String uploadStatus) {
860+
public void onMediaTapped(final String mediaId, String url, final JSONObject meta, String uploadStatus) {
797861
switch (uploadStatus) {
798862
case "uploading":
799863
// Display 'cancel upload' dialog
800864
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
801865
builder.setTitle(getString(R.string.stop_upload_dialog_title));
802866
builder.setPositiveButton(R.string.stop_upload_button, new DialogInterface.OnClickListener() {
803867
public void onClick(DialogInterface dialog, int id) {
804-
mEditorFragmentListener.onMediaUploadCancelClicked(mediaId);
868+
mEditorFragmentListener.onMediaUploadCancelClicked(mediaId, true);
805869

806870
mWebView.post(new Runnable() {
807871
@Override
@@ -832,6 +896,7 @@ public void onClick(DialogInterface dialog, int id) {
832896
public void run() {
833897
mWebView.execJavaScriptFromString("ZSSEditor.unmarkImageUploadFailed(" + mediaId + ");");
834898
mWebView.execJavaScriptFromString("ZSSEditor.setProgressOnImage(" + mediaId + ", " + 0 + ");");
899+
mFailedMediaIds.remove(mediaId);
835900
mUploadingMediaIds.add(mediaId);
836901
}
837902
});
@@ -850,8 +915,14 @@ public void run() {
850915

851916
Bundle dialogBundle = new Bundle();
852917

853-
dialogBundle.putString("imageMeta", meta);
918+
dialogBundle.putString("imageMeta", meta.toString());
854919
dialogBundle.putString("maxWidth", mBlogSettingMaxImageWidth);
920+
dialogBundle.putBoolean("featuredImageSupported", mFeaturedImageSupported);
921+
922+
String imageId = JSONUtils.getString(meta, "attachment_id");
923+
if (!imageId.isEmpty()) {
924+
dialogBundle.putBoolean("isFeatured", mFeaturedImageId == Integer.parseInt(imageId));
925+
}
855926

856927
imageSettingsDialogFragment.setArguments(dialogBundle);
857928

@@ -907,6 +978,13 @@ public void onGetHtmlResponse(Map<String, String> inputArgs) {
907978
mJavaScriptResult = inputArgs.get("result");
908979
mGetSelectedTextCountDownLatch.countDown();
909980
break;
981+
case "getFailedImages":
982+
String[] mediaIds = inputArgs.get("ids").split(",");
983+
for (String mediaId : mediaIds) {
984+
if (!mediaId.equals("")) {
985+
mFailedMediaIds.add(mediaId);
986+
}
987+
}
910988
}
911989
}
912990

WordPressEditor/src/main/java/org/wordpress/android/editor/EditorFragmentAbstract.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public abstract class EditorFragmentAbstract extends Fragment {
1818
public abstract CharSequence getContent();
1919
public abstract void appendMediaFile(MediaFile mediaFile, String imageUrl, ImageLoader imageLoader);
2020
public abstract void appendGallery(MediaGallery mediaGallery);
21+
public abstract boolean hasFailedMediaUploads();
2122
public abstract void setTitlePlaceholder(CharSequence text);
2223
public abstract void setContentPlaceholder(CharSequence text);
2324

@@ -29,6 +30,7 @@ public abstract class EditorFragmentAbstract extends Fragment {
2930

3031
protected EditorFragmentListener mEditorFragmentListener;
3132
protected boolean mFeaturedImageSupported;
33+
protected int mFeaturedImageId;
3234
protected String mBlogSettingMaxImageWidth;
3335
protected ImageLoader mImageLoader;
3436
protected boolean mDebugModeEnabled;
@@ -77,6 +79,10 @@ public void setBlogSettingMaxImageWidth(String blogSettingMaxImageWidth) {
7779
mBlogSettingMaxImageWidth = blogSettingMaxImageWidth;
7880
}
7981

82+
public void setFeaturedImageId(int featuredImageId) {
83+
mFeaturedImageId = featuredImageId;
84+
}
85+
8086
public void setDebugModeEnabled(boolean debugModeEnabled) {
8187
mDebugModeEnabled = debugModeEnabled;
8288
}
@@ -105,9 +111,9 @@ public interface EditorFragmentListener {
105111
void onSettingsClicked();
106112
void onAddMediaClicked();
107113
void onMediaRetryClicked(String mediaId);
108-
void onMediaUploadCancelClicked(String mediaId);
109-
// TODO: remove saveMediaFile, it's currently needed for the legacy editor - we should have something like
110-
// "EditorFragmentAbstract.getFeaturedImage()" returning the remote id
114+
void onMediaUploadCancelClicked(String mediaId, boolean delete);
115+
void onFeaturedImageChanged(int mediaId);
116+
// TODO: remove saveMediaFile, it's currently needed for the legacy editor
111117
void saveMediaFile(MediaFile mediaFile);
112118
}
113119
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package org.wordpress.android.editor;
22

33
public interface EditorMediaUploadListener {
4-
void onMediaUploadSucceeded(String localId, String remoteUrl);
4+
void onMediaUploadSucceeded(String localId, String remoteId, String remoteUrl);
55
void onMediaUploadProgress(String localId, float progress);
66
void onMediaUploadFailed(String localId);
77
}

0 commit comments

Comments
 (0)