use of androidx.recyclerview.widget.StaggeredGridLayoutManager in project SmoothRefreshLayout by dkzwm.
the class HorizontalScrollCompat method canAutoRefresh.
public static boolean canAutoRefresh(View view) {
if (ViewCatcherUtil.isRecyclerView(view)) {
RecyclerView recyclerView = (RecyclerView) view;
RecyclerView.LayoutManager manager = recyclerView.getLayoutManager();
if (manager == null) {
return false;
}
int firstVisiblePosition = -1;
if (manager instanceof LinearLayoutManager) {
LinearLayoutManager linearManager = ((LinearLayoutManager) manager);
if (linearManager.getOrientation() != RecyclerView.HORIZONTAL) {
return false;
}
firstVisiblePosition = linearManager.findFirstVisibleItemPosition();
} else if (manager instanceof StaggeredGridLayoutManager) {
StaggeredGridLayoutManager gridLayoutManager = (StaggeredGridLayoutManager) manager;
if (gridLayoutManager.getOrientation() != RecyclerView.HORIZONTAL) {
return false;
}
int[] firstPositions = new int[gridLayoutManager.getSpanCount()];
gridLayoutManager.findFirstVisibleItemPositions(firstPositions);
for (int value : firstPositions) {
if (value == 0) {
firstVisiblePosition = 0;
break;
}
}
}
RecyclerView.Adapter adapter = recyclerView.getAdapter();
return adapter != null && firstVisiblePosition == 0;
}
return false;
}
use of androidx.recyclerview.widget.StaggeredGridLayoutManager in project SmoothRefreshLayout by dkzwm.
the class HorizontalScrollCompat method canAutoLoadMore.
public static boolean canAutoLoadMore(View view) {
if (ViewCatcherUtil.isRecyclerView(view)) {
RecyclerView recyclerView = (RecyclerView) view;
RecyclerView.LayoutManager manager = recyclerView.getLayoutManager();
if (manager == null) {
return false;
}
int lastVisiblePosition = 0;
if (manager instanceof LinearLayoutManager) {
LinearLayoutManager linearManager = ((LinearLayoutManager) manager);
if (linearManager.getOrientation() != RecyclerView.HORIZONTAL) {
return false;
}
lastVisiblePosition = linearManager.findLastVisibleItemPosition();
} else if (manager instanceof StaggeredGridLayoutManager) {
StaggeredGridLayoutManager gridLayoutManager = (StaggeredGridLayoutManager) manager;
if (gridLayoutManager.getOrientation() != RecyclerView.HORIZONTAL) {
return false;
}
int[] lastPositions = new int[gridLayoutManager.getSpanCount()];
gridLayoutManager.findLastVisibleItemPositions(lastPositions);
for (int value : lastPositions) {
if (value > lastVisiblePosition) {
lastVisiblePosition = value;
}
}
}
RecyclerView.Adapter adapter = recyclerView.getAdapter();
return adapter != null && adapter.getItemCount() > 0 && lastVisiblePosition >= 0 && lastVisiblePosition >= adapter.getItemCount() - 1;
}
return false;
}
use of androidx.recyclerview.widget.StaggeredGridLayoutManager in project SmoothRefreshLayout by dkzwm.
the class ScrollCompat method isScrollingView.
public static boolean isScrollingView(View view) {
if (view instanceof AbsListView || view instanceof ScrollView || view instanceof WebView) {
return true;
}
if (ViewCatcherUtil.isRecyclerView(view)) {
RecyclerView recyclerView = (RecyclerView) view;
RecyclerView.LayoutManager manager = recyclerView.getLayoutManager();
if (manager != null) {
if (manager instanceof LinearLayoutManager) {
LinearLayoutManager linearManager = ((LinearLayoutManager) manager);
return linearManager.getOrientation() == RecyclerView.VERTICAL;
} else if (manager instanceof StaggeredGridLayoutManager) {
StaggeredGridLayoutManager gridLayoutManager = (StaggeredGridLayoutManager) manager;
return gridLayoutManager.getOrientation() == RecyclerView.VERTICAL;
}
}
return true;
} else {
return view instanceof ScrollingView;
}
}
use of androidx.recyclerview.widget.StaggeredGridLayoutManager in project SwipeRecyclerView by yanzhenjie.
the class SwipeRecyclerView method onScrolled.
@Override
public void onScrolled(int dx, int dy) {
LayoutManager layoutManager = getLayoutManager();
if (layoutManager instanceof LinearLayoutManager) {
LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager;
int itemCount = layoutManager.getItemCount();
if (itemCount <= 0)
return;
int lastVisiblePosition = linearLayoutManager.findLastVisibleItemPosition();
if (itemCount == lastVisiblePosition + 1 && (mScrollState == SCROLL_STATE_DRAGGING || mScrollState == SCROLL_STATE_SETTLING)) {
dispatchLoadMore();
}
} else if (layoutManager instanceof StaggeredGridLayoutManager) {
StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
int itemCount = layoutManager.getItemCount();
if (itemCount <= 0)
return;
int[] lastVisiblePositionArray = staggeredGridLayoutManager.findLastCompletelyVisibleItemPositions(null);
int lastVisiblePosition = lastVisiblePositionArray[lastVisiblePositionArray.length - 1];
if (itemCount == lastVisiblePosition + 1 && (mScrollState == SCROLL_STATE_DRAGGING || mScrollState == SCROLL_STATE_SETTLING)) {
dispatchLoadMore();
}
}
}
use of androidx.recyclerview.widget.StaggeredGridLayoutManager in project Signal-Android by WhisperSystems.
the class GiphyMp4Fragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
boolean isForMms = requireArguments().getBoolean(IS_FOR_MMS, false);
FrameLayout frameLayout = view.findViewById(R.id.giphy_parent);
RecyclerView recycler = view.findViewById(R.id.giphy_recycler);
ContentLoadingProgressBar progressBar = view.findViewById(R.id.content_loading);
TextView nothingFound = view.findViewById(R.id.nothing_found);
GiphyMp4ViewModel viewModel = ViewModelProviders.of(requireActivity(), new GiphyMp4ViewModel.Factory(isForMms)).get(GiphyMp4ViewModel.class);
GiphyMp4Adapter adapter = new GiphyMp4Adapter(viewModel::saveToBlob);
List<GiphyMp4ProjectionPlayerHolder> holders = GiphyMp4ProjectionPlayerHolder.injectVideoViews(requireContext(), getViewLifecycleOwner().getLifecycle(), frameLayout, GiphyMp4PlaybackPolicy.maxSimultaneousPlaybackInSearchResults());
GiphyMp4ProjectionRecycler callback = new GiphyMp4ProjectionRecycler(holders);
recycler.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
recycler.setAdapter(adapter);
recycler.setItemAnimator(null);
progressBar.show();
GiphyMp4PlaybackController.attach(recycler, callback, GiphyMp4PlaybackPolicy.maxSimultaneousPlaybackInSearchResults());
viewModel.getImages().observe(getViewLifecycleOwner(), images -> {
nothingFound.setVisibility(images.isEmpty() ? View.VISIBLE : View.INVISIBLE);
adapter.submitList(images, progressBar::hide);
});
viewModel.getPagingController().observe(getViewLifecycleOwner(), adapter::setPagingController);
viewModel.getPagedData().observe(getViewLifecycleOwner(), unused -> recycler.scrollToPosition(0));
}
Aggregations