android/lib/src/main/java/org/libreoffice/androidlib/LOActivity.java |   15 
+++++++
 loleaflet/css/toolbar.css                                            |    1 
 loleaflet/src/control/Control.MobileTopBar.js                        |    2 
 loleaflet/src/control/Control.Toolbar.js                             |    8 +++
 loleaflet/src/control/Control.UIManager.js                           |   21 
+++++++++-
 loleaflet/src/control/Permission.js                                  |    7 +++
 loleaflet/src/map/Map.js                                             |    5 ++
 7 files changed, 56 insertions(+), 3 deletions(-)

New commits:
commit 4cd1baa02d0b36e68a7194c77fdeb68c5af59f8a
Author:     mert <mert.tu...@collabora.com>
AuthorDate: Wed Feb 12 20:53:34 2020 +0300
Commit:     Mert Tumer <mert.tu...@collabora.com>
CommitDate: Tue Sep 15 12:22:10 2020 +0200

    android: back button switches to readonly mode instead of closing
    
    Currently pressing back button on edit mode closes the document,
    this patch may prevent unintentional touches
    
    Change-Id: Ic7061186fa8794203fd4614c07a11b219d3a10d9
    Reviewed-on: https://gerrit.libreoffice.org/c/online/+/100666
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Mert Tumer <mert.tu...@collabora.com>
    Reviewed-by: Jan Holesovsky <ke...@collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/online/+/88555

diff --git 
a/android/lib/src/main/java/org/libreoffice/androidlib/LOActivity.java 
b/android/lib/src/main/java/org/libreoffice/androidlib/LOActivity.java
index 77f9e0e68..88b1fdafd 100644
--- a/android/lib/src/main/java/org/libreoffice/androidlib/LOActivity.java
+++ b/android/lib/src/main/java/org/libreoffice/androidlib/LOActivity.java
@@ -122,6 +122,7 @@ public class LOActivity extends AppCompatActivity {
 
     /** In case the mobile-wizard is visible, we have to intercept the 
Android's Back button. */
     private boolean mMobileWizardVisible = false;
+    private boolean mIsEditModeActive = false;
 
     private ValueCallback<Uri[]> valueCallback;
 
@@ -697,6 +698,9 @@ public class LOActivity extends AppCompatActivity {
             // just return one level up in the mobile-wizard (or close it)
             callFakeWebsocketOnMessage("'mobile: mobilewizardback'");
             return;
+        } else if (mIsEditModeActive) {
+            callFakeWebsocketOnMessage("'mobile: readonlymode'");
+            return;
         }
 
         finishWithProgress();
@@ -928,6 +932,17 @@ public class LOActivity extends AppCompatActivity {
                 startActivity(intent);
                 return false;
             }
+            case "EDITMODE": {
+                switch (messageAndParam[1]) {
+                    case "on":
+                        mIsEditModeActive = true;
+                        break;
+                    case "off":
+                        mIsEditModeActive = false;
+                        break;
+                }
+                return false;
+            }
         }
         return true;
     }
diff --git a/loleaflet/css/toolbar.css b/loleaflet/css/toolbar.css
index 343ebd8d6..a994cd4b2 100644
--- a/loleaflet/css/toolbar.css
+++ b/loleaflet/css/toolbar.css
@@ -753,6 +753,7 @@ button.leaflet-control-search-next
 .w2ui-icon.users{ background: url('images/contacts-dark.svg') no-repeat 
center; }
 .w2ui-icon.fullscreen{ background: url('images/lc_fullscreen.svg') no-repeat 
center !important; }
 .w2ui-icon.closemobile{ background: url('images/lc_closedocmobile.svg') 
no-repeat center !important; }
+.w2ui-icon.editmode { background: url('images/lc_listitem-selected.svg') 
no-repeat center / 28px !important; }
 .w2ui-icon.closetoolbar{ background: url('images/close_toolbar.svg') no-repeat 
center !important; }
 .w2ui-icon.sidebar_modify_page{ background: 
url('images/lc_formproperties.svg') no-repeat center !important; }
 .w2ui-icon.sidebar_slide_change{ background: 
url('images/sidebar-transition-large.svg') no-repeat center !important; }
diff --git a/loleaflet/src/control/Control.MobileTopBar.js 
b/loleaflet/src/control/Control.MobileTopBar.js
index 05fd7c7ed..b562c0153 100644
--- a/loleaflet/src/control/Control.MobileTopBar.js
+++ b/loleaflet/src/control/Control.MobileTopBar.js
@@ -193,6 +193,7 @@ L.Control.MobileTopBar = L.Control.extend({
                                toolbarDownButtons.forEach(function(id) {
                                        toolbar.enable(id);
                                });
+                               toolbar.set('closemobile', {img: 'editmode'});
                        }
                } else {
                        toolbar = w2ui['actionbar'];
@@ -200,6 +201,7 @@ L.Control.MobileTopBar = L.Control.extend({
                                toolbarDownButtons.forEach(function(id) {
                                        toolbar.disable(id);
                                });
+                               toolbar.set('closemobile', {img: 
'closemobile'});
                        }
                }
        },
diff --git a/loleaflet/src/control/Control.Toolbar.js 
b/loleaflet/src/control/Control.Toolbar.js
index 8effb9de3..d073afa4d 100644
--- a/loleaflet/src/control/Control.Toolbar.js
+++ b/loleaflet/src/control/Control.Toolbar.js
@@ -142,7 +142,7 @@ function onClick(e, id, item) {
                map.uiManager.toggleMenubar();
        }
        else if (id === 'close' || id === 'closemobile') {
-               onClose();
+               map.uiManager.enterReadonlyOrClose();
        }
        else if (id === 'link') {
                map.showHyperlinkDialog();
@@ -979,6 +979,12 @@ function onUpdatePermission(e) {
                                toolbar.disable(items[idx].id);
                        }
                }
+               if (e.perm === 'edit') {
+                       toolbar.set('closemobile', {img: 'editmode'});
+               } else {
+                       toolbar.set('closemobile', {img: 'closemobile'});
+               }
+
        }
 }
 
diff --git a/loleaflet/src/control/Control.UIManager.js 
b/loleaflet/src/control/Control.UIManager.js
index 9f18fd511..8f603eadd 100644
--- a/loleaflet/src/control/Control.UIManager.js
+++ b/loleaflet/src/control/Control.UIManager.js
@@ -265,9 +265,11 @@ L.Control.UIManager = L.Control.extend({
        onUpdatePermission: function(e) {
                if (window.mode.isMobile()) {
                        if (e.perm === 'edit') {
+                               history.pushState({context: 'app-started'}, 
'edit-mode');
                                $('#toolbar-down').show();
                        }
                        else {
+                               history.pushState({context: 'app-started'}, 
'readonly-mode');
                                $('#toolbar-down').hide();
                        }
                }
@@ -292,16 +294,31 @@ L.Control.UIManager = L.Control.extend({
                this.map.invalidateSize();
        },
 
+       enterReadonlyOrClose: function() {
+               if (this.map.isPermissionEdit()) {
+                       // in edit mode, passing 'edit' actually enters 
readonly mode
+                       // and bring the blue circle editmode button back
+                       this.map.setPermission('edit');
+                       var toolbar = w2ui['actionbar'];
+                       if (toolbar) {
+                               toolbar.uncheck('closemobile');
+                               toolbar.uncheck('close');
+                       }
+               } else {
+                       window.onClose();
+               }
+       },
+
        onGoBack: function(popStateEvent) {
                if (popStateEvent.state && popStateEvent.state.context) {
                        if (popStateEvent.state.context === 'mobile-wizard' && 
this.mobileWizard) {
                                if (this.mobileWizard.isOpen()) {
                                        this.mobileWizard.goLevelUp(true);
                                } else {
-                                       window.onClose();
+                                       this.enterReadonlyOrClose();
                                }
                        } else if (popStateEvent.state.context === 
'app-started') {
-                               window.onClose();
+                               this.enterReadonlyOrClose();
                        }
                }
        },
diff --git a/loleaflet/src/control/Permission.js 
b/loleaflet/src/control/Permission.js
index c4035145c..6d4868919 100644
--- a/loleaflet/src/control/Permission.js
+++ b/loleaflet/src/control/Permission.js
@@ -99,6 +99,9 @@ L.Map.include({
                if (this._docLayer._docType === 'text') {
                        this.setZoom(10);
                }
+
+               if (window.ThisIsTheAndroidApp)
+                       window.postMobileMessage('EDITMODE on');
        },
 
        _enterReadOnlyMode: function (perm) {
@@ -112,6 +115,10 @@ L.Map.include({
                        this._docLayer._onUpdateTextSelection();
                }
                this.fire('updatepermission', {perm : perm});
+               this.fire('closemobilewizard');
+
+               if (window.ThisIsTheAndroidApp)
+                       window.postMobileMessage('EDITMODE off');
        },
 
        enableSelection: function () {
diff --git a/loleaflet/src/map/Map.js b/loleaflet/src/map/Map.js
index b774debf9..6a3cf22cc 100644
--- a/loleaflet/src/map/Map.js
+++ b/loleaflet/src/map/Map.js
@@ -215,6 +215,11 @@ L.Map = L.Evented.extend({
                                this._fireInitComplete('CharFontName');
                        }
                });
+               if (window.ThisIsTheAndroidApp) {
+                       this.on('readonlymode', function() {
+                               this.setPermission('edit');
+                       });
+               }
 
                this.showBusy(_('Initializing...'), false);
                this.on('statusindicator', this._onUpdateProgress, this);
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to