[go: nahoru, domu]

Skip to content

Commit

Permalink
Squashed 'libs/editor/' changes from 50ddd25..7f3b589
Browse files Browse the repository at this point in the history
7f3b589 Updated example app to use the modified onMediaUploadSucceeded call
b203bf0 Fixed an outdated reference in the ZSSEditor
f9dbe59 Editor 0.6 version bump
76711d6 Updated localized string calls in ZSSEditor video methods
c0b804b Merge branch 'feature/visual-editor' into feature/visual-editor-insert-video
b87b917 Escape quotes for URLs being passed to the JS editor
d06f2e2 Use hasAttribute to null-check when parsing for failed media items
d3dff92 Wrapped called to getThumbnailURL in notNullStr() in the editor fragment
951bb3d Removed unnecessary console.logs
11feabd Drop data-failed attribute from ZSSEditor.insertLocalVideo
3c54e44 Merge branch 'feature/visual-editor' into feature/visual-editor-insert-video
7feb0e9 Use API<19 compatibility upload UI for video (imported from images)
d806115 Include videos in count of failed media uploads
2fc0151 Mark uploading videos as failed when opening a post containing them, so they can be retried
c6ac1e9 Send VideoPress shortcode and poster URL to visual editor when video upload completes
8f74166 Stop adding unnecessary 'data-wpid' attributed to completed video uploads
b16606a Merge branch 'feature/visual-editor' into feature/visual-editor-insert-video
916c025 Handle video upload failure and support retrying
fe3e855 Support cancelling in-progress video uploads and removing the video from the UI
2b14632 Differentiate media types in OnJsEditorStateChangedListener.onMediaTapped() native-side
26032af Added handling for completed video uploads, using the new remote URL and clearing placeholder and container
adebbff Add CSS for video_container in API<19 compatibility mode
282dbea Use appropriate JS methods for local video insertion and upload progress updates
d6ca1c7 Use placeholder image instead of video tag for uploading videos
10ae531 Track media type along with id in current uploads
2c9380b s/photo/image/ in example activity demo menu
7486336 Added video upload demo options to example activity
d923987 Merge branch 'feature/visual-editor' into feature/visual-editor-insert-video
7487a90 Add support for remote video insertion to visual editor
5497330 Merge branch 'feature/visual-editor' into feature/visual-editor-add-video
9594791 Append break tags when inserting video tags for non-VideoPress videos
a8a7858 Remove unused fullscreen video functionality from ZSSEditor

git-subtree-dir: libs/editor
git-subtree-split: 7f3b589d033fea945b226ccd85f31fe7dd7f0832
  • Loading branch information
aforcier committed Feb 23, 2016
1 parent 87b5e7c commit 108ed89
Show file tree
Hide file tree
Showing 11 changed files with 324 additions and 194 deletions.
4 changes: 2 additions & 2 deletions WordPressEditor/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ android {
buildToolsVersion "23.0.2"

defaultConfig {
versionCode 5
versionName "0.5"
versionCode 6
versionName "0.6"
minSdkVersion 14
targetSdkVersion 23
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.wordpress.android.util.AppLog.T;
import org.wordpress.android.util.JSONUtils;
import org.wordpress.android.util.ProfilingUtils;
import org.wordpress.android.util.ShortcodeUtils;
import org.wordpress.android.util.StringUtils;
import org.wordpress.android.util.ToastUtils;
import org.wordpress.android.util.UrlUtils;
Expand Down Expand Up @@ -93,7 +94,7 @@ public class EditorFragment extends EditorFragmentAbstract implements View.OnCli

private ConcurrentHashMap<String, MediaFile> mWaitingMediaFiles;
private Set<MediaGallery> mWaitingGalleries;
private Set<String> mUploadingMediaIds;
private Map<String, MediaType> mUploadingMedia;
private Set<String> mFailedMediaIds;
private MediaGallery mUploadingMediaGallery;

Expand Down Expand Up @@ -137,7 +138,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa

mWaitingMediaFiles = new ConcurrentHashMap<>();
mWaitingGalleries = Collections.newSetFromMap(new ConcurrentHashMap<MediaGallery, Boolean>());
mUploadingMediaIds = new HashSet<>();
mUploadingMedia = new HashMap<>();
mFailedMediaIds = new HashSet<>();

// -- WebView configuration
Expand Down Expand Up @@ -234,7 +235,7 @@ public void onResume() {
@Override
public void onDetach() {
// Soft cancel (delete flag off) all media uploads currently in progress
for (String mediaId : mUploadingMediaIds) {
for (String mediaId : mUploadingMedia.keySet()) {
mEditorFragmentListener.onMediaUploadCancelClicked(mediaId, false);
}
super.onDetach();
Expand Down Expand Up @@ -411,7 +412,7 @@ public void onClick(View v) {
mEditorFragmentListener.onTrackableEvent(TrackableEvent.HTML_BUTTON_TAPPED);

// Don't switch to HTML mode if currently uploading media
if (!mUploadingMediaIds.isEmpty()) {
if (!mUploadingMedia.isEmpty()) {
((ToggleButton) v).setChecked(false);

if (isAdded()) {
Expand Down Expand Up @@ -753,17 +754,38 @@ public void appendMediaFile(final MediaFile mediaFile, final String mediaUrl, Im
return;
}

final String safeMediaUrl = Utils.escapeQuotes(mediaUrl);

mWebView.post(new Runnable() {
@Override
public void run() {
if (URLUtil.isNetworkUrl(mediaUrl)) {
String mediaId = mediaFile.getMediaId();
mWebView.execJavaScriptFromString("ZSSEditor.insertImage('" + mediaUrl + "', '" + mediaId + "');");
if (mediaFile.isVideo()) {
String posterUrl = Utils.escapeQuotes(StringUtils.notNullStr(mediaFile.getThumbnailURL()));
String videoPressId = ShortcodeUtils.getVideoPressIdFromShortCode(
mediaFile.getVideoPressShortCode());

mWebView.execJavaScriptFromString("ZSSEditor.insertVideo('" + safeMediaUrl + "', '" +
posterUrl + "', '" + videoPressId + "');");
} else {
mWebView.execJavaScriptFromString("ZSSEditor.insertImage('" + safeMediaUrl + "', '" + mediaId +
"');");
}
} else {
String id = mediaFile.getMediaId();
mWebView.execJavaScriptFromString("ZSSEditor.insertLocalImage(" + id + ", '" + mediaUrl + "');");
mWebView.execJavaScriptFromString("ZSSEditor.setProgressOnImage(" + id + ", " + 0 + ");");
mUploadingMediaIds.add(id);
if (mediaFile.isVideo()) {
String posterUrl = Utils.escapeQuotes(StringUtils.notNullStr(mediaFile.getThumbnailURL()));
mWebView.execJavaScriptFromString("ZSSEditor.insertLocalVideo(" + id + ", '" + posterUrl +
"');");
mWebView.execJavaScriptFromString("ZSSEditor.setProgressOnVideo(" + id + ", " + 0 + ");");
mUploadingMedia.put(id, MediaType.VIDEO);
} else {
mWebView.execJavaScriptFromString("ZSSEditor.insertLocalImage(" + id + ", '" + safeMediaUrl +
"');");
mWebView.execJavaScriptFromString("ZSSEditor.setProgressOnImage(" + id + ", " + 0 + ");");
mUploadingMedia.put(id, MediaType.IMAGE);
}
}
}
});
Expand Down Expand Up @@ -796,8 +818,8 @@ public void setUrlForVideoPressId(final String videoId, final String videoUrl, f
mWebView.post(new Runnable() {
@Override
public void run() {
mWebView.execJavaScriptFromString("ZSSEditor.setVideoPressLinks('" + videoId + "', '" +
videoUrl + "', '" + posterUrl + "');");
mWebView.execJavaScriptFromString("ZSSEditor.setVideoPressLinks('" + videoId + "', '" +
Utils.escapeQuotes(videoUrl) + "', '" + Utils.escapeQuotes(posterUrl) + "');");
}
});
}
Expand All @@ -823,38 +845,67 @@ public void setContentPlaceholder(CharSequence placeholderText) {
}

@Override
public void onMediaUploadSucceeded(final String mediaId, final String remoteId, final String remoteUrl) {
mWebView.post(new Runnable() {
@Override
public void run() {
mWebView.execJavaScriptFromString("ZSSEditor.replaceLocalImageWithRemoteImage(" + mediaId + ", '" +
remoteId + "', '" + remoteUrl + "');");
mUploadingMediaIds.remove(mediaId);
}
});
public void onMediaUploadSucceeded(final String localMediaId, final MediaFile mediaFile) {
final MediaType mediaType = mUploadingMedia.get(localMediaId);
if (mediaType != null) {
mWebView.post(new Runnable() {
@Override
public void run() {
String remoteUrl = Utils.escapeQuotes(mediaFile.getFileURL());
if (mediaType.equals(MediaType.IMAGE)) {
String remoteMediaId = mediaFile.getMediaId();
mWebView.execJavaScriptFromString("ZSSEditor.replaceLocalImageWithRemoteImage(" + localMediaId +
", '" + remoteMediaId + "', '" + remoteUrl + "');");
} else if (mediaType.equals(MediaType.VIDEO)) {
String posterUrl = Utils.escapeQuotes(StringUtils.notNullStr(mediaFile.getThumbnailURL()));
String videoPressId = ShortcodeUtils.getVideoPressIdFromShortCode(
mediaFile.getVideoPressShortCode());
mWebView.execJavaScriptFromString("ZSSEditor.replaceLocalVideoWithRemoteVideo(" + localMediaId +
", '" + remoteUrl + "', '" + posterUrl + "', '" + videoPressId + "');");
}
mUploadingMedia.remove(localMediaId);
}
});
}
}

@Override
public void onMediaUploadProgress(final String mediaId, final float progress) {
mWebView.post(new Runnable() {
@Override
public void run() {
String progressString = String.format(Locale.US, "%.1f", progress);
mWebView.execJavaScriptFromString("ZSSEditor.setProgressOnImage(" + mediaId + ", " +
progressString + ");");
}
});
final MediaType mediaType = mUploadingMedia.get(mediaId);
if (mediaType != null) {
mWebView.post(new Runnable() {
@Override
public void run() {
String progressString = String.format(Locale.US, "%.1f", progress);
if (mediaType.equals(MediaType.IMAGE)) {
mWebView.execJavaScriptFromString("ZSSEditor.setProgressOnImage(" + mediaId + ", " +
progressString + ");");
} else if (mediaType.equals(MediaType.VIDEO)) {
mWebView.execJavaScriptFromString("ZSSEditor.setProgressOnVideo(" + mediaId + ", " +
progressString + ");");
}
}
});
}
}

@Override
public void onMediaUploadFailed(final String mediaId, final String errorMessage) {
mWebView.post(new Runnable() {
@Override
public void run() {
mWebView.execJavaScriptFromString("ZSSEditor.markImageUploadFailed(" + mediaId + ", '"
+ errorMessage.replace("'", "\\'").replace("\"", "\\\"") + "');");
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) + "');");
}
mFailedMediaIds.add(mediaId);
mUploadingMediaIds.remove(mediaId);
mUploadingMedia.remove(mediaId);
}
});
}
Expand Down Expand Up @@ -900,11 +951,11 @@ public void run() {

// If there are images that are still in progress (because the editor exited before they completed),
// set them to failed, so the user can restart them (otherwise they will stay stuck in 'uploading' mode)
mWebView.execJavaScriptFromString("ZSSEditor.markAllUploadingImagesAsFailed('"
mWebView.execJavaScriptFromString("ZSSEditor.markAllUploadingMediaAsFailed('"
+ getString(R.string.tap_to_try_again) + "');");

// Update the list of failed media uploads
mWebView.execJavaScriptFromString("ZSSEditor.getFailedImages();");
mWebView.execJavaScriptFromString("ZSSEditor.getFailedMedia();");

hideActionBarIfNeeded();

Expand Down Expand Up @@ -980,7 +1031,11 @@ public void run() {
});
}

public void onMediaTapped(final String mediaId, String url, final JSONObject meta, String uploadStatus) {
public void onMediaTapped(final String mediaId, final MediaType mediaType, final JSONObject meta, String uploadStatus) {
if (mediaType == null) {
return;
}

switch (uploadStatus) {
case "uploading":
// Display 'cancel upload' dialog
Expand All @@ -993,8 +1048,14 @@ public void onClick(DialogInterface dialog, int id) {
mWebView.post(new Runnable() {
@Override
public void run() {
mWebView.execJavaScriptFromString("ZSSEditor.removeImage(" + mediaId + ");");
mUploadingMediaIds.remove(mediaId);
switch (mediaType) {
case IMAGE:
mWebView.execJavaScriptFromString("ZSSEditor.removeImage(" + mediaId + ");");
break;
case VIDEO:
mWebView.execJavaScriptFromString("ZSSEditor.removeVideo(" + mediaId + ");");
}
mUploadingMedia.remove(mediaId);
}
});
dialog.dismiss();
Expand All @@ -1017,15 +1078,30 @@ public void onClick(DialogInterface dialog, int id) {
mWebView.post(new Runnable() {
@Override
public void run() {
mWebView.execJavaScriptFromString("ZSSEditor.unmarkImageUploadFailed(" + mediaId + ");");
mWebView.execJavaScriptFromString("ZSSEditor.setProgressOnImage(" + mediaId + ", " + 0 + ");");
switch (mediaType) {
case IMAGE:
mWebView.execJavaScriptFromString("ZSSEditor.unmarkImageUploadFailed(" + mediaId
+ ");");
mWebView.execJavaScriptFromString("ZSSEditor.setProgressOnImage(" + mediaId + ", "
+ 0 + ");");
break;
case VIDEO:
mWebView.execJavaScriptFromString("ZSSEditor.unmarkVideoUploadFailed(" + mediaId
+ ");");
mWebView.execJavaScriptFromString("ZSSEditor.setProgressOnVideo(" + mediaId + ", "
+ 0 + ");");
}
mFailedMediaIds.remove(mediaId);
mUploadingMediaIds.add(mediaId);
mUploadingMedia.put(mediaId, mediaType);
}
});
break;
default:
// Show media options fragment
if (!mediaType.equals(MediaType.IMAGE)) {
return;
}

// Only show image options fragment for image taps
FragmentManager fragmentManager = getFragmentManager();

if (fragmentManager.findFragmentByTag(ImageSettingsDialogFragment.IMAGE_SETTINGS_DIALOG_TAG) != null) {
Expand Down Expand Up @@ -1125,7 +1201,7 @@ public void onGetHtmlResponse(Map<String, String> inputArgs) {
mJavaScriptResult = inputArgs.get("result");
mGetSelectedTextCountDownLatch.countDown();
break;
case "getFailedImages":
case "getFailedMedia":
String[] mediaIds = inputArgs.get("ids").split(",");
for (String mediaId : mediaIds) {
if (!mediaId.equals("")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ public abstract class EditorFragmentAbstract extends Fragment {
// TODO: remove this as soon as we can (we'll need to drop the legacy editor or fix html2spanned translation)
public abstract Spanned getSpannedContent();

public enum MediaType {
IMAGE, VIDEO;

public static MediaType fromString(String value) {
if (value != null) {
for (MediaType mediaType : MediaType.values()) {
if (value.equalsIgnoreCase(mediaType.toString())) {
return mediaType;
}
}
}
return null;
}
}

private static final String FEATURED_IMAGE_SUPPORT_KEY = "featured-image-supported";
private static final String FEATURED_IMAGE_WIDTH_KEY = "featured-image-width";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.wordpress.android.editor;

import org.wordpress.android.util.helpers.MediaFile;

public interface EditorMediaUploadListener {
void onMediaUploadSucceeded(String localId, String remoteId, String remoteUrl);
void onMediaUploadSucceeded(String localId, MediaFile mediaFile);
void onMediaUploadProgress(String localId, float progress);
void onMediaUploadFailed(String localId, String errorMessage);
void onGalleryMediaUploadSucceeded(long galleryId, String remoteId, int remaining);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import java.util.Map;
import java.util.Set;

import static org.wordpress.android.editor.EditorFragmentAbstract.MediaType;

public class JsCallbackReceiver {
private static final String JS_CALLBACK_DELIMITER = "~";

Expand Down Expand Up @@ -103,6 +105,7 @@ public void executeCallback(String callbackId, String params) {
mediaIds.add("id");
mediaIds.add("url");
mediaIds.add("meta");
mediaIds.add("type");

Set<String> mediaDataSet = Utils.splitValuePairDelimitedString(params, JS_CALLBACK_DELIMITER, mediaIds);
Map<String, String> mediaDataMap = Utils.buildMapFromKeyValuePairs(mediaDataSet);
Expand All @@ -114,6 +117,8 @@ public void executeCallback(String callbackId, String params) {
mediaUrl = Utils.decodeHtml(mediaUrl);
}

MediaType mediaType = MediaType.fromString(mediaDataMap.get("type"));

String mediaMeta = mediaDataMap.get("meta");
JSONObject mediaMetaJson = new JSONObject();

Expand All @@ -136,7 +141,7 @@ public void executeCallback(String callbackId, String params) {
}
}

mListener.onMediaTapped(mediaId, mediaUrl, mediaMetaJson, uploadStatus);
mListener.onMediaTapped(mediaId, mediaType, mediaMetaJson, uploadStatus);
break;
case CALLBACK_LINK_TAP:
// Extract and HTML-decode the link data from the callback params
Expand Down Expand Up @@ -188,7 +193,7 @@ public void executeCallback(String callbackId, String params) {
case "getSelectedText":
responseIds.add("result");
break;
case "getFailedImages":
case "getFailedMedia":
responseIds.add("ids");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

import java.util.Map;

import static org.wordpress.android.editor.EditorFragmentAbstract.MediaType;

public interface OnJsEditorStateChangedListener {
void onDomLoaded();
void onSelectionChanged(Map<String, String> selectionArgs);
void onSelectionStyleChanged(Map<String, Boolean> changeSet);
void onMediaTapped(String mediaId, String url, JSONObject meta, String uploadStatus);
void onMediaTapped(String mediaId, MediaType mediaType, JSONObject meta, String uploadStatus);
void onLinkTapped(String url, String title);
void onVideoPressInfoRequested(String videoId);
void onGetHtmlResponse(Map<String, String> responseArgs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ public static String decodeHtml(String html) {
return html;
}

public static String escapeQuotes(String text) {
if (text != null) {
text = text.replace("'", "\\'").replace("\"", "\\\"");
}
return text;
}

/**
* Splits a delimited string into a set of strings.
* @param string the delimited string to split
Expand Down
Loading

0 comments on commit 108ed89

Please sign in to comment.