diff options
author | Mert Tümer <merttumer7@gmail.com> | 2018-03-18 17:49:19 +0300 |
---|---|---|
committer | Thorsten Behrens <Thorsten.Behrens@CIB.de> | 2018-03-27 16:25:46 +0200 |
commit | fc88892e9964554d4440637e11a7325c4200fedf (patch) | |
tree | b64b71df500dc85bf85294e02ec6c6f784f56b20 /android/source | |
parent | 19ca4e8a5eb40f3c776a8089a4a043e7fe4a9247 (diff) |
.uno:Save callback for the Android Viewer
Change-Id: Ic2e16985e52869092faa2a31a59a85cb77b8e28c
Signed-off-by: Mert Tümer <merttumer7@gmail.com>
Reviewed-on: https://gerrit.libreoffice.org/51506
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
Diffstat (limited to 'android/source')
6 files changed, 69 insertions, 30 deletions
diff --git a/android/source/src/java/org/libreoffice/InvalidationHandler.java b/android/source/src/java/org/libreoffice/InvalidationHandler.java index eb22f6c8f3d3..b33f678de90f 100644 --- a/android/source/src/java/org/libreoffice/InvalidationHandler.java +++ b/android/source/src/java/org/libreoffice/InvalidationHandler.java @@ -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 diff --git a/android/source/src/java/org/libreoffice/LOEvent.java b/android/source/src/java/org/libreoffice/LOEvent.java index 979d8ba29ed7..7e15dea2b988 100644 --- a/android/source/src/java/org/libreoffice/LOEvent.java +++ b/android/source/src/java/org/libreoffice/LOEvent.java @@ -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"; diff --git a/android/source/src/java/org/libreoffice/LOKitThread.java b/android/source/src/java/org/libreoffice/LOKitThread.java index 63f49dc6253f..92303f588c2f 100644 --- a/android/source/src/java/org/libreoffice/LOKitThread.java +++ b/android/source/src/java/org/libreoffice/LOKitThread.java @@ -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; diff --git a/android/source/src/java/org/libreoffice/LOKitTileProvider.java b/android/source/src/java/org/libreoffice/LOKitTileProvider.java index addbc16a9cf7..0f1e9f9e444e 100644 --- a/android/source/src/java/org/libreoffice/LOKitTileProvider.java +++ b/android/source/src/java/org/libreoffice/LOKitTileProvider.java @@ -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) { diff --git a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java index 3d9e13f343ad..dee54d5ac2da 100644 --- a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java +++ b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java @@ -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 diff --git a/android/source/src/java/org/libreoffice/TileProvider.java b/android/source/src/java/org/libreoffice/TileProvider.java index 10d578337680..240d3ce52057 100644 --- a/android/source/src/java/org/libreoffice/TileProvider.java +++ b/android/source/src/java/org/libreoffice/TileProvider.java @@ -124,6 +124,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 */ |