Search in sources :

Example 66 with GridLayoutManager

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

the class DefaultEndlessRecyclerAdapter method onAttachedToRecyclerView.

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

Example 67 with GridLayoutManager

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

the class DemoActivity method onPhotosLoaded.

/**
 * Photos loading results callback.
 */
@Result(FlickrApi.LOAD_IMAGES_EVENT)
private void onPhotosLoaded(List<Photo> photos, boolean hasMore) {
    // RecyclerView will continue scrolling when new items are added, we need to stop it.
    // Seems like this buggy behavior was introduced in support library v26.0.x
    final boolean onBottom = views.grid.findViewHolderForAdapterPosition(gridAdapter.getCount() - 1) != null;
    if (onBottom) {
        views.grid.stopScroll();
    }
    // Setting new photos list
    gridAdapter.setPhotos(photos, hasMore);
    pagerAdapter.setPhotos(photos);
    gridAdapter.onNextItemsLoaded();
    // Ensure listener called for 0 position
    pagerListener.onPageSelected(views.pager.getCurrentItem());
    // Restoring saved state
    if (savedPagerPosition != NO_POSITION && savedPagerPosition < photos.size()) {
        pagerAdapter.setActivated(true);
        listAnimator.enter(savedPagerPosition, false);
    }
    if (savedGridPosition != NO_POSITION && savedGridPosition < photos.size()) {
        GridLayoutManager manager = (GridLayoutManager) Objects.requireNonNull(views.grid.getLayoutManager());
        manager.scrollToPositionWithOffset(savedGridPosition, savedGridPositionFromTop);
    }
    clearScreenState();
}
Also used : GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) Result(com.alexvasilkov.events.Events.Result)

Example 68 with GridLayoutManager

use of androidx.recyclerview.widget.GridLayoutManager in project Conversations by siacs.

the class GridManager method setupLayoutManager.

public static void setupLayoutManager(final Context context, RecyclerView recyclerView, @DimenRes int desiredSize) {
    int maxWidth = context.getResources().getDisplayMetrics().widthPixels;
    ColumnInfo columnInfo = calculateColumnCount(context, maxWidth, desiredSize);
    Log.d(Config.LOGTAG, "preliminary count=" + columnInfo.count);
    MediaAdapter.setMediaSize(recyclerView, columnInfo.width);
    recyclerView.setLayoutManager(new GridLayoutManager(context, columnInfo.count));
    recyclerView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            recyclerView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            final int availableWidth = recyclerView.getMeasuredWidth();
            if (availableWidth == 0) {
                Log.e(Config.LOGTAG, "GridManager: available width was 0; probably because layout was hidden");
                return;
            }
            final ColumnInfo columnInfo = calculateColumnCount(context, recyclerView.getMeasuredWidth(), desiredSize);
            Log.d(Config.LOGTAG, "final count " + columnInfo.count);
            final RecyclerView.Adapter adapter = recyclerView.getAdapter();
            if (adapter != null && adapter.getItemCount() != 0) {
                Log.e(Config.LOGTAG, "adapter already has items; just go with it now");
                return;
            }
            setupLayoutManagerInternal(recyclerView, columnInfo);
            MediaAdapter.setMediaSize(recyclerView, columnInfo.width);
        }
    });
}
Also used : GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) MediaAdapter(eu.siacs.conversations.ui.adapter.MediaAdapter) ViewTreeObserver(android.view.ViewTreeObserver)

Example 69 with GridLayoutManager

use of androidx.recyclerview.widget.GridLayoutManager in project AntennaPod by AntennaPod.

the class SubscriptionFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View root = inflater.inflate(R.layout.fragment_subscriptions, container, false);
    toolbar = root.findViewById(R.id.toolbar);
    toolbar.setOnMenuItemClickListener(this);
    displayUpArrow = getParentFragmentManager().getBackStackEntryCount() != 0;
    if (savedInstanceState != null) {
        displayUpArrow = savedInstanceState.getBoolean(KEY_UP_ARROW);
    }
    ((MainActivity) getActivity()).setupToolbarToggle(toolbar, displayUpArrow);
    toolbar.inflateMenu(R.menu.subscriptions);
    for (int i = 0; i < COLUMN_CHECKBOX_IDS.length; i++) {
        // Do this in Java to localize numbers
        toolbar.getMenu().findItem(COLUMN_CHECKBOX_IDS[i]).setTitle(String.format(Locale.getDefault(), "%d", i + MIN_NUM_COLUMNS));
    }
    refreshToolbarState();
    if (getArguments() != null) {
        displayedFolder = getArguments().getString(ARGUMENT_FOLDER, null);
        if (displayedFolder != null) {
            toolbar.setTitle(displayedFolder);
        }
    }
    subscriptionRecycler = root.findViewById(R.id.subscriptions_grid);
    GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), prefs.getInt(PREF_NUM_COLUMNS, getDefaultNumOfColumns()), RecyclerView.VERTICAL, false);
    subscriptionRecycler.setLayoutManager(gridLayoutManager);
    subscriptionRecycler.addItemDecoration(new SubscriptionsRecyclerAdapter.GridDividerItemDecorator());
    gridLayoutManager.setSpanCount(prefs.getInt(PREF_NUM_COLUMNS, getDefaultNumOfColumns()));
    registerForContextMenu(subscriptionRecycler);
    subscriptionAddButton = root.findViewById(R.id.subscriptions_add);
    progressBar = root.findViewById(R.id.progLoading);
    feedsFilteredMsg = root.findViewById(R.id.feeds_filtered_message);
    feedsFilteredMsg.setOnClickListener((l) -> SubscriptionsFilterDialog.showDialog(requireContext()));
    SwipeRefreshLayout swipeRefreshLayout = root.findViewById(R.id.swipeRefresh);
    swipeRefreshLayout.setDistanceToTriggerSync(getResources().getInteger(R.integer.swipe_refresh_distance));
    swipeRefreshLayout.setOnRefreshListener(() -> {
        AutoUpdateManager.runImmediate(requireContext());
        new Handler(Looper.getMainLooper()).postDelayed(() -> swipeRefreshLayout.setRefreshing(false), getResources().getInteger(R.integer.swipe_to_refresh_duration_in_ms));
    });
    speedDialView = root.findViewById(R.id.fabSD);
    speedDialView.setOverlayLayout(root.findViewById(R.id.fabSDOverlay));
    speedDialView.inflate(R.menu.nav_feed_action_speeddial);
    speedDialView.setOnChangeListener(new SpeedDialView.OnChangeListener() {

        @Override
        public boolean onMainActionSelected() {
            return false;
        }

        @Override
        public void onToggleChanged(boolean isOpen) {
        }
    });
    speedDialView.setOnActionSelectedListener(actionItem -> {
        new FeedMultiSelectActionHandler((MainActivity) getActivity(), subscriptionAdapter.getSelectedItems()).handleAction(actionItem.getId());
        return true;
    });
    return root;
}
Also used : Handler(android.os.Handler) EmptyViewHandler(de.danoeh.antennapod.view.EmptyViewHandler) FeedMultiSelectActionHandler(de.danoeh.antennapod.fragment.actions.FeedMultiSelectActionHandler) MainActivity(de.danoeh.antennapod.activity.MainActivity) SpeedDialView(com.leinardi.android.speeddial.SpeedDialView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) SuppressLint(android.annotation.SuppressLint) SubscriptionsRecyclerAdapter(de.danoeh.antennapod.adapter.SubscriptionsRecyclerAdapter) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) SpeedDialView(com.leinardi.android.speeddial.SpeedDialView) FeedMultiSelectActionHandler(de.danoeh.antennapod.fragment.actions.FeedMultiSelectActionHandler)

Example 70 with GridLayoutManager

use of androidx.recyclerview.widget.GridLayoutManager in project AntennaPod by AntennaPod.

the class SubscriptionFragment method setColumnNumber.

private void setColumnNumber(int columns) {
    GridLayoutManager gridLayoutManager = (GridLayoutManager) subscriptionRecycler.getLayoutManager();
    gridLayoutManager.setSpanCount(columns);
    subscriptionAdapter.notifyDataSetChanged();
    prefs.edit().putInt(PREF_NUM_COLUMNS, columns).apply();
    refreshToolbarState();
}
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