mirror of
https://github.com/leanote/leanote-android.git
synced 2025-10-14 22:25:40 +00:00
be compatible with desktop-app
This commit is contained in:
@@ -7,6 +7,25 @@
|
||||
<script src="./tinymce/tinymce.min.js"></script>
|
||||
<style type="text/css">
|
||||
.without-border {outline: 0px solid transparent;}
|
||||
.ace-tomorrow {
|
||||
overflow: auto;
|
||||
font-family: monospace, monospace;
|
||||
font-size: 18px;
|
||||
border: 1px solid rgb(221, 219, 204);
|
||||
border-top-left-radius: 3px;
|
||||
border-top-right-radius: 3px;
|
||||
border-bottom-right-radius: 3px;
|
||||
border-bottom-left-radius: 3px;
|
||||
margin-top: 0px;
|
||||
margin-bottom: 40px;
|
||||
padding: 15px 20px;
|
||||
color: rgb(66, 66, 66);
|
||||
line-height: normal;
|
||||
widows: 1;
|
||||
background-color: rgb(241, 240, 234);
|
||||
background-position: initial initial;
|
||||
background-repeat: initial initial;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
@@ -190,6 +209,11 @@
|
||||
return tinyMCE.editors[0].selection.getNode().getAttribute('href');
|
||||
}
|
||||
|
||||
function getContent() {
|
||||
var body = tinyMCE.$(tinyMCE.editors[0].getBody()).clone();
|
||||
return $(body).clone().html();
|
||||
}
|
||||
|
||||
function getListState() {
|
||||
var node = tinyMCE.editors[0].selection.getNode()
|
||||
var parents = tinymce.dom.DomQuery(node).parents();
|
||||
|
@@ -4,6 +4,7 @@ package org.houxg.leamonax.editor;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.webkit.WebView;
|
||||
|
||||
import org.houxg.leamonax.utils.AppLog;
|
||||
import org.houxg.leamonax.utils.HtmlUtils;
|
||||
|
||||
import java.util.Locale;
|
||||
@@ -63,13 +64,16 @@ public class RichTextEditor extends Editor implements TinnyMceCallback.TinnyMceL
|
||||
|
||||
@Override
|
||||
public void setContent(String content) {
|
||||
execJs(String.format(Locale.US, "tinyMCE.editors[0].setContent('%s');", HtmlUtils.escapeHtml(content)));
|
||||
content = HtmlUtils.escapeHtml(content);
|
||||
AppLog.i(TAG, "escaped=" + content);
|
||||
execJs(String.format(Locale.US, "tinyMCE.editors[0].setContent('%s');", content));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getContent() {
|
||||
String content = HtmlUtils.unescapeHtml(new JsRunner().get(mWebView, "tinyMCE.editors[0].getContent();"));
|
||||
content = content.replaceAll("\\n", "");
|
||||
String content = new JsRunner().get(mWebView, "getContent();");
|
||||
content = HtmlUtils.unescapeHtml(content);
|
||||
AppLog.i(TAG, "unescaped=" + content);
|
||||
return content;
|
||||
}
|
||||
|
||||
|
@@ -6,16 +6,19 @@ import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.text.TextUtils;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
|
||||
import org.houxg.leamonax.BuildConfig;
|
||||
import org.houxg.leamonax.R;
|
||||
import org.houxg.leamonax.database.AppDataBase;
|
||||
import org.houxg.leamonax.model.Note;
|
||||
import org.houxg.leamonax.service.NoteService;
|
||||
import org.houxg.leamonax.ui.edit.EditorFragment;
|
||||
import org.houxg.leamonax.ui.edit.NoteEditActivity;
|
||||
import org.houxg.leamonax.utils.AppLog;
|
||||
import org.houxg.leamonax.utils.DialogDisplayer;
|
||||
import org.houxg.leamonax.utils.NetworkUtils;
|
||||
import org.houxg.leamonax.utils.ToastUtils;
|
||||
@@ -69,6 +72,8 @@ public class NotePreviewActivity extends BaseActivity implements EditorFragment.
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.preview, menu);
|
||||
menu.findItem(R.id.action_print).setVisible(BuildConfig.DEBUG);
|
||||
menu.findItem(R.id.action_get).setVisible(BuildConfig.DEBUG);
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
|
||||
@@ -78,6 +83,22 @@ public class NotePreviewActivity extends BaseActivity implements EditorFragment.
|
||||
case R.id.action_edit:
|
||||
startActivityForResult(NoteEditActivity.getOpenIntent(this, mNote.getId(), false), REQ_EDIT);
|
||||
return true;
|
||||
case R.id.action_get:
|
||||
Observable.create(
|
||||
new Observable.OnSubscribe<Void>() {
|
||||
@Override
|
||||
public void call(Subscriber<? super Void> subscriber) {
|
||||
mEditorFragment.getContent();
|
||||
subscriber.onNext(null);
|
||||
subscriber.onCompleted();
|
||||
}
|
||||
})
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe();
|
||||
return true;
|
||||
case R.id.action_print:
|
||||
AppLog.i(TAG, mNote.getContent());
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
@@ -201,7 +222,7 @@ public class NotePreviewActivity extends BaseActivity implements EditorFragment.
|
||||
mActionContainer.setVisibility(mNote.isDirty() ? View.VISIBLE : View.GONE);
|
||||
mRevertBtn.setVisibility(mNote.getUsn() > 0 ? View.VISIBLE : View.GONE);
|
||||
|
||||
mEditorFragment.setTitle(mNote.getTitle());
|
||||
mEditorFragment.setTitle(TextUtils.isEmpty(mNote.getTitle()) ? getString(R.string.untitled) : mNote.getTitle());
|
||||
mEditorFragment.setContent(mNote.getContent());
|
||||
}
|
||||
}
|
||||
|
@@ -214,11 +214,11 @@ public class NoteEditActivity extends BaseActivity implements EditorFragment.Edi
|
||||
public void call(Subscriber<? super Wrapper> subscriber) {
|
||||
if (!subscriber.isUnsubscribed()) {
|
||||
updateNote();
|
||||
if (mModified.note.isDirty()
|
||||
|| mOriginal.note.hasChanges(mModified.note)
|
||||
|| isLocalNote(mModified.note)
|
||||
if (mOriginal.note.hasChanges(mModified.note)
|
||||
|| isTitleContentEmpty(mModified.note)
|
||||
|| !CollectionUtils.isTheSame(mOriginal.tags, mModified.tags)) {
|
||||
|| !CollectionUtils.isTheSame(mOriginal.tags, mModified.tags)
|
||||
|| mModified.note.isDirty()
|
||||
|| isLocalNote(mModified.note)) {
|
||||
subscriber.onNext(mModified);
|
||||
}
|
||||
subscriber.onCompleted();
|
||||
|
18
app/src/main/java/org/houxg/leamonax/utils/AppLog.java
Normal file
18
app/src/main/java/org/houxg/leamonax/utils/AppLog.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package org.houxg.leamonax.utils;
|
||||
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
public class AppLog {
|
||||
|
||||
private static final int LOG_LIMIT = 3000;
|
||||
|
||||
public static void i(String tag, String message) {
|
||||
do {
|
||||
int offset = Math.min(message.length(), LOG_LIMIT);
|
||||
String print = message.substring(0, offset);
|
||||
message = message.substring(offset);
|
||||
Log.i(tag, print);
|
||||
} while (message.length() > 0);
|
||||
}
|
||||
}
|
@@ -7,4 +7,14 @@
|
||||
app:showAsAction="always"
|
||||
android:title="@string/edit"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/action_print"
|
||||
app:showAsAction="never"
|
||||
android:title="Print"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/action_get"
|
||||
app:showAsAction="never"
|
||||
android:title="Get"/>
|
||||
|
||||
</menu>
|
Reference in New Issue
Block a user