android/source/src/java/org/libreoffice/LOKitThread.java |   20 ++++-----------
 1 file changed, 6 insertions(+), 14 deletions(-)

New commits:
commit d2572dc9d6c7cda9d6e08e46c42048e12e4f04e0
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Wed Apr 13 13:52:40 2022 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Wed Apr 13 18:23:02 2022 +0200

    android: Deduplicate LOKitThread#load{,New}Document
    
    After Change-Id I15ecc2eba6c5ee441f6e14f8229594cab05dbba7
    "tdf#148556 android: Don't delay refresh when loading doc",
    the only thing that `LOKitThread#loadNewDocument` does
    in addition to `LOKithThread#loadDocument` is to save the
    newly created document (to a temp file) if loading was
    successful.
    
    So, have `loadDocument` return a boolean saying whether
    loading was successful and call that method from
    `loadNewDocument` to reduce duplication.
    
    Change-Id: I9b99e011b3f5105bb60f95174de393462ff08271
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132966
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/android/source/src/java/org/libreoffice/LOKitThread.java 
b/android/source/src/java/org/libreoffice/LOKitThread.java
index b4aee40c1cd3..c29f98461fb9 100644
--- a/android/source/src/java/org/libreoffice/LOKitThread.java
+++ b/android/source/src/java/org/libreoffice/LOKitThread.java
@@ -204,8 +204,9 @@ class LOKitThread extends Thread {
     /**
      * Handle load document event.
      * @param filePath - filePath to where the document is located
+     * @return Whether the document has been loaded successfully.
      */
-    private void loadDocument(String filePath) {
+    private boolean loadDocument(String filePath) {
         mLayerClient = mContext.getLayerClient();
 
         mInvalidationHandler = new InvalidationHandler(mContext);
@@ -216,8 +217,10 @@ class LOKitThread extends Thread {
             updateZoomConstraints();
             refresh(true);
             LOKitShell.hideProgressSpinner(mContext);
+            return true;
         } else {
             closeDocument();
+            return false;
         }
     }
 
@@ -227,20 +230,9 @@ class LOKitThread extends Thread {
      * @param fileType - fileType what type of new document is to be loaded
      */
     private void loadNewDocument(String filePath, String fileType) {
-        mLayerClient = mContext.getLayerClient();
-
-        mInvalidationHandler = new InvalidationHandler(mContext);
-        mTileProvider = TileProviderFactory.create(mContext, 
mInvalidationHandler, fileType);
-
-        if (mTileProvider.isReady()) {
-            LOKitShell.showProgressSpinner(mContext);
-            updateZoomConstraints();
-            refresh(true);
-            LOKitShell.hideProgressSpinner(mContext);
-
+        boolean ok = loadDocument(fileType);
+        if (ok) {
             mTileProvider.saveDocumentAs(filePath, true);
-        } else {
-            closeDocument();
         }
     }
 

Reply via email to