jenkins-bot has submitted this change and it was merged.

Change subject: Simplify loading of styles.
......................................................................


Simplify loading of styles.

This simplifies the way that we load CSS styles into our WebView
by simply including them in a <link> tag within the <head> element in
the HTML file, instead of loading the CSS via a Bridge event. This was a
vestige of the time when the app used to dynamically download CSS
bundles in the field, and is no longer necessary.

Change-Id: I481d5102ccffca407178e6b98b3e5d2c8363809b
---
M app/src/main/assets/bundle-test.js
M app/src/main/assets/bundle.js
M app/src/main/assets/index.html
M app/src/main/assets/preview.html
M app/src/main/assets/preview.js
M app/src/main/java/org/wikipedia/NightModeHandler.java
M app/src/main/java/org/wikipedia/bridge/CommunicationBridge.java
D app/src/main/java/org/wikipedia/bridge/StyleBundle.java
M app/src/main/java/org/wikipedia/editing/EditPreviewFragment.java
M app/src/main/java/org/wikipedia/page/PageFragment.java
M www/index.html
M www/js/loader.js
M www/js/night.js
M www/preview.html
14 files changed, 11 insertions(+), 120 deletions(-)

Approvals:
  Mholloway: Looks good to me, approved
  jenkins-bot: Verified
  Niedzielski: Looks good to me, but someone else must approve



diff --git a/app/src/main/assets/bundle-test.js 
b/app/src/main/assets/bundle-test.js
index 9bb16c7..4d76dda 100644
--- a/app/src/main/assets/bundle-test.js
+++ b/app/src/main/assets/bundle-test.js
@@ -37,8 +37,6 @@
     module.exports.sendMessage( "DOMLoaded", {} );
 };
 },{}],2:[function(require,module,exports){
-var bridge = require( "./bridge" );
-
 function addStyleLink( href ) {
     var link = document.createElement( "link" );
     link.setAttribute( "rel", "stylesheet" );
@@ -48,17 +46,10 @@
     document.getElementsByTagName( "head" )[0].appendChild( link );
 }
 
-bridge.registerListener( "injectStyles", function( payload ) {
-    var style_paths = payload.style_paths;
-    for ( var i = 0; i < style_paths.length; i++ ) {
-        addStyleLink( style_paths[i] );
-    }
-});
-
 module.exports = {
        addStyleLink: addStyleLink
 };
-},{"./bridge":1}],3:[function(require,module,exports){
+},{}],3:[function(require,module,exports){
 var bridge = require( "./bridge" );
 var transformer = require("./transformer");
 
diff --git a/app/src/main/assets/bundle.js b/app/src/main/assets/bundle.js
index 2a21e83..81a4e21 100644
--- a/app/src/main/assets/bundle.js
+++ b/app/src/main/assets/bundle.js
@@ -164,8 +164,6 @@
 } );
 
 },{"./transformer":13}],6:[function(require,module,exports){
-var bridge = require( "./bridge" );
-
 function addStyleLink( href ) {
     var link = document.createElement( "link" );
     link.setAttribute( "rel", "stylesheet" );
@@ -175,17 +173,10 @@
     document.getElementsByTagName( "head" )[0].appendChild( link );
 }
 
-bridge.registerListener( "injectStyles", function( payload ) {
-    var style_paths = payload.style_paths;
-    for ( var i = 0; i < style_paths.length; i++ ) {
-        addStyleLink( style_paths[i] );
-    }
-});
-
 module.exports = {
        addStyleLink: addStyleLink
 };
-},{"./bridge":2}],7:[function(require,module,exports){
+},{}],7:[function(require,module,exports){
 var bridge = require( "./bridge" );
 var transformer = require("./transformer");
 
@@ -315,7 +306,7 @@
 }
 
 bridge.registerListener( 'toggleNightMode', function( payload ) {
-       toggle( payload.nightStyleBundle.style_paths[0], payload.hasPageLoaded 
);
+       toggle( payload.nightStyleURL, payload.hasPageLoaded );
 } );
 
 module.exports = {
diff --git a/app/src/main/assets/index.html b/app/src/main/assets/index.html
index 3298b8a..fcf2f2a 100644
--- a/app/src/main/assets/index.html
+++ b/app/src/main/assets/index.html
@@ -3,6 +3,7 @@
 <head>
     <base href="" /> <!-- Set dynamically when loading each page -->
     <script src="file:///android_asset/bundle.js"></script>
+    <link rel="stylesheet" href="file:///android_asset/styles.css"/>
 
     <meta name="viewport" content="width=device-width, user-scalable=no" />
 </head>
diff --git a/app/src/main/assets/preview.html b/app/src/main/assets/preview.html
index 5719ead..185cf1d 100644
--- a/app/src/main/assets/preview.html
+++ b/app/src/main/assets/preview.html
@@ -3,6 +3,7 @@
 <head>
     <base href="https://wikipedia.org"; /> <!-- Force links to resolve with 
https as protocol, rather than file:// -->
     <script src="file:///android_asset/preview.js"></script>
+    <link rel="stylesheet" href="file:///android_asset/preview.css"/>
 
     <meta name="viewport" content="width=device-width, user-scalable=no" />
 </head>
diff --git a/app/src/main/assets/preview.js b/app/src/main/assets/preview.js
index a8c2235..74ac8ab 100644
--- a/app/src/main/assets/preview.js
+++ b/app/src/main/assets/preview.js
@@ -117,8 +117,6 @@
     module.exports.sendMessage( "DOMLoaded", {} );
 };
 },{}],3:[function(require,module,exports){
-var bridge = require( "./bridge" );
-
 function addStyleLink( href ) {
     var link = document.createElement( "link" );
     link.setAttribute( "rel", "stylesheet" );
@@ -128,17 +126,10 @@
     document.getElementsByTagName( "head" )[0].appendChild( link );
 }
 
-bridge.registerListener( "injectStyles", function( payload ) {
-    var style_paths = payload.style_paths;
-    for ( var i = 0; i < style_paths.length; i++ ) {
-        addStyleLink( style_paths[i] );
-    }
-});
-
 module.exports = {
        addStyleLink: addStyleLink
 };
-},{"./bridge":2}],4:[function(require,module,exports){
+},{}],4:[function(require,module,exports){
 var bridge = require("./bridge");
 var loader = require("./loader");
 var utilities = require("./utilities");
@@ -215,7 +206,7 @@
 }
 
 bridge.registerListener( 'toggleNightMode', function( payload ) {
-       toggle( payload.nightStyleBundle.style_paths[0], payload.hasPageLoaded 
);
+       toggle( payload.nightStyleURL, payload.hasPageLoaded );
 } );
 
 module.exports = {
diff --git a/app/src/main/java/org/wikipedia/NightModeHandler.java 
b/app/src/main/java/org/wikipedia/NightModeHandler.java
index fa8957a..d8604e2 100644
--- a/app/src/main/java/org/wikipedia/NightModeHandler.java
+++ b/app/src/main/java/org/wikipedia/NightModeHandler.java
@@ -3,7 +3,6 @@
 import org.json.JSONException;
 import org.json.JSONObject;
 import org.wikipedia.bridge.CommunicationBridge;
-import org.wikipedia.bridge.StyleBundle;
 
 public class NightModeHandler {
     private final CommunicationBridge bridge;
@@ -27,8 +26,7 @@
         JSONObject payload = new JSONObject();
         try {
             payload.put("hasPageLoaded", hasPageLoaded);
-            payload.put("nightStyleBundle",
-                    
StyleBundle.getAvailableBundle(StyleBundle.BUNDLE_NIGHT_MODE).toJSON());
+            payload.put("nightStyleURL", "file:///android_asset/night.css");
         } catch (JSONException e) {
             throw new RuntimeException(e);
         }
diff --git a/app/src/main/java/org/wikipedia/bridge/CommunicationBridge.java 
b/app/src/main/java/org/wikipedia/bridge/CommunicationBridge.java
index d2d04e2..8d2da3f 100644
--- a/app/src/main/java/org/wikipedia/bridge/CommunicationBridge.java
+++ b/app/src/main/java/org/wikipedia/bridge/CommunicationBridge.java
@@ -80,15 +80,6 @@
         }
     }
 
-    /**
-     * Inject the styles specified by the bundle into this webview.
-     *
-     * @param styleBundle The bundle representing the styles to load.
-     */
-    public void injectStyleBundle(StyleBundle styleBundle) {
-        sendMessage("injectStyles", styleBundle.toJSON());
-    }
-
     public void sendMessage(String messageName, JSONObject messageData) {
         String messagePointer =  marshaller.putPayload(messageData.toString());
 
diff --git a/app/src/main/java/org/wikipedia/bridge/StyleBundle.java 
b/app/src/main/java/org/wikipedia/bridge/StyleBundle.java
deleted file mode 100644
index 973613f..0000000
--- a/app/src/main/java/org/wikipedia/bridge/StyleBundle.java
+++ /dev/null
@@ -1,61 +0,0 @@
-package org.wikipedia.bridge;
-
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
-
-/**
- * Represents a bundle of CSS files that can be loaded into a
- * webview via a CommunicationBridge
- */
-public class StyleBundle {
-    public static final String BUNDLE_PAGEVIEW = "styles.css";
-    public static final String BUNDLE_PREVIEW = "preview.css";
-    public static final String BUNDLE_NIGHT_MODE = "night.css";
-
-    /**
-     * Array containing full path of the CSS files in this
-     * bundle.
-     */
-    private final String[] stylePaths;
-
-    /**
-     * Returns a bundle of styles of a specific type.
-     * @return Requested style bundle.
-     */
-    public static StyleBundle getAvailableBundle(String type) {
-        return new StyleBundle(type);
-    }
-
-    /**
-     * Creates a new StyleBundle with a styles from a common prefix.
-     *
-     * @param styles Array of CSS File names that are available together in
-     *               the prefix.
-     */
-    public StyleBundle(String... styles) {
-        stylePaths = new String[styles.length];
-        for (int i = 0; i < styles.length; i++) {
-            stylePaths[i] = "file:///android_asset/" + styles[i];
-        }
-    }
-
-    /**
-     * Return a JSON encoded version of this bundle.
-     *
-     * @return A JSONObject which fully encodes the data in this bundle.
-     */
-    public JSONObject toJSON() {
-        JSONObject json = new JSONObject();
-        JSONArray stylesJSON = new JSONArray();
-        for (String stylePath : stylePaths) {
-            stylesJSON.put(stylePath);
-        }
-        try {
-            json.put("style_paths", stylesJSON);
-            return json;
-        } catch (JSONException e) {
-            throw new RuntimeException(e);
-        }
-    }
-}
diff --git a/app/src/main/java/org/wikipedia/editing/EditPreviewFragment.java 
b/app/src/main/java/org/wikipedia/editing/EditPreviewFragment.java
index a11957c..88eb4d8 100644
--- a/app/src/main/java/org/wikipedia/editing/EditPreviewFragment.java
+++ b/app/src/main/java/org/wikipedia/editing/EditPreviewFragment.java
@@ -23,7 +23,6 @@
 import org.wikipedia.ViewAnimations;
 import org.wikipedia.WikipediaApp;
 import org.wikipedia.analytics.EditFunnel;
-import org.wikipedia.bridge.StyleBundle;
 import org.wikipedia.page.PageActivity;
 import org.wikipedia.page.PageTitle;
 import org.wikipedia.util.L10nUtil;
@@ -177,7 +176,6 @@
     private void displayPreview(final String html) {
         if (!isWebViewSetup) {
             isWebViewSetup = true;
-            
bridge.injectStyleBundle(StyleBundle.getAvailableBundle(StyleBundle.BUNDLE_PREVIEW));
             
L10nUtil.setupDirectionality(parentActivity.getPageTitle().getSite().languageCode(),
 Locale.getDefault().getLanguage(), bridge);
             if (WikipediaApp.getInstance().isCurrentThemeDark()) {
                 new NightModeHandler(bridge).turnOn(false);
diff --git a/app/src/main/java/org/wikipedia/page/PageFragment.java 
b/app/src/main/java/org/wikipedia/page/PageFragment.java
index 1a1669c..84b86e1 100755
--- a/app/src/main/java/org/wikipedia/page/PageFragment.java
+++ b/app/src/main/java/org/wikipedia/page/PageFragment.java
@@ -44,7 +44,6 @@
 import org.wikipedia.analytics.PageScrollFunnel;
 import org.wikipedia.analytics.TabFunnel;
 import org.wikipedia.bridge.CommunicationBridge;
-import org.wikipedia.bridge.StyleBundle;
 import org.wikipedia.concurrency.CallbackTask;
 import org.wikipedia.editing.EditHandler;
 import org.wikipedia.history.HistoryEntry;
@@ -351,8 +350,6 @@
                 showBottomSheet(new ReferenceDialog(getActivity(), 
linkHandler, refHtml));
             }
         };
-
-        
bridge.injectStyleBundle(StyleBundle.getAvailableBundle(StyleBundle.BUNDLE_PAGEVIEW));
 
         // make sure styles get injected before the NightModeHandler and other 
handlers
         if (app.isCurrentThemeDark()) {
diff --git a/www/index.html b/www/index.html
index 3298b8a..fcf2f2a 100644
--- a/www/index.html
+++ b/www/index.html
@@ -3,6 +3,7 @@
 <head>
     <base href="" /> <!-- Set dynamically when loading each page -->
     <script src="file:///android_asset/bundle.js"></script>
+    <link rel="stylesheet" href="file:///android_asset/styles.css"/>
 
     <meta name="viewport" content="width=device-width, user-scalable=no" />
 </head>
diff --git a/www/js/loader.js b/www/js/loader.js
index 068f8f0..bce50fd 100644
--- a/www/js/loader.js
+++ b/www/js/loader.js
@@ -1,5 +1,3 @@
-var bridge = require( "./bridge" );
-
 function addStyleLink( href ) {
     var link = document.createElement( "link" );
     link.setAttribute( "rel", "stylesheet" );
@@ -8,13 +6,6 @@
     link.setAttribute( "href", href );
     document.getElementsByTagName( "head" )[0].appendChild( link );
 }
-
-bridge.registerListener( "injectStyles", function( payload ) {
-    var style_paths = payload.style_paths;
-    for ( var i = 0; i < style_paths.length; i++ ) {
-        addStyleLink( style_paths[i] );
-    }
-});
 
 module.exports = {
        addStyleLink: addStyleLink
diff --git a/www/js/night.js b/www/js/night.js
index 9316304..fc592e5 100644
--- a/www/js/night.js
+++ b/www/js/night.js
@@ -74,7 +74,7 @@
 }
 
 bridge.registerListener( 'toggleNightMode', function( payload ) {
-       toggle( payload.nightStyleBundle.style_paths[0], payload.hasPageLoaded 
);
+       toggle( payload.nightStyleURL, payload.hasPageLoaded );
 } );
 
 module.exports = {
diff --git a/www/preview.html b/www/preview.html
index 5719ead..185cf1d 100644
--- a/www/preview.html
+++ b/www/preview.html
@@ -3,6 +3,7 @@
 <head>
     <base href="https://wikipedia.org"; /> <!-- Force links to resolve with 
https as protocol, rather than file:// -->
     <script src="file:///android_asset/preview.js"></script>
+    <link rel="stylesheet" href="file:///android_asset/preview.css"/>
 
     <meta name="viewport" content="width=device-width, user-scalable=no" />
 </head>

-- 
To view, visit https://gerrit.wikimedia.org/r/313809
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I481d5102ccffca407178e6b98b3e5d2c8363809b
Gerrit-PatchSet: 3
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Dbrant <[email protected]>
Gerrit-Reviewer: BearND <[email protected]>
Gerrit-Reviewer: Brion VIBBER <[email protected]>
Gerrit-Reviewer: Dbrant <[email protected]>
Gerrit-Reviewer: Mholloway <[email protected]>
Gerrit-Reviewer: Niedzielski <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to