use of me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager 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(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;
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(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.Views.CatchStaggeredGridLayoutManager 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 = ((RecyclerView) v.findViewById(R.id.vertical_content));
final PreCachingLayoutManager mLayoutManager;
mLayoutManager = new PreCachingLayoutManager(getContext());
rv.setLayoutManager(mLayoutManager);
v.findViewById(R.id.post_floating_action_button).setVisibility(View.GONE);
final SwipeRefreshLayout mSwipeRefreshLayout = (SwipeRefreshLayout) 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((Toolbar) getActivity().findViewById(R.id.toolbar), getActivity().findViewById(R.id.header)) {
@Override
public void onScrolled(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.Views.CatchStaggeredGridLayoutManager 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(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;
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 {
fab.hide();
}
}
}
@Override
public void onScrollStateChanged(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.Views.CatchStaggeredGridLayoutManager in project Slide by ccrama.
the class MainActivity method getCurrentPage.
public int getCurrentPage() {
int position = 0;
int currentOrientation = getResources().getConfiguration().orientation;
if (adapter.getCurrentFragment() == null) {
return 0;
}
if (((SubmissionsView) adapter.getCurrentFragment()).rv.getLayoutManager() instanceof LinearLayoutManager && currentOrientation == Configuration.ORIENTATION_LANDSCAPE) {
position = ((LinearLayoutManager) ((SubmissionsView) adapter.getCurrentFragment()).rv.getLayoutManager()).findFirstCompletelyVisibleItemPosition() - 1;
} else if (((SubmissionsView) adapter.getCurrentFragment()).rv.getLayoutManager() instanceof CatchStaggeredGridLayoutManager) {
int[] firstVisibleItems = null;
firstVisibleItems = ((CatchStaggeredGridLayoutManager) ((SubmissionsView) adapter.getCurrentFragment()).rv.getLayoutManager()).findFirstCompletelyVisibleItemPositions(firstVisibleItems);
if (firstVisibleItems != null && firstVisibleItems.length > 0) {
position = firstVisibleItems[0] - 1;
}
} else {
position = ((PreCachingLayoutManager) ((SubmissionsView) adapter.getCurrentFragment()).rv.getLayoutManager()).findFirstCompletelyVisibleItemPosition() - 1;
}
return position;
}
use of me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager in project Slide by ccrama.
the class MultiredditOverview method setDataSet.
private void setDataSet(List<MultiReddit> data) {
try {
usedArray = data;
if (usedArray.isEmpty()) {
buildDialog();
} else {
if (adapter == null) {
adapter = new OverviewPagerAdapter(getSupportFragmentManager());
} else {
adapter.notifyDataSetChanged();
}
pager.setAdapter(adapter);
pager.setOffscreenPageLimit(1);
tabs.setupWithViewPager(pager);
tabs.setSelectedTabIndicatorColor(new ColorPreferences(MultiredditOverview.this).getColor(usedArray.get(0).getDisplayName()));
doDrawerSubs(0);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = this.getWindow();
window.setStatusBarColor(Palette.getDarkerColor(usedArray.get(0).getDisplayName()));
}
final View header = findViewById(R.id.header);
tabs.setOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(pager) {
@Override
public void onTabReselected(TabLayout.Tab tab) {
super.onTabReselected(tab);
int[] firstVisibleItems;
int pastVisiblesItems = 0;
firstVisibleItems = ((CatchStaggeredGridLayoutManager) (((MultiredditView) adapter.getCurrentFragment()).rv.getLayoutManager())).findFirstVisibleItemPositions(null);
if (firstVisibleItems != null && firstVisibleItems.length > 0) {
for (int firstVisibleItem : firstVisibleItems) {
pastVisiblesItems = firstVisibleItem;
}
}
if (pastVisiblesItems > 8) {
((MultiredditView) adapter.getCurrentFragment()).rv.scrollToPosition(0);
if (header != null) {
header.animate().translationY(header.getHeight()).setInterpolator(new LinearInterpolator()).setDuration(0);
}
} else {
((MultiredditView) adapter.getCurrentFragment()).rv.smoothScrollToPosition(0);
}
}
});
findViewById(R.id.header).setBackgroundColor(Palette.getColor(usedArray.get(0).getDisplayName()));
}
} catch (NullPointerException e) {
buildDialog(true);
Log.e(LogUtil.getTag(), "Cannot load multis:\n" + e);
}
}
Aggregations