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);
}
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;
}
}
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;
}
});
}
}
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;
}
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());
}
Aggregations