Skip to content

Commit a03a146

Browse files
committed
Squashed 'libs/editor/' changes from 7f3b589..57802bf
57802bf Merge pull request #304 from wordpress-mobile/issue/281-drop-opensans-use-roboto-instead e8c702a Merge remote-tracking branch 'origin/develop' into issue/281-drop-opensans-use-roboto-instead 5f2d175 Updated gradle to 2.0.0-beta6 96e8929 catch a common JS exception 49e1cf8 Merge branch 'develop' into issue/288editor-log-js-errors-in-crashlytics bae59f4 fix wordpress-mobile/WordPress-Editor-Android#288: new EditorWebViewAbstract.ErrorListener used to forward JS errors to Crashlytics e5c4fd0 Keep the format bar disabled on rotation when the title field is in focus 1edf554 Rely on ZSSEditor to flag uploads as completed in native-side checks 4bea5f7 Added null checking for MediaType onMediaUploadFailed 4bcb424 Wait until the ZSSEditor has replaced the local media with remote before marking it as completed 121bf63 Strip any trailing   when returning the title 50346d4 fix #281: drop OpenSans, use Roboto instead git-subtree-dir: libs/editor git-subtree-split: 57802bf962cfe8f6945936b1f8533f74508f6029
1 parent 108ed89 commit a03a146

File tree

16 files changed

+104
-60
lines changed

16 files changed

+104
-60
lines changed

WordPressEditor/build.gradle

Lines changed: 1 addition & 1 deletion
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:2.0.0-beta5'
6+
classpath 'com.android.tools.build:gradle:2.0.0-beta6'
77
}
88
}
99

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

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
import org.json.JSONException;
3434
import org.json.JSONObject;
35+
import org.wordpress.android.editor.EditorWebViewAbstract.ErrorListener;
3536
import org.wordpress.android.util.AppLog;
3637
import org.wordpress.android.util.AppLog.T;
3738
import org.wordpress.android.util.JSONUtils;
@@ -91,6 +92,7 @@ public class EditorFragment extends EditorFragmentAbstract implements View.OnCli
9192
private boolean mIsKeyboardOpen = false;
9293
private boolean mEditorWasPaused = false;
9394
private boolean mHideActionBarOnSoftKeyboardUp = false;
95+
private boolean mIsFormatBarDisabled = false;
9496

9597
private ConcurrentHashMap<String, MediaFile> mWaitingMediaFiles;
9698
private Set<MediaGallery> mWaitingGalleries;
@@ -163,7 +165,8 @@ public void onLayoutChange(View v, int left, int top, int right, int bottom,
163165
mWebView.post(new Runnable() {
164166
@Override
165167
public void run() {
166-
mWebView.execJavaScriptFromString("ZSSEditor.refreshVisibleViewportSize();");
168+
mWebView.execJavaScriptFromString("try {ZSSEditor.refreshVisibleViewportSize();} catch (e) " +
169+
"{console.log(e)}");
167170
}
168171
});
169172
}
@@ -293,6 +296,10 @@ public void onConfigurationChanged(Configuration newConfig) {
293296

294297
setupFormatBarButtonMap(formatBar);
295298

299+
if (mIsFormatBarDisabled) {
300+
updateFormatBarEnabledState(false);
301+
}
302+
296303
// Restore the active format bar buttons
297304
for (String tag : activeTags) {
298305
mTagToggleButtonMap.get(tag).setChecked(true);
@@ -703,7 +710,7 @@ public void run() {
703710
Thread.currentThread().interrupt();
704711
}
705712

706-
return StringUtils.notNullStr(mTitle);
713+
return StringUtils.notNullStr(mTitle.replaceAll("&nbsp;$", ""));
707714
}
708715

709716
/**
@@ -824,6 +831,11 @@ public void run() {
824831
});
825832
}
826833

834+
@Override
835+
public boolean isUploadingMedia() {
836+
return (mUploadingMedia.size() > 0);
837+
}
838+
827839
@Override
828840
public boolean hasFailedMediaUploads() {
829841
return (mFailedMediaIds.size() > 0);
@@ -863,7 +875,6 @@ public void run() {
863875
mWebView.execJavaScriptFromString("ZSSEditor.replaceLocalVideoWithRemoteVideo(" + localMediaId +
864876
", '" + remoteUrl + "', '" + posterUrl + "', '" + videoPressId + "');");
865877
}
866-
mUploadingMedia.remove(localMediaId);
867878
}
868879
});
869880
}
@@ -895,17 +906,19 @@ public void onMediaUploadFailed(final String mediaId, final String errorMessage)
895906
@Override
896907
public void run() {
897908
MediaType mediaType = mUploadingMedia.get(mediaId);
898-
switch (mediaType) {
899-
case IMAGE:
900-
mWebView.execJavaScriptFromString("ZSSEditor.markImageUploadFailed(" + mediaId + ", '"
901-
+ Utils.escapeQuotes(errorMessage) + "');");
902-
break;
903-
case VIDEO:
904-
mWebView.execJavaScriptFromString("ZSSEditor.markVideoUploadFailed(" + mediaId + ", '"
905-
+ Utils.escapeQuotes(errorMessage) + "');");
909+
if (mediaType != null) {
910+
switch (mediaType) {
911+
case IMAGE:
912+
mWebView.execJavaScriptFromString("ZSSEditor.markImageUploadFailed(" + mediaId + ", '"
913+
+ Utils.escapeQuotes(errorMessage) + "');");
914+
break;
915+
case VIDEO:
916+
mWebView.execJavaScriptFromString("ZSSEditor.markVideoUploadFailed(" + mediaId + ", '"
917+
+ Utils.escapeQuotes(errorMessage) + "');");
918+
}
919+
mFailedMediaIds.add(mediaId);
920+
mUploadingMedia.remove(mediaId);
906921
}
907-
mFailedMediaIds.add(mediaId);
908-
mUploadingMedia.remove(mediaId);
909922
}
910923
});
911924
}
@@ -1168,6 +1181,11 @@ public void onLinkTapped(String url, String title) {
11681181
linkDialogFragment.show(getFragmentManager(), "LinkDialogFragment");
11691182
}
11701183

1184+
@Override
1185+
public void onMediaReplaced(String mediaId) {
1186+
mUploadingMedia.remove(mediaId);
1187+
}
1188+
11711189
@Override
11721190
public void onVideoPressInfoRequested(final String videoId) {
11731191
mEditorFragmentListener.onVideoPressInfoRequested(videoId);
@@ -1211,6 +1229,10 @@ public void onGetHtmlResponse(Map<String, String> inputArgs) {
12111229
}
12121230
}
12131231

1232+
public void setWebViewErrorListener(ErrorListener errorListener) {
1233+
mWebView.setErrorListener(errorListener);
1234+
}
1235+
12141236
private void updateVisualEditorFields() {
12151237
mWebView.execJavaScriptFromString("ZSSEditor.getField('zss_field_title').setPlainText('" +
12161238
Utils.escapeHtml(mTitle) + "');");
@@ -1262,6 +1284,8 @@ void updateFormatBarEnabledState(boolean enabled) {
12621284
button.setEnabled(enabled);
12631285
button.setAlpha(alpha);
12641286
}
1287+
1288+
mIsFormatBarDisabled = !enabled;
12651289
}
12661290

12671291
private void clearFormatBarButtons() {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public abstract class EditorFragmentAbstract extends Fragment {
2020
public abstract void appendMediaFile(MediaFile mediaFile, String imageUrl, ImageLoader imageLoader);
2121
public abstract void appendGallery(MediaGallery mediaGallery);
2222
public abstract void setUrlForVideoPressId(String videoPressId, String url, String posterUrl);
23+
public abstract boolean isUploadingMedia();
2324
public abstract boolean hasFailedMediaUploads();
2425
public abstract void setTitlePlaceholder(CharSequence text);
2526
public abstract void setContentPlaceholder(CharSequence text);

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

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import android.view.KeyEvent;
1010
import android.view.View;
1111
import android.webkit.ConsoleMessage;
12+
import android.webkit.ConsoleMessage.MessageLevel;
1213
import android.webkit.JsResult;
1314
import android.webkit.URLUtil;
1415
import android.webkit.WebChromeClient;
@@ -19,6 +20,7 @@
1920
import android.webkit.WebViewClient;
2021

2122
import org.wordpress.android.util.AppLog;
23+
import org.wordpress.android.util.AppLog.T;
2224
import org.wordpress.android.util.HTTPUtils;
2325
import org.wordpress.android.util.StringUtils;
2426
import org.wordpress.android.util.UrlUtils;
@@ -36,6 +38,7 @@ public abstract class EditorWebViewAbstract extends WebView {
3638

3739
private OnImeBackListener mOnImeBackListener;
3840
private AuthHeaderRequestListener mAuthHeaderRequestListener;
41+
private ErrorListener mErrorListener;
3942
private JsCallbackReceiver mJsCallbackReceiver;
4043

4144
private Map<String, String> mHeaderMap = new HashMap<>();
@@ -65,7 +68,7 @@ public boolean shouldOverrideUrlLoading(WebView view, String url) {
6568

6669
@Override
6770
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
68-
AppLog.e(AppLog.T.EDITOR, description);
71+
AppLog.e(T.EDITOR, description);
6972
}
7073

7174
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@@ -96,7 +99,7 @@ public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceReque
9699
return new WebResourceResponse(conn.getContentType(), conn.getContentEncoding(),
97100
conn.getInputStream());
98101
} catch (IOException e) {
99-
AppLog.e(AppLog.T.EDITOR, e);
102+
AppLog.e(T.EDITOR, e);
100103
}
101104
}
102105

@@ -128,7 +131,7 @@ public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
128131
return new WebResourceResponse(conn.getContentType(), conn.getContentEncoding(),
129132
conn.getInputStream());
130133
} catch (IOException e) {
131-
AppLog.e(AppLog.T.EDITOR, e);
134+
AppLog.e(T.EDITOR, e);
132135
}
133136
}
134137

@@ -139,13 +142,23 @@ public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
139142
this.setWebChromeClient(new WebChromeClient() {
140143
@Override
141144
public boolean onConsoleMessage(@NonNull ConsoleMessage cm) {
142-
AppLog.d(AppLog.T.EDITOR, cm.message() + " -- From line " + cm.lineNumber() + " of " + cm.sourceId());
145+
if (cm.messageLevel() == MessageLevel.ERROR) {
146+
if (mErrorListener != null) {
147+
mErrorListener.onJavaScriptError(cm.sourceId(), cm.lineNumber(), cm.message());
148+
}
149+
AppLog.e(T.EDITOR, cm.message() + " -- From line " + cm.lineNumber() + " of " + cm.sourceId());
150+
} else {
151+
AppLog.d(T.EDITOR, cm.message() + " -- From line " + cm.lineNumber() + " of " + cm.sourceId());
152+
}
143153
return true;
144154
}
145155

146156
@Override
147157
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
148-
AppLog.d(AppLog.T.EDITOR, message);
158+
AppLog.d(T.EDITOR, message);
159+
if (mErrorListener != null) {
160+
mErrorListener.onJavaScriptAlert(url, message);
161+
}
149162
return true;
150163
}
151164
});
@@ -164,6 +177,7 @@ public void setVisibility(int visibility) {
164177

165178
/**
166179
* Handles events that should be triggered when the WebView is hidden or is shown to the user
180+
*
167181
* @param visible the new visibility status of the WebView
168182
*/
169183
public void notifyVisibilityChanged(boolean visible) {
@@ -207,7 +221,16 @@ public void setCustomHeader(String name, String value) {
207221
mHeaderMap.put(name, value);
208222
}
209223

224+
public void setErrorListener(ErrorListener errorListener) {
225+
mErrorListener = errorListener;
226+
}
227+
210228
public interface AuthHeaderRequestListener {
211229
String onAuthHeaderRequested(String url);
212230
}
231+
232+
public interface ErrorListener {
233+
void onJavaScriptError(String sourceFile, int lineNumber, String message);
234+
void onJavaScriptAlert(String url, String message);
235+
}
213236
}

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class JsCallbackReceiver {
2929
private static final String CALLBACK_FOCUS_OUT = "callback-focus-out";
3030

3131
private static final String CALLBACK_IMAGE_REPLACED = "callback-image-replaced";
32+
private static final String CALLBACK_VIDEO_REPLACED = "callback-video-replaced";
3233
private static final String CALLBACK_IMAGE_TAP = "callback-image-tap";
3334
private static final String CALLBACK_LINK_TAP = "callback-link-tap";
3435

@@ -93,8 +94,20 @@ public void executeCallback(String callbackId, String params) {
9394
AppLog.d(AppLog.T.EDITOR, "New field created, " + params);
9495
break;
9596
case CALLBACK_IMAGE_REPLACED:
96-
// TODO: Notifies that image upload has finished and that the local url was replaced by the remote url in the ZSS editor
9797
AppLog.d(AppLog.T.EDITOR, "Image replaced, " + params);
98+
99+
// Extract the local media id from the callback string (stripping the 'id=' part)
100+
if (params.length() > 3) {
101+
mListener.onMediaReplaced(params.substring(3));
102+
}
103+
break;
104+
case CALLBACK_VIDEO_REPLACED:
105+
AppLog.d(AppLog.T.EDITOR, "Video replaced, " + params);
106+
107+
// Extract the local media id from the callback string (stripping the 'id=' part)
108+
if (params.length() > 3) {
109+
mListener.onMediaReplaced(params.substring(3));
110+
}
98111
break;
99112
case CALLBACK_IMAGE_TAP:
100113
AppLog.d(AppLog.T.EDITOR, "Image tapped, " + params);

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,11 @@ public void setUrlForVideoPressId(String videoPressId, String url, String poster
11331133

11341134
}
11351135

1136+
@Override
1137+
public boolean isUploadingMedia() {
1138+
return false;
1139+
}
1140+
11361141
@Override
11371142
public boolean hasFailedMediaUploads() {
11381143
return false;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public interface OnJsEditorStateChangedListener {
1212
void onSelectionStyleChanged(Map<String, Boolean> changeSet);
1313
void onMediaTapped(String mediaId, MediaType mediaType, JSONObject meta, String uploadStatus);
1414
void onLinkTapped(String url, String title);
15+
void onMediaReplaced(String mediaId);
1516
void onVideoPressInfoRequested(String videoId);
1617
void onGetHtmlResponse(Map<String, String> responseArgs);
1718
}

WordPressEditor/src/test/java/org/wordpress/android/editor/EditorFragmentAbstractTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ public void setUrlForVideoPressId(String videoPressId, String url, String poster
7474

7575
}
7676

77+
@Override
78+
public boolean isUploadingMedia() {
79+
return false;
80+
}
81+
7782
@Override
7883
public boolean hasFailedMediaUploads() {
7984
return false;

example/build.gradle

Lines changed: 1 addition & 1 deletion
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:2.0.0-beta5'
6+
classpath 'com.android.tools.build:gradle:2.0.0-beta6'
77
}
88
}
99

libs/editor-common/assets/ZSSRichTextEditor.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -976,9 +976,6 @@ ZSSEditor.setProgressOnImage = function(imageNodeIdentifier, progress) {
976976
* @param imageNodeIdentifier The unique image ID for the uploaded image
977977
*/
978978
ZSSEditor.markImageUploadDone = function(imageNodeIdentifier) {
979-
980-
this.sendImageReplacedCallback(imageNodeIdentifier);
981-
982979
var imageNode = this.getImageNodeWithIdentifier(imageNodeIdentifier);
983980
if (imageNode.length == 0){
984981
return;
@@ -997,6 +994,9 @@ ZSSEditor.markImageUploadDone = function(imageNodeIdentifier) {
997994
// Wrap link around image
998995
var linkTag = '<a href="' + imageNode.attr("src") + '"></a>';
999996
imageNode.wrap(linkTag);
997+
998+
var thisObj = this;
999+
setTimeout(function() { thisObj.sendImageReplacedCallback(imageNodeIdentifier);}, 500);
10001000
};
10011001

10021002
/**

0 commit comments

Comments
 (0)