android/source/src/java/org/libreoffice/LOEvent.java                 |    1 
 android/source/src/java/org/libreoffice/LOKitShell.java              |    4 +
 android/source/src/java/org/libreoffice/LOKitThread.java             |   19 
+---
 android/source/src/java/org/libreoffice/LOKitTileProvider.java       |   31 
++++++-
 android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java |   39 
++++------
 android/source/src/java/org/libreoffice/TileProvider.java            |   18 
++++
 android/source/src/java/org/libreoffice/ToolbarController.java       |    6 -
 7 files changed, 73 insertions(+), 45 deletions(-)

New commits:
commit d342851b9f68680d3f001546e543795cd0786cb1
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Tue Mar 30 15:17:42 2021 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Wed Mar 31 07:03:50 2021 +0200

    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.wegh...@posteo.de>
    (cherry picked from commit 2e86226cff95100e3c34d0f22ec5ce6429efb8cb)

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);
@@ -361,13 +358,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();
commit 1b2f2b730b24103ca231fe3123172bb4503dedb9
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Tue Mar 30 15:01:31 2021 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Wed Mar 31 07:03:39 2021 +0200

    tdf#139350 android: Add param to allow a "real" "Save As"
    
    So far, LOKitTileProvider's 'saveDocumentAs' method
    was always saving a copy of the current document
    (or doing an export), but was not continuing to use
    the newly saved doc afterwards.
    
    Add an additional parameter 'takeOwnership' to the
    method to specify whether to do so.
    
    In other words,
    
    * the 'takeOwnership=false' case continues to
      do what was done previously, it basically does what
      "File" -> "Save a Copy" or "File" -> "Export"
      does in the desktop version
    
    * the 'takeOwnership=true' case now basically does the
      same as "File" -> "Save As" in the desktop version
      (except that the path is already known in the
      Android case)
    
    This essentially forwards the "TakeOwnership"
    param to LibreOfficeKit, which was originally
    added there in
    
        commit a121074cbd07939713e169586469b934aedbe594
        Date:   Wed Feb 10 13:26:50 2016 +0100
    
            lok: Introduce a "TakeOwnership" filter option for saveAs().
    
            It is consumed by the saveAs() itself, and when provided, the 
document
            identity changes to the provided pUrl - meaning that 
'.uno:ModifiedStatus' is
            triggered as with the "Save As..." in the UI.
    
            This mode must not be used when saving to PNG or PDF.
    
            Change-Id: I11b5aa814476a8dcab9eac5202bd052828ebbd96
    
    This also adds a new 'SAVE_COPY_AS' event type to save a
    copy without taking ownership, and switches all uses of the
    'SAVE_AS' event to that new one for now. (So the behavior
    remains unchanged, but the terminology is hopefully clearer.)
    
    Except for one instance in LOKitTileProver::saveDocument (where
    the cached version of the document is written to the original
    URI, if present), all other places are left with the previous
    behaviour in this commit.
    Further changes will be done in follow-up commits.
    
    Change-Id: I11996cd7276a6c6f2774535cd3e53cb997c8cd4e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113375
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    (cherry picked from commit a1abf2c865228e6ed33e99ab73b94357ddbc590f)

diff --git a/android/source/src/java/org/libreoffice/LOEvent.java 
b/android/source/src/java/org/libreoffice/LOEvent.java
index 4db48a5bbd6d..74a09c92cc1d 100644
--- a/android/source/src/java/org/libreoffice/LOEvent.java
+++ b/android/source/src/java/org/libreoffice/LOEvent.java
@@ -42,6 +42,7 @@ public class LOEvent implements Comparable<LOEvent> {
     public static final int REFRESH = 21;
     public static final int PAGE_SIZE_CHANGED = 22;
     public static final int UNO_COMMAND_NOTIFY = 23;
+    public static final int SAVE_COPY_AS = 24;
 
 
     public final int mType;
diff --git a/android/source/src/java/org/libreoffice/LOKitShell.java 
b/android/source/src/java/org/libreoffice/LOKitShell.java
index 46ca256c7993..75b2fb09b260 100644
--- a/android/source/src/java/org/libreoffice/LOKitShell.java
+++ b/android/source/src/java/org/libreoffice/LOKitShell.java
@@ -119,6 +119,10 @@ public class LOKitShell {
         LOKitShell.sendEvent(new LOEvent(filePath, fileFormat, 
LOEvent.SAVE_AS));
     }
 
+    public static void sendSaveCopyAsEvent(String filePath, String fileFormat) 
{
+        LOKitShell.sendEvent(new LOEvent(filePath, fileFormat, 
LOEvent.SAVE_COPY_AS));
+    }
+
     public static void sendResumeEvent(String inputFile, int partIndex) {
         LOKitShell.sendEvent(new LOEvent(LOEvent.RESUME, inputFile, 
partIndex));
     }
diff --git a/android/source/src/java/org/libreoffice/LOKitThread.java 
b/android/source/src/java/org/libreoffice/LOKitThread.java
index e80e5af6c990..c20365d58fad 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);
+            mTileProvider.saveDocumentAs(filePath, false);
         } else {
             closeDocument();
         }
@@ -274,11 +274,11 @@ class LOKitThread extends Thread {
     /**
      * Save the currently loaded document.
      */
-    private void saveDocumentAs(String filePath, String fileType) {
+    private void saveDocumentAs(String filePath, String fileType, boolean 
bTakeOwnership) {
        if (mTileProvider == null) {
            Log.e(LOGTAG, "Error in saving, Tile Provider instance is null");
        } else {
-           mTileProvider.saveDocumentAs(filePath, fileType);
+           mTileProvider.saveDocumentAs(filePath, fileType, bTakeOwnership);
        }
     }
 
@@ -305,7 +305,10 @@ class LOKitThread extends Thread {
                 loadNewDocument(event.filePath, event.fileType);
                 break;
             case LOEvent.SAVE_AS:
-                saveDocumentAs(event.filePath, event.fileType);
+                saveDocumentAs(event.filePath, event.fileType, true);
+                break;
+            case LOEvent.SAVE_COPY_AS:
+                saveDocumentAs(event.filePath, event.fileType, false);
                 break;
             case LOEvent.RESUME:
                 resumeDocument(event.mString, event.mPartIndex);
diff --git a/android/source/src/java/org/libreoffice/LOKitTileProvider.java 
b/android/source/src/java/org/libreoffice/LOKitTileProvider.java
index a887118c6aaa..0a9ad6a90685 100644
--- a/android/source/src/java/org/libreoffice/LOKitTileProvider.java
+++ b/android/source/src/java/org/libreoffice/LOKitTileProvider.java
@@ -42,7 +42,7 @@ class LOKitTileProvider implements TileProvider {
     private static int TILE_SIZE = 256;
     private final float mTileWidth;
     private final float mTileHeight;
-    private final String mInputFile;
+    private String mInputFile;
     private Office mOffice;
     private Document mDocument;
     private boolean mIsReady = false;
@@ -298,11 +298,16 @@ class LOKitTileProvider implements TileProvider {
 
 
     @Override
-    public void saveDocumentAs(final String filePath, String format) {
+    public void saveDocumentAs(final String filePath, String format, boolean 
takeOwnership) {
+        String options = "";
+        if (takeOwnership) {
+            options = "TakeOwnership";
+        }
+
         final String newFilePath = "file://" + filePath;
         Log.d("saveFilePathURL", newFilePath);
         LOKitShell.showProgressSpinner(mContext);
-        mDocument.saveAs(newFilePath, format, "");
+        mDocument.saveAs(newFilePath, format, options);
         if (!mOffice.getError().isEmpty()){
             Log.e("Save Error", mOffice.getError());
             if (format.equals("svg")) {
@@ -344,6 +349,7 @@ class LOKitTileProvider implements TileProvider {
                     }
                 });
             } else {
+                mInputFile = filePath;
                 LOKitShell.getMainHandler().post(new Runnable() {
                     @Override
                     public void run() {
@@ -357,16 +363,16 @@ class LOKitTileProvider implements TileProvider {
     }
 
     @Override
-    public void saveDocumentAs(final String filePath) {
+    public void saveDocumentAs(final String filePath, boolean takeOwnership) {
         final int docType = mDocument.getDocumentType();
         if (docType == Document.DOCTYPE_TEXT)
-            saveDocumentAs(filePath, "odt");
+            saveDocumentAs(filePath, "odt", takeOwnership);
         else if (docType == Document.DOCTYPE_SPREADSHEET)
-            saveDocumentAs(filePath, "ods");
+            saveDocumentAs(filePath, "ods", takeOwnership);
         else if (docType == Document.DOCTYPE_PRESENTATION)
-            saveDocumentAs(filePath, "odp");
+            saveDocumentAs(filePath, "odp", takeOwnership);
         else if (docType == Document.DOCTYPE_DRAWING)
-            saveDocumentAs(filePath, "odg");
+            saveDocumentAs(filePath, "odg", takeOwnership);
         else
             Log.w(LOGTAG, "Cannot determine file format from document. Not 
saving.");
     }
@@ -385,7 +391,7 @@ class LOKitTileProvider implements TileProvider {
             mDocument.saveAs("file://"+cacheFile,"pdf","");
             printDocument(cacheFile);
         }else{
-            saveDocumentAs(dir+"/"+file,"pdf");
+            saveDocumentAs(dir+"/"+file,"pdf", false);
         }
     }
 
@@ -435,7 +441,7 @@ class LOKitTileProvider implements TileProvider {
             File input = new File(mInputFile);
             final String cacheFile = cacheDir + "/lo_cached_" + 
input.getName();
             String path = input.getAbsolutePath();
-            saveDocumentAs(path, format);
+            saveDocumentAs(path, format, true);
             (new File(cacheFile)).delete();
         }else{
             mContext.saveDocument();
diff --git 
a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java 
b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java
index 368d19af1375..210b2bf2ffd5 100644
--- a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java
+++ b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java
@@ -365,7 +365,7 @@ public class LibreOfficeMainActivity extends 
AppCompatActivity implements Settin
      * Save a new document
      * */
     public void saveAs(){
-        LOKitShell.sendSaveAsEvent(mInputFile.getPath(), 
FileUtilities.getExtension(mInputFile.getPath()).substring(1));
+        LOKitShell.sendSaveCopyAsEvent(mInputFile.getPath(), 
FileUtilities.getExtension(mInputFile.getPath()).substring(1));
     }
 
     /**
@@ -1057,7 +1057,7 @@ public class LibreOfficeMainActivity extends 
AppCompatActivity implements Settin
             if (mTempSlideShowFile.exists() && !isDocumentChanged) {
                 startPresentation("file://" + tempPath);
             } else {
-                LOKitShell.sendSaveAsEvent(tempPath, "svg");
+                LOKitShell.sendSaveCopyAsEvent(tempPath, "svg");
             }
         }
     }
diff --git a/android/source/src/java/org/libreoffice/TileProvider.java 
b/android/source/src/java/org/libreoffice/TileProvider.java
index a848b4ae98d0..1a20c8b080d0 100644
--- a/android/source/src/java/org/libreoffice/TileProvider.java
+++ b/android/source/src/java/org/libreoffice/TileProvider.java
@@ -23,14 +23,22 @@ public interface TileProvider {
 
     /**
      * Save the current document under the given path.
+     * @param takeOwnership Whether to take ownership of the new file,
+     *                      i.e. whether the current document is changed to the
+     *                      newly saved document (takeOwnership = true),
+     *                      as compared to just saving a copy of the current 
document
+     *                      or exporting to a different file format.
+     *                      Must be 'false' when using this method for export 
to e.g. PNG or PDF.
      */
-    void saveDocumentAs(String filePath, String format);
+    void saveDocumentAs(String filePath, String format, boolean takeOwnership);
 
     /**
      * Saves the current document under the given path,
      * using the default file format.
+     * @param takeOwnership (s. documentation for
+     *                      'saveDocumentAs(String filePath, String format, 
boolean takeOwnership)')
      */
-    void saveDocumentAs(String filePath);
+    void saveDocumentAs(String filePath, boolean takeOwnership);
 
     /**
      * Returns the page width in pixels.
commit 76114ef23c02c21de31b3c9b9be4255772b279f3
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Tue Mar 30 11:40:21 2021 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Wed Mar 31 07:03:27 2021 +0200

    android: TileKitProvider: Optionally detect file type from document
    
    Add an overload for the 'saveDocumentAs' method that takes just one
    parameter and auto-detects the file type to use from the document.
    
    Use it when creating new documents.
    
    Change-Id: I0f275ce159176292ffa1e52ed37673a486ab9428
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113374
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    (cherry picked from commit 4dbc9c87a09922072c0250e4e932228de93961db)

diff --git a/android/source/src/java/org/libreoffice/LOKitThread.java 
b/android/source/src/java/org/libreoffice/LOKitThread.java
index 03b7070e783a..e80e5af6c990 100644
--- a/android/source/src/java/org/libreoffice/LOKitThread.java
+++ b/android/source/src/java/org/libreoffice/LOKitThread.java
@@ -265,15 +265,7 @@ class LOKitThread extends Thread {
             refresh();
             LOKitShell.hideProgressSpinner(mContext);
 
-            if (fileType.matches(LibreOfficeUIActivity.NEW_WRITER_STRING_KEY))
-                mTileProvider.saveDocumentAs(filePath, "odt");
-            else if 
(fileType.matches(LibreOfficeUIActivity.NEW_CALC_STRING_KEY))
-                mTileProvider.saveDocumentAs(filePath, "ods");
-            else if 
(fileType.matches(LibreOfficeUIActivity.NEW_IMPRESS_STRING_KEY))
-                mTileProvider.saveDocumentAs(filePath, "odp");
-            else
-                mTileProvider.saveDocumentAs(filePath, "odg");
-
+            mTileProvider.saveDocumentAs(filePath);
         } else {
             closeDocument();
         }
diff --git a/android/source/src/java/org/libreoffice/LOKitTileProvider.java 
b/android/source/src/java/org/libreoffice/LOKitTileProvider.java
index 0e2649337322..a887118c6aaa 100644
--- a/android/source/src/java/org/libreoffice/LOKitTileProvider.java
+++ b/android/source/src/java/org/libreoffice/LOKitTileProvider.java
@@ -356,6 +356,21 @@ class LOKitTileProvider implements TileProvider {
         LOKitShell.hideProgressSpinner(mContext);
     }
 
+    @Override
+    public void saveDocumentAs(final String filePath) {
+        final int docType = mDocument.getDocumentType();
+        if (docType == Document.DOCTYPE_TEXT)
+            saveDocumentAs(filePath, "odt");
+        else if (docType == Document.DOCTYPE_SPREADSHEET)
+            saveDocumentAs(filePath, "ods");
+        else if (docType == Document.DOCTYPE_PRESENTATION)
+            saveDocumentAs(filePath, "odp");
+        else if (docType == Document.DOCTYPE_DRAWING)
+            saveDocumentAs(filePath, "odg");
+        else
+            Log.w(LOGTAG, "Cannot determine file format from document. Not 
saving.");
+    }
+
     public void exportToPDF(boolean print){
         String dir = 
Environment.getExternalStorageDirectory().getAbsolutePath()+"/Documents";
         File docDir = new File(dir);
diff --git a/android/source/src/java/org/libreoffice/TileProvider.java 
b/android/source/src/java/org/libreoffice/TileProvider.java
index dabf30b834f7..a848b4ae98d0 100644
--- a/android/source/src/java/org/libreoffice/TileProvider.java
+++ b/android/source/src/java/org/libreoffice/TileProvider.java
@@ -22,10 +22,16 @@ import org.mozilla.gecko.gfx.IntSize;
 public interface TileProvider {
 
     /**
-     * Save the current document.
+     * Save the current document under the given path.
      */
     void saveDocumentAs(String filePath, String format);
 
+    /**
+     * Saves the current document under the given path,
+     * using the default file format.
+     */
+    void saveDocumentAs(String filePath);
+
     /**
      * Returns the page width in pixels.
      */
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to