[go: nahoru, domu]

Skip to content

Commit

Permalink
Squashed 'libs/editor/' changes from 68d15ed..b207f3f
Browse files Browse the repository at this point in the history
b207f3f Merge pull request #406 from wordpress-mobile/issue/405-invisible-separator-html-mode
40618cc Merge pull request #407 from wordpress-mobile/sync-wpandroid
d9e4113 Bumped Travis target SDK version to 16
4ed7e84 Bumped example app midSdk to 16
88fc198 Merge commit 'a4c57ecdddaac606bb9da697c055ccd3c78162e3' into sync-editor
af266b4 Updating gradle plugin to 2.1.2
af4f18b Escape invisible unicode separator characters in HTML mode
d62ddc3 Merge pull request #402 from wordpress-mobile/issue/401-empty-blockquote-off-new-post
5664496 Fixed removing leftover newline when clearing blockquotes on API 21+
84bc04c Merge pull request #399 from wordpress-mobile/issue/385-autocorrect-blockquote-bug
58fb473 When removing an empty blockquote in an otherwise empty post, ensure no leftover paragraph tags are left and that the placeholder is visible again
43d673a Fixed issue of being unable to toggle off empty blockquotes at the start of posts on API19 and below
49042e7 Merge branch 'develop' into issue/385-autocorrect-blockquote-bug
9b0eb28 Merge pull request #400 from wordpress-mobile/issue/398-old-api-new-post-blockquote
94c7577 Fix #398, buggy blockquote paragraphs at start of posts (API 19 and below)
93d0b11 Fix issue with autocorrect removing blockquotes at start of post when backspacing
aacd3b4 Made matching for autocorrect blockquote fix stricter
30b54bf Fix bug where autocorrect can toggle blockquote off at the start of posts
5bfd024 Correct extra break tag sometimes added in blockquotes by autocorrect
054448f Merge branch 'hotfix/5.4.1' into release/5.5
88c040e Merge commit '0e7e33bb330aea12fc3845d1c95b483845e63c6a' into hotfix/5.4.1
e116f48 Merge pull request #4165 from wordpress-mobile/issue/4147-translated-original-size
9d0a8bf Merge commit 'e8a087f9fc25fa4e0dea63715bdd1a05e92f7db0' into hotfix/5.4.1
0aec1e3 Merge branch 'hotfix/5.4.1' into issue/4147-translated-original-size
c801408 fix an issue with initial max width value in legacy image settings
c3798b5 Update to latest utils version
fbb73ab use MediaUtils.getImageWidthSettingFromString instead of referring to 'Original Size'
a22d95f Merge pull request #4161 from wordpress-mobile/issue/391editor-fix-legacy-image-settings
5032dde Merge commit '961a76c0bc931c3a484640f9fb1e3d6f7877857b' into hotfix/5.4.1
e37555f associate the mediafile with newly created image span
613c9ce Don't attempt to remove image selection formatting if the image is no longer attached to the document
e8ff0d8 On API 19 and below, don't set focus on the container when showing the edit overlay
7d03ec2 When applying the edit image overlay, give focus to the edit container instead of the image
dfed869 Merge branch 'release/5.4' into release/5.5
e98a21f check for null parameters in createWPEditImageSpanRemote
939948e fix #4137: check if context and media file is null
3f9f44e Merge branch 'release/5.4' into develop
6561baa Merge commit '5da21eda6aa762a51acc7f29263ea5b6e42b3cd2' into release/5.4
09c3838 Merge branch 'release/5.4' into develop
751e919 Block media button if action in progress
3bea532 fix editor tests
9fcf821 Don't allow publishing if insert image or insert video action in progress
021572c fix wordpress-mobile/WordPress-Editor-Android#294: Block HTML mode until insert image or video has finished
95dea3f Merge pull request #4121 from wordpress-mobile/issue/294editor-block-switch-to-html-mode-until-insert-image-finished
8edbac6 Merge branch 'release/5.4' into develop
32b150c Block media button if action in progress
fabde1c bump minSdkVersion from 14 to 16
c6f0c2a remove specific code for API < 16 in editor
a64e81f fix editor tests
45f2000 Don't allow publishing if insert image or insert video action in progress
d060f82 fix wordpress-mobile/WordPress-Editor-Android#294: Block HTML mode until insert image or video has finished
dc40200 chmod 644 image files
8d6f9f1 Merge commit '3418d3e2da66bf5ecc19b5e073794c866711e776' into develop
e334198 Merge pull request #3856 from wordpress-mobile/issue/3791-support-library-23.2
6448d26 Updating to support library 23.4.0
178aa19 Merge branch 'develop' into issue/3791-support-library-23.2
6ae6ec3 Improved error message displayed when failing to load visual editor HTML
b7a48b3 Merge branch 'develop' into feature/magic-link
efe90e8 Merge branch 'develop' into feature/magic-link
f9ef8f5 Merge branch 'develop' into feature/magic-link
ad37b12 Merge branch 'develop' into feature/magic-link
639a45b Merge branch 'develop' into feature/magic-link
57fc6b4 Merge branch 'develop' into feature/magic-link
61a180a Adding MissingPrefix ignore rule to Editor as well
6981157 Merge branch 'develop' into issue/3791-support-library-23.2
52f96bc Button is no longer screen width and extracting string resource
0039a31 Updating support library to 23.3.0
893b509 Updating to gradle 2.0
28ec9a8 Merge branch 'develop' into issue/3791-support-library-23.2
a28cf69 Updating build.gradle to latest rc3
1b9d708 Merge branch 'develop' into issue/3791-support-library-23.2
dabacd6 Updating the rest of the modules to buildToolsVersion 23.0.3
4b40e3f Merge branch 'develop' into issue/3791-support-library-23.2
ae9e36d Converting all android:src to app:srcCompat to handle VectorDrawables
2fa6196 Changing all Activity classes to AppCompatActivity to handle vector drawables
49304a0 Merge branch 'develop' into issue/3791-support-library-23.2
b28d697 Merge branch 'develop' into issue/3791-support-library-23.2
ada1d86 Updating support library to 23.2.1

git-subtree-dir: libs/editor
git-subtree-split: b207f3f831a674d28add9b391c0d55559a9d8be6
  • Loading branch information
maxme committed Jun 9, 2016
1 parent 0e7e33b commit 19320ef
Show file tree
Hide file tree
Showing 20 changed files with 219 additions and 114 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ android:
env:
global:
- GRADLE_OPTS="-XX:MaxPermSize=4g -Xmx4g"
- ANDROID_SDKS=android-14
- ANDROID_TARGET=android-14
- ANDROID_SDKS=android-16
- ANDROID_TARGET=android-16

script:
- ./gradlew build
6 changes: 3 additions & 3 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:2.1.0'
classpath 'com.android.tools.build:gradle:2.1.2'
}
}

Expand All @@ -24,7 +24,7 @@ android {
defaultConfig {
versionCode 11
versionName "1.1"
minSdkVersion 14
minSdkVersion 16
targetSdkVersion 23
}
buildTypes {
Expand All @@ -48,7 +48,7 @@ dependencies {
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:support-v4:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'org.wordpress:utils:1.9.0'
compile 'org.wordpress:utils:1.10.0'

// Test libraries
testCompile 'junit:junit:4.11'
Expand Down
4 changes: 4 additions & 0 deletions WordPressEditor/lint.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@
<issue id="InvalidPackage">
<ignore regexp="robolectric-2.4.jar" />
</issue>

<issue id="MissingPrefix">
<ignore regexp="Unexpected namespace prefix &quot;app&quot; found for tag `Image.*`" />
</issue>
</lint>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.wordpress.android.editor;

import android.app.Activity;
import android.support.v7.app.AppCompatActivity;

public class MockActivity extends Activity {
public class MockActivity extends AppCompatActivity {

}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public class EditorFragment extends EditorFragmentAbstract implements View.OnCli

private static final float TOOLBAR_ALPHA_ENABLED = 1;
private static final float TOOLBAR_ALPHA_DISABLED = 0.5f;
public static final int MAX_ACTION_TIME_MS = 2000;

private String mTitle = "";
private String mContentHtml = "";
Expand Down Expand Up @@ -106,6 +107,8 @@ public class EditorFragment extends EditorFragmentAbstract implements View.OnCli

private final Map<String, ToggleButton> mTagToggleButtonMap = new HashMap<>();

private long mActionStartedAt = -1;

public static EditorFragment newInstance(String title, String content) {
EditorFragment fragment = new EditorFragment();
Bundle args = new Bundle();
Expand Down Expand Up @@ -435,6 +438,10 @@ public void onClick(DialogInterface dialog, int which) {
}
}

public boolean isActionInProgress() {
return System.currentTimeMillis() - mActionStartedAt < MAX_ACTION_TIME_MS;
}

private void toggleHtmlMode(final ToggleButton toggleButton) {
if (!isAdded()) {
return;
Expand All @@ -443,10 +450,9 @@ private void toggleHtmlMode(final ToggleButton toggleButton) {
mEditorFragmentListener.onTrackableEvent(TrackableEvent.HTML_BUTTON_TAPPED);

// Don't switch to HTML mode if currently uploading media
if (!mUploadingMedia.isEmpty()) {
if (!mUploadingMedia.isEmpty() || isActionInProgress()) {
toggleButton.setChecked(false);

ToastUtils.showToast(getActivity(), R.string.alert_html_toggle_uploading, ToastUtils.Duration.LONG);
ToastUtils.showToast(getActivity(), R.string.alert_action_while_uploading, ToastUtils.Duration.LONG);
return;
}

Expand Down Expand Up @@ -578,6 +584,11 @@ public void onClick(View v) {
mEditorFragmentListener.onTrackableEvent(TrackableEvent.MEDIA_BUTTON_TAPPED);
((ToggleButton) v).setChecked(false);

if (isActionInProgress()) {
ToastUtils.showToast(getActivity(), R.string.alert_action_while_uploading, ToastUtils.Duration.LONG);
return;
}

if (mSourceView.getVisibility() == View.VISIBLE) {
ToastUtils.showToast(getActivity(), R.string.alert_insert_image_html_mode, ToastUtils.Duration.LONG);
} else {
Expand Down Expand Up @@ -843,6 +854,7 @@ public void run() {
mWebView.execJavaScriptFromString("ZSSEditor.insertImage('" + safeMediaUrl + "', '" + mediaId +
"');");
}
mActionStartedAt = System.currentTimeMillis();
} else {
String id = mediaFile.getMediaId();
if (mediaFile.isVideo()) {
Expand Down Expand Up @@ -1471,4 +1483,9 @@ private void applyFormattingHtmlMode(ToggleButton toggleButton, String tag) {
mSourceViewContent.setSelection(selectionEnd + endTag.length());
}
}

@Override
public void onActionFinished() {
mActionStartedAt = -1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public abstract class EditorFragmentAbstract extends Fragment {
public abstract void appendGallery(MediaGallery mediaGallery);
public abstract void setUrlForVideoPressId(String videoPressId, String url, String posterUrl);
public abstract boolean isUploadingMedia();
public abstract boolean isActionInProgress();
public abstract boolean hasFailedMediaUploads();
public abstract void removeAllFailedMediaUploads();
public abstract void setTitlePlaceholder(CharSequence text);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.wordpress.android.editor;

import android.content.Context;
import android.os.Build;
import android.os.Message;
import android.util.AttributeSet;
import android.webkit.WebView;
Expand Down Expand Up @@ -65,26 +64,18 @@ private void initReflection() throws ReflectionException {
}
Object webViewProvider;
try {
if (Build.VERSION.SDK_INT >= 16) {
// On API >= 16, the WebViewCore instance is not defined inside WebView itself but inside a
// WebViewClassic (implementation of WebViewProvider), referenced from the WebView as mProvider

// Access WebViewClassic object
Field webViewProviderField = WebView.class.getDeclaredField("mProvider");
webViewProviderField.setAccessible(true);
webViewProvider = webViewProviderField.get(this);

// Access WebViewCore object
Field webViewCoreField = webViewProvider.getClass().getDeclaredField("mWebViewCore");
webViewCoreField.setAccessible(true);
mWebViewCore = webViewCoreField.get(webViewProvider);
} else {
// On API < 16, the WebViewCore is directly accessible from the WebView
// Access WebViewCore object
Field webViewCoreField = WebView.class.getDeclaredField("mWebViewCore");
webViewCoreField.setAccessible(true);
mWebViewCore = webViewCoreField.get(this);
}
// On API >= 16, the WebViewCore instance is not defined inside WebView itself but inside a
// WebViewClassic (implementation of WebViewProvider), referenced from the WebView as mProvider

// Access WebViewClassic object
Field webViewProviderField = WebView.class.getDeclaredField("mProvider");
webViewProviderField.setAccessible(true);
webViewProvider = webViewProviderField.get(this);

// Access WebViewCore object
Field webViewCoreField = webViewProvider.getClass().getDeclaredField("mWebViewCore");
webViewCoreField.setAccessible(true);
mWebViewCore = webViewCoreField.get(webViewProvider);

// Access WebViewCore#sendMessage(Message) method
if (mWebViewCore != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.json.JSONException;
import org.json.JSONObject;
import org.wordpress.android.util.AppLog;
import org.wordpress.android.util.MediaUtils;
import org.wordpress.android.util.ToastUtils;

import java.util.Arrays;
Expand All @@ -41,12 +42,9 @@
* when the fragment is dismissed to restore it.
*/
public class ImageSettingsDialogFragment extends DialogFragment {

public static final int IMAGE_SETTINGS_DIALOG_REQUEST_CODE = 5;
public static final String IMAGE_SETTINGS_DIALOG_TAG = "image-settings";

private static final int DEFAULT_MAX_IMAGE_WIDTH = 1024;

private JSONObject mImageMeta;
private int mMaxImageWidth;

Expand Down Expand Up @@ -170,7 +168,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa

mLinkTo.setText(mImageMeta.getString("linkUrl"));

mMaxImageWidth = getMaximumImageWidth(mImageMeta.getInt("naturalWidth"), bundle.getString("maxWidth"));
mMaxImageWidth = MediaUtils.getMaximumImageWidth(mImageMeta.getInt("naturalWidth"),
bundle.getString("maxWidth"));

setupWidthSeekBar(widthSeekBar, mWidthText, mImageMeta.getInt("width"));

Expand Down Expand Up @@ -396,34 +395,6 @@ public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
});
}

/**
* Calculate and return the maximum allowed image width by comparing the width of the image at its full size with
* the maximum upload width set in the blog settings
* @param naturalImageWidth the image's natural (full) width
* @param imageWidthBlogSettingString the maximum upload width set in the blog settings
* @return
*/
public static int getMaximumImageWidth(int naturalImageWidth, String imageWidthBlogSettingString) {
int imageWidthBlogSetting = Integer.MAX_VALUE;

if (!imageWidthBlogSettingString.equals("Original Size")) {
try {
imageWidthBlogSetting = Integer.valueOf(imageWidthBlogSettingString);
} catch (NumberFormatException e) {
AppLog.e(AppLog.T.EDITOR, e);
}
}

int imageWidthPictureSetting = naturalImageWidth == 0 ? Integer.MAX_VALUE : naturalImageWidth;

if (Math.min(imageWidthPictureSetting, imageWidthBlogSetting) == Integer.MAX_VALUE) {
// Default value in case of errors reading the picture size and the blog settings is set to Original size
return DEFAULT_MAX_IMAGE_WIDTH;
} else {
return Math.min(imageWidthPictureSetting, imageWidthBlogSetting);
}
}

/**
* Return the integer value of the width EditText, adjusted to be within the given min and max, and stripped of the
* 'px' units
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public class JsCallbackReceiver {

private static final String CALLBACK_RESPONSE_STRING = "callback-response-string";

private static final String CALLBACK_ACTION_FINISHED = "callback-action-finished";

private final OnJsEditorStateChangedListener mListener;

private Set<String> mPreviousStyleSet = new HashSet<>();
Expand Down Expand Up @@ -224,6 +226,9 @@ public void executeCallback(String callbackId, String params) {
}
mListener.onGetHtmlResponse(Utils.buildMapFromKeyValuePairs(responseDataSet));
break;
case CALLBACK_ACTION_FINISHED:
mListener.onActionFinished();
break;
default:
AppLog.d(AppLog.T.EDITOR, "Unhandled callback: " + callbackId + ":" + params);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,17 @@
import org.wordpress.android.util.DisplayUtils;
import org.wordpress.android.util.ImageUtils;
import org.wordpress.android.util.MediaUtils;
import org.wordpress.android.util.ToastUtils;
import org.wordpress.android.util.ToastUtils.Duration;
import org.wordpress.android.util.helpers.MediaFile;
import org.wordpress.android.util.helpers.MediaGallery;
import org.wordpress.android.util.helpers.MediaGalleryImageSpan;
import org.wordpress.android.util.helpers.WPImageSpan;
import org.wordpress.android.util.helpers.WPUnderlineSpan;
import org.wordpress.android.util.widgets.WPEditText;

import java.util.Locale;

public class LegacyEditorFragment extends EditorFragmentAbstract implements TextWatcher,
WPEditText.OnSelectionChangedListener, View.OnTouchListener {
public static final int ACTIVITY_REQUEST_CODE_CREATE_LINK = 4;
Expand Down Expand Up @@ -464,6 +468,9 @@ public void onClick(View v) {
};

private WPEditImageSpan createWPEditImageSpanLocal(Context context, MediaFile mediaFile) {
if (context == null || mediaFile == null || mediaFile.getFilePath() == null) {
return null;
}
Uri imageUri = Uri.parse(mediaFile.getFilePath());
Bitmap thumbnailBitmap;
if (MediaUtils.isVideo(imageUri.toString())) {
Expand All @@ -478,11 +485,15 @@ private WPEditImageSpan createWPEditImageSpanLocal(Context context, MediaFile me
}
}
WPEditImageSpan imageSpan = new WPEditImageSpan(context, thumbnailBitmap, imageUri);
mediaFile.setWidth(MediaUtils.getMinimumImageWidth(context, imageUri, mBlogSettingMaxImageWidth));
mediaFile.setWidth(MediaUtils.getMaximumImageWidth(context, imageUri, mBlogSettingMaxImageWidth));
imageSpan.setMediaFile(mediaFile);
return imageSpan;
}

private WPEditImageSpan createWPEditImageSpanRemote(Context context, MediaFile mediaFile) {
if (context == null || mediaFile == null || mediaFile.getFileURL() == null) {
return null;
}
int drawable = mediaFile.isVideo() ? R.drawable.media_movieclip : R.drawable.legacy_dashicon_format_image_big_grey;
Uri uri = Uri.parse(mediaFile.getFileURL());
WPEditImageSpan imageSpan = new WPEditImageSpan(context, drawable, uri);
Expand Down Expand Up @@ -733,7 +744,6 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
alignmentSpinner.setAdapter(adapter);

imageWidthText.setText(String.valueOf(mediaFile.getWidth()) + "px");
seekBar.setProgress(mediaFile.getWidth());
titleText.setText(mediaFile.getTitle());
caption.setText(mediaFile.getCaption());
Expand All @@ -749,9 +759,10 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

alignmentSpinner.setSelection(mediaFile.getHorizontalAlignment(), true);

final int maxWidth = MediaUtils.getMinimumImageWidth(getActivity(),
final int maxWidth = MediaUtils.getMaximumImageWidth(getActivity(),
imageSpan.getImageSource(), mBlogSettingMaxImageWidth);
seekBar.setMax(maxWidth / 10);
imageWidthText.setText(String.format(Locale.US, "%dpx", maxWidth));
if (mediaFile.getWidth() != 0) {
seekBar.setProgress(mediaFile.getWidth() / 10);
}
Expand All @@ -769,7 +780,7 @@ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (progress == 0) {
progress = 1;
}
imageWidthText.setText(progress * 10 + "px");
imageWidthText.setText(String.format(Locale.US, "%dpx", progress * 10));
}
});

Expand Down Expand Up @@ -1046,6 +1057,12 @@ protected WPEditImageSpan doInBackground(Void... voids) {
}

protected void onPostExecute(WPEditImageSpan imageSpan) {
if (imageSpan == null) {
if (isAdded()) {
ToastUtils.showToast(getActivity(), R.string.alert_error_adding_media, Duration.LONG);
}
return ;
}
// Insert the WPImageSpan in the content field
int selectionStart = mStart;
int selectionEnd = mEnd;
Expand Down Expand Up @@ -1164,11 +1181,14 @@ public void removeAllFailedMediaUploads() {}

@Override
public void setTitlePlaceholder(CharSequence text) {

}

@Override
public void setContentPlaceholder(CharSequence text) {
}

@Override
public boolean isActionInProgress() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ public interface OnJsEditorStateChangedListener {
void onMediaReplaced(String mediaId);
void onVideoPressInfoRequested(String videoId);
void onGetHtmlResponse(Map<String, String> responseArgs);
void onActionFinished();
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static String getHtmlFromFile(Activity activity, String filename) {
InputStream in = assetManager.open(filename);
return getStringFromInputStream(in);
} catch (IOException e) {
AppLog.e(AppLog.T.EDITOR, e.getMessage());
AppLog.e(AppLog.T.EDITOR, "Unable to load editor HTML (is the assets symlink working?): " + e.getMessage());
return null;
}
}
Expand All @@ -61,6 +61,11 @@ public static String escapeHtml(String html) {
html = html.replace("'", "\\'");
html = html.replace("\r", "\\r");
html = html.replace("\n", "\\n");

// Escape invisible line separator (U+2028) and paragraph separator (U+2029) characters
// https://github.com/wordpress-mobile/WordPress-Editor-Android/issues/405
html = html.replace("\u2028", "\\u2028");
html = html.replace("\u2029", "\\u2029");
}
return html;
}
Expand Down
Loading

0 comments on commit 19320ef

Please sign in to comment.