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

Change subject: Show Search icon in Feed when Search bar scrolled away.
......................................................................


Show Search icon in Feed when Search bar scrolled away.

Bug: T145683
Change-Id: I20530a194de02f0847e0a3cc40ee0acb582a47d4
---
M app/src/main/java/org/wikipedia/feed/FeedFragment.java
M app/src/main/java/org/wikipedia/feed/view/FeedView.java
2 files changed, 15 insertions(+), 9 deletions(-)

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



diff --git a/app/src/main/java/org/wikipedia/feed/FeedFragment.java 
b/app/src/main/java/org/wikipedia/feed/FeedFragment.java
index 3693135..2ee7e97 100644
--- a/app/src/main/java/org/wikipedia/feed/FeedFragment.java
+++ b/app/src/main/java/org/wikipedia/feed/FeedFragment.java
@@ -4,10 +4,10 @@
 import android.support.annotation.IntRange;
 import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
-import android.support.design.widget.AppBarLayout;
 import android.support.design.widget.Snackbar;
 import android.support.v4.app.Fragment;
 import android.support.v4.widget.SwipeRefreshLayout;
+import android.support.v7.widget.RecyclerView;
 import android.view.LayoutInflater;
 import android.view.Menu;
 import android.view.MenuInflater;
@@ -29,7 +29,6 @@
 import org.wikipedia.feed.view.FeedViewCallback;
 import org.wikipedia.history.HistoryEntry;
 import org.wikipedia.settings.Prefs;
-import org.wikipedia.util.DimenUtil;
 import org.wikipedia.util.FeedbackUtil;
 import org.wikipedia.util.ResourceUtil;
 
@@ -47,8 +46,7 @@
     private FeedCoordinator coordinator;
     private FeedFunnel funnel;
     private FeedViewCallback feedCallback = new FeedCallback();
-    private FeedHeaderOffsetChangedListener headerOffsetChangedListener = new 
FeedHeaderOffsetChangedListener();
-    private int searchIconShowThresholdPx;
+    private FeedScrollListener feedScrollListener = new FeedScrollListener();
     private boolean searchIconVisible;
 
     public interface Callback {
@@ -87,7 +85,7 @@
 
         unbinder = ButterKnife.bind(this, view);
         feedView.set(coordinator, feedCallback);
-        searchIconShowThresholdPx = (int) 
getResources().getDimension(R.dimen.view_feed_header_height) - 
DimenUtil.getContentTopOffsetPx(getContext());
+        feedView.addOnScrollListener(feedScrollListener);
 
         swipeRefreshLayout.setColorSchemeResources(R.color.foundation_blue);
         swipeRefreshLayout.setOnRefreshListener(new 
SwipeRefreshLayout.OnRefreshListener() {
@@ -122,6 +120,7 @@
     public void onDestroyView() {
         coordinator.setFeedUpdateListener(null);
         swipeRefreshLayout.setOnRefreshListener(null);
+        feedView.removeOnScrollListener(feedScrollListener);
         unbinder.unbind();
         unbinder = null;
         super.onDestroyView();
@@ -257,15 +256,15 @@
         }
     }
 
-    private class FeedHeaderOffsetChangedListener implements 
AppBarLayout.OnOffsetChangedListener {
+    private class FeedScrollListener extends RecyclerView.OnScrollListener {
         @Override
-        public void onOffsetChanged(AppBarLayout appBarLayout, int 
verticalOffset) {
-            boolean shouldShowSearchIcon = !((searchIconShowThresholdPx + 
verticalOffset) > 0);
+        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
+            super.onScrolled(recyclerView, dx, dy);
+            boolean shouldShowSearchIcon = 
feedView.getFirstVisibleItemPosition() != 0;
             if (shouldShowSearchIcon != searchIconVisible) {
                 searchIconVisible = shouldShowSearchIcon;
                 getActivity().supportInvalidateOptionsMenu();
             }
-            swipeRefreshLayout.setEnabled(verticalOffset == 0);
         }
     }
 
diff --git a/app/src/main/java/org/wikipedia/feed/view/FeedView.java 
b/app/src/main/java/org/wikipedia/feed/view/FeedView.java
index e2736f2..fdf90af 100644
--- a/app/src/main/java/org/wikipedia/feed/view/FeedView.java
+++ b/app/src/main/java/org/wikipedia/feed/view/FeedView.java
@@ -55,6 +55,13 @@
         }
     }
 
+    public int getFirstVisibleItemPosition() {
+        StaggeredGridLayoutManager manager = ((StaggeredGridLayoutManager) 
getLayoutManager());
+        int[] visibleItems = new int[manager.getSpanCount()];
+        manager.findFirstVisibleItemPositions(visibleItems);
+        return visibleItems[0];
+    }
+
     private void init() {
         setVerticalScrollBarEnabled(true);
         minColumnWidth((int) 
getResources().getDimension(R.dimen.view_feed_min_column_width));

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I20530a194de02f0847e0a3cc40ee0acb582a47d4
Gerrit-PatchSet: 2
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: Mholloway <mhollo...@wikimedia.org>
Gerrit-Reviewer: Niedzielski <sniedziel...@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