Search in sources :

Example 21 with GridLayoutManager

use of androidx.recyclerview.widget.GridLayoutManager in project GestureViews by alexvasilkov.

the class DemoActivity method initGrid.

/**
 * Initializing grid view (RecyclerView) and endless loading.
 */
private void initGrid() {
    // Setting up images grid
    final int cols = getResources().getInteger(R.integer.images_grid_columns);
    views.grid.setLayoutManager(new GridLayoutManager(this, cols));
    gridAdapter = new PhotoListAdapter(this);
    gridAdapter.setLoadingOffset(PAGE_SIZE / 2);
    gridAdapter.setCallbacks(new EndlessRecyclerAdapter.LoaderCallbacks() {

        @Override
        public boolean canLoadNextItems() {
            return gridAdapter.canLoadNext();
        }

        @Override
        public void loadNextItems() {
            // We should either load all items that were loaded before state save / restore,
            // or next page if we already loaded all previously shown items
            int count = Math.max(savedPhotoCount, gridAdapter.getCount() + PAGE_SIZE);
            Events.create(FlickrApi.LOAD_IMAGES_EVENT).param(count).post();
        }
    });
    views.grid.setAdapter(gridAdapter);
}
Also used : GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) PhotoListAdapter(com.alexvasilkov.gestures.sample.demo.adapter.PhotoListAdapter) EndlessRecyclerAdapter(com.alexvasilkov.gestures.sample.demo.adapter.EndlessRecyclerAdapter) SuppressLint(android.annotation.SuppressLint)

Example 22 with GridLayoutManager

use of androidx.recyclerview.widget.GridLayoutManager in project GestureViews by alexvasilkov.

the class DefaultEndlessRecyclerAdapter method onDetachedFromRecyclerView.

@Override
public void onDetachedFromRecyclerView(@NonNull RecyclerView recyclerView) {
    super.onDetachedFromRecyclerView(recyclerView);
    if (recyclerView.getLayoutManager() instanceof GridLayoutManager) {
        GridLayoutManager gridManager = (GridLayoutManager) recyclerView.getLayoutManager();
        gridManager.setSpanSizeLookup(originalSpanLookup);
        originalSpanLookup = null;
        spanCount = 1;
    }
}
Also used : GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager)

Example 23 with GridLayoutManager

use of androidx.recyclerview.widget.GridLayoutManager in project android_packages_apps_Settings by omnirom.

the class ContextualCardsAdapter method onAttachedToRecyclerView.

@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
    super.onAttachedToRecyclerView(recyclerView);
    mRecyclerView = recyclerView;
    final RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager) {
        final GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
        gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {

            @Override
            public int getSpanSize(int position) {
                final int viewType = mContextualCards.get(position).getViewType();
                if (viewType == ConditionContextualCardRenderer.VIEW_TYPE_HALF_WIDTH || viewType == SliceContextualCardRenderer.VIEW_TYPE_HALF_WIDTH) {
                    return HALF_WIDTH;
                }
                return FULL_WIDTH;
            }
        });
    }
}
Also used : GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 24 with GridLayoutManager

use of androidx.recyclerview.widget.GridLayoutManager in project android_packages_apps_Settings by omnirom.

the class ContextualCardsFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final Context context = getContext();
    final View rootView = inflater.inflate(R.layout.settings_homepage, container, false);
    mCardsContainer = rootView.findViewById(R.id.card_container);
    mLayoutManager = new GridLayoutManager(getActivity(), SPAN_COUNT, GridLayoutManager.VERTICAL, false);
    mCardsContainer.setLayoutManager(mLayoutManager);
    mContextualCardsAdapter = new ContextualCardsAdapter(context, this, /* lifecycleOwner */
    mContextualCardManager);
    mCardsContainer.setItemAnimator(null);
    mCardsContainer.setAdapter(mContextualCardsAdapter);
    mContextualCardManager.setListener(mContextualCardsAdapter);
    mCardsContainer.setListener(this);
    mItemTouchHelper = new ItemTouchHelper(new SwipeDismissalDelegate(mContextualCardsAdapter));
    mItemTouchHelper.attachToRecyclerView(mCardsContainer);
    return rootView;
}
Also used : Context(android.content.Context) ItemTouchHelper(androidx.recyclerview.widget.ItemTouchHelper) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) SwipeDismissalDelegate(com.android.settings.homepage.contextualcards.slices.SwipeDismissalDelegate) View(android.view.View)

Example 25 with GridLayoutManager

use of androidx.recyclerview.widget.GridLayoutManager in project apps-android-commons by commons-app.

the class ContributionsListFragment method onSaveInstanceState.

@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
    super.onSaveInstanceState(outState);
    final GridLayoutManager layoutManager = (GridLayoutManager) rvContributionsList.getLayoutManager();
    outState.putParcelable(RV_STATE, layoutManager.onSaveInstanceState());
}
Also used : GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager)

Aggregations

GridLayoutManager (androidx.recyclerview.widget.GridLayoutManager)122 RecyclerView (androidx.recyclerview.widget.RecyclerView)63 View (android.view.View)45 TextView (android.widget.TextView)19 StaggeredGridLayoutManager (androidx.recyclerview.widget.StaggeredGridLayoutManager)16 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)13 ImageView (android.widget.ImageView)12 Nullable (androidx.annotation.Nullable)11 Toolbar (androidx.appcompat.widget.Toolbar)10 ViewGroup (android.view.ViewGroup)7 SmoothScrollGridLayoutManager (eu.davidea.flexibleadapter.common.SmoothScrollGridLayoutManager)7 SuppressLint (android.annotation.SuppressLint)6 Context (android.content.Context)6 ArrayList (java.util.ArrayList)6 NonNull (androidx.annotation.NonNull)5 SwipeRefreshLayout (androidx.swiperefreshlayout.widget.SwipeRefreshLayout)5 List (java.util.List)5 RefreshingListenerAdapter (me.dkzwm.widget.srl.RefreshingListenerAdapter)5 Drawable (android.graphics.drawable.Drawable)4 Handler (android.os.Handler)3