Skip to content

Commit

Permalink
Squashed 'libs/editor/' changes from 7f3b589..57802bf
Browse files Browse the repository at this point in the history
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
  • Loading branch information
maxme committed Mar 2, 2016
1 parent 108ed89 commit a03a146
Show file tree
Hide file tree
Showing 16 changed files with 104 additions and 60 deletions.
2 changes: 1 addition & 1 deletion WordPressEditor/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0-beta5'
classpath 'com.android.tools.build:gradle:2.0.0-beta6'
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import org.json.JSONException;
import org.json.JSONObject;
import org.wordpress.android.editor.EditorWebViewAbstract.ErrorListener;
import org.wordpress.android.util.AppLog;
import org.wordpress.android.util.AppLog.T;
import org.wordpress.android.util.JSONUtils;
Expand Down Expand Up @@ -91,6 +92,7 @@ public class EditorFragment extends EditorFragmentAbstract implements View.OnCli
private boolean mIsKeyboardOpen = false;
private boolean mEditorWasPaused = false;
private boolean mHideActionBarOnSoftKeyboardUp = false;
private boolean mIsFormatBarDisabled = false;

private ConcurrentHashMap<String, MediaFile> mWaitingMediaFiles;
private Set<MediaGallery> mWaitingGalleries;
Expand Down Expand Up @@ -163,7 +165,8 @@ public void onLayoutChange(View v, int left, int top, int right, int bottom,
mWebView.post(new Runnable() {
@Override
public void run() {
mWebView.execJavaScriptFromString("ZSSEditor.refreshVisibleViewportSize();");
mWebView.execJavaScriptFromString("try {ZSSEditor.refreshVisibleViewportSize();} catch (e) " +
"{console.log(e)}");
}
});
}
Expand Down Expand Up @@ -293,6 +296,10 @@ public void onConfigurationChanged(Configuration newConfig) {

setupFormatBarButtonMap(formatBar);

if (mIsFormatBarDisabled) {
updateFormatBarEnabledState(false);
}

// Restore the active format bar buttons
for (String tag : activeTags) {
mTagToggleButtonMap.get(tag).setChecked(true);
Expand Down Expand Up @@ -703,7 +710,7 @@ public void run() {
Thread.currentThread().interrupt();
}

return StringUtils.notNullStr(mTitle);
return StringUtils.notNullStr(mTitle.replaceAll("&nbsp;$", ""));
}

/**
Expand Down Expand Up @@ -824,6 +831,11 @@ public void run() {
});
}

@Override
public boolean isUploadingMedia() {
return (mUploadingMedia.size() > 0);
}

@Override
public boolean hasFailedMediaUploads() {
return (mFailedMediaIds.size() > 0);
Expand Down Expand Up @@ -863,7 +875,6 @@ public void run() {
mWebView.execJavaScriptFromString("ZSSEditor.replaceLocalVideoWithRemoteVideo(" + localMediaId +
", '" + remoteUrl + "', '" + posterUrl + "', '" + videoPressId + "');");
}
mUploadingMedia.remove(localMediaId);
}
});
}
Expand Down Expand Up @@ -895,17 +906,19 @@ public void onMediaUploadFailed(final String mediaId, final String errorMessage)
@Override
public void run() {
MediaType mediaType = mUploadingMedia.get(mediaId);
switch (mediaType) {
case IMAGE:
mWebView.execJavaScriptFromString("ZSSEditor.markImageUploadFailed(" + mediaId + ", '"
+ Utils.escapeQuotes(errorMessage) + "');");
break;
case VIDEO:
mWebView.execJavaScriptFromString("ZSSEditor.markVideoUploadFailed(" + mediaId + ", '"
+ Utils.escapeQuotes(errorMessage) + "');");
if (mediaType != null) {
switch (mediaType) {
case IMAGE:
mWebView.execJavaScriptFromString("ZSSEditor.markImageUploadFailed(" + mediaId + ", '"
+ Utils.escapeQuotes(errorMessage) + "');");
break;
case VIDEO:
mWebView.execJavaScriptFromString("ZSSEditor.markVideoUploadFailed(" + mediaId + ", '"
+ Utils.escapeQuotes(errorMessage) + "');");
}
mFailedMediaIds.add(mediaId);
mUploadingMedia.remove(mediaId);
}
mFailedMediaIds.add(mediaId);
mUploadingMedia.remove(mediaId);
}
});
}
Expand Down Expand Up @@ -1168,6 +1181,11 @@ public void onLinkTapped(String url, String title) {
linkDialogFragment.show(getFragmentManager(), "LinkDialogFragment");
}

@Override
public void onMediaReplaced(String mediaId) {
mUploadingMedia.remove(mediaId);
}

@Override
public void onVideoPressInfoRequested(final String videoId) {
mEditorFragmentListener.onVideoPressInfoRequested(videoId);
Expand Down Expand Up @@ -1211,6 +1229,10 @@ public void onGetHtmlResponse(Map<String, String> inputArgs) {
}
}

public void setWebViewErrorListener(ErrorListener errorListener) {
mWebView.setErrorListener(errorListener);
}

private void updateVisualEditorFields() {
mWebView.execJavaScriptFromString("ZSSEditor.getField('zss_field_title').setPlainText('" +
Utils.escapeHtml(mTitle) + "');");
Expand Down Expand Up @@ -1262,6 +1284,8 @@ void updateFormatBarEnabledState(boolean enabled) {
button.setEnabled(enabled);
button.setAlpha(alpha);
}

mIsFormatBarDisabled = !enabled;
}

private void clearFormatBarButtons() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public abstract class EditorFragmentAbstract extends Fragment {
public abstract void appendMediaFile(MediaFile mediaFile, String imageUrl, ImageLoader imageLoader);
public abstract void appendGallery(MediaGallery mediaGallery);
public abstract void setUrlForVideoPressId(String videoPressId, String url, String posterUrl);
public abstract boolean isUploadingMedia();
public abstract boolean hasFailedMediaUploads();
public abstract void setTitlePlaceholder(CharSequence text);
public abstract void setContentPlaceholder(CharSequence text);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.view.KeyEvent;
import android.view.View;
import android.webkit.ConsoleMessage;
import android.webkit.ConsoleMessage.MessageLevel;
import android.webkit.JsResult;
import android.webkit.URLUtil;
import android.webkit.WebChromeClient;
Expand All @@ -19,6 +20,7 @@
import android.webkit.WebViewClient;

import org.wordpress.android.util.AppLog;
import org.wordpress.android.util.AppLog.T;
import org.wordpress.android.util.HTTPUtils;
import org.wordpress.android.util.StringUtils;
import org.wordpress.android.util.UrlUtils;
Expand All @@ -36,6 +38,7 @@ public abstract class EditorWebViewAbstract extends WebView {

private OnImeBackListener mOnImeBackListener;
private AuthHeaderRequestListener mAuthHeaderRequestListener;
private ErrorListener mErrorListener;
private JsCallbackReceiver mJsCallbackReceiver;

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

@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
AppLog.e(AppLog.T.EDITOR, description);
AppLog.e(T.EDITOR, description);
}

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
Expand Down Expand Up @@ -96,7 +99,7 @@ public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceReque
return new WebResourceResponse(conn.getContentType(), conn.getContentEncoding(),
conn.getInputStream());
} catch (IOException e) {
AppLog.e(AppLog.T.EDITOR, e);
AppLog.e(T.EDITOR, e);
}
}

Expand Down Expand Up @@ -128,7 +131,7 @@ public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
return new WebResourceResponse(conn.getContentType(), conn.getContentEncoding(),
conn.getInputStream());
} catch (IOException e) {
AppLog.e(AppLog.T.EDITOR, e);
AppLog.e(T.EDITOR, e);
}
}

Expand All @@ -139,13 +142,23 @@ public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
this.setWebChromeClient(new WebChromeClient() {
@Override
public boolean onConsoleMessage(@NonNull ConsoleMessage cm) {
AppLog.d(AppLog.T.EDITOR, cm.message() + " -- From line " + cm.lineNumber() + " of " + cm.sourceId());
if (cm.messageLevel() == MessageLevel.ERROR) {
if (mErrorListener != null) {
mErrorListener.onJavaScriptError(cm.sourceId(), cm.lineNumber(), cm.message());
}
AppLog.e(T.EDITOR, cm.message() + " -- From line " + cm.lineNumber() + " of " + cm.sourceId());
} else {
AppLog.d(T.EDITOR, cm.message() + " -- From line " + cm.lineNumber() + " of " + cm.sourceId());
}
return true;
}

@Override
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
AppLog.d(AppLog.T.EDITOR, message);
AppLog.d(T.EDITOR, message);
if (mErrorListener != null) {
mErrorListener.onJavaScriptAlert(url, message);
}
return true;
}
});
Expand All @@ -164,6 +177,7 @@ public void setVisibility(int visibility) {

/**
* Handles events that should be triggered when the WebView is hidden or is shown to the user
*
* @param visible the new visibility status of the WebView
*/
public void notifyVisibilityChanged(boolean visible) {
Expand Down Expand Up @@ -207,7 +221,16 @@ public void setCustomHeader(String name, String value) {
mHeaderMap.put(name, value);
}

public void setErrorListener(ErrorListener errorListener) {
mErrorListener = errorListener;
}

public interface AuthHeaderRequestListener {
String onAuthHeaderRequested(String url);
}

public interface ErrorListener {
void onJavaScriptError(String sourceFile, int lineNumber, String message);
void onJavaScriptAlert(String url, String message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class JsCallbackReceiver {
private static final String CALLBACK_FOCUS_OUT = "callback-focus-out";

private static final String CALLBACK_IMAGE_REPLACED = "callback-image-replaced";
private static final String CALLBACK_VIDEO_REPLACED = "callback-video-replaced";
private static final String CALLBACK_IMAGE_TAP = "callback-image-tap";
private static final String CALLBACK_LINK_TAP = "callback-link-tap";

Expand Down Expand Up @@ -93,8 +94,20 @@ public void executeCallback(String callbackId, String params) {
AppLog.d(AppLog.T.EDITOR, "New field created, " + params);
break;
case CALLBACK_IMAGE_REPLACED:
// TODO: Notifies that image upload has finished and that the local url was replaced by the remote url in the ZSS editor
AppLog.d(AppLog.T.EDITOR, "Image replaced, " + params);

// Extract the local media id from the callback string (stripping the 'id=' part)
if (params.length() > 3) {
mListener.onMediaReplaced(params.substring(3));
}
break;
case CALLBACK_VIDEO_REPLACED:
AppLog.d(AppLog.T.EDITOR, "Video replaced, " + params);

// Extract the local media id from the callback string (stripping the 'id=' part)
if (params.length() > 3) {
mListener.onMediaReplaced(params.substring(3));
}
break;
case CALLBACK_IMAGE_TAP:
AppLog.d(AppLog.T.EDITOR, "Image tapped, " + params);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,11 @@ public void setUrlForVideoPressId(String videoPressId, String url, String poster

}

@Override
public boolean isUploadingMedia() {
return false;
}

@Override
public boolean hasFailedMediaUploads() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public interface OnJsEditorStateChangedListener {
void onSelectionStyleChanged(Map<String, Boolean> changeSet);
void onMediaTapped(String mediaId, MediaType mediaType, JSONObject meta, String uploadStatus);
void onLinkTapped(String url, String title);
void onMediaReplaced(String mediaId);
void onVideoPressInfoRequested(String videoId);
void onGetHtmlResponse(Map<String, String> responseArgs);
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ public void setUrlForVideoPressId(String videoPressId, String url, String poster

}

@Override
public boolean isUploadingMedia() {
return false;
}

@Override
public boolean hasFailedMediaUploads() {
return false;
Expand Down
2 changes: 1 addition & 1 deletion example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0-beta5'
classpath 'com.android.tools.build:gradle:2.0.0-beta6'
}
}

Expand Down
6 changes: 3 additions & 3 deletions libs/editor-common/assets/ZSSRichTextEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -976,9 +976,6 @@ ZSSEditor.setProgressOnImage = function(imageNodeIdentifier, progress) {
* @param imageNodeIdentifier The unique image ID for the uploaded image
*/
ZSSEditor.markImageUploadDone = function(imageNodeIdentifier) {

this.sendImageReplacedCallback(imageNodeIdentifier);

var imageNode = this.getImageNodeWithIdentifier(imageNodeIdentifier);
if (imageNode.length == 0){
return;
Expand All @@ -997,6 +994,9 @@ ZSSEditor.markImageUploadDone = function(imageNodeIdentifier) {
// Wrap link around image
var linkTag = '<a href="' + imageNode.attr("src") + '"></a>';
imageNode.wrap(linkTag);

var thisObj = this;
setTimeout(function() { thisObj.sendImageReplacedCallback(imageNodeIdentifier);}, 500);
};

/**
Expand Down
4 changes: 2 additions & 2 deletions libs/editor-common/assets/editor-android.css
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ display:block on the image and setting a width limit we get around this issue. *
width:100%;
z-index: 100;
min-width: 60px;
font-family:OpenSans;
font-family: sans-serif;
font-size:20px;
font-weight:600;
text-align: center;
Expand All @@ -83,4 +83,4 @@ display:block on the image and setting a width limit we get around this issue. *
.img_container .upload-overlay.failed,
.video_container .upload-overlay.failed{
visibility: hidden;
}
}
Loading

0 comments on commit a03a146

Please sign in to comment.