Fix #912 Crash because of ArrayIndexOutOfBoundsException

This commit is contained in:
Stefan Niedermann 2020-07-27 14:45:32 +02:00
parent f2b81ed38e
commit 83024f6efe
3 changed files with 10 additions and 7 deletions

View file

@ -29,14 +29,14 @@ public class GridItemDecoration extends SectionItemDecoration {
public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
super.getItemOffsets(outRect, view, parent, state);
final int position = parent.getChildAdapterPosition(view);
final StaggeredGridLayoutManager.LayoutParams lp = (StaggeredGridLayoutManager.LayoutParams) view.getLayoutParams();
if (position >= 0) {
final StaggeredGridLayoutManager.LayoutParams lp = (StaggeredGridLayoutManager.LayoutParams) view.getLayoutParams();
if (adapter.getItemViewType(position) == ItemAdapter.TYPE_SECTION) {
lp.setFullSpan(true);
} else {
final int spanIndex = lp.getSpanIndex();
if (adapter.getItemViewType(position) == ItemAdapter.TYPE_SECTION) {
lp.setFullSpan(true);
} else {
final int spanIndex = lp.getSpanIndex();
if (position >= 0) {
// First row gets some spacing at the top
if (position < spanCount && position < adapter.getFirstPositionOfViewType(ItemAdapter.TYPE_SECTION)) {
outRect.top = gutter;

View file

@ -30,7 +30,7 @@ public class SectionItemDecoration extends RecyclerView.ItemDecoration {
@CallSuper
public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
final int position = parent.getChildAdapterPosition(view);
if (adapter.getItemViewType(position) == ItemAdapter.TYPE_SECTION) {
if (position >= 0 && adapter.getItemViewType(position) == ItemAdapter.TYPE_SECTION) {
outRect.left = sectionLeft;
outRect.top = sectionTop;
outRect.right = sectionRight;

View file

@ -0,0 +1,3 @@
- 🌎 Language updates
- 🐞 Prevent CalledFromWrongThreadException
- 🐞 Prevent ArrayIndexOutOfBoundsException (#912)