summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Weghorn <m.weghorn@posteo.de>2021-03-30 15:17:42 +0200
committerMichael Weghorn <m.weghorn@posteo.de>2021-03-31 07:03:50 +0200
commitd342851b9f68680d3f001546e543795cd0786cb1 (patch)
tree7564916a62d980a5621c8e41fbd506b1c1f3fbd1
parent1b2f2b730b24103ca231fe3123172bb4503dedb9 (diff)
tdf#139350 android: Fix handling of new docs
Pass param 'takeOwnership=true' to the 'saveDocumentAs' method when saving a newly created document in Android Viewer in 'LOKitThread::loadNewDocument', so the newly written document is used subsequently, rather than continuing to more or less operate on "private:factory/swriter" (for the Writer case, similar for the others). Extend 'LibreOfficeMainActivity::saveFileToOriginalSource' to handle this case as well (show a proper message and reset the modified state after saving). Drop now unnecessary special handling for the case of saving new files from the toolbar or the dialog shown when exiting without having saved previously. Change-Id: Ief95620e324aa2abc318f1add0b91376ffe669d6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113376 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.weghorn@posteo.de> (cherry picked from commit 2e86226cff95100e3c34d0f22ec5ce6429efb8cb)
-rw-r--r--android/source/src/java/org/libreoffice/LOKitThread.java2
-rw-r--r--android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java37
-rw-r--r--android/source/src/java/org/libreoffice/ToolbarController.java6
3 files changed, 19 insertions, 26 deletions
diff --git a/android/source/src/java/org/libreoffice/LOKitThread.java b/android/source/src/java/org/libreoffice/LOKitThread.java
index c20365d58fad..a3c6733ad81f 100644
--- a/android/source/src/java/org/libreoffice/LOKitThread.java
+++ b/android/source/src/java/org/libreoffice/LOKitThread.java
@@ -265,7 +265,7 @@ class LOKitThread extends Thread {
refresh();
LOKitShell.hideProgressSpinner(mContext);
- mTileProvider.saveDocumentAs(filePath, false);
+ mTileProvider.saveDocumentAs(filePath, true);
} else {
closeDocument();
}
diff --git a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java
index 210b2bf2ffd5..b9896c3c046c 100644
--- a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java
+++ b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java
@@ -179,17 +179,16 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin
// create TextCursorLayer
mDocumentOverlay = new DocumentOverlay(this, layerView);
- // New document type string is not null, meaning we want to open a new document
+ mbISReadOnlyMode = !isExperimentalMode();
+
if (getIntent().getStringExtra(LibreOfficeUIActivity.NEW_DOC_TYPE_KEY) != null) {
+ // New document type string is not null, meaning we want to open a new document
String newDocumentType = getIntent().getStringExtra(LibreOfficeUIActivity.NEW_DOC_TYPE_KEY);
String newFilePath = getIntent().getStringExtra(LibreOfficeUIActivity.NEW_FILE_PATH_KEY);
// Load the new document
loadNewDocument(newFilePath, newDocumentType);
- }
-
- mbISReadOnlyMode = !isExperimentalMode();
- if (getIntent().getData() != null) {
+ } else if (getIntent().getData() != null) {
if (getIntent().getData().getScheme().equals(ContentResolver.SCHEME_CONTENT)) {
if (copyFileToTemp() && mTempFile != null) {
mInputFile = mTempFile;
@@ -218,9 +217,7 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin
"org.libreoffice.document_uri");
}
} else {
- if (!isNewDocument) {
- mInputFile = new File(DEFAULT_DOC_PATH);
- }
+ mInputFile = new File(DEFAULT_DOC_PATH);
}
mDrawerLayout = findViewById(R.id.drawer_layout);
@@ -362,13 +359,6 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin
}
/**
- * Save a new document
- * */
- public void saveAs(){
- LOKitShell.sendSaveCopyAsEvent(mInputFile.getPath(), FileUtilities.getExtension(mInputFile.getPath()).substring(1));
- }
-
- /**
* Save the document and invoke save on document provider to upload the file
* to the cloud if necessary.
*/
@@ -387,6 +377,17 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin
if (documentUri != null) {
// case where file was opened using IDocumentProvider from within LO app
saveFilesToCloud();
+ } else if (isNewDocument) {
+ // nothing to do for actual save, the actual (local) file is already handled
+ // by LOKitTileProvider
+ runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ Toast.makeText(LibreOfficeMainActivity.this, R.string.message_saved,
+ Toast.LENGTH_SHORT).show();
+ }
+ });
+ setDocumentChanged(false);
} else {
// case where file was passed via Intent
if (isReadOnlyMode() || mInputFile == null || getIntent().getData() == null || !getIntent().getData().getScheme().equals(ContentResolver.SCHEME_CONTENT))
@@ -551,11 +552,7 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin
public void onClick(DialogInterface dialog, int which) {
switch (which){
case DialogInterface.BUTTON_POSITIVE:
- if (isNewDocument) {
- saveAs();
- } else {
- mTileProvider.saveDocument();
- }
+ mTileProvider.saveDocument();
isDocumentChanged=false;
onBackPressed();
break;
diff --git a/android/source/src/java/org/libreoffice/ToolbarController.java b/android/source/src/java/org/libreoffice/ToolbarController.java
index 76c67a06375f..308bc9e6b254 100644
--- a/android/source/src/java/org/libreoffice/ToolbarController.java
+++ b/android/source/src/java/org/libreoffice/ToolbarController.java
@@ -172,11 +172,7 @@ public class ToolbarController implements Toolbar.OnMenuItemClickListener {
mContext.showAbout();
return true;
case R.id.action_save:
- if (mContext.isNewDocument) {
- mContext.saveAs();
- } else {
- mContext.getTileProvider().saveDocument();
- }
+ mContext.getTileProvider().saveDocument();
return true;
case R.id.action_parts:
mContext.openDrawer();