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

Change subject: Fix a couple issues with single WebView.
......................................................................


Fix a couple issues with single WebView.

- Properly remember the y-scroll offset of the previous page.
- Improve our WebView's custom onClick handler so that it gets
  consumed properly if it's handled by the Lead Image or Bottom
  Content container.

Change-Id: Iafcbfadb9fcfac6d86841e2094808adb6c662848
---
M wikipedia/src/main/java/org/wikipedia/page/PageViewFragmentInternal.java
M 
wikipedia/src/main/java/org/wikipedia/page/bottomcontent/BottomContentHandler.java
M 
wikipedia/src/main/java/org/wikipedia/page/bottomcontent/BottomContentHandlerOld.java
M wikipedia/src/main/java/org/wikipedia/page/leadimages/LeadImagesHandler.java
M wikipedia/src/main/java/org/wikipedia/views/ObservableWebView.java
5 files changed, 38 insertions(+), 11 deletions(-)

Approvals:
  BearND: Looks good to me, approved
  jenkins-bot: Verified



diff --git 
a/wikipedia/src/main/java/org/wikipedia/page/PageViewFragmentInternal.java 
b/wikipedia/src/main/java/org/wikipedia/page/PageViewFragmentInternal.java
index 608d5af..777f0bd 100644
--- a/wikipedia/src/main/java/org/wikipedia/page/PageViewFragmentInternal.java
+++ b/wikipedia/src/main/java/org/wikipedia/page/PageViewFragmentInternal.java
@@ -485,10 +485,9 @@
             return;
         }
         PageBackStackItem item = backStack.get(backStack.size() - 1);
-        // display the page based on the backstack item...
-        displayNewPage(item.getTitle(), item.getHistoryEntry(), true, false);
-        // and stage the scrollY position based on the backstack item.
-        stagedScrollY = item.getScrollY();
+        // display the page based on the backstack item, stage the scrollY 
position based on
+        // the backstack item.
+        displayNewPage(item.getTitle(), item.getHistoryEntry(), true, false, 
item.getScrollY());
     }
 
     /**
@@ -504,6 +503,22 @@
      */
     public void displayNewPage(PageTitle title, HistoryEntry entry, boolean 
tryFromCache,
                                boolean pushBackStack) {
+        displayNewPage(title, entry, tryFromCache, pushBackStack, 0);
+    }
+
+    /**
+     * Load a new page into the WebView in this fragment.
+     * This shall be the single point of entry for loading content into the 
WebView, whether it's
+     * loading an entirely new page, refreshing the current page, retrying a 
failed network
+     * request, etc.
+     * @param title Title of the new page to load.
+     * @param entry HistoryEntry associated with the new page.
+     * @param tryFromCache Whether to try loading the page from cache 
(otherwise load directly
+     *                     from network).
+     * @param pushBackStack Whether to push the new page onto the backstack.
+     */
+    public void displayNewPage(PageTitle title, HistoryEntry entry, boolean 
tryFromCache,
+                               boolean pushBackStack, int stagedScrollY) {
         if (pushBackStack) {
             // update the topmost entry in the backstack, before we start 
overwriting things.
             updateBackStackItem();
@@ -538,6 +553,7 @@
             // whatever we pass to this event will be passed back to us by the 
WebView!
             wrapper.put("sequence", pageSequenceNum);
             wrapper.put("tryFromCache", tryFromCache);
+            wrapper.put("stagedScrollY", stagedScrollY);
             bridge.sendMessage("beginNewPage", wrapper);
         } catch (JSONException e) {
             //nope
@@ -545,9 +561,6 @@
     }
 
     private void loadPageOnWebViewReady(boolean tryFromCache) {
-        // reset staged scroll position to the top.
-        stagedScrollY = 0;
-
         // stage any section-specific link target from the title, since the 
title may be
         // replaced (normalized)
         sectionTargetFromTitle = title.getFragment();
@@ -647,6 +660,7 @@
                     if (messagePayload.getInt("sequence") != pageSequenceNum) {
                         return;
                     }
+                    stagedScrollY = messagePayload.getInt("stagedScrollY");
                     
loadPageOnWebViewReady(messagePayload.getBoolean("tryFromCache"));
                 } catch (JSONException e) {
                     //nope
diff --git 
a/wikipedia/src/main/java/org/wikipedia/page/bottomcontent/BottomContentHandler.java
 
b/wikipedia/src/main/java/org/wikipedia/page/bottomcontent/BottomContentHandler.java
index f55caba..58fab03 100644
--- 
a/wikipedia/src/main/java/org/wikipedia/page/bottomcontent/BottomContentHandler.java
+++ 
b/wikipedia/src/main/java/org/wikipedia/page/bottomcontent/BottomContentHandler.java
@@ -91,7 +91,10 @@
 
         webview.addOnClickListener(new ObservableWebView.OnClickListener() {
             @Override
-            public void onClick(float x, float y) {
+            public boolean onClick(float x, float y) {
+                if (bottomContentContainer.getVisibility() != View.VISIBLE) {
+                    return false;
+                }
                 // if the click event is within the area of the lead image, 
then the user
                 // must have wanted to click on the lead image!
                 int[] pos = new int[2];
@@ -102,6 +105,7 @@
                     activity.displayNewPage(title, historyEntry);
                     funnel.logSuggestionClicked(pageTitle, 
readMoreItems.getPageTitles(), 0);
                 }
+                return true;
             }
         });
 
@@ -176,6 +180,10 @@
     }
 
     public void beginLayout() {
+        firstTimeShown = false;
+        image1.setImageDrawable(null);
+        image1.setVisibility(View.INVISIBLE);
+        imagePlaceholder.setVisibility(View.VISIBLE);
         setupAttribution();
         if (parentFragment.getPage().couldHaveReadMoreSection()) {
             preRequestReadMoreItems();
diff --git 
a/wikipedia/src/main/java/org/wikipedia/page/bottomcontent/BottomContentHandlerOld.java
 
b/wikipedia/src/main/java/org/wikipedia/page/bottomcontent/BottomContentHandlerOld.java
index a7f6dcd..6e67ca4 100644
--- 
a/wikipedia/src/main/java/org/wikipedia/page/bottomcontent/BottomContentHandlerOld.java
+++ 
b/wikipedia/src/main/java/org/wikipedia/page/bottomcontent/BottomContentHandlerOld.java
@@ -189,6 +189,7 @@
     }
 
     public void beginLayout() {
+        firstTimeShown = false;
         setupAttribution();
         if (parentFragment.getPage().couldHaveReadMoreSection()) {
             preRequestReadMoreItems(activity.getLayoutInflater());
diff --git 
a/wikipedia/src/main/java/org/wikipedia/page/leadimages/LeadImagesHandler.java 
b/wikipedia/src/main/java/org/wikipedia/page/leadimages/LeadImagesHandler.java
index 9a85d73..1d9fd4a 100644
--- 
a/wikipedia/src/main/java/org/wikipedia/page/leadimages/LeadImagesHandler.java
+++ 
b/wikipedia/src/main/java/org/wikipedia/page/leadimages/LeadImagesHandler.java
@@ -140,7 +140,7 @@
 
         webview.addOnClickListener(new ObservableWebView.OnClickListener() {
             @Override
-            public void onClick(float x, float y) {
+            public boolean onClick(float x, float y) {
                 // if the click event is within the area of the lead image, 
then the user
                 // must have wanted to click on the lead image!
                 if (leadImagesEnabled && y < imageContainer.getHeight() - 
webView.getScrollY()) {
@@ -152,7 +152,9 @@
                                                                            
.getSite());
                         parentFragment.showImageGallery(imageTitle);
                     }
+                    return true;
                 }
+                return false;
             }
         });
 
diff --git a/wikipedia/src/main/java/org/wikipedia/views/ObservableWebView.java 
b/wikipedia/src/main/java/org/wikipedia/views/ObservableWebView.java
index ac48678..eec65e9 100644
--- a/wikipedia/src/main/java/org/wikipedia/views/ObservableWebView.java
+++ b/wikipedia/src/main/java/org/wikipedia/views/ObservableWebView.java
@@ -48,7 +48,7 @@
     }
 
     public interface OnClickListener {
-        void onClick(float x, float y);
+        boolean onClick(float x, float y);
     }
 
     public interface OnScrollChangeListener {
@@ -119,7 +119,9 @@
                 if (Math.abs(event.getX() - touchStartX) <= touchSlop
                     && Math.abs(event.getY() - touchStartY) <= touchSlop) {
                     for (OnClickListener listener : onClickListeners) {
-                        listener.onClick(event.getX(), event.getY());
+                        if (listener.onClick(event.getX(), event.getY())) {
+                            return true;
+                        }
                     }
                 }
             case MotionEvent.ACTION_CANCEL:

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Iafcbfadb9fcfac6d86841e2094808adb6c662848
Gerrit-PatchSet: 3
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Dbrant <dbr...@wikimedia.org>
Gerrit-Reviewer: BearND <bsitzm...@wikimedia.org>
Gerrit-Reviewer: Brion VIBBER <br...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to