Skip to content

Commit 9b0b5fa

Browse files
committed
Squashed 'libs/editor/' changes from eb8d070..bed2a4e
bed2a4e Merge pull request #326 from wordpress-mobile/issue/314-html-mode-toggle-cursor 7b5bdb4 Force cursor to move to start of content field when switching back from HTML mode dca8254 Merge pull request #3896 from wordpress-mobile/issue/300editor-broken-images-after-upload-2 ffeec5f remove debug logs d695c87 Use remoteurl in the link wrapper 373467f Merge branch 'develop' into issue/300editor-broken-images-after-upload-2 1dd8be0 Merge branch 'develop' into issue/297editor-backspace-media bf525c8 update to com.android.tools.build:gradle:2.0.0-beta7 196f82c Merge branch 'develop' into issue/297editor-backspace-media c576833 Merge commit '8db246f15ce6f4d2c7f7f7ec51c68b87e9a66c2f' into develop ddcb207 Changed MutationObserver handling to check if the WebView supports it, rather than rely on API levels d79bc00 Refactor: grouped mutation observation methods together eeb6373 Refactored DOM element mutation listening, delegating everything to one trackNodeForMutation method 7b54573 Changed MutationObserver behavior to track individual media nodes instead of each contenteditable div a933e5b Moved failed media methods to the generic media method group cfb836b Parse for failed media when returning from HTML to visual mode c0df468 Track DOMNodeRemoved events when parsing for failed media 839b3e5 Fixed a variable name error in ZSSEditor.removeImage 392e1d7 On API<19, use DOMNodeRemoved events to track media deletions (instead of the unsupported MutationObserver used for newer APIs) 5c3bb59 Merge branch 'develop' into issue/297editor-backspace-media 4c7ca43 Merge pull request #3804 from wordpress-mobile/issue/enable-editor-debug-mode cc332a9 Consume KEYCODE_VOLUME_UP event when debug print is called cf492d0 broken retries 449abbd Merge branch 'issue/enable-editor-debug-mode' into issue/300editor-broken-images-after-upload-2 63bb901 use a remoteUrl attribute to avoid seeing broken image if download failed 55677b6 remove debug action bar button and log raw html when volume up button is pressed 7ba5069 fix function call errors 886e274 Add back image swapping onError 920c8d3 fix wordpress-mobile/WordPress-Editor-Android#300: Retry download onError after an upload 7fa191f add missing comment 01fbeed Fixes an issue where manually deleting uploading/failed media will cause the caret to disappear 5904f03 Notify native through a callback whenever uploading/failed media are manually deleted git-subtree-dir: libs/editor git-subtree-split: bed2a4ef1ea0a86e4237791da8e867f17590c5b3
1 parent 8db246f commit 9b0b5fa

File tree

10 files changed

+301
-108
lines changed

10 files changed

+301
-108
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-beta6'
6+
classpath 'com.android.tools.build:gradle:2.0.0-beta7'
77
}
88
}
99

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

Lines changed: 14 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
import android.text.Spanned;
2020
import android.text.TextUtils;
2121
import android.view.LayoutInflater;
22-
import android.view.Menu;
23-
import android.view.MenuInflater;
24-
import android.view.MenuItem;
2522
import android.view.MotionEvent;
2623
import android.view.View;
2724
import android.view.ViewGroup;
@@ -74,8 +71,6 @@ public class EditorFragment extends EditorFragmentAbstract implements View.OnCli
7471
private static final float TOOLBAR_ALPHA_ENABLED = 1;
7572
private static final float TOOLBAR_ALPHA_DISABLED = 0.5f;
7673

77-
protected static final int BUTTON_ID_LOG_HTML = 555;
78-
7974
private String mTitle = "";
8075
private String mContentHtml = "";
8176

@@ -409,8 +404,6 @@ protected void initJsEditor() {
409404

410405
if (mDebugModeEnabled) {
411406
enableWebDebugging(true);
412-
// Enable the HTML logging button
413-
setHasOptionsMenu(true);
414407
}
415408
}
416409

@@ -457,7 +450,11 @@ public void onClick(View v) {
457450
mContentHtml = mSourceViewContent.getText().toString();
458451
updateVisualEditorFields();
459452

460-
mWebView.execJavaScriptFromString("ZSSEditor.getField('zss_field_content').focus();");
453+
// Update the list of failed media uploads
454+
mWebView.execJavaScriptFromString("ZSSEditor.getFailedMedia();");
455+
456+
// Reset selection to avoid buggy cursor behavior
457+
mWebView.execJavaScriptFromString("ZSSEditor.resetSelectionOnField('zss_field_content');");
461458
}
462459
} else if (id == R.id.format_bar_button_media) {
463460
mEditorFragmentListener.onTrackableEvent(TrackableEvent.MEDIA_BUTTON_TAPPED);
@@ -640,38 +637,11 @@ public void run() {
640637

641638
@SuppressLint("NewApi")
642639
private void enableWebDebugging(boolean enable) {
643-
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
640+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
644641
AppLog.i(T.EDITOR, "Enabling web debugging");
645642
WebView.setWebContentsDebuggingEnabled(enable);
646643
}
647-
}
648-
649-
@Override
650-
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
651-
menu.add(0, BUTTON_ID_LOG_HTML, 0, "Log HTML")
652-
.setIcon(R.drawable.ic_log_html)
653-
.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
654-
super.onCreateOptionsMenu(menu, inflater);
655-
}
656-
657-
@Override
658-
public boolean onOptionsItemSelected(MenuItem item) {
659-
if (item.getItemId() == BUTTON_ID_LOG_HTML) {
660-
if (mDebugModeEnabled) {
661-
// Log the raw html
662-
mWebView.post(new Runnable() {
663-
@Override
664-
public void run() {
665-
mWebView.execJavaScriptFromString("console.log(document.body.innerHTML);");
666-
}
667-
});
668-
} else {
669-
AppLog.d(T.EDITOR, "Could not execute JavaScript - debug mode not enabled");
670-
}
671-
return true;
672-
} else {
673-
return super.onOptionsItemSelected(item);
674-
}
644+
mWebView.setDebugModeEnabled(mDebugModeEnabled);
675645
}
676646

677647
@Override
@@ -1191,6 +1161,13 @@ public void onLinkTapped(String url, String title) {
11911161
linkDialogFragment.show(getFragmentManager(), "LinkDialogFragment");
11921162
}
11931163

1164+
@Override
1165+
public void onMediaRemoved(String mediaId) {
1166+
mUploadingMedia.remove(mediaId);
1167+
mFailedMediaIds.remove(mediaId);
1168+
mEditorFragmentListener.onMediaUploadCancelClicked(mediaId, true);
1169+
}
1170+
11941171
@Override
11951172
public void onMediaReplaced(String mediaId) {
11961173
mUploadingMedia.remove(mediaId);

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.wordpress.android.util.AppLog.T;
2424
import org.wordpress.android.util.HTTPUtils;
2525
import org.wordpress.android.util.StringUtils;
26+
import org.wordpress.android.util.ToastUtils;
2627
import org.wordpress.android.util.UrlUtils;
2728

2829
import java.io.IOException;
@@ -40,6 +41,7 @@ public abstract class EditorWebViewAbstract extends WebView {
4041
private AuthHeaderRequestListener mAuthHeaderRequestListener;
4142
private ErrorListener mErrorListener;
4243
private JsCallbackReceiver mJsCallbackReceiver;
44+
private boolean mDebugModeEnabled;
4345

4446
private Map<String, String> mHeaderMap = new HashMap<>();
4547

@@ -175,6 +177,10 @@ public void setVisibility(int visibility) {
175177
super.setVisibility(visibility);
176178
}
177179

180+
public void setDebugModeEnabled(boolean enabled) {
181+
mDebugModeEnabled = enabled;
182+
}
183+
178184
/**
179185
* Handles events that should be triggered when the WebView is hidden or is shown to the user
180186
*
@@ -214,6 +220,13 @@ public boolean onKeyPreIme(int keyCode, KeyEvent event) {
214220
mOnImeBackListener.onImeBack();
215221
}
216222
}
223+
if (mDebugModeEnabled && event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP
224+
&& event.getAction() == KeyEvent.ACTION_DOWN) {
225+
// Log the raw html
226+
execJavaScriptFromString("console.log(document.body.innerHTML);");
227+
ToastUtils.showToast(getContext(), "Debug: Raw HTML has been logged");
228+
return true;
229+
}
217230
return super.onKeyPreIme(keyCode, event);
218231
}
219232

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public class JsCallbackReceiver {
3232
private static final String CALLBACK_VIDEO_REPLACED = "callback-video-replaced";
3333
private static final String CALLBACK_IMAGE_TAP = "callback-image-tap";
3434
private static final String CALLBACK_LINK_TAP = "callback-link-tap";
35+
private static final String CALLBACK_MEDIA_REMOVED = "callback-media-removed";
3536

3637
private static final String CALLBACK_VIDEOPRESS_INFO_REQUEST = "callback-videopress-info-request";
3738

@@ -179,6 +180,13 @@ public void executeCallback(String callbackId, String params) {
179180

180181
mListener.onLinkTapped(url, title);
181182
break;
183+
case CALLBACK_MEDIA_REMOVED:
184+
AppLog.d(AppLog.T.EDITOR, "Media removed, " + params);
185+
// Extract the media id from the callback string (stripping the 'id=' part of the callback string)
186+
if (params.length() > 3) {
187+
mListener.onMediaRemoved(params.substring(3));
188+
}
189+
break;
182190
case CALLBACK_VIDEOPRESS_INFO_REQUEST:
183191
// Extract the VideoPress id from the callback string (stripping the 'id=' part of the callback string)
184192
if (params.length() > 3) {

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 onMediaRemoved(String mediaId);
1516
void onMediaReplaced(String mediaId);
1617
void onVideoPressInfoRequested(String videoId);
1718
void onGetHtmlResponse(Map<String, String> responseArgs);
-180 Bytes
Binary file not shown.
-214 Bytes
Binary file not shown.
-295 Bytes
Binary file not shown.

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-beta6'
6+
classpath 'com.android.tools.build:gradle:2.0.0-beta7'
77
}
88
}
99

0 commit comments

Comments
 (0)