Skip to content

Commit

Permalink
add setFooterView method
Browse files Browse the repository at this point in the history
  • Loading branch information
Chanven committed Jul 28, 2016
1 parent 6405f9a commit f88e791
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,16 @@ public void run() {
}
mAdapter.notifyDataSetChanged();
ptrClassicFrameLayout.refreshComplete();
ptrClassicFrameLayout.setLoadMoreEnable(true);

if (!ptrClassicFrameLayout.isLoadMoreEnable()) {
ptrClassicFrameLayout.setLoadMoreEnable(true);
}
}
}, 1500);
}
});


ptrClassicFrameLayout.setOnLoadMoreListener(new OnLoadMoreListener() {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void run() {
mSwipeRefreshHelper.refreshComplete();
mSwipeRefreshHelper.setLoadMoreEnable(true);
}
}, 1000);
}, 1500);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import android.content.Context;
import android.util.AttributeSet;

import com.chanven.lib.cptr.loadmore.DefaultLoadMoreViewFooter;
import com.chanven.lib.cptr.loadmore.ILoadMoreViewFactory;

public class PtrClassicFrameLayout extends PtrFrameLayout {

private PtrClassicDefaultHeader mPtrClassicHeader;
Expand All @@ -26,6 +29,9 @@ private void initViews() {
mPtrClassicHeader = new PtrClassicDefaultHeader(getContext());
setHeaderView(mPtrClassicHeader);
addPtrUIHandler(mPtrClassicHeader);

ILoadMoreViewFactory loadMoreViewFactory = new DefaultLoadMoreViewFooter();
setFooterView(loadMoreViewFactory);
}

public PtrClassicDefaultHeader getHeader() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,7 @@ public void tryToScrollTo(int to, int duration) {
private boolean isLoadMoreEnable = false;
private boolean hasInitLoadMoreView = false;

private ILoadMoreViewFactory loadViewFactory = new DefaultLoadMoreViewFooter();
private ILoadMoreViewFactory loadMoreViewFactory;
private ILoadMoreView mLoadMoreView;

private LoadMoreHandler mLoadMoreHandler;
Expand All @@ -1055,6 +1055,25 @@ public void tryToScrollTo(int to, int duration) {
public void setIsAutoLoadMore(boolean isAutoLoadMore) {
this.isAutoLoadMore = isAutoLoadMore;
}

public void setFooterView(ILoadMoreViewFactory factory) {
if (null == factory || (null != loadMoreViewFactory && loadMoreViewFactory == factory)) {
return;
}

loadMoreViewFactory = factory;

if (hasInitLoadMoreView) {
mLoadMoreHandler.removeFooter();
mLoadMoreView = loadMoreViewFactory.madeLoadMoreView();
hasInitLoadMoreView = mLoadMoreHandler.handleSetAdapter(mContentView, mLoadMoreView,
onClickLoadMoreListener);
if (!isLoadMoreEnable) {
mLoadMoreHandler.removeFooter();
}
}

}

public void setLoadMoreEnable(boolean loadMoreEnable) {
if (this.isLoadMoreEnable == loadMoreEnable) {
Expand All @@ -1063,7 +1082,10 @@ public void setLoadMoreEnable(boolean loadMoreEnable) {
this.isLoadMoreEnable = loadMoreEnable;
if (!hasInitLoadMoreView && isLoadMoreEnable) {
mContentView = getContentView();
mLoadMoreView = loadViewFactory.madeLoadMoreView();
if (null == loadMoreViewFactory) {
loadMoreViewFactory = new DefaultLoadMoreViewFooter();
}
mLoadMoreView = loadMoreViewFactory.madeLoadMoreView();

if (null == mLoadMoreHandler) {
if (mContentView instanceof GridView) {
Expand All @@ -1082,7 +1104,9 @@ public void setLoadMoreEnable(boolean loadMoreEnable) {
hasInitLoadMoreView = mLoadMoreHandler.handleSetAdapter(mContentView, mLoadMoreView,
onClickLoadMoreListener);
mLoadMoreHandler.setOnScrollBottomListener(mContentView, onScrollBottomListener);
return;
}

if (hasInitLoadMoreView) {
if (isLoadMoreEnable) {
mLoadMoreHandler.addFooter();
Expand All @@ -1092,6 +1116,10 @@ public void setLoadMoreEnable(boolean loadMoreEnable) {
}
}

public boolean isLoadMoreEnable() {
return isLoadMoreEnable;
}

private OnScrollBottomListener onScrollBottomListener = new OnScrollBottomListener() {
@Override
public void onScorllBootom() {
Expand All @@ -1106,7 +1134,7 @@ public void onScorllBootom() {

@Override
public void onClick(View v) {
if (isLoadMoreEnable && !isLoadingMore) {
if (isLoadMoreEnable && !isLoadingMore()) {
loadMore();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ public class SwipeRefreshHelper {

private LoadMoreHandler mLoadMoreHandler;

private boolean isLoading = false;
private boolean isLoadingMore = false;
private boolean isAutoLoadMore = true;
private boolean isLoadMoreEnable = false;
private boolean hasInitLoadMoreView = false;
private ILoadMoreViewFactory loadViewFactory = new DefaultLoadMoreViewFooter();
private ILoadMoreViewFactory loadMoreViewFactory = new DefaultLoadMoreViewFooter();

private OnLoadMoreListener mOnLoadMoreListener;
private ILoadMoreViewFactory.ILoadMoreView mLoadMoreView;
Expand Down Expand Up @@ -77,13 +77,31 @@ public void refreshComplete() {
mSwipeRefreshLayout.setRefreshing(false);
}

public void setFooterView(ILoadMoreViewFactory factory) {
if (null == factory || (null != loadMoreViewFactory && loadMoreViewFactory == factory)) {
return;
}

loadMoreViewFactory = factory;

if (hasInitLoadMoreView) {
mLoadMoreHandler.removeFooter();
mLoadMoreView = loadMoreViewFactory.madeLoadMoreView();
hasInitLoadMoreView = mLoadMoreHandler.handleSetAdapter(mContentView, mLoadMoreView,
onClickLoadMoreListener);
if (!isLoadMoreEnable) {
mLoadMoreHandler.removeFooter();
}
}
}

public void setLoadMoreEnable(boolean enable) {
if (this.isLoadMoreEnable == enable) {
return;
}
this.isLoadMoreEnable = enable;
if (!hasInitLoadMoreView && isLoadMoreEnable) {
mLoadMoreView = loadViewFactory.madeLoadMoreView();
mLoadMoreView = loadMoreViewFactory.madeLoadMoreView();

if (null == mLoadMoreHandler) {
if (mContentView instanceof GridView) {
Expand All @@ -102,7 +120,9 @@ public void setLoadMoreEnable(boolean enable) {
hasInitLoadMoreView = mLoadMoreHandler.handleSetAdapter(mContentView, mLoadMoreView,
onClickLoadMoreListener);
mLoadMoreHandler.setOnScrollBottomListener(mContentView, onScrollBottomListener);
return;
}

if (hasInitLoadMoreView) {
if (isLoadMoreEnable) {
mLoadMoreHandler.addFooter();
Expand All @@ -112,14 +132,18 @@ public void setLoadMoreEnable(boolean enable) {
}
}

public boolean isLoadMoreEnable() {
return isLoadMoreEnable;
}

public void setIsAutoLoadMore(boolean isAutoLoadMore) {
this.isAutoLoadMore = isAutoLoadMore;
}

private OnScrollBottomListener onScrollBottomListener = new OnScrollBottomListener() {
@Override
public void onScorllBootom() {
if (isAutoLoadMore && isLoadMoreEnable && !isLoading()) {
if (isAutoLoadMore && isLoadMoreEnable && !isLoadingMore()) {
// can check network here
loadMore();
}
Expand All @@ -130,20 +154,22 @@ public void onScorllBootom() {

@Override
public void onClick(View v) {
loadMore();
if (isLoadMoreEnable && !isLoadingMore()) {
loadMore();
}
}
};

private void loadMore() {
isLoading = true;
isLoadingMore = true;
mLoadMoreView.showLoading();
if (null != mOnLoadMoreListener) {
mOnLoadMoreListener.loadMore();
}
}

public void loadMoreComplete(boolean hasMore) {
isLoading = false;
isLoadingMore = false;
if (hasMore) {
mLoadMoreView.showNormal();
} else {
Expand All @@ -152,12 +178,12 @@ public void loadMoreComplete(boolean hasMore) {
}

public void setNoMoreData() {
isLoading = false;
isLoadingMore = false;
mLoadMoreView.showNomore();
}

public boolean isLoading() {
return isLoading;
public boolean isLoadingMore() {
return isLoadingMore;
}

public static interface OnSwipeRefreshListener {
Expand Down

0 comments on commit f88e791

Please sign in to comment.