Search in sources :

Example 16 with StaggeredGridLayoutManager

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;
}
Also used : RecyclerView(androidx.recyclerview.widget.RecyclerView) StaggeredGridLayoutManager(androidx.recyclerview.widget.StaggeredGridLayoutManager) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager)

Example 17 with StaggeredGridLayoutManager

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;
}
Also used : RecyclerView(androidx.recyclerview.widget.RecyclerView) StaggeredGridLayoutManager(androidx.recyclerview.widget.StaggeredGridLayoutManager) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager)

Example 18 with StaggeredGridLayoutManager

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;
    }
}
Also used : NestedScrollView(androidx.core.widget.NestedScrollView) ScrollView(android.widget.ScrollView) ScrollingView(androidx.core.view.ScrollingView) AbsListView(android.widget.AbsListView) RecyclerView(androidx.recyclerview.widget.RecyclerView) StaggeredGridLayoutManager(androidx.recyclerview.widget.StaggeredGridLayoutManager) WebView(android.webkit.WebView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager)

Example 19 with StaggeredGridLayoutManager

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();
        }
    }
}
Also used : GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) StaggeredGridLayoutManager(androidx.recyclerview.widget.StaggeredGridLayoutManager) StaggeredGridLayoutManager(androidx.recyclerview.widget.StaggeredGridLayoutManager) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager)

Example 20 with StaggeredGridLayoutManager

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));
}
Also used : StaggeredGridLayoutManager(androidx.recyclerview.widget.StaggeredGridLayoutManager) FrameLayout(android.widget.FrameLayout) ContentLoadingProgressBar(androidx.core.widget.ContentLoadingProgressBar) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView)

Aggregations

StaggeredGridLayoutManager (androidx.recyclerview.widget.StaggeredGridLayoutManager)36 RecyclerView (androidx.recyclerview.widget.RecyclerView)25 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)16 View (android.view.View)14 GridLayoutManager (androidx.recyclerview.widget.GridLayoutManager)9 Toolbar (androidx.appcompat.widget.Toolbar)6 AbsListView (android.widget.AbsListView)5 SwipeRefreshLayout (androidx.swiperefreshlayout.widget.SwipeRefreshLayout)4 WebView (android.webkit.WebView)3 ScrollView (android.widget.ScrollView)3 BindView (butterknife.BindView)3 OnItemLongClickListener (xyz.zpayh.adapter.OnItemLongClickListener)3 DialogInterface (android.content.DialogInterface)2 Adapter (android.widget.Adapter)2 FrameLayout (android.widget.FrameLayout)2 TextView (android.widget.TextView)2 Nullable (androidx.annotation.Nullable)2 ContentLoadingProgressBar (androidx.core.widget.ContentLoadingProgressBar)2 SimpleItemAnimator (androidx.recyclerview.widget.SimpleItemAnimator)2 FloatingActionButton (com.google.android.material.floatingactionbutton.FloatingActionButton)2