Search in sources :

Example 21 with StaggeredGridLayoutManager

use of androidx.recyclerview.widget.StaggeredGridLayoutManager in project MyJapanese by 54wall.

the class FavLessonFragment method setData.

@Override
public void setData(List<LessonFav> data) {
    Log.e(TAG, "setData!!!!!!");
    lessonFavList = data;
    staggeredGridAdapter = new StaggeredGridAdapter(getActivity(), data);
    mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL));
    mRecyclerView.setAdapter(staggeredGridAdapter);
    staggeredGridAdapter.setOnItemClickLitener(new OnItemClickLitener() {

        @Override
        public void onItemClick(View view, int position) {
            staggeredGridAdapter.notifyItemRemoved(position);
            ((MainActivity) getActivity()).switchFavWord(staggeredGridAdapter.getItemLessonId(position), false);
        }

        @Override
        public void onItemLongClick(View view, final int position) {
        }
    });
    ItemTouchHelper itemTouchHelper = new ItemTouchHelper(callback);
    itemTouchHelper.attachToRecyclerView(mRecyclerView);
}
Also used : OnItemClickLitener(pri.weiqiang.liyujapanese.ui.adapter.stagger.OnItemClickLitener) ItemTouchHelper(androidx.recyclerview.widget.ItemTouchHelper) StaggeredGridAdapter(pri.weiqiang.liyujapanese.ui.adapter.StaggeredGridAdapter) StaggeredGridLayoutManager(androidx.recyclerview.widget.StaggeredGridLayoutManager) FavLessonFragmentView(pri.weiqiang.liyujapanese.mvp.view.dic.FavLessonFragmentView) BindView(butterknife.BindView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 22 with StaggeredGridLayoutManager

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

the class FlexibleLayoutManager method findFirstVisibleItemPosition.

/**
 * Helper method to find the adapter position of the <b>first partially</b> visible view
 * [for each span], no matter which Layout is.
 *
 * @return the adapter position of the <b>first partially</b> visible item or {@code RecyclerView.NO_POSITION}
 * if there aren't any visible items.
 * @see #findFirstCompletelyVisibleItemPosition()
 * @since 5.0.0-rc1
 */
@Override
public int findFirstVisibleItemPosition() {
    RecyclerView.LayoutManager layoutManager = getLayoutManager();
    if (layoutManager instanceof StaggeredGridLayoutManager) {
        StaggeredGridLayoutManager staggeredGLM = (StaggeredGridLayoutManager) layoutManager;
        int position = staggeredGLM.findFirstVisibleItemPositions(null)[0];
        for (int i = 1; i < getSpanCount(); i++) {
            int nextPosition = staggeredGLM.findFirstVisibleItemPositions(null)[i];
            if (nextPosition < position) {
                position = nextPosition;
            }
        }
        return position;
    } else {
        return ((LinearLayoutManager) layoutManager).findFirstVisibleItemPosition();
    }
}
Also used : RecyclerView(androidx.recyclerview.widget.RecyclerView) StaggeredGridLayoutManager(androidx.recyclerview.widget.StaggeredGridLayoutManager) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager)

Example 23 with StaggeredGridLayoutManager

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

the class FragmentOverall method onPrepareOptionsMenu.

@Override
public void onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    MenuItem gridMenuItem = menu.findItem(R.id.action_list_type);
    if (mRecyclerView.getLayoutManager() instanceof StaggeredGridLayoutManager) {
        gridMenuItem.setIcon(R.drawable.ic_view_agenda_white_24dp);
        gridMenuItem.setTitle(R.string.linear_layout);
    } else if (mRecyclerView.getLayoutManager() instanceof GridLayoutManager) {
        gridMenuItem.setIcon(R.drawable.ic_dashboard_white_24dp);
        gridMenuItem.setTitle(R.string.staggered_layout);
    } else {
        gridMenuItem.setIcon(R.drawable.ic_view_grid_white_24dp);
        gridMenuItem.setTitle(R.string.grid_layout);
    }
}
Also used : GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) StaggeredGridLayoutManager(androidx.recyclerview.widget.StaggeredGridLayoutManager) SmoothScrollGridLayoutManager(eu.davidea.flexibleadapter.common.SmoothScrollGridLayoutManager) MenuItem(android.view.MenuItem) StaggeredGridLayoutManager(androidx.recyclerview.widget.StaggeredGridLayoutManager)

Example 24 with StaggeredGridLayoutManager

use of androidx.recyclerview.widget.StaggeredGridLayoutManager in project SmoothRefreshLayout by dkzwm.

the class ScrollCompat method canAutoLoadMore.

public static boolean canAutoLoadMore(View view) {
    if (view instanceof AbsListView) {
        AbsListView listView = (AbsListView) view;
        final int lastVisiblePosition = listView.getLastVisiblePosition();
        final Adapter adapter = listView.getAdapter();
        return adapter != null && adapter.getCount() > 0 && lastVisiblePosition >= 0 && lastVisiblePosition >= adapter.getCount() - 1;
    } else if (ViewCatcherUtil.isRecyclerView(view)) {
        RecyclerView recyclerView = (RecyclerView) view;
        RecyclerView.LayoutManager manager = recyclerView.getLayoutManager();
        if (manager == null) {
            return false;
        }
        int lastVisiblePosition = -1;
        if (manager instanceof LinearLayoutManager) {
            LinearLayoutManager linearManager = ((LinearLayoutManager) manager);
            if (linearManager.getOrientation() == RecyclerView.HORIZONTAL) {
                return false;
            }
            lastVisiblePosition = linearManager.findLastVisibleItemPosition();
        } else if (manager instanceof StaggeredGridLayoutManager) {
            StaggeredGridLayoutManager gridLayoutManager = (StaggeredGridLayoutManager) manager;
            if (gridLayoutManager.getOrientation() == RecyclerView.HORIZONTAL) {
                return false;
            }
            int[] lastPositions = new int[gridLayoutManager.getSpanCount()];
            gridLayoutManager.findLastVisibleItemPositions(lastPositions);
            for (int value : lastPositions) {
                if (value > lastVisiblePosition) {
                    lastVisiblePosition = value;
                }
            }
        }
        RecyclerView.Adapter adapter = recyclerView.getAdapter();
        return adapter != null && adapter.getItemCount() > 0 && lastVisiblePosition >= 0 && lastVisiblePosition >= adapter.getItemCount() - 1;
    }
    return false;
}
Also used : LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) StaggeredGridLayoutManager(androidx.recyclerview.widget.StaggeredGridLayoutManager) AbsListView(android.widget.AbsListView) Adapter(android.widget.Adapter) RecyclerView(androidx.recyclerview.widget.RecyclerView) StaggeredGridLayoutManager(androidx.recyclerview.widget.StaggeredGridLayoutManager) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager)

Example 25 with StaggeredGridLayoutManager

use of androidx.recyclerview.widget.StaggeredGridLayoutManager in project SmoothRefreshLayout by dkzwm.

the class ScrollCompat method canAutoRefresh.

public static boolean canAutoRefresh(View view) {
    if (view instanceof AbsListView) {
        AbsListView listView = (AbsListView) view;
        final int lastVisiblePosition = listView.getLastVisiblePosition();
        final Adapter adapter = listView.getAdapter();
        return adapter != null && lastVisiblePosition == 0;
    } else if (ViewCatcherUtil.isRecyclerView(view)) {
        RecyclerView recyclerView = (RecyclerView) view;
        RecyclerView.LayoutManager manager = recyclerView.getLayoutManager();
        if (manager == null) {
            return false;
        }
        int firstVisiblePosition = -1;
        if (manager instanceof LinearLayoutManager) {
            LinearLayoutManager linearManager = ((LinearLayoutManager) manager);
            if (linearManager.getOrientation() == RecyclerView.HORIZONTAL) {
                return false;
            }
            firstVisiblePosition = linearManager.findFirstVisibleItemPosition();
        } else if (manager instanceof StaggeredGridLayoutManager) {
            StaggeredGridLayoutManager gridLayoutManager = (StaggeredGridLayoutManager) manager;
            if (gridLayoutManager.getOrientation() == RecyclerView.HORIZONTAL) {
                return false;
            }
            int[] firstPositions = new int[gridLayoutManager.getSpanCount()];
            gridLayoutManager.findFirstVisibleItemPositions(firstPositions);
            for (int value : firstPositions) {
                if (value == 0) {
                    firstVisiblePosition = 0;
                    break;
                }
            }
        }
        RecyclerView.Adapter adapter = recyclerView.getAdapter();
        return adapter != null && firstVisiblePosition == 0;
    }
    return false;
}
Also used : LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) StaggeredGridLayoutManager(androidx.recyclerview.widget.StaggeredGridLayoutManager) AbsListView(android.widget.AbsListView) Adapter(android.widget.Adapter) RecyclerView(androidx.recyclerview.widget.RecyclerView) StaggeredGridLayoutManager(androidx.recyclerview.widget.StaggeredGridLayoutManager) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager)

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