diff options
author | Jacobo Aragunde Pérez <jaragunde@igalia.com> | 2015-09-11 12:10:41 +0000 |
---|---|---|
committer | Jacobo Aragunde Pérez <jaragunde@igalia.com> | 2015-09-11 18:29:58 +0000 |
commit | 315ca033c696a6d7339a4c3f2fc617e01d80fcb8 (patch) | |
tree | 5e1bb0b83612eaf2095a80a4a72777cffdbeb6be /android | |
parent | 626ebde44f56755a413945dcb260740ddacf90ba (diff) |
Android: check file modify date to know if save is complete
The API does not allow to set a callback for the save operation, we
work this limitation around by checking the modification date of the
local file periodically. When that date changes, we are sure the
local save operation is complete and we can invoke the document
provider save operation to push the changes to the cloud, if
necessary.
Users may press "save" on a document with no changes, in this case we
have set a 20 seconds limit to stop checking the modification date.
We also add a "save complete" message for the user.
Change-Id: Ib8871fac682a5c03a187a7238e11874984143527
Diffstat (limited to 'android')
-rw-r--r-- | android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java | 40 |
1 files changed, 33 insertions, 7 deletions
diff --git a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java index 098a91b8fbb8..255c4744ea39 100644 --- a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java +++ b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java @@ -256,6 +256,8 @@ public class LibreOfficeMainActivity extends ActionBarActivity { * to the cloud if necessary. */ private void saveDocument() { + final long lastModified = mInputFile.lastModified(); + final Activity activity = LibreOfficeMainActivity.this; Toast.makeText(this, "Saving the document...", Toast.LENGTH_SHORT).show(); // local save LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:Save")); @@ -271,7 +273,6 @@ public class LibreOfficeMainActivity extends ActionBarActivity { mStorageFile.saveDocument(mInputFile); } catch (final RuntimeException e) { - final Activity activity = LibreOfficeMainActivity.this; activity.runOnUiThread(new Runnable() { @Override public void run() { @@ -283,16 +284,41 @@ public class LibreOfficeMainActivity extends ActionBarActivity { } return null; } + + @Override + protected void onPostExecute(Void param) { + Toast.makeText(activity, "Save complete", Toast.LENGTH_SHORT) + .show(); + } }; - // Delay the call to document provider save operation to ensure the local - // file has been saved. - // FIXME: horrible hack, ideally the save operation should have a callback - new Handler().postDelayed(new Runnable() { + // 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() { - task.execute(); + 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, + "Save incomplete. Were there any changes?", + Toast.LENGTH_LONG).show(); + } + } } - }, 5000); + }; + new Handler().postDelayed(runTask, 5000); } @Override |