use of me.ccrama.redditslide.handler.ToolbarScrollHideHandler in project Slide by ccrama.
the class NewsView method resetScroll.
public void resetScroll() {
if (toolbarScroll == null) {
toolbarScroll = new ToolbarScrollHideHandler(((BaseActivity) getActivity()).mToolbar, header) {
@Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
if (!posts.loading && !posts.nomore && !posts.offline && !adapter.isError) {
visibleItemCount = rv.getLayoutManager().getChildCount();
totalItemCount = rv.getLayoutManager().getItemCount();
int[] firstVisibleItems = ((CatchStaggeredGridLayoutManager) rv.getLayoutManager()).findFirstVisibleItemPositions(null);
if (firstVisibleItems != null && firstVisibleItems.length > 0) {
for (int firstVisibleItem : firstVisibleItems) {
pastVisiblesItems = firstVisibleItem;
if (SettingValues.scrollSeen && pastVisiblesItems > 0 && SettingValues.storeHistory) {
HasSeen.addSeenScrolling(posts.posts.get(pastVisiblesItems - 1).getFullName());
}
}
}
if ((visibleItemCount + pastVisiblesItems) + 5 >= totalItemCount) {
posts.loading = true;
posts.loadMore(mSwipeRefreshLayout.getContext(), NewsView.this, false, posts.subreddit);
}
}
if (recyclerView.getScrollState() == RecyclerView.SCROLL_STATE_DRAGGING) {
diff += dy;
} else {
diff = 0;
}
if (fab != null) {
if (dy <= 0 && fab.getId() != 0 && SettingValues.fab) {
if (recyclerView.getScrollState() != RecyclerView.SCROLL_STATE_DRAGGING || diff < -fab.getHeight() * 2) {
fab.show();
}
} else {
fab.hide();
}
}
}
@Override
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
// switch (newState) {
// case RecyclerView.SCROLL_STATE_IDLE:
// ((Reddit)getActivity().getApplicationContext()).getImageLoader().resume();
// break;
// case RecyclerView.SCROLL_STATE_DRAGGING:
// ((Reddit)getActivity().getApplicationContext()).getImageLoader().resume();
// break;
// case RecyclerView.SCROLL_STATE_SETTLING:
// ((Reddit)getActivity().getApplicationContext()).getImageLoader().pause();
// break;
// }
super.onScrollStateChanged(recyclerView, newState);
// If the toolbar search is open, and the user scrolls in the Main view--close the search UI
if (getActivity() instanceof MainActivity && (SettingValues.subredditSearchMethod == Constants.SUBREDDIT_SEARCH_METHOD_TOOLBAR || SettingValues.subredditSearchMethod == Constants.SUBREDDIT_SEARCH_METHOD_BOTH) && ((MainActivity) getContext()).findViewById(R.id.toolbar_search).getVisibility() == View.VISIBLE) {
((MainActivity) getContext()).findViewById(R.id.close_search_toolbar).performClick();
}
}
};
rv.addOnScrollListener(toolbarScroll);
} else {
toolbarScroll.reset = true;
}
}
use of me.ccrama.redditslide.handler.ToolbarScrollHideHandler in project Slide by ccrama.
the class ReadLaterView method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_verticalcontent, container, false);
final RecyclerView rv = v.findViewById(R.id.vertical_content);
final PreCachingLayoutManager mLayoutManager = new PreCachingLayoutManager(getContext());
rv.setLayoutManager(mLayoutManager);
v.findViewById(R.id.post_floating_action_button).setVisibility(View.GONE);
final SwipeRefreshLayout mSwipeRefreshLayout = v.findViewById(R.id.activity_main_swipe_refresh_layout);
mSwipeRefreshLayout.setColorSchemeColors(Palette.getColors("default", getActivity()));
// If we use 'findViewById(R.id.header).getMeasuredHeight()', 0 is always returned.
// So, we estimate the height of the header in dp
mSwipeRefreshLayout.setProgressViewOffset(false, Constants.SINGLE_HEADER_VIEW_OFFSET - Constants.PTR_OFFSET_TOP, Constants.SINGLE_HEADER_VIEW_OFFSET + Constants.PTR_OFFSET_BOTTOM);
mSwipeRefreshLayout.post(new Runnable() {
@Override
public void run() {
mSwipeRefreshLayout.setRefreshing(true);
}
});
posts = new HistoryPosts("readLater");
adapter = new ContributionAdapter(getActivity(), posts, rv);
rv.setAdapter(adapter);
posts.bindAdapter(adapter, mSwipeRefreshLayout);
// TODO catch errors
mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
posts.loadMore(adapter, true);
// TODO catch errors
}
});
rv.addOnScrollListener(new ToolbarScrollHideHandler(getActivity().findViewById(R.id.toolbar), getActivity().findViewById(R.id.header)) {
@Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
visibleItemCount = rv.getLayoutManager().getChildCount();
totalItemCount = rv.getLayoutManager().getItemCount();
if (rv.getLayoutManager() instanceof PreCachingLayoutManager) {
pastVisiblesItems = ((PreCachingLayoutManager) rv.getLayoutManager()).findFirstVisibleItemPosition();
} else {
int[] firstVisibleItems = null;
firstVisibleItems = ((CatchStaggeredGridLayoutManager) rv.getLayoutManager()).findFirstVisibleItemPositions(firstVisibleItems);
if (firstVisibleItems != null && firstVisibleItems.length > 0) {
pastVisiblesItems = firstVisibleItems[0];
}
}
if (!posts.loading) {
if ((visibleItemCount + pastVisiblesItems) + 5 >= totalItemCount && !posts.nomore) {
posts.loading = true;
posts.loadMore(adapter, false);
}
}
}
});
return v;
}
use of me.ccrama.redditslide.handler.ToolbarScrollHideHandler in project Slide by ccrama.
the class SubmissionsView method resetScroll.
public void resetScroll() {
if (toolbarScroll == null) {
toolbarScroll = new ToolbarScrollHideHandler(((BaseActivity) getActivity()).mToolbar, header) {
@Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
if (!posts.loading && !posts.nomore && !posts.offline && !adapter.isError) {
visibleItemCount = rv.getLayoutManager().getChildCount();
totalItemCount = rv.getLayoutManager().getItemCount();
int[] firstVisibleItems = ((CatchStaggeredGridLayoutManager) rv.getLayoutManager()).findFirstVisibleItemPositions(null);
if (firstVisibleItems != null && firstVisibleItems.length > 0) {
for (int firstVisibleItem : firstVisibleItems) {
pastVisiblesItems = firstVisibleItem;
if (SettingValues.scrollSeen && pastVisiblesItems > 0 && SettingValues.storeHistory) {
HasSeen.addSeenScrolling(posts.posts.get(pastVisiblesItems - 1).getFullName());
}
}
}
if ((visibleItemCount + pastVisiblesItems) + 5 >= totalItemCount) {
posts.loading = true;
posts.loadMore(mSwipeRefreshLayout.getContext(), SubmissionsView.this, false, posts.subreddit);
}
}
if (recyclerView.getScrollState() == RecyclerView.SCROLL_STATE_DRAGGING) {
diff += dy;
} else {
diff = 0;
}
if (fab != null) {
if (dy <= 0 && fab.getId() != 0 && SettingValues.fab) {
if (recyclerView.getScrollState() != RecyclerView.SCROLL_STATE_DRAGGING || diff < -fab.getHeight() * 2) {
fab.show();
}
} else {
if (!SettingValues.alwaysShowFAB) {
fab.hide();
}
}
}
}
@Override
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
// switch (newState) {
// case RecyclerView.SCROLL_STATE_IDLE:
// ((Reddit)getActivity().getApplicationContext()).getImageLoader().resume();
// break;
// case RecyclerView.SCROLL_STATE_DRAGGING:
// ((Reddit)getActivity().getApplicationContext()).getImageLoader().resume();
// break;
// case RecyclerView.SCROLL_STATE_SETTLING:
// ((Reddit)getActivity().getApplicationContext()).getImageLoader().pause();
// break;
// }
super.onScrollStateChanged(recyclerView, newState);
// If the toolbar search is open, and the user scrolls in the Main view--close the search UI
if (getActivity() instanceof MainActivity && (SettingValues.subredditSearchMethod == Constants.SUBREDDIT_SEARCH_METHOD_TOOLBAR || SettingValues.subredditSearchMethod == Constants.SUBREDDIT_SEARCH_METHOD_BOTH) && ((MainActivity) getContext()).findViewById(R.id.toolbar_search).getVisibility() == View.VISIBLE) {
((MainActivity) getContext()).findViewById(R.id.close_search_toolbar).performClick();
}
}
};
rv.addOnScrollListener(toolbarScroll);
} else {
toolbarScroll.reset = true;
}
}
use of me.ccrama.redditslide.handler.ToolbarScrollHideHandler in project Slide by ccrama.
the class SubredditListView method doAdapter.
public void doAdapter() {
mSwipeRefreshLayout.post(new Runnable() {
@Override
public void run() {
mSwipeRefreshLayout.setRefreshing(true);
}
});
posts = new SubredditNames(where, getContext(), SubredditListView.this);
adapter = new SubredditAdapter(getActivity(), posts, rv, where, this);
rv.setAdapter(adapter);
posts.loadMore(mSwipeRefreshLayout.getContext(), true, where);
mSwipeRefreshLayout.setOnRefreshListener(this::refresh);
rv.addOnScrollListener(new ToolbarScrollHideHandler(((BaseActivity) getActivity()).mToolbar, getActivity().findViewById(R.id.header)) {
@Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
if (!posts.loading && !posts.nomore) {
visibleItemCount = rv.getLayoutManager().getChildCount();
totalItemCount = rv.getLayoutManager().getItemCount();
pastVisiblesItems = ((LinearLayoutManager) rv.getLayoutManager()).findFirstVisibleItemPosition();
if ((visibleItemCount + pastVisiblesItems) >= totalItemCount) {
posts.loading = true;
LogUtil.v("Loading more");
posts.loadMore(mSwipeRefreshLayout.getContext(), false, where);
}
}
}
});
}
use of me.ccrama.redditslide.handler.ToolbarScrollHideHandler in project Slide by ccrama.
the class ModPage method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_verticalcontent, container, false);
RecyclerView rv = v.findViewById(R.id.vertical_content);
final PreCachingLayoutManager mLayoutManager = new PreCachingLayoutManager(getActivity());
rv.setLayoutManager(mLayoutManager);
v.findViewById(R.id.post_floating_action_button).setVisibility(View.GONE);
final SwipeRefreshLayout mSwipeRefreshLayout = v.findViewById(R.id.activity_main_swipe_refresh_layout);
mSwipeRefreshLayout.setColorSchemeColors(Palette.getColors(id, getActivity()));
// If we use 'findViewById(R.id.header).getMeasuredHeight()', 0 is always returned.
// So, we estimate the height of the header in dp
mSwipeRefreshLayout.setProgressViewOffset(false, Constants.TAB_HEADER_VIEW_OFFSET - Constants.PTR_OFFSET_TOP, Constants.TAB_HEADER_VIEW_OFFSET + Constants.PTR_OFFSET_BOTTOM);
mSwipeRefreshLayout.post(new Runnable() {
@Override
public void run() {
mSwipeRefreshLayout.setRefreshing(true);
}
});
posts = new ModeratorPosts(id, sub);
adapter = new ModeratorAdapter(getActivity(), posts, rv);
rv.setAdapter(adapter);
rv.addOnScrollListener(new ToolbarScrollHideHandler(((ModQueue) getActivity()).mToolbar, (getActivity()).findViewById(R.id.header)));
posts.bindAdapter(adapter, mSwipeRefreshLayout);
mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
posts.loadMore(adapter, id, sub);
}
});
return v;
}
Aggregations