Search in sources :

Example 41 with GridLayoutManager

use of androidx.recyclerview.widget.GridLayoutManager in project epoxy by airbnb.

the class EpoxyItemSpacingDecorator method calculatePositionDetails.

private void calculatePositionDetails(RecyclerView parent, int position, LayoutManager layout) {
    int itemCount = parent.getAdapter().getItemCount();
    firstItem = position == 0;
    lastItem = position == itemCount - 1;
    horizontallyScrolling = layout.canScrollHorizontally();
    verticallyScrolling = layout.canScrollVertically();
    grid = layout instanceof GridLayoutManager;
    if (grid) {
        GridLayoutManager grid = (GridLayoutManager) layout;
        final SpanSizeLookup spanSizeLookup = grid.getSpanSizeLookup();
        int spanSize = spanSizeLookup.getSpanSize(position);
        int spanCount = grid.getSpanCount();
        int spanIndex = spanSizeLookup.getSpanIndex(position, spanCount);
        isFirstItemInRow = spanIndex == 0;
        fillsLastSpan = spanIndex + spanSize == spanCount;
        isInFirstRow = isInFirstRow(position, spanSizeLookup, spanCount);
        isInLastRow = !isInFirstRow && isInLastRow(position, itemCount, spanSizeLookup, spanCount);
    }
}
Also used : SpanSizeLookup(androidx.recyclerview.widget.GridLayoutManager.SpanSizeLookup) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager)

Example 42 with GridLayoutManager

use of androidx.recyclerview.widget.GridLayoutManager in project Signal-Android by WhisperSystems.

the class PaymentsRecoveryPhraseFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    Toolbar toolbar = view.findViewById(R.id.payments_recovery_phrase_fragment_toolbar);
    RecyclerView recyclerView = view.findViewById(R.id.payments_recovery_phrase_fragment_recycler);
    TextView message = view.findViewById(R.id.payments_recovery_phrase_fragment_message);
    View next = view.findViewById(R.id.payments_recovery_phrase_fragment_next);
    View edit = view.findViewById(R.id.payments_recovery_phrase_fragment_edit);
    View copy = view.findViewById(R.id.payments_recovery_phrase_fragment_copy);
    GridLayoutManager gridLayoutManager = new GridLayoutManager(requireContext(), SPAN_COUNT);
    PaymentsRecoveryPhraseFragmentArgs args = PaymentsRecoveryPhraseFragmentArgs.fromBundle(requireArguments());
    final List<String> words;
    if (args.getWords() != null) {
        words = Arrays.asList(args.getWords());
        setUpForConfirmation(message, next, edit, copy, words);
    } else {
        Mnemonic mnemonic = SignalStore.paymentsValues().getPaymentsMnemonic();
        words = mnemonic.getWords();
        setUpForDisplay(message, next, edit, copy, words, args);
    }
    List<MnemonicPart> parts = Stream.of(words).mapIndexed(MnemonicPart::new).sorted(new MnemonicPartComparator(words.size(), SPAN_COUNT)).toList();
    MnemonicPartAdapter adapter = new MnemonicPartAdapter();
    recyclerView.setLayoutManager(gridLayoutManager);
    recyclerView.setAdapter(adapter);
    recyclerView.setOverScrollMode(View.OVER_SCROLL_NEVER);
    toolbar.setNavigationOnClickListener(v -> {
        if (args.getFinishOnConfirm()) {
            requireActivity().finish();
        } else {
            toolbar.setNavigationOnClickListener(t -> Navigation.findNavController(view).popBackStack(R.id.paymentsHome, false));
        }
    });
    adapter.submitList(parts);
}
Also used : View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) Mnemonic(org.thoughtcrime.securesms.payments.Mnemonic) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) Toolbar(androidx.appcompat.widget.Toolbar)

Example 43 with GridLayoutManager

use of androidx.recyclerview.widget.GridLayoutManager in project boilerplate by koush.

the class GridRecyclerView method setNumColumns.

private void setNumColumns(Context context, int numColumns) {
    if (gridLayoutManager == null) {
        gridLayoutManager = new GridLayoutManager(context, numColumns);
        typeToSpan = new Hashtable<Integer, Integer>();
        gridLayoutManager.setSpanSizeLookup(spanSizeLookup = new GridLayoutManager.SpanSizeLookup() {

            @Override
            public int getSpanSize(int position) {
                int viewType = getAdapter().getItemViewType(position);
                Integer span = typeToSpan.get(viewType);
                if (span != null)
                    return span;
                ViewHolder vh = getAdapter().createViewHolder(GridRecyclerView.this, viewType);
                int foundSpan;
                if (vh instanceof SpanningViewHolder)
                    foundSpan = ((SpanningViewHolder) vh).getSpanSize(gridLayoutManager.getSpanCount());
                else
                    foundSpan = 1;
                typeToSpan.put(viewType, foundSpan);
                return foundSpan;
            }
        });
        setLayoutManager(gridLayoutManager);
    } else {
        gridLayoutManager.setSpanCount(numColumns);
    }
    typeToSpan.clear();
    spanSizeLookup.invalidateSpanIndexCache();
    requestLayout();
}
Also used : GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager)

Example 44 with GridLayoutManager

use of androidx.recyclerview.widget.GridLayoutManager in project FlexibleAdapter by davideas.

the class FlexibleItemDecoration method getItemOffsets.

/*====================*/
/* OFFSET CALCULATION */
/*====================*/
/**
 * @since 1.0.0-b1
 */
@Override
public void getItemOffsets(final Rect outRect, View view, RecyclerView recyclerView, RecyclerView.State state) {
    int position = recyclerView.getChildAdapterPosition(view);
    // Skip check so on item deleted, offset is kept (only if general offset was set!)
    // if (position == RecyclerView.NO_POSITION) return;
    // Get custom Item Decoration or default
    RecyclerView.Adapter adapter = recyclerView.getAdapter();
    int itemType = (position != RecyclerView.NO_POSITION ? adapter.getItemViewType(position) : 0);
    ItemDecoration deco = getItemDecoration(itemType);
    // No offset set, applies the general offset to this item decoration
    if (!deco.hasOffset()) {
        deco = new ItemDecoration(mOffset);
    }
    // Default values (LinearLayout)
    int spanIndex = 0;
    int spanSize = 1;
    int spanCount = 1;
    int orientation = RecyclerView.VERTICAL;
    if (recyclerView.getLayoutManager() instanceof GridLayoutManager) {
        GridLayoutManager.LayoutParams lp = (GridLayoutManager.LayoutParams) view.getLayoutParams();
        spanIndex = lp.getSpanIndex();
        spanSize = lp.getSpanSize();
        GridLayoutManager lm = (GridLayoutManager) recyclerView.getLayoutManager();
        // Assume that there are spanCount items in this row/column.
        spanCount = lm.getSpanCount();
        orientation = lm.getOrientation();
    } else if (recyclerView.getLayoutManager() instanceof StaggeredGridLayoutManager) {
        StaggeredGridLayoutManager.LayoutParams lp = (StaggeredGridLayoutManager.LayoutParams) view.getLayoutParams();
        spanIndex = lp.getSpanIndex();
        StaggeredGridLayoutManager lm = (StaggeredGridLayoutManager) recyclerView.getLayoutManager();
        // Assume that there are spanCount items in this row/column.
        spanCount = lm.getSpanCount();
        spanSize = lp.isFullSpan() ? spanCount : 1;
        orientation = lm.getOrientation();
    }
    boolean isFirstRowOrColumn = isFirstRowOrColumn(position, adapter, spanIndex, itemType);
    boolean isLastRowOrColumn = isLastRowOrColumn(position, adapter, spanIndex, spanCount, spanSize, itemType);
    // Reset offset values
    int left = 0, top = 0, right = 0, bottom = 0;
    if (orientation == GridLayoutManager.VERTICAL) {
        int index = spanIndex;
        if (withLeftEdge)
            index = spanCount - spanIndex;
        left = deco.left * index / spanCount;
        index = (spanCount - (spanIndex + spanSize - 1) - 1);
        if (withRightEdge)
            index = spanIndex + spanSize;
        right = deco.right * index / spanCount;
        if (isFirstRowOrColumn && (withTopEdge)) {
            top = deco.top;
        }
        if (isLastRowOrColumn) {
            if (withBottomEdge) {
                bottom = deco.bottom;
            }
        } else {
            bottom = deco.bottom;
        }
    } else {
        int index = spanIndex;
        if (withTopEdge)
            index = spanCount - spanIndex;
        top = deco.top * index / spanCount;
        index = (spanCount - (spanIndex + spanSize - 1) - 1);
        if (withBottomEdge)
            index = spanIndex + spanSize;
        bottom = deco.bottom * index / spanCount;
        if (isFirstRowOrColumn && (withLeftEdge)) {
            left = deco.left;
        }
        if (isLastRowOrColumn) {
            if (withRightEdge) {
                right = deco.right;
            }
        } else {
            right = deco.right;
        }
    }
    outRect.set(left, top, right, bottom);
    applySectionGap(outRect, adapter, position, orientation);
}
Also used : GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) StaggeredGridLayoutManager(androidx.recyclerview.widget.StaggeredGridLayoutManager) RecyclerView(androidx.recyclerview.widget.RecyclerView) StaggeredGridLayoutManager(androidx.recyclerview.widget.StaggeredGridLayoutManager) SuppressLint(android.annotation.SuppressLint)

Example 45 with GridLayoutManager

use of androidx.recyclerview.widget.GridLayoutManager in project FlexibleAdapter by davideas.

the class FragmentExpandableSections method createNewGridLayoutManager.

@Override
protected GridLayoutManager createNewGridLayoutManager() {
    GridLayoutManager gridLayoutManager = new SmoothScrollGridLayoutManager(getActivity(), mColumnCount);
    gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {

        @Override
        public int getSpanSize(int position) {
            // here, you should use them and not Layout integers
            switch(mAdapter.getItemViewType(position)) {
                case R.layout.recycler_scrollable_layout_item:
                case R.layout.recycler_scrollable_uls_item:
                case R.layout.recycler_header_item:
                case R.layout.recycler_expandable_header_item:
                case R.layout.recycler_expandable_item:
                    return mColumnCount;
                default:
                    return 1;
            }
        }
    });
    return gridLayoutManager;
}
Also used : GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) SmoothScrollGridLayoutManager(eu.davidea.flexibleadapter.common.SmoothScrollGridLayoutManager) SmoothScrollGridLayoutManager(eu.davidea.flexibleadapter.common.SmoothScrollGridLayoutManager)

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