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