Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,8 @@ public boolean onOptionsItemSelected(final MenuItem item) {
MediaUploadService mediaUploadService = MediaUploadService.getInstance();

// Disable format bar buttons while a media upload is in progress
if ((mediaUploadService != null && mediaUploadService.hasUploads()) || mEditorFragment.isUploadingMedia()) {
if ((mediaUploadService != null && mediaUploadService.hasUploads()) || mEditorFragment.isUploadingMedia() ||
mEditorFragment.isActionInProgress()) {
ToastUtils.showToast(this, R.string.editor_toast_uploading_please_wait, Duration.SHORT);
return false;
}
Expand Down
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
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 @@ -1164,11 +1164,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 @@ -15,7 +15,7 @@
<string name="uploading_gallery_placeholder">Uploading gallery…</string>

<string name="alert_insert_image_html_mode">Can\'t insert media directly in HTML mode. Please switch back to visual mode.</string>
<string name="alert_html_toggle_uploading">You are currently uploading media. Please wait until this completes.</string>
<string name="alert_action_while_uploading">You are currently uploading media. Please wait until this completes.</string>

<string name="stop_upload_dialog_title">Stop uploading?</string>
<string name="stop_upload_button">Stop Upload</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ public boolean isUploadingMedia() {
return false;
}

@Override
public boolean isActionInProgress() {
return false;
}

@Override
public boolean hasFailedMediaUploads() {
return false;
Expand Down
2 changes: 2 additions & 0 deletions libs/editor/libs/editor-common/assets/ZSSRichTextEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -1205,6 +1205,7 @@ ZSSEditor.insertImage = function(url, remoteId, alt) {
this.insertHTMLWrappedInParagraphTags(html);

this.sendEnabledStyles();
this.callback("callback-action-finished");
};

/**
Expand Down Expand Up @@ -1516,6 +1517,7 @@ ZSSEditor.insertVideo = function(videoURL, posterURL, videopressID) {
this.insertHTMLWrappedInParagraphTags(html);

this.sendEnabledStyles();
this.callback("callback-action-finished");
};

/**
Expand Down