mirror of
https://github.com/leanote/leanote-android.git
synced 2026-01-13 07:03:54 +08:00
编辑笔记页面: 笔记加载完,才能保存
This commit is contained in:
@@ -242,6 +242,13 @@
|
||||
function isChildOfBody(elm) {
|
||||
return tinyMCE.editors[0].$.contains(tinyMCE.editors[0].getBody(), elm);
|
||||
}
|
||||
|
||||
function setTitleAndContent(title, content) {
|
||||
setTitle(title);
|
||||
tinyMCE.editors[0].setContent(content);
|
||||
hostApp.loadCompleted();
|
||||
return "";
|
||||
}
|
||||
</script>
|
||||
|
||||
</html>
|
||||
|
||||
@@ -10,5 +10,12 @@
|
||||
$('#title').attr('placeholderText', '标题')
|
||||
$('#wmd-input-sub').attr('placeholderText', '内容')
|
||||
}
|
||||
|
||||
function setTitleAndContent(title, content) {
|
||||
document.getElementById('title').innerHTML = title;
|
||||
ZSSEditor.getField('mdEditor').setHTML(content);
|
||||
hostApp.loadCompleted();
|
||||
return "";
|
||||
}
|
||||
</script>
|
||||
</body></html>
|
||||
@@ -73,6 +73,8 @@ public abstract class Editor {
|
||||
return "";
|
||||
}
|
||||
|
||||
public abstract void setTitleAndContent(String title, String content);
|
||||
|
||||
public interface EditorListener {
|
||||
void onPageLoaded();
|
||||
void onClickedLink(String title, String url);
|
||||
|
||||
15
app/src/main/java/org/houxg/leamonax/editor/HostApp.java
Normal file
15
app/src/main/java/org/houxg/leamonax/editor/HostApp.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package org.houxg.leamonax.editor;
|
||||
|
||||
import android.webkit.JavascriptInterface;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.houxg.leamonax.model.CompleteEvent;
|
||||
|
||||
public class HostApp {
|
||||
|
||||
@JavascriptInterface
|
||||
public void loadCompleted() {
|
||||
EventBus.getDefault().post(new CompleteEvent());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,6 +25,7 @@ public class MarkdownEditor extends Editor {
|
||||
mWebView = view;
|
||||
mWebView.setScrollBarStyle(SCROLLBARS_OUTSIDE_OVERLAY);
|
||||
mWebView.getSettings().setJavaScriptEnabled(true);
|
||||
mWebView.addJavascriptInterface(new HostApp(), "hostApp");
|
||||
mWebView.setWebViewClient(new Editor.EditorClient());
|
||||
mWebView.setWebChromeClient(new WebChromeClient());
|
||||
mWebView.loadUrl("file:///android_asset/markdownEditor/editor-mobile.min.html?lang=" + Locale.getDefault().getLanguage());
|
||||
@@ -71,6 +72,12 @@ public class MarkdownEditor extends Editor {
|
||||
return content;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTitleAndContent(String title, String content) {
|
||||
String script = String.format(Locale.US, "setTitleAndContent('%s', '%s');", HtmlUtils.escapeHtml(title), HtmlUtils.escapeHtml(content));
|
||||
new JsRunner().get(mWebView, script);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insertImage(String title, String url) {
|
||||
execJs(String.format(Locale.US, "ZSSEditor.insertImage('%s', '%s');", url, title));
|
||||
|
||||
@@ -29,6 +29,7 @@ public class RichTextEditor extends Editor implements TinnyMceCallback.TinnyMceL
|
||||
mWebView = view;
|
||||
mWebView.setScrollBarStyle(SCROLLBARS_OUTSIDE_OVERLAY);
|
||||
mWebView.getSettings().setJavaScriptEnabled(true);
|
||||
mWebView.addJavascriptInterface(new HostApp(), "hostApp");
|
||||
mWebView.setWebViewClient(new EditorClient());
|
||||
mWebView.setWebChromeClient(new EditorChromeClient());
|
||||
mWebView.addJavascriptInterface(new TinnyMceCallback(this), JS_CALLBACK_HANDLER);
|
||||
@@ -81,6 +82,14 @@ public class RichTextEditor extends Editor implements TinnyMceCallback.TinnyMceL
|
||||
return content;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTitleAndContent(String title, String content) {
|
||||
content = HtmlUtils.escapeHtml(content);
|
||||
XLog.i(TAG + "escaped=" + content);
|
||||
String script = String.format(Locale.US, "setTitleAndContent('%s', '%s');", title, content);
|
||||
new JsRunner().get(mWebView, script);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insertImage(String title, String url) {
|
||||
execJs(String.format(Locale.US, "insertImage('%s');", url));
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
package org.houxg.leamonax.model;
|
||||
|
||||
public class CompleteEvent {
|
||||
}
|
||||
@@ -166,6 +166,10 @@ public class EditorFragment extends Fragment implements Editor.EditorListener {
|
||||
mEditor.setContent(content);
|
||||
}
|
||||
|
||||
public void setTitleAndContent(String title, String content) {
|
||||
mEditor.setTitleAndContent(title, content);
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return mEditor.getTitle();
|
||||
}
|
||||
|
||||
@@ -14,10 +14,14 @@ import android.view.ViewGroup;
|
||||
|
||||
import com.elvishew.xlog.XLog;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
import org.houxg.leamonax.Leamonax;
|
||||
import org.houxg.leamonax.R;
|
||||
import org.houxg.leamonax.ReadableException;
|
||||
import org.houxg.leamonax.database.NoteDataStore;
|
||||
import org.houxg.leamonax.model.CompleteEvent;
|
||||
import org.houxg.leamonax.model.Note;
|
||||
import org.houxg.leamonax.model.Tag;
|
||||
import org.houxg.leamonax.service.NoteFileService;
|
||||
@@ -58,6 +62,7 @@ public class NoteEditActivity extends BaseActivity implements EditorFragment.Edi
|
||||
private Wrapper mOriginal;
|
||||
private Wrapper mModified;
|
||||
private boolean mIsNewNote;
|
||||
private boolean mIsMenuSaveEnabled = false;
|
||||
|
||||
private LeaViewPager mPager;
|
||||
|
||||
@@ -81,6 +86,7 @@ public class NoteEditActivity extends BaseActivity implements EditorFragment.Edi
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
EventBus.getDefault().register(this);
|
||||
mIsNewNote = getIntent().getBooleanExtra(EXT_IS_NEW_NOTE, false);
|
||||
mOriginal = new Wrapper(NoteDataStore.getByLocalId(noteLocalId));
|
||||
mModified = new Wrapper(NoteDataStore.getByLocalId(noteLocalId));
|
||||
@@ -114,12 +120,17 @@ public class NoteEditActivity extends BaseActivity implements EditorFragment.Edi
|
||||
intent.setAction("android.appwidget.action.APPWIDGET_UPDATE");
|
||||
this.sendBroadcast(intent);
|
||||
super.onDestroy();
|
||||
EventBus.getDefault().unregister(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(final MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_save:
|
||||
if (!mIsMenuSaveEnabled) {
|
||||
ToastUtils.show(this, R.string.note_not_load_completed);
|
||||
return true;
|
||||
}
|
||||
filterUnchanged()
|
||||
.doOnNext(new Action1<Wrapper>() {
|
||||
@Override
|
||||
@@ -323,8 +334,12 @@ public class NoteEditActivity extends BaseActivity implements EditorFragment.Edi
|
||||
|
||||
@Override
|
||||
public void onInitialized() {
|
||||
mEditorFragment.setTitle(mModified.note.getTitle());
|
||||
mEditorFragment.setContent(mModified.note.getContent());
|
||||
mEditorFragment.setTitleAndContent(mModified.note.getTitle(), mModified.note.getContent());
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onEvent(CompleteEvent event) {
|
||||
mIsMenuSaveEnabled = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -121,4 +121,5 @@
|
||||
<string name="allow">允许</string>
|
||||
<string name="lea_api_error_need_upgrade_account">需要升级蚂蚁笔记账户</string>
|
||||
<string name="webview_select_picture">选择图片</string>
|
||||
<string name="note_not_load_completed">笔记未加载完,不能保存</string>
|
||||
</resources>
|
||||
@@ -123,4 +123,5 @@
|
||||
<string name="allow">allow</string>
|
||||
<string name="lea_api_error_need_upgrade_account">need upgrade Leanote account</string>
|
||||
<string name="webview_select_picture">Select Picture</string>
|
||||
<string name="note_not_load_completed">Notes are not loaded and cannot be saved</string>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user