[go: nahoru, domu]

Skip to content

Commit

Permalink
Squashed 'libs/editor/' changes from 6647346..d99856b
Browse files Browse the repository at this point in the history
d99856b Merge branch 'merge-wpandroid' into develop
aee093e Implemented missing onAuthHeaderRequested method in the example app
fdccfc1 Hide video fullscreen button
6fd8591 Pause video playback when the WebView is no longer visible to the user
84da174 Use a blank placeholder src instead of videopress.mp4 to trigger videopress video loading
435c012 Added some sanity checks for substring usage to JsCallbackReceiver
6c4d042 Fixed a bug where videos would sometimes get deleted if they were the only thing in the post
d1aeaca Added support for video shortcodes on non-VideoPress sites
9f1b954 Merge branch 'feature/visual-editor' into feature/editor-video-playback
a61fbf9 Added missing bracket in JS editor
040ceb8 Follow redirects when requesting thumbnails for the image settings dialog
4fbd821 Always defer to super.shouldInterceptRequest in editor WebView unless an auth header is present
c933ee8 Merge branch 'feature/visual-editor' into feature/editor-video-playback
10a08fa Merge pull request #273 from wordpress-mobile/issue/15-track-editor-evnts
bce6d92 Merge branch 'develop' into issue/15-track-editor-evnts
3e2c261 When looking up a VideoPress ID in the DB fails, refresh the blog media and check again
c803d21 Remove the onError attribute from VideoPress videos if an empty video url is returned
4ca4c4c Added the ability to tap a placeholder VideoPress video to attempt to load it
1c638bf Don't use the placeholder poster image for videopress videos
e9e8f7f Implemented missing method in example app
d8a8510 fix typo in event name
b13ac66 Track EDITOR_EDITED_IMAGE
da3cd0c Add space after videos when converting from VideoPress shortcode
ca6499f track most editor events
74b9932 use wp-analytics 1.1.0
1964844 Only apply custom headers for network URL resource requests
b3dd7e3 Implement new EditorFragmentListener method in mock activity for integration tests
fee3ffb Convert VideoPress shortcodes to video elements and back in the visual editor
9d56f49 Imported ZSSRichTextEditor video methods and callback methods from iOS
5b9a4c3 Imported video CSS from iOS
5bbc482 Added missing method implementation to test mock activity
77f7096 Retrieve an auth header if necessary when launching the image settings dialog
1214827 Use the safeToAddWordPressComAuthHeader utility method for resource requests in the new editor's WebView
b2e2b74 Updated the utils artifact version for the editor
12f748a Moved setupUrlConnection() to the utils library
108a24c Renamed EditorFragment's setWebViewHeader to setCustomHttpHeader
1ac139e Use custom headers for image settings dialog image requests
542db23 Extracted some duplicated HttpURLConnection building code into a utility method
96984f0 When an Authorization HTTP header is detected, force using the HTTPS protocol in the WebViewClient
3302ab9 Added support for custom headers to the editor's WebView, set through the EditorFragmentAbstract
02ce3e4 Editor 0.5 version bump
190a822 Added full support for gallery types
25b3632 Added a fix enabling galleries to be added to the editor before the DOM loads
acd7f9c Fixed creating a new post by making a gallery from the Media Library (the gallery wasn't being added to the new post)
1b6d47c Merge branch 'feature/visual-editor' into feature/editor-galleries
b1cb369 Added support for creating galleries from local images, using a placeholder shortcode while uploading
92a3359 Extracted duplicate paragraph-wrapping code into a separate method in the ZSS editor
26d93c0 Added support for inserting galleries using media library images

git-subtree-dir: libs/editor
git-subtree-split: d99856bfb3e35e5c86f74af3f517739749e923ea
  • Loading branch information
aforcier committed Jan 27, 2016
1 parent 2467f23 commit c0c935f
Show file tree
Hide file tree
Showing 17 changed files with 988 additions and 44 deletions.
8 changes: 4 additions & 4 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 4
versionName "0.4"
versionCode 5
versionName "0.5"
minSdkVersion 14
targetSdkVersion 23
}
Expand All @@ -48,8 +48,8 @@ android {
dependencies {
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
compile 'org.wordpress:analytics:1.0.0'
compile 'org.wordpress:utils:1.6.0'
compile 'org.wordpress:analytics:1.2.0'
compile 'org.wordpress:utils:1.7.0'

// Test libraries
testCompile 'junit:junit:4.11'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ public void onFeaturedImageChanged(int mediaId) {

}

@Override
public void onVideoPressInfoRequested(String videoId) {

}

@Override
public String onAuthHeaderRequested(String url) {
return "";
}

@Override
public void saveMediaFile(MediaFile mediaFile) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,21 @@

import com.android.volley.toolbox.ImageLoader;

import org.json.JSONException;
import org.json.JSONObject;
import org.wordpress.android.analytics.AnalyticsTracker;
import org.wordpress.android.analytics.AnalyticsTracker.Stat;
import org.wordpress.android.util.AppLog;
import org.wordpress.android.util.AppLog.T;
import org.wordpress.android.util.JSONUtils;
import org.wordpress.android.util.StringUtils;
import org.wordpress.android.util.ToastUtils;
import org.wordpress.android.util.UrlUtils;
import org.wordpress.android.util.helpers.MediaFile;
import org.wordpress.android.util.helpers.MediaGallery;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Locale;
Expand All @@ -50,7 +55,8 @@
import java.util.concurrent.TimeUnit;

public class EditorFragment extends EditorFragmentAbstract implements View.OnClickListener, View.OnTouchListener,
OnJsEditorStateChangedListener, OnImeBackListener, EditorMediaUploadListener {
OnJsEditorStateChangedListener, OnImeBackListener, EditorWebViewAbstract.AuthHeaderRequestListener,
EditorMediaUploadListener {
private static final String ARG_PARAM_TITLE = "param_title";
private static final String ARG_PARAM_CONTENT = "param_content";

Expand Down Expand Up @@ -87,8 +93,10 @@ public class EditorFragment extends EditorFragmentAbstract implements View.OnCli
private boolean mHideActionBarOnSoftKeyboardUp = false;

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

private String mJavaScriptResult = "";

Expand Down Expand Up @@ -126,6 +134,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
}

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

Expand All @@ -135,6 +144,13 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa

mWebView.setOnTouchListener(this);
mWebView.setOnImeBackListener(this);
mWebView.setAuthHeaderRequestListener(this);

if (mCustomHttpHeaders != null && mCustomHttpHeaders.size() > 0) {
for (Map.Entry<String, String> entry : mCustomHttpHeaders.entrySet()) {
mWebView.setCustomHeader(entry.getKey(), entry.getValue());
}
}

// Ensure that the content field is always filling the remaining screen space
mWebView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
Expand Down Expand Up @@ -222,6 +238,14 @@ public void onDetach() {
super.onDetach();
}

@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
if (mDomHasLoaded) {
mWebView.notifyVisibilityChanged(isVisibleToUser);
}
super.setUserVisibleHint(isVisibleToUser);
}

@Override
public void onSaveInstanceState(Bundle outState) {
outState.putCharSequence(KEY_TITLE, getTitle());
Expand Down Expand Up @@ -365,6 +389,8 @@ protected void initJsEditor() {
public void onClick(View v) {
int id = v.getId();
if (id == R.id.format_bar_button_html) {
AnalyticsTracker.track(Stat.EDITOR_TAPPED_HTML);

// Don't switch to HTML mode if currently uploading media
if (!mUploadingMediaIds.isEmpty()) {
((ToggleButton) v).setChecked(false);
Expand Down Expand Up @@ -405,6 +431,7 @@ public void onClick(View v) {
mWebView.execJavaScriptFromString("ZSSEditor.getField('zss_field_content').focus();");
}
} else if (id == R.id.format_bar_button_media) {
AnalyticsTracker.track(Stat.EDITOR_TAPPED_IMAGE);
((ToggleButton) v).setChecked(false);

if (mSourceView.getVisibility() == View.VISIBLE) {
Expand All @@ -419,8 +446,10 @@ public void onClick(View v) {
if (!((ToggleButton) v).isChecked()) {
// The link button was checked when it was pressed; remove the current link
mWebView.execJavaScriptFromString("ZSSEditor.unlink();");
AnalyticsTracker.track(Stat.EDITOR_TAPPED_UNLINK);
return;
}
AnalyticsTracker.track(Stat.EDITOR_TAPPED_LINK);

((ToggleButton) v).setChecked(false);

Expand Down Expand Up @@ -479,6 +508,11 @@ public void onImeBack() {
showActionBarIfNeeded();
}

@Override
public String onAuthHeaderRequested(String url) {
return mEditorFragmentListener.onAuthHeaderRequested(url);
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Expand Down Expand Up @@ -706,19 +740,49 @@ public void run() {
if (URLUtil.isNetworkUrl(mediaUrl)) {
String mediaId = mediaFile.getMediaId();
mWebView.execJavaScriptFromString("ZSSEditor.insertImage('" + mediaUrl + "', '" + mediaId + "');");
AnalyticsTracker.track(Stat.EDITOR_ADDED_PHOTO_VIA_WP_MEDIA_LIBRARY);
} else {
String id = mediaFile.getMediaId();
mWebView.execJavaScriptFromString("ZSSEditor.insertLocalImage(" + id + ", '" + mediaUrl + "');");
mWebView.execJavaScriptFromString("ZSSEditor.setProgressOnImage(" + id + ", " + 0 + ");");
mUploadingMediaIds.add(id);
AnalyticsTracker.track(Stat.EDITOR_ADDED_PHOTO_VIA_LOCAL_LIBRARY);
}
}
});
}

@Override
public void appendGallery(MediaGallery mediaGallery) {
// TODO
if (!mDomHasLoaded) {
// If the DOM hasn't loaded yet, we won't be able to add a gallery to the ZSSEditor
// Place it in a queue to be handled when the DOM loaded callback is received
mWaitingGalleries.add(mediaGallery);
return;
}

if (mediaGallery.getIds().isEmpty()) {
mUploadingMediaGallery = mediaGallery;
mWebView.execJavaScriptFromString("ZSSEditor.insertLocalGallery('" + mediaGallery.getUniqueId() + "');");
} else {
// Ensure that the content field is in focus (it may not be if we're adding a gallery to a new post by a
// share action and not via the format bar button)
mWebView.execJavaScriptFromString("ZSSEditor.getField('zss_field_content').focus();");

mWebView.execJavaScriptFromString("ZSSEditor.insertGallery('" + mediaGallery.getIdsStr() + "', '" +
mediaGallery.getType() + "', " + mediaGallery.getNumColumns() + ");");
}
}

@Override
public void setUrlForVideoPressId(final String videoId, final String videoUrl, final String posterUrl) {
mWebView.post(new Runnable() {
@Override
public void run() {
mWebView.execJavaScriptFromString("ZSSEditor.setVideoPressLinks('" + videoId + "', '" +
videoUrl + "', '" + posterUrl + "');");
}
});
}

@Override
Expand Down Expand Up @@ -770,13 +834,35 @@ public void onMediaUploadFailed(final String mediaId) {
mWebView.post(new Runnable() {
@Override
public void run() {
AnalyticsTracker.track(Stat.EDITOR_UPLOAD_MEDIA_FAILED);
mWebView.execJavaScriptFromString("ZSSEditor.markImageUploadFailed(" + mediaId + ");");
mFailedMediaIds.add(mediaId);
mUploadingMediaIds.remove(mediaId);
}
});
}

@Override
public void onGalleryMediaUploadSucceeded(final long galleryId, String remoteMediaId, int remaining) {
if (galleryId == mUploadingMediaGallery.getUniqueId()) {
ArrayList<String> mediaIds = mUploadingMediaGallery.getIds();
mediaIds.add(remoteMediaId);
mUploadingMediaGallery.setIds(mediaIds);

if (remaining == 0) {
mWebView.post(new Runnable() {
@Override
public void run() {
mWebView.execJavaScriptFromString("ZSSEditor.replacePlaceholderGallery('" + galleryId + "', '" +
mUploadingMediaGallery.getIdsStr() + "', '" +
mUploadingMediaGallery.getType() + "', " +
mUploadingMediaGallery.getNumColumns() + ");");
}
});
}
}
}

public void onDomLoaded() {
mWebView.post(new Runnable() {
public void run() {
Expand Down Expand Up @@ -820,6 +906,19 @@ public void run() {
}
mWaitingMediaFiles.clear();
}

// Add any galleries that were placed in a queue due to the DOM not having loaded yet
if (mWaitingGalleries.size() > 0) {
// Gallery insertion will only work if the content field is in focus
// (for a new post, no field is in focus until user action)
mWebView.execJavaScriptFromString("ZSSEditor.getField('zss_field_content').focus();");

for (MediaGallery mediaGallery : mWaitingGalleries) {
appendGallery(mediaGallery);
}

mWaitingGalleries.clear();
}
}
});
}
Expand Down Expand Up @@ -894,6 +993,7 @@ public void onClick(DialogInterface dialog, int id) {
mWebView.post(new Runnable() {
@Override
public void run() {
AnalyticsTracker.track(Stat.EDITOR_UPLOAD_MEDIA_RETRIED);
mWebView.execJavaScriptFromString("ZSSEditor.unmarkImageUploadFailed(" + mediaId + ");");
mWebView.execJavaScriptFromString("ZSSEditor.setProgressOnImage(" + mediaId + ", " + 0 + ");");
mFailedMediaIds.remove(mediaId);
Expand All @@ -908,17 +1008,34 @@ public void run() {
if (fragmentManager.findFragmentByTag(ImageSettingsDialogFragment.IMAGE_SETTINGS_DIALOG_TAG) != null) {
return;
}

AnalyticsTracker.track(Stat.EDITOR_EDITED_IMAGE);
ImageSettingsDialogFragment imageSettingsDialogFragment = new ImageSettingsDialogFragment();
imageSettingsDialogFragment.setTargetFragment(this,
ImageSettingsDialogFragment.IMAGE_SETTINGS_DIALOG_REQUEST_CODE);

Bundle dialogBundle = new Bundle();

dialogBundle.putString("imageMeta", meta.toString());
dialogBundle.putString("maxWidth", mBlogSettingMaxImageWidth);
dialogBundle.putBoolean("featuredImageSupported", mFeaturedImageSupported);

// Request and add an authorization header for HTTPS images
// Use https:// when requesting the auth header, in case the image is incorrectly using http://.
// If an auth header is returned, force https:// for the actual HTTP request.
HashMap<String, String> headerMap = new HashMap<>(mCustomHttpHeaders);
try {
final String imageSrc = meta.getString("src");
String authHeader = mEditorFragmentListener.onAuthHeaderRequested(UrlUtils.makeHttps(imageSrc));
if (authHeader.length() > 0) {
meta.put("src", UrlUtils.makeHttps(imageSrc));
headerMap.put("Authorization", authHeader);
}
} catch (JSONException e) {
AppLog.e(T.EDITOR, "Could not retrieve image url from JSON metadata");
}
dialogBundle.putSerializable("headerMap", headerMap);

dialogBundle.putString("imageMeta", meta.toString());

String imageId = JSONUtils.getString(meta, "attachment_id");
if (!imageId.isEmpty()) {
dialogBundle.putBoolean("isFeatured", mFeaturedImageId == Integer.parseInt(imageId));
Expand All @@ -933,6 +1050,8 @@ public void run() {
ImageSettingsDialogFragment.IMAGE_SETTINGS_DIALOG_TAG)
.addToBackStack(null)
.commit();

mWebView.notifyVisibilityChanged(false);
break;
}
}
Expand All @@ -950,6 +1069,11 @@ public void onLinkTapped(String url, String title) {
linkDialogFragment.show(getFragmentManager(), "LinkDialogFragment");
}

@Override
public void onVideoPressInfoRequested(final String videoId) {
mEditorFragmentListener.onVideoPressInfoRequested(videoId);
}

public void onGetHtmlResponse(Map<String, String> inputArgs) {
String functionId = inputArgs.get("function");

Expand Down Expand Up @@ -1051,14 +1175,31 @@ private void clearFormatBarButtons() {

private void onFormattingButtonClicked(ToggleButton toggleButton) {
String tag = toggleButton.getTag().toString();

trackFormattingButtonClicked(toggleButton);
if (mWebView.getVisibility() == View.VISIBLE) {
mWebView.execJavaScriptFromString("ZSSEditor.set" + StringUtils.capitalize(tag) + "();");
} else {
applyFormattingHtmlMode(toggleButton, tag);
}
}

private void trackFormattingButtonClicked(ToggleButton toggleButton) {
int id = toggleButton.getId();
if (id == R.id.format_bar_button_bold) {
AnalyticsTracker.track(Stat.EDITOR_TAPPED_BOLD);
} else if (id == R.id.format_bar_button_italic) {
AnalyticsTracker.track(Stat.EDITOR_TAPPED_ITALIC);
} else if (id == R.id.format_bar_button_ol) {
AnalyticsTracker.track(Stat.EDITOR_TAPPED_ORDERED_LIST);
} else if (id == R.id.format_bar_button_ul) {
AnalyticsTracker.track(Stat.EDITOR_TAPPED_UNORDERED_LIST);
} else if (id == R.id.format_bar_button_quote) {
AnalyticsTracker.track(Stat.EDITOR_TAPPED_BLOCKQUOTE);
} else if (id == R.id.format_bar_button_strikethrough) {
AnalyticsTracker.track(Stat.EDITOR_TAPPED_STRIKETHROUGH);
}
}

/**
* In HTML mode, applies formatting to selected text, or inserts formatting tag at current cursor position
* @param toggleButton format bar button which was clicked
Expand Down
Loading

0 comments on commit c0c935f

Please sign in to comment.