Search in sources :

Example 31 with StaggeredGridLayoutManager

use of androidx.recyclerview.widget.StaggeredGridLayoutManager in project BGARefreshLayout-Android by bingoogolapple.

the class BGARefreshScrollingUtil method isRecyclerViewToBottom.

public static boolean isRecyclerViewToBottom(RecyclerView recyclerView) {
    if (recyclerView != null) {
        RecyclerView.LayoutManager manager = recyclerView.getLayoutManager();
        if (manager == null || manager.getItemCount() == 0) {
            return false;
        }
        if (manager instanceof LinearLayoutManager) {
            // 处理item高度超过一屏幕时的情况
            View lastVisibleChild = recyclerView.getChildAt(recyclerView.getChildCount() - 1);
            if (lastVisibleChild != null && lastVisibleChild.getMeasuredHeight() >= recyclerView.getMeasuredHeight()) {
                if (android.os.Build.VERSION.SDK_INT < 14) {
                    return !(ViewCompat.canScrollVertically(recyclerView, 1) || recyclerView.getScrollY() < 0);
                } else {
                    return !ViewCompat.canScrollVertically(recyclerView, 1);
                }
            }
            LinearLayoutManager layoutManager = (LinearLayoutManager) manager;
            if (layoutManager.findLastCompletelyVisibleItemPosition() == layoutManager.getItemCount() - 1) {
                BGAStickyNavLayout stickyNavLayout = getStickyNavLayout(recyclerView);
                if (stickyNavLayout != null) {
                    // 处理BGAStickyNavLayout中findLastCompletelyVisibleItemPosition失效问题
                    View lastCompletelyVisibleChild = layoutManager.getChildAt(layoutManager.findLastCompletelyVisibleItemPosition());
                    if (lastCompletelyVisibleChild == null) {
                        return true;
                    } else {
                        // 0表示x,1表示y
                        int[] location = new int[2];
                        lastCompletelyVisibleChild.getLocationOnScreen(location);
                        int lastChildBottomOnScreen = location[1] + lastCompletelyVisibleChild.getMeasuredHeight();
                        stickyNavLayout.getLocationOnScreen(location);
                        int stickyNavLayoutBottomOnScreen = location[1] + stickyNavLayout.getMeasuredHeight();
                        return lastChildBottomOnScreen <= stickyNavLayoutBottomOnScreen;
                    }
                } else {
                    return true;
                }
            }
        } else if (manager instanceof StaggeredGridLayoutManager) {
            StaggeredGridLayoutManager layoutManager = (StaggeredGridLayoutManager) manager;
            int[] out = layoutManager.findLastCompletelyVisibleItemPositions(null);
            int lastPosition = layoutManager.getItemCount() - 1;
            for (int position : out) {
                if (position == lastPosition) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : BGAStickyNavLayout(cn.bingoogolapple.refreshlayout.BGAStickyNavLayout) RecyclerView(androidx.recyclerview.widget.RecyclerView) StaggeredGridLayoutManager(androidx.recyclerview.widget.StaggeredGridLayoutManager) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) AbsListView(android.widget.AbsListView) ScrollView(android.widget.ScrollView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) WebView(android.webkit.WebView)

Example 32 with StaggeredGridLayoutManager

use of androidx.recyclerview.widget.StaggeredGridLayoutManager in project CloudReader by youlookwhat.

the class DoubanTopActivity method initRecyclerView.

private void initRecyclerView() {
    mDouBanTopAdapter = new DouBanTopAdapter(this);
    bindingView.xrvTop.setLayoutManager(new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL));
    bindingView.xrvTop.setItemAnimator(null);
    bindingView.xrvTop.setAdapter(mDouBanTopAdapter);
    mDouBanTopAdapter.setListener((bean, view) -> OneMovieDetailActivity.start(DoubanTopActivity.this, bean, view));
    bindingView.xrvTop.setOnLoadMoreListener(new ByRecyclerView.OnLoadMoreListener() {

        @Override
        public void onLoadMore() {
            viewModel.handleNextStart();
            loadDouBanTop250();
        }
    });
}
Also used : ByRecyclerView(me.jingbin.library.ByRecyclerView) DouBanTopAdapter(com.example.jingbin.cloudreader.adapter.DouBanTopAdapter) StaggeredGridLayoutManager(androidx.recyclerview.widget.StaggeredGridLayoutManager)

Example 33 with StaggeredGridLayoutManager

use of androidx.recyclerview.widget.StaggeredGridLayoutManager in project UltimateRecyclerView by cymcsg.

the class UltimateRecyclerView method scroll_load_more_detection.

private void scroll_load_more_detection(RecyclerView recyclerView) {
    RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
    if (layoutManagerType == null) {
        if (layoutManager instanceof GridLayoutManager) {
            layoutManagerType = LAYOUT_MANAGER_TYPE.GRID;
        } else if (layoutManager instanceof StaggeredGridLayoutManager) {
            layoutManagerType = LAYOUT_MANAGER_TYPE.STAGGERED_GRID;
        } else if (layoutManager instanceof LinearLayoutManager) {
            layoutManagerType = LAYOUT_MANAGER_TYPE.LINEAR;
        } else {
            throw new RuntimeException("Unsupported LayoutManager used. Valid ones are LinearLayoutManager, GridLayoutManager and StaggeredGridLayoutManager");
        }
    }
    mTotalItemCount = layoutManager.getItemCount();
    mVisibleItemCount = layoutManager.getChildCount();
    switch(layoutManagerType) {
        case LINEAR:
            mFirstVisibleItem = mRecyclerViewHelper.findFirstVisibleItemPosition();
            lastVisibleItemPosition = mRecyclerViewHelper.findLastVisibleItemPosition();
            break;
        case GRID:
            if (layoutManager instanceof GridLayoutManager) {
                GridLayoutManager ly = (GridLayoutManager) layoutManager;
                lastVisibleItemPosition = ly.findLastVisibleItemPosition();
                mFirstVisibleItem = ly.findFirstVisibleItemPosition();
            }
            break;
        case STAGGERED_GRID:
            if (layoutManager instanceof StaggeredGridLayoutManager) {
                StaggeredGridLayoutManager sy = (StaggeredGridLayoutManager) layoutManager;
                if (mlastPositionsStaggeredGridLayout == null)
                    mlastPositionsStaggeredGridLayout = new int[sy.getSpanCount()];
                sy.findLastVisibleItemPositions(mlastPositionsStaggeredGridLayout);
                lastVisibleItemPosition = findMax(mlastPositionsStaggeredGridLayout);
                sy.findFirstVisibleItemPositions(mlastPositionsStaggeredGridLayout);
                mFirstVisibleItem = findMin(mlastPositionsStaggeredGridLayout);
            }
            break;
    }
    if (automaticLoadMoreEnabled) {
        if (mTotalItemCount > previousTotal) {
            automaticLoadMoreEnabled = false;
            previousTotal = mTotalItemCount;
        }
    }
    boolean bottomEdgeHit = (mTotalItemCount - mVisibleItemCount) <= mFirstVisibleItem;
    if (bottomEdgeHit) {
        if (mIsLoadMoreWidgetEnabled) {
            /**
             *auto activate load more*
             */
            if (!automaticLoadMoreEnabled) {
                onLoadMoreListener.loadMore(mRecyclerView.getAdapter().getItemCount(), lastVisibleItemPosition);
                automaticLoadMoreEnabled = true;
            }
        }
        mAdapter.internalExecuteLoadingView();
        previousTotal = mTotalItemCount;
    }
}
Also used : GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) StaggeredGridLayoutManager(androidx.recyclerview.widget.StaggeredGridLayoutManager) RecyclerView(androidx.recyclerview.widget.RecyclerView) StaggeredGridLayoutManager(androidx.recyclerview.widget.StaggeredGridLayoutManager) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager)

Example 34 with StaggeredGridLayoutManager

use of androidx.recyclerview.widget.StaggeredGridLayoutManager in project Signal-Android by signalapp.

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)

Example 35 with StaggeredGridLayoutManager

use of androidx.recyclerview.widget.StaggeredGridLayoutManager in project BaseProject by fly803.

the class GirlListActivity method initView.

private void initView() {
    Toolbar toolbar = (Toolbar) findViewById(R.id.tool_bar);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            finish();
        }
    });
    toolbar.setTitle(R.string.award_list);
    mRecyuclerView = (RecyclerView) findViewById(R.id.gank_recycler_view);
    StaggeredGridLayoutManager manager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
    mRecyuclerView.setLayoutManager(manager);
    mRecyuclerView.addItemDecoration(new MyItemDecoration());
    mAdapter = new GanKAdapter();
    mRecyuclerView.setAdapter(mAdapter);
}
Also used : StaggeredGridLayoutManager(androidx.recyclerview.widget.StaggeredGridLayoutManager) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) GanKAdapter(com.ivy.baseproject.test.adapter.GanKAdapter) Toolbar(androidx.appcompat.widget.Toolbar)

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