Skip to content
This repository has been archived by the owner on Nov 4, 2022. It is now read-only.

Fix layoutmanager toggle #124

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions SuperRecyclerView.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="SuperRecyclerView" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="java-gradle" name="Java-Gradle">
<configuration>
<option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
<option name="BUILDABLE" value="false" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
<excludeFolder url="file://$MODULE_DIR$/build" />
</content>
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -315,6 +319,7 @@ private void update() {
*/
public void setLayoutManager(RecyclerView.LayoutManager manager) {
mRecycler.setLayoutManager(manager);
setLayoutManagerType(manager);
}

/**
Expand Down