From 13251b356bf6c5302381a8c09673563cd9d55947 Mon Sep 17 00:00:00 2001 From: "hanaa.moh" Date: Thu, 5 Apr 2018 14:52:34 +0200 Subject: [PATCH 1/2] fix layoutmanager toggle crash --- SuperRecyclerView.iml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 SuperRecyclerView.iml diff --git a/SuperRecyclerView.iml b/SuperRecyclerView.iml new file mode 100644 index 0000000..a0b7a07 --- /dev/null +++ b/SuperRecyclerView.iml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file From 07793f24928915c28c4b96c5230d3916d736a95a Mon Sep 17 00:00:00 2001 From: "hanaa.moh" Date: Thu, 5 Apr 2018 14:57:41 +0200 Subject: [PATCH 2/2] fix layoutmanager toggle crash --- .../superrecyclerview/SuperRecyclerView.java | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/SuperRecyclerView/src/main/java/com/malinskiy/superrecyclerview/SuperRecyclerView.java b/SuperRecyclerView/src/main/java/com/malinskiy/superrecyclerview/SuperRecyclerView.java index 7424cf3..5752292 100644 --- a/SuperRecyclerView/src/main/java/com/malinskiy/superrecyclerview/SuperRecyclerView.java +++ b/SuperRecyclerView/src/main/java/com/malinskiy/superrecyclerview/SuperRecyclerView.java @@ -182,8 +182,8 @@ private void processOnMore() { int totalItemCount = layoutManager.getItemCount(); if (((totalItemCount - lastVisibleItemPosition) <= ITEM_LEFT_TO_LOAD_MORE || - (totalItemCount - lastVisibleItemPosition) == 0 && totalItemCount > visibleItemCount) - && !isLoadingMore) { + (totalItemCount - lastVisibleItemPosition) == 0 && totalItemCount > visibleItemCount) + && !isLoadingMore) { isLoadingMore = true; if (mOnMoreListener != null) { @@ -193,20 +193,24 @@ private void processOnMore() { } } - private int getLastVisibleItemPosition(RecyclerView.LayoutManager layoutManager) { - int lastVisibleItemPosition = -1; - if (layoutManagerType == null) { - if (layoutManager instanceof GridLayoutManager) { - layoutManagerType = LAYOUT_MANAGER_TYPE.GRID; - } else if (layoutManager instanceof LinearLayoutManager) { - layoutManagerType = LAYOUT_MANAGER_TYPE.LINEAR; - } else if (layoutManager instanceof StaggeredGridLayoutManager) { - layoutManagerType = LAYOUT_MANAGER_TYPE.STAGGERED_GRID; - } else { - throw new RuntimeException("Unsupported LayoutManager used. Valid ones are LinearLayoutManager, GridLayoutManager and StaggeredGridLayoutManager"); - } + private void setLayoutManagerType(RecyclerView.LayoutManager layoutManager) { +// if (layoutManagerType == null) { + if (layoutManager instanceof GridLayoutManager) { + layoutManagerType = LAYOUT_MANAGER_TYPE.GRID; + } else if (layoutManager instanceof LinearLayoutManager) { + layoutManagerType = LAYOUT_MANAGER_TYPE.LINEAR; + } else if (layoutManager instanceof StaggeredGridLayoutManager) { + layoutManagerType = LAYOUT_MANAGER_TYPE.STAGGERED_GRID; + } else { + throw new RuntimeException("Unsupported LayoutManager used. Valid ones are LinearLayoutManager, GridLayoutManager and StaggeredGridLayoutManager"); } +// } + } + private int getLastVisibleItemPosition(RecyclerView.LayoutManager layoutManager) { + int lastVisibleItemPosition = -1; + if (layoutManagerType == null) + setLayoutManagerType(layoutManager); switch (layoutManagerType) { case LINEAR: lastVisibleItemPosition = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition(); @@ -305,8 +309,8 @@ private void update() { if (mEmptyId != 0) { mEmpty.setVisibility(null != adapter && adapter.getItemCount() > 0 - ? View.GONE - : View.VISIBLE); + ? View.GONE + : View.VISIBLE); } } @@ -315,6 +319,7 @@ private void update() { */ public void setLayoutManager(RecyclerView.LayoutManager manager) { mRecycler.setLayoutManager(manager); + setLayoutManagerType(manager); } /**