Yuvipanda has uploaded a new change for review. https://gerrit.wikimedia.org/r/115871
Change subject: Make sure dir attribute is set on RTL pages ...................................................................... Make sure dir attribute is set on RTL pages Bug: 61867 Change-Id: Ib1479511c99e188eb2f79262255048142d2a276d --- M wikipedia/assets/abusefilter.js M wikipedia/assets/bundle.js M wikipedia/assets/preview.js M wikipedia/src/main/java/org/wikipedia/Utils.java M wikipedia/src/main/java/org/wikipedia/editing/EditPreviewFragment.java M wikipedia/src/main/java/org/wikipedia/editing/EditSectionActivity.java M wikipedia/src/main/java/org/wikipedia/page/PageViewFragment.java M www/Gruntfile.js M www/abusefilter.js A www/js/rtlsupport.js M www/preview.js 11 files changed, 87 insertions(+), 18 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia refs/changes/71/115871/1 diff --git a/wikipedia/assets/abusefilter.js b/wikipedia/assets/abusefilter.js index 0c16147..00a511b 100644 --- a/wikipedia/assets/abusefilter.js +++ b/wikipedia/assets/abusefilter.js @@ -21,7 +21,7 @@ content.appendChild( warning ); } ); -},{"./bridge":2,"./transformer":3}],2:[function(require,module,exports){ +},{"./bridge":2,"./transformer":4}],2:[function(require,module,exports){ function Bridge() { } @@ -60,6 +60,12 @@ module.exports.sendMessage( "DOMLoaded", {} ); }; },{}],3:[function(require,module,exports){ +var bridge = require("./bridge"); + +bridge.registerListener( "setDirectionality", function( payload ) { + document.getElementsByTagName( "html" )[0].setAttribute( "dir", payload.dir ); +} ); +},{"./bridge":2}],4:[function(require,module,exports){ function Transformer() { } @@ -83,4 +89,4 @@ module.exports = new Transformer(); -},{}]},{},[2,1]) \ No newline at end of file +},{}]},{},[2,1,3]) \ No newline at end of file diff --git a/wikipedia/assets/bundle.js b/wikipedia/assets/bundle.js index 9089297..98ac29b 100644 --- a/wikipedia/assets/bundle.js +++ b/wikipedia/assets/bundle.js @@ -98,6 +98,12 @@ } ); },{"./bridge":2}],5:[function(require,module,exports){ var bridge = require("./bridge"); + +bridge.registerListener( "setDirectionality", function( payload ) { + document.getElementsByTagName( "html" )[0].setAttribute( "dir", payload.dir ); +} ); +},{"./bridge":2}],6:[function(require,module,exports){ +var bridge = require("./bridge"); var transformer = require("./transformer"); bridge.registerListener( "displayLeadSection", function( payload ) { @@ -164,7 +170,7 @@ window.scrollTo(0, scrollY); }); -},{"./bridge":2,"./transformer":6}],6:[function(require,module,exports){ +},{"./bridge":2,"./transformer":7}],7:[function(require,module,exports){ function Transformer() { } @@ -188,7 +194,7 @@ module.exports = new Transformer(); -},{}],7:[function(require,module,exports){ +},{}],8:[function(require,module,exports){ var bridge = require("./bridge"); var transformer = require("./transformer"); @@ -226,4 +232,4 @@ return content; } ); -},{"./bridge":2,"./transformer":6}]},{},[4,6,7,2,1,3,5]) \ No newline at end of file +},{"./bridge":2,"./transformer":7}]},{},[4,7,8,2,1,3,6,5]) \ No newline at end of file diff --git a/wikipedia/assets/preview.js b/wikipedia/assets/preview.js index da569cf..1e8c969 100644 --- a/wikipedia/assets/preview.js +++ b/wikipedia/assets/preview.js @@ -77,4 +77,10 @@ content.innerHTML = payload.html; } ); -},{"./bridge":2}]},{},[2,1,3]) \ No newline at end of file +},{"./bridge":2}],4:[function(require,module,exports){ +var bridge = require("./bridge"); + +bridge.registerListener( "setDirectionality", function( payload ) { + document.getElementsByTagName( "html" )[0].setAttribute( "dir", payload.dir ); +} ); +},{"./bridge":2}]},{},[2,1,3,4]) \ No newline at end of file diff --git a/wikipedia/src/main/java/org/wikipedia/Utils.java b/wikipedia/src/main/java/org/wikipedia/Utils.java index a669489..1af1563 100644 --- a/wikipedia/src/main/java/org/wikipedia/Utils.java +++ b/wikipedia/src/main/java/org/wikipedia/Utils.java @@ -294,5 +294,30 @@ return "wikipedia-android-official"; } } + + /** + * List of wiki language codes for which the content is primarily RTL. + * + * Ensure that this is always sorted alphabetically. + */ + private static String[] rtlLangs = { + "arc", "arz", "ar", "bcc", "bqi", "ckb", "dv", "fa", "glk", "ha", "he", + "khw", "ks", "mzn", "pnb", "ps", "sd", "ug", "ur", "yi" + }; + public static void setupDirectionality(String lang, CommunicationBridge bridge) { + JSONObject payload = new JSONObject(); + try { + if (Arrays.binarySearch(rtlLangs, lang, null) < 0) { + payload.put("dir", "ltr"); + } else { + payload.put("dir", "rtl"); + } + Log.d("Wikipedia", lang); + Log.d("Wikipedia", payload.toString(4)); + } catch (JSONException e) { + throw new RuntimeException(e); + } + bridge.sendMessage("setDirectionality", payload); + } } diff --git a/wikipedia/src/main/java/org/wikipedia/editing/EditPreviewFragment.java b/wikipedia/src/main/java/org/wikipedia/editing/EditPreviewFragment.java index a9cc961..f8a687e 100644 --- a/wikipedia/src/main/java/org/wikipedia/editing/EditPreviewFragment.java +++ b/wikipedia/src/main/java/org/wikipedia/editing/EditPreviewFragment.java @@ -1,13 +1,9 @@ package org.wikipedia.editing; import android.app.*; -import android.os.Bundle; -import android.support.v4.app.*; +import android.os.*; import android.support.v4.app.Fragment; -import android.util.*; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; +import android.view.*; import org.json.*; import org.wikipedia.*; @@ -52,12 +48,19 @@ bridge.sendMessage("displayPreviewHTML", payload); } + private boolean isDirectionSetup = false; + public void showPreview(PageTitle title, String wikiText) { Utils.hideSoftKeyboard(getActivity()); final ProgressDialog dialog = new ProgressDialog(getActivity()); dialog.setIndeterminate(true); dialog.setMessage(getString(R.string.edit_preview_fetching_dialog_message)); + if (!isDirectionSetup) { + Utils.setupDirectionality(title.getSite().getLanguage(), bridge); + isDirectionSetup = true; + } + new EditPreviewTask(getActivity(), wikiText, title) { @Override public void onBeforeExecute() { diff --git a/wikipedia/src/main/java/org/wikipedia/editing/EditSectionActivity.java b/wikipedia/src/main/java/org/wikipedia/editing/EditSectionActivity.java index 705d0d0..12d458b 100644 --- a/wikipedia/src/main/java/org/wikipedia/editing/EditSectionActivity.java +++ b/wikipedia/src/main/java/org/wikipedia/editing/EditSectionActivity.java @@ -73,6 +73,7 @@ abusefilterContainer = findViewById(R.id.edit_section_abusefilter_container); abusefilterWebView = (WebView) findViewById(R.id.edit_section_abusefilter_webview); abusefilterBridge = new CommunicationBridge(abusefilterWebView, "file:///android_asset/abusefilter.html"); + Utils.setupDirectionality(title.getSite().getLanguage(), abusefilterBridge); abuseFilterBackAction = findViewById(R.id.edit_section_abusefilter_back); captchaHandler = new CaptchaHandler(this, title.getSite(), progressDialog, sectionContainer, R.string.edit_section_activity_title); diff --git a/wikipedia/src/main/java/org/wikipedia/page/PageViewFragment.java b/wikipedia/src/main/java/org/wikipedia/page/PageViewFragment.java index 8c5e16a..bf9510f 100644 --- a/wikipedia/src/main/java/org/wikipedia/page/PageViewFragment.java +++ b/wikipedia/src/main/java/org/wikipedia/page/PageViewFragment.java @@ -161,6 +161,7 @@ bridge = new CommunicationBridge(webView, "file:///android_asset/index.html"); Utils.addUtilityMethodsToBridge(getActivity(), bridge); + Utils.setupDirectionality(title.getSite().getLanguage(), bridge); linkHandler = new LinkHandler(getActivity(), bridge, title.getSite()); app = (WikipediaApp)getActivity().getApplicationContext(); api = ((WikipediaApp)getActivity().getApplicationContext()).getAPIForSite(title.getSite()); diff --git a/www/Gruntfile.js b/www/Gruntfile.js index 06be39d..f1dd319 100644 --- a/www/Gruntfile.js +++ b/www/Gruntfile.js @@ -7,6 +7,7 @@ "js/actions.js", "js/editaction.js", "js/sections.js", + "js/rtlsupport.js", "tests/*.js" ]; var allStyleFiles = [ @@ -28,7 +29,8 @@ "js/bridge.js", "js/actions.js", "js/editaction.js", - "js/sections.js" + "js/sections.js", + "js/rtlsupport.js" ], "bundle-test.js": [ "js/main.js", @@ -37,12 +39,14 @@ ], "abusefilter.js": [ "js/bridge.js", - "js/abusefilter.js" + "js/abusefilter.js", + "js/rtlsupport.js" ], "preview.js": [ "js/bridge.js", "js/actions.js", - "js/preview.js" + "js/preview.js", + "js/rtlsupport.js" ] } } diff --git a/www/abusefilter.js b/www/abusefilter.js index 0c16147..00a511b 100644 --- a/www/abusefilter.js +++ b/www/abusefilter.js @@ -21,7 +21,7 @@ content.appendChild( warning ); } ); -},{"./bridge":2,"./transformer":3}],2:[function(require,module,exports){ +},{"./bridge":2,"./transformer":4}],2:[function(require,module,exports){ function Bridge() { } @@ -60,6 +60,12 @@ module.exports.sendMessage( "DOMLoaded", {} ); }; },{}],3:[function(require,module,exports){ +var bridge = require("./bridge"); + +bridge.registerListener( "setDirectionality", function( payload ) { + document.getElementsByTagName( "html" )[0].setAttribute( "dir", payload.dir ); +} ); +},{"./bridge":2}],4:[function(require,module,exports){ function Transformer() { } @@ -83,4 +89,4 @@ module.exports = new Transformer(); -},{}]},{},[2,1]) \ No newline at end of file +},{}]},{},[2,1,3]) \ No newline at end of file diff --git a/www/js/rtlsupport.js b/www/js/rtlsupport.js new file mode 100644 index 0000000..2cc1e85 --- /dev/null +++ b/www/js/rtlsupport.js @@ -0,0 +1,5 @@ +var bridge = require("./bridge"); + +bridge.registerListener( "setDirectionality", function( payload ) { + document.getElementsByTagName( "html" )[0].setAttribute( "dir", payload.dir ); +} ); \ No newline at end of file diff --git a/www/preview.js b/www/preview.js index da569cf..1e8c969 100644 --- a/www/preview.js +++ b/www/preview.js @@ -77,4 +77,10 @@ content.innerHTML = payload.html; } ); -},{"./bridge":2}]},{},[2,1,3]) \ No newline at end of file +},{"./bridge":2}],4:[function(require,module,exports){ +var bridge = require("./bridge"); + +bridge.registerListener( "setDirectionality", function( payload ) { + document.getElementsByTagName( "html" )[0].setAttribute( "dir", payload.dir ); +} ); +},{"./bridge":2}]},{},[2,1,3,4]) \ No newline at end of file -- To view, visit https://gerrit.wikimedia.org/r/115871 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib1479511c99e188eb2f79262255048142d2a276d Gerrit-PatchSet: 1 Gerrit-Project: apps/android/wikipedia Gerrit-Branch: master Gerrit-Owner: Yuvipanda <yuvipa...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits