Dbrant has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/311131

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
1 file changed, 12 insertions(+), 9 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia 
refs/changes/31/311131/1

diff --git a/app/src/main/java/org/wikipedia/feed/FeedFragment.java 
b/app/src/main/java/org/wikipedia/feed/FeedFragment.java
index 3693135..68c01f7 100644
--- a/app/src/main/java/org/wikipedia/feed/FeedFragment.java
+++ b/app/src/main/java/org/wikipedia/feed/FeedFragment.java
@@ -4,10 +4,11 @@
 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.support.v7.widget.StaggeredGridLayoutManager;
 import android.view.LayoutInflater;
 import android.view.Menu;
 import android.view.MenuInflater;
@@ -29,7 +30,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 +47,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 +86,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 +121,7 @@
     public void onDestroyView() {
         coordinator.setFeedUpdateListener(null);
         swipeRefreshLayout.setOnRefreshListener(null);
+        feedView.removeOnScrollListener(feedScrollListener);
         unbinder.unbind();
         unbinder = null;
         super.onDestroyView();
@@ -257,15 +257,18 @@
         }
     }
 
-    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);
+            StaggeredGridLayoutManager manager = ((StaggeredGridLayoutManager) 
recyclerView.getLayoutManager());
+            int[] visibleItems = new int[manager.getSpanCount()];
+            manager.findFirstVisibleItemPositions(visibleItems);
+            boolean shouldShowSearchIcon = visibleItems[0] != 0;
             if (shouldShowSearchIcon != searchIconVisible) {
                 searchIconVisible = shouldShowSearchIcon;
                 getActivity().supportInvalidateOptionsMenu();
             }
-            swipeRefreshLayout.setEnabled(verticalOffset == 0);
         }
     }
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I20530a194de02f0847e0a3cc40ee0acb582a47d4
Gerrit-PatchSet: 1
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Dbrant <dbr...@wikimedia.org>

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

Reply via email to