Kaydet (Commit) 315ca033 authored tarafından Jacobo Aragunde Pérez's avatar Jacobo Aragunde Pérez

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
üst 626ebde4
...@@ -256,6 +256,8 @@ public class LibreOfficeMainActivity extends ActionBarActivity { ...@@ -256,6 +256,8 @@ public class LibreOfficeMainActivity extends ActionBarActivity {
* to the cloud if necessary. * to the cloud if necessary.
*/ */
private void saveDocument() { private void saveDocument() {
final long lastModified = mInputFile.lastModified();
final Activity activity = LibreOfficeMainActivity.this;
Toast.makeText(this, "Saving the document...", Toast.LENGTH_SHORT).show(); Toast.makeText(this, "Saving the document...", Toast.LENGTH_SHORT).show();
// local save // local save
LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:Save")); LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:Save"));
...@@ -271,7 +273,6 @@ public class LibreOfficeMainActivity extends ActionBarActivity { ...@@ -271,7 +273,6 @@ public class LibreOfficeMainActivity extends ActionBarActivity {
mStorageFile.saveDocument(mInputFile); mStorageFile.saveDocument(mInputFile);
} }
catch (final RuntimeException e) { catch (final RuntimeException e) {
final Activity activity = LibreOfficeMainActivity.this;
activity.runOnUiThread(new Runnable() { activity.runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
...@@ -283,16 +284,41 @@ public class LibreOfficeMainActivity extends ActionBarActivity { ...@@ -283,16 +284,41 @@ public class LibreOfficeMainActivity extends ActionBarActivity {
} }
return null; 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 // Delay the call to document provider save operation and check the
// file has been saved. // modification time periodically to ensure the local file has been saved.
// FIXME: horrible hack, ideally the save operation should have a callback // TODO: ideally the save operation should have a callback
new Handler().postDelayed(new Runnable() { Runnable runTask = new Runnable() {
private int timesRun = 0;
@Override @Override
public void run() { public void run() {
if (lastModified < mInputFile.lastModified()) {
// we are sure local save is complete, push changes to cloud
task.execute(); task.execute();
} }
}, 5000); 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();
}
}
}
};
new Handler().postDelayed(runTask, 5000);
} }
@Override @Override
......
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