mirror of
https://github.com/leanote/leanote-android.git
synced 2025-10-15 23:00:55 +00:00
be compatible with desktop-app
This commit is contained in:
@@ -7,6 +7,25 @@
|
|||||||
<script src="./tinymce/tinymce.min.js"></script>
|
<script src="./tinymce/tinymce.min.js"></script>
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
.without-border {outline: 0px solid transparent;}
|
.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>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
@@ -190,6 +209,11 @@
|
|||||||
return tinyMCE.editors[0].selection.getNode().getAttribute('href');
|
return tinyMCE.editors[0].selection.getNode().getAttribute('href');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getContent() {
|
||||||
|
var body = tinyMCE.$(tinyMCE.editors[0].getBody()).clone();
|
||||||
|
return $(body).clone().html();
|
||||||
|
}
|
||||||
|
|
||||||
function getListState() {
|
function getListState() {
|
||||||
var node = tinyMCE.editors[0].selection.getNode()
|
var node = tinyMCE.editors[0].selection.getNode()
|
||||||
var parents = tinymce.dom.DomQuery(node).parents();
|
var parents = tinymce.dom.DomQuery(node).parents();
|
||||||
|
@@ -4,6 +4,7 @@ package org.houxg.leamonax.editor;
|
|||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
|
|
||||||
|
import org.houxg.leamonax.utils.AppLog;
|
||||||
import org.houxg.leamonax.utils.HtmlUtils;
|
import org.houxg.leamonax.utils.HtmlUtils;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
@@ -63,13 +64,16 @@ public class RichTextEditor extends Editor implements TinnyMceCallback.TinnyMceL
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setContent(String content) {
|
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
|
@Override
|
||||||
public String getContent() {
|
public String getContent() {
|
||||||
String content = HtmlUtils.unescapeHtml(new JsRunner().get(mWebView, "tinyMCE.editors[0].getContent();"));
|
String content = new JsRunner().get(mWebView, "getContent();");
|
||||||
content = content.replaceAll("\\n", "");
|
content = HtmlUtils.unescapeHtml(content);
|
||||||
|
AppLog.i(TAG, "unescaped=" + content);
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -6,16 +6,19 @@ import android.content.Intent;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
|
import org.houxg.leamonax.BuildConfig;
|
||||||
import org.houxg.leamonax.R;
|
import org.houxg.leamonax.R;
|
||||||
import org.houxg.leamonax.database.AppDataBase;
|
import org.houxg.leamonax.database.AppDataBase;
|
||||||
import org.houxg.leamonax.model.Note;
|
import org.houxg.leamonax.model.Note;
|
||||||
import org.houxg.leamonax.service.NoteService;
|
import org.houxg.leamonax.service.NoteService;
|
||||||
import org.houxg.leamonax.ui.edit.EditorFragment;
|
import org.houxg.leamonax.ui.edit.EditorFragment;
|
||||||
import org.houxg.leamonax.ui.edit.NoteEditActivity;
|
import org.houxg.leamonax.ui.edit.NoteEditActivity;
|
||||||
|
import org.houxg.leamonax.utils.AppLog;
|
||||||
import org.houxg.leamonax.utils.DialogDisplayer;
|
import org.houxg.leamonax.utils.DialogDisplayer;
|
||||||
import org.houxg.leamonax.utils.NetworkUtils;
|
import org.houxg.leamonax.utils.NetworkUtils;
|
||||||
import org.houxg.leamonax.utils.ToastUtils;
|
import org.houxg.leamonax.utils.ToastUtils;
|
||||||
@@ -69,6 +72,8 @@ public class NotePreviewActivity extends BaseActivity implements EditorFragment.
|
|||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
getMenuInflater().inflate(R.menu.preview, 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);
|
return super.onCreateOptionsMenu(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,6 +83,22 @@ public class NotePreviewActivity extends BaseActivity implements EditorFragment.
|
|||||||
case R.id.action_edit:
|
case R.id.action_edit:
|
||||||
startActivityForResult(NoteEditActivity.getOpenIntent(this, mNote.getId(), false), REQ_EDIT);
|
startActivityForResult(NoteEditActivity.getOpenIntent(this, mNote.getId(), false), REQ_EDIT);
|
||||||
return true;
|
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);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
@@ -201,7 +222,7 @@ public class NotePreviewActivity extends BaseActivity implements EditorFragment.
|
|||||||
mActionContainer.setVisibility(mNote.isDirty() ? View.VISIBLE : View.GONE);
|
mActionContainer.setVisibility(mNote.isDirty() ? View.VISIBLE : View.GONE);
|
||||||
mRevertBtn.setVisibility(mNote.getUsn() > 0 ? 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());
|
mEditorFragment.setContent(mNote.getContent());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -214,11 +214,11 @@ public class NoteEditActivity extends BaseActivity implements EditorFragment.Edi
|
|||||||
public void call(Subscriber<? super Wrapper> subscriber) {
|
public void call(Subscriber<? super Wrapper> subscriber) {
|
||||||
if (!subscriber.isUnsubscribed()) {
|
if (!subscriber.isUnsubscribed()) {
|
||||||
updateNote();
|
updateNote();
|
||||||
if (mModified.note.isDirty()
|
if (mOriginal.note.hasChanges(mModified.note)
|
||||||
|| mOriginal.note.hasChanges(mModified.note)
|
|
||||||
|| isLocalNote(mModified.note)
|
|
||||||
|| isTitleContentEmpty(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.onNext(mModified);
|
||||||
}
|
}
|
||||||
subscriber.onCompleted();
|
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"
|
app:showAsAction="always"
|
||||||
android:title="@string/edit"/>
|
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>
|
</menu>
|
Reference in New Issue
Block a user