Skip to content

Commit

Permalink
Squashed 'libs/editor/' changes from ce4343d..6647346
Browse files Browse the repository at this point in the history
6647346 Merge pull request #267 from wordpress-mobile/issue/261-image-settings-nav
8b0ee06 Added featured image to state of image settings dialog, which is checked when attempting to exit without saving
47b7874 Error handling for retrieving featured image from JSON meta data
e963027 Merge branch 'develop' into issue/261-image-settings-nav
ca9c4ed Merge pull request #266 from wordpress-mobile/sync-featured-wpandroid
fd6901d Merge branch 'develop' into sync-featured-wpandroid
156dbf0 Make travis use the latest platform-tools
021b485 Fixed onMediaUploadSucceeded implementation in the example activity
c3b2934 Updated travis build tools to 23.0.2
888b271 Update gradle and build tools versions for example app
6917b66 Merge branch 'feature/visual-editor' into feature/editor-featured-images
8507915 Merge branch 'develop' into feature/visual-editor
91effe7 Removed unused 'Include image in post content' checkbox from image settings
3192b38 Updating gradle plugin to 1.5.0 and support/build tools to latest for sub projects
92683c0 Show a 'Changes saved' toast when saving and exiting the image settings dialog
f5c2f13 Fixed a capitalization issue when setting the alignment spinner value
396ffcd Return to the editor when the back button is pressed within the image settings fragment
d5d4c91 Fixed a capitalization issue with image alignment meta values
9fd836c Show a confirmation dialog when closing the image settings fragment with unsaved changes
ec7e853 Use a callback instead of a getter to notify the host activity when the featured image changes
13b5f5a Add the remote media id to image tags when inserting from media gallery
04f9cf9 Hide the featured image checkbox if feature images aren't supported
b8c8ba2 Updated Editor example project with changes to onMediaUploadProgress
b3031d6 Fixed a crash issue in the image settings dialog fragment
b44742e Converted featured id handling methods to be part of EditorFragmentAbstract
9d4facf Added support for getting and setting the featured image id to the editor fragments
10cc6f0 Don't clear all class data in ZSSEditor.markImageUploadDone
0a6722b Add the remote image ID to the image tag when an image upload completes
6d1c12d Added support for setting/unsetting an image as featured to the image settings dialog
2c1c98e Modified onMediaTapped to pass the image meta data as a JSONObject
477e0c9 Merge pull request #262 from wordpress-mobile/issue/233-media-sharing
7e6ee2d Fixed a potential NPE in getTitle() and getContent()
10cdca9 Queue media insertions that arrive before the DOM has loaded, and execute them later
e69588f Fixed a broken test and an issue with the editor demo activity
862972f Implemented missing method in EditorFragmentAbstractTest
580c259 Added some empty string checking when retrieving failed media ids from the ZSSEditor
06c3f3a Adjusted the pattern used by the ZSSEditor to find images that are uploading
383840a Disable editor format bar buttons when post/page contains failed uploads
4ac4dfb Updated EditorFragment to handle exiting the editor with media uploads in progress more gracefully
8c34a40 Added a 'delete' flag to onMediaUploadCancelClicked
49a69f5 Fixed a bug where the media upload progress bar wouldn't display due to a localization issue
32b2696 Visual editor lib version bump
bda0e0f Updated image settings dialog to always clear the custom ActionBar view
438916b Merge commit '7b6a9d464896683ba4aef6f4dccc9021641e5d71' into develop
14f89b2 Updating build tools to 23.0.1
f378f6e Merge branch 'release/4.4' into develop
de1085d use default AppCompat theme on EditLink and AddCategory dialog
7bae170 set targetSdkVersion to 23 and clean up lib dependencies
1624a01 migrate from mavenCentral to jcenter (which is now the default for Android Studio)
f55a91e upgrade subtrees to latest android tools
e0a098f update to gradle plugin 1.3.1 and gradle 2.6
62e18f1 Merge branch 'develop' into feature/update-to-gradle-2.4
d2e000e upgrade to gradle 2.5 and gradle plugin 1.3.0

git-subtree-dir: libs/editor
git-subtree-split: 664734643e6728e2dca9859bdf5e5b940db92491
  • Loading branch information
aforcier committed Dec 2, 2015
1 parent 7b6a9d4 commit 2467f23
Show file tree
Hide file tree
Showing 17 changed files with 334 additions and 71 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ android:
components:
- extra-android-m2repository
- extra-android-support
- build-tools-23.0.1
- platform-tools
- tools
- build-tools-23.0.2
- android-23

env:
Expand Down
12 changes: 6 additions & 6 deletions 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:1.3.1'
classpath 'com.android.tools.build:gradle:1.5.0'
}
}

Expand All @@ -20,11 +20,11 @@ android {
publishNonDefault true

compileSdkVersion 23
buildToolsVersion "23.0.1"
buildToolsVersion "23.0.2"

defaultConfig {
versionCode 3
versionName "0.3"
versionCode 4
versionName "0.4"
minSdkVersion 14
targetSdkVersion 23
}
Expand All @@ -46,8 +46,8 @@ android {
}

dependencies {
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:support-v4:23.0.1'
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'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ public void onMediaRetryClicked(String mediaId) {
}

@Override
public void onMediaUploadCancelClicked(String mediaId) {
public void onMediaUploadCancelClicked(String mediaId, boolean delete) {

}

@Override
public void onFeaturedImageChanged(int mediaId) {

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@

import com.android.volley.toolbox.ImageLoader;

import org.json.JSONObject;
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.helpers.MediaFile;
Expand All @@ -40,8 +42,10 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -77,11 +81,14 @@ public class EditorFragment extends EditorFragmentAbstract implements View.OnCli
private String mTitlePlaceholder = "";
private String mContentPlaceholder = "";

private boolean mDomHasLoaded = false;
private boolean mIsKeyboardOpen = false;
private boolean mEditorWasPaused = false;
private boolean mHideActionBarOnSoftKeyboardUp = false;

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

private String mJavaScriptResult = "";

Expand Down Expand Up @@ -118,7 +125,9 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
mHideActionBarOnSoftKeyboardUp = true;
}

mWaitingMediaFiles = new ConcurrentHashMap<>();
mUploadingMediaIds = new HashSet<>();
mFailedMediaIds = new HashSet<>();

// -- WebView configuration

Expand Down Expand Up @@ -206,6 +215,10 @@ public void onResume() {

@Override
public void onDetach() {
// Soft cancel (delete flag off) all media uploads currently in progress
for (String mediaId : mUploadingMediaIds) {
mEditorFragmentListener.onMediaUploadCancelClicked(mediaId, false);
}
super.onDetach();
}

Expand Down Expand Up @@ -529,13 +542,28 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
}

final String imageMeta = extras.getString("imageMeta");
final int imageRemoteId = extras.getInt("imageRemoteId");
final boolean isFeaturedImage = extras.getBoolean("isFeatured");

mWebView.post(new Runnable() {
@Override
public void run() {
mWebView.execJavaScriptFromString("ZSSEditor.updateCurrentImageMeta('" + imageMeta + "');");
}
});

if (imageRemoteId != 0) {
if (isFeaturedImage) {
mFeaturedImageId = imageRemoteId;
mEditorFragmentListener.onFeaturedImageChanged(mFeaturedImageId);
} else {
// If this image was unset as featured, clear the featured image id
if (mFeaturedImageId == imageRemoteId) {
mFeaturedImageId = 0;
mEditorFragmentListener.onFeaturedImageChanged(mFeaturedImageId);
}
}
}
}
}

Expand Down Expand Up @@ -595,7 +623,7 @@ public CharSequence getTitle() {
return "";
}

if (mSourceView.getVisibility() == View.VISIBLE) {
if (mSourceView != null && mSourceView.getVisibility() == View.VISIBLE) {
mTitle = mSourceViewTitle.getText().toString();
return StringUtils.notNullStr(mTitle);
}
Expand Down Expand Up @@ -634,7 +662,7 @@ public CharSequence getContent() {
return "";
}

if (mSourceView.getVisibility() == View.VISIBLE) {
if (mSourceView != null && mSourceView.getVisibility() == View.VISIBLE) {
mContentHtml = mSourceViewContent.getText().toString();
return StringUtils.notNullStr(mContentHtml);
}
Expand Down Expand Up @@ -665,11 +693,19 @@ public void run() {

@Override
public void appendMediaFile(final MediaFile mediaFile, final String mediaUrl, ImageLoader imageLoader) {
if (!mDomHasLoaded) {
// If the DOM hasn't loaded yet, we won't be able to add media to the ZSSEditor
// Place them in a queue to be handled when the DOM loaded callback is received
mWaitingMediaFiles.put(mediaUrl, mediaFile);
return;
}

mWebView.post(new Runnable() {
@Override
public void run() {
if (URLUtil.isNetworkUrl(mediaUrl)) {
mWebView.execJavaScriptFromString("ZSSEditor.insertImage('" + mediaUrl + "');");
String mediaId = mediaFile.getMediaId();
mWebView.execJavaScriptFromString("ZSSEditor.insertImage('" + mediaUrl + "', '" + mediaId + "');");
} else {
String id = mediaFile.getMediaId();
mWebView.execJavaScriptFromString("ZSSEditor.insertLocalImage(" + id + ", '" + mediaUrl + "');");
Expand All @@ -685,6 +721,11 @@ public void appendGallery(MediaGallery mediaGallery) {
// TODO
}

@Override
public boolean hasFailedMediaUploads() {
return (mFailedMediaIds.size() > 0);
}

@Override
public Spanned getSpannedContent() {
return null;
Expand All @@ -701,12 +742,12 @@ public void setContentPlaceholder(CharSequence placeholderText) {
}

@Override
public void onMediaUploadSucceeded(final String mediaId, final String remoteUrl) {
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 + ", '" +
remoteUrl + "');");
remoteId + "', '" + remoteUrl + "');");
mUploadingMediaIds.remove(mediaId);
}
});
Expand All @@ -717,7 +758,7 @@ public void onMediaUploadProgress(final String mediaId, final float progress) {
mWebView.post(new Runnable() {
@Override
public void run() {
String progressString = String.format("%.1f", progress);
String progressString = String.format(Locale.US, "%.1f", progress);
mWebView.execJavaScriptFromString("ZSSEditor.setProgressOnImage(" + mediaId + ", " +
progressString + ");");
}
Expand All @@ -730,6 +771,7 @@ public void onMediaUploadFailed(final String mediaId) {
@Override
public void run() {
mWebView.execJavaScriptFromString("ZSSEditor.markImageUploadFailed(" + mediaId + ");");
mFailedMediaIds.add(mediaId);
mUploadingMediaIds.remove(mediaId);
}
});
Expand All @@ -738,6 +780,8 @@ public void run() {
public void onDomLoaded() {
mWebView.post(new Runnable() {
public void run() {
mDomHasLoaded = true;

mWebView.execJavaScriptFromString("ZSSEditor.getField('zss_field_content').setMultiline('true');");

// Set title and content placeholder text
Expand All @@ -748,6 +792,14 @@ public void run() {

// Load title and content into ZSSEditor
updateVisualEditorFields();

// 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();");

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

hideActionBarIfNeeded();

// Reset all format bar buttons (in case they remained active through activity re-creation)
Expand All @@ -756,6 +808,18 @@ public void run() {
for (ToggleButton button : mTagToggleButtonMap.values()) {
button.setChecked(false);
}

// Add any media files that were placed in a queue due to the DOM not having loaded yet
if (mWaitingMediaFiles.size() > 0) {
// Image 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 (Map.Entry<String, MediaFile> entry : mWaitingMediaFiles.entrySet()) {
appendMediaFile(entry.getValue(), entry.getKey(), null);
}
mWaitingMediaFiles.clear();
}
}
});
}
Expand Down Expand Up @@ -793,15 +857,15 @@ public void run() {
});
}

public void onMediaTapped(final String mediaId, String url, final String meta, String uploadStatus) {
public void onMediaTapped(final String mediaId, String url, final JSONObject meta, String uploadStatus) {
switch (uploadStatus) {
case "uploading":
// Display 'cancel upload' dialog
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(getString(R.string.stop_upload_dialog_title));
builder.setPositiveButton(R.string.stop_upload_button, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
mEditorFragmentListener.onMediaUploadCancelClicked(mediaId);
mEditorFragmentListener.onMediaUploadCancelClicked(mediaId, true);

mWebView.post(new Runnable() {
@Override
Expand Down Expand Up @@ -832,6 +896,7 @@ public void onClick(DialogInterface dialog, int id) {
public void run() {
mWebView.execJavaScriptFromString("ZSSEditor.unmarkImageUploadFailed(" + mediaId + ");");
mWebView.execJavaScriptFromString("ZSSEditor.setProgressOnImage(" + mediaId + ", " + 0 + ");");
mFailedMediaIds.remove(mediaId);
mUploadingMediaIds.add(mediaId);
}
});
Expand All @@ -850,8 +915,14 @@ public void run() {

Bundle dialogBundle = new Bundle();

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

String imageId = JSONUtils.getString(meta, "attachment_id");
if (!imageId.isEmpty()) {
dialogBundle.putBoolean("isFeatured", mFeaturedImageId == Integer.parseInt(imageId));
}

imageSettingsDialogFragment.setArguments(dialogBundle);

Expand Down Expand Up @@ -907,6 +978,13 @@ public void onGetHtmlResponse(Map<String, String> inputArgs) {
mJavaScriptResult = inputArgs.get("result");
mGetSelectedTextCountDownLatch.countDown();
break;
case "getFailedImages":
String[] mediaIds = inputArgs.get("ids").split(",");
for (String mediaId : mediaIds) {
if (!mediaId.equals("")) {
mFailedMediaIds.add(mediaId);
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public abstract class EditorFragmentAbstract extends Fragment {
public abstract CharSequence getContent();
public abstract void appendMediaFile(MediaFile mediaFile, String imageUrl, ImageLoader imageLoader);
public abstract void appendGallery(MediaGallery mediaGallery);
public abstract boolean hasFailedMediaUploads();
public abstract void setTitlePlaceholder(CharSequence text);
public abstract void setContentPlaceholder(CharSequence text);

Expand All @@ -29,6 +30,7 @@ public abstract class EditorFragmentAbstract extends Fragment {

protected EditorFragmentListener mEditorFragmentListener;
protected boolean mFeaturedImageSupported;
protected int mFeaturedImageId;
protected String mBlogSettingMaxImageWidth;
protected ImageLoader mImageLoader;
protected boolean mDebugModeEnabled;
Expand Down Expand Up @@ -77,6 +79,10 @@ public void setBlogSettingMaxImageWidth(String blogSettingMaxImageWidth) {
mBlogSettingMaxImageWidth = blogSettingMaxImageWidth;
}

public void setFeaturedImageId(int featuredImageId) {
mFeaturedImageId = featuredImageId;
}

public void setDebugModeEnabled(boolean debugModeEnabled) {
mDebugModeEnabled = debugModeEnabled;
}
Expand Down Expand Up @@ -105,9 +111,9 @@ public interface EditorFragmentListener {
void onSettingsClicked();
void onAddMediaClicked();
void onMediaRetryClicked(String mediaId);
void onMediaUploadCancelClicked(String mediaId);
// TODO: remove saveMediaFile, it's currently needed for the legacy editor - we should have something like
// "EditorFragmentAbstract.getFeaturedImage()" returning the remote id
void onMediaUploadCancelClicked(String mediaId, boolean delete);
void onFeaturedImageChanged(int mediaId);
// TODO: remove saveMediaFile, it's currently needed for the legacy editor
void saveMediaFile(MediaFile mediaFile);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.wordpress.android.editor;

public interface EditorMediaUploadListener {
void onMediaUploadSucceeded(String localId, String remoteUrl);
void onMediaUploadSucceeded(String localId, String remoteId, String remoteUrl);
void onMediaUploadProgress(String localId, float progress);
void onMediaUploadFailed(String localId);
}
Loading

0 comments on commit 2467f23

Please sign in to comment.