Kaydet (Commit) fc88892e authored tarafından Mert Tümer's avatar Mert Tümer Kaydeden (comit) Thorsten Behrens

.uno:Save callback for the Android Viewer

Change-Id: Ic2e16985e52869092faa2a31a59a85cb77b8e28c
Signed-off-by: 's avatarMert Tümer <merttumer7@gmail.com>
Reviewed-on: https://gerrit.libreoffice.org/51506Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarThorsten Behrens <Thorsten.Behrens@CIB.de>
üst 19ca4e8a
......@@ -213,7 +213,7 @@ public class Document {
* @param command - the command, like ".uno:Bold"
* @param arguments
*/
public native void postUnoCommand(String command, String arguments);
public native void postUnoCommand(String command, String arguments, boolean notifyWhenFinished);
/**
* Change text selection.
......
......@@ -62,6 +62,9 @@ public class InvalidationHandler implements Document.MessageCallback, Office.Mes
case Document.CALLBACK_INVALIDATE_TILES:
invalidateTiles(payload);
break;
case Document.CALLBACK_UNO_COMMAND_RESULT:
unoCommandResult(payload);
break;
case Document.CALLBACK_INVALIDATE_VISIBLE_CURSOR:
invalidateCursor(payload);
break;
......@@ -116,10 +119,24 @@ public class InvalidationHandler implements Document.MessageCallback, Office.Mes
case Document.CALLBACK_DOCUMENT_SIZE_CHANGED:
pageSizeChanged(payload);
default:
Log.d(LOGTAG, "LOK_CALLBACK uncaught: " + messageID + " : " + payload);
}
}
private void unoCommandResult(String payload) {
try {
JSONObject payloadObject = new JSONObject(payload);
if (payloadObject.getString("commandName").equals(".uno:Save")) {
if (payloadObject.getString("success").equals("true")) {
mContext.saveFilesToCloud();
}
}
}catch(JSONException e){
e.printStackTrace();
}
}
private void cellFormula(final String payload) {
LOKitShell.getMainHandler().post(new Runnable() {
@Override
......
......@@ -41,6 +41,8 @@ public class LOEvent implements Comparable<LOEvent> {
public static final int UPDATE_CALC_HEADERS = 20;
public static final int REFRESH = 21;
public static final int PAGE_SIZE_CHANGED = 22;
public static final int UNO_COMMAND_NOTIFY = 23;
public final int mType;
public int mPriority = 0;
......@@ -60,6 +62,7 @@ public class LOEvent implements Comparable<LOEvent> {
public String mValue;
public int mPageWidth;
public int mPageHeight;
public boolean mNotify;
public LOEvent(int type) {
mType = type;
......@@ -78,6 +81,14 @@ public class LOEvent implements Comparable<LOEvent> {
mValue = null;
}
public LOEvent(int type, String someString, boolean notify) {
mType = type;
mTypeString = "String";
mString = someString;
mValue = null;
mNotify = notify;
}
public LOEvent(int type, String key, String value) {
mType = type;
mTypeString = "key / value";
......
......@@ -366,6 +366,12 @@ class LOKitThread extends Thread {
case LOEvent.UPDATE_CALC_HEADERS:
updateCalcHeaders();
break;
case LOEvent.UNO_COMMAND_NOTIFY:
if (null == mTileProvider)
Log.e(LOGTAG, "no mTileProvider when trying to process "+event.mValue+" from UNO_COMMAND "+event.mString);
else
mTileProvider.postUnoCommand(event.mString, event.mValue, event.mNotify);
break;
case LOEvent.REFRESH:
refresh();
break;
......
......@@ -584,7 +584,17 @@ class LOKitTileProvider implements TileProvider {
*/
@Override
public void postUnoCommand(String command, String arguments) {
mDocument.postUnoCommand(command, arguments);
postUnoCommand(command, arguments, false);
}
/**
* @param command
* @param arguments
* @param notifyWhenFinished
*/
@Override
public void postUnoCommand(String command, String arguments, boolean notifyWhenFinished) {
mDocument.postUnoCommand(command, arguments, notifyWhenFinished);
}
private void setTextSelection(int type, PointF documentCoordinate) {
......
......@@ -118,6 +118,8 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin
private boolean isSearchToolbarOpen = false;
private static boolean isDocumentChanged = false;
public boolean isNewDocument = false;
private long lastModified = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
Log.w(LOGTAG, "onCreate..");
......@@ -216,6 +218,8 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin
mDrawerList.setOnItemClickListener(new DocumentPartClickListener());
}
lastModified = mInputFile.lastModified();
mToolbarController.setupToolbars();
TabHost host = findViewById(R.id.toolbarTabHost);
......@@ -314,13 +318,15 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin
if (!mInputFile.exists()) {
// Needed for handling null in case new document is not created.
mInputFile = new File(DEFAULT_DOC_PATH);
lastModified = mInputFile.lastModified();
}
final long lastModified = mInputFile.lastModified();
final Activity activity = LibreOfficeMainActivity.this;
Toast.makeText(this, R.string.message_saving, Toast.LENGTH_SHORT).show();
// local save
LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:Save"));
LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND_NOTIFY, ".uno:Save", true));
}
public void saveFilesToCloud(){
final Activity activity = LibreOfficeMainActivity.this;
final AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
......@@ -348,35 +354,16 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin
protected void onPostExecute(Void param) {
Toast.makeText(activity, R.string.message_saved,
Toast.LENGTH_SHORT).show();
isDocumentChanged=false;
setDocumentChanged(false);
}
};
// Delay the call to document provider save operation and check the
// modification time periodically to ensure the local file has been saved.
// TODO: ideally the save operation should have a callback
Runnable runTask = new Runnable() {
private int timesRun = 0;
@Override
public void run() {
if (lastModified < mInputFile.lastModified()) {
// we are sure local save is complete, push changes to cloud
task.execute();
}
else {
timesRun++;
if(timesRun < 4) {
new Handler().postDelayed(this, 5000);
}
else {
// 20 seconds later, the local file has not changed,
// maybe there were no changes at all
Toast.makeText(activity, R.string.message_save_incomplete, Toast.LENGTH_LONG).show();
}
}
}
};
new Handler().postDelayed(runTask, 5000);
if (lastModified < mInputFile.lastModified()) {
task.execute();
lastModified = mInputFile.lastModified();
} else {
Toast.makeText(activity, R.string.message_save_incomplete, Toast.LENGTH_LONG).show();
}
}
@Override
......
......@@ -123,6 +123,14 @@ public interface TileProvider {
*/
void postUnoCommand(String command, String arguments);
/**
* This is the actual reference to the function in LOK, used for getting notified when uno:save event finishes
* @param command
* @param arguments
* @param notifyWhenFinished
*/
void postUnoCommand(String command, String arguments, boolean notifyWhenFinished);
/**
* Send text selection start coordinate.
* @param documentCoordinate
......
......@@ -12,7 +12,6 @@
#include <sal/types.h>
#include <vcl/event.hxx>
#include <android/log.h>
#include <osl/detail/android-bootstrap.h>
......@@ -330,7 +329,7 @@ extern "C" SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Document_postMou
}
extern "C" SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Document_postUnoCommand
(JNIEnv* pEnv, jobject aObject, jstring command, jstring arguments)
(JNIEnv* pEnv, jobject aObject, jstring command, jstring arguments, jboolean bNotifyWhenFinished)
{
LibreOfficeKitDocument* pDocument = getHandle<LibreOfficeKitDocument>(pEnv, aObject);
......@@ -339,7 +338,7 @@ extern "C" SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Document_postUno
if (arguments != NULL)
pArguments = pEnv->GetStringUTFChars(arguments, NULL);
pDocument->pClass->postUnoCommand(pDocument, pCommand, pArguments, false);
pDocument->pClass->postUnoCommand(pDocument, pCommand, pArguments, bNotifyWhenFinished);
pEnv->ReleaseStringUTFChars(command, pCommand);
if (arguments != NULL)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment