Skip to content

Commit

Permalink
make the custom footer view work
Browse files Browse the repository at this point in the history
  • Loading branch information
af913337456 committed Nov 7, 2017
1 parent 3f45e97 commit 1dd9d22
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 4 deletions.
20 changes: 20 additions & 0 deletions app/src/main/java/com/example/xrecyclerview/LinearActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,26 @@ protected void onCreate(Bundle savedInstanceState) {
mRecyclerView.getDefaultFootView().setLoadingHint("自定义加载中提示");
mRecyclerView.getDefaultFootView().setNoMoreHint("自定义加载完毕提示");

// if you use setFooterView,the default footerView will unUseful
// TextView tv = new TextView(this);
// tv.setText("自定义 footer");
// mRecyclerView.setFootView(tv, new CustomFooterViewCallBack() {
// @Override
// public void onLoadingMore(View yourFooterView) {
//
// }
//
// @Override
// public void onLoadMoreComplete(View yourFooterView) {
//
// }
//
// @Override
// public void onSetNoMore(View yourFooterView, boolean noMore) {
//
// }
// });

mRecyclerView.setLoadingListener(new XRecyclerView.LoadingListener() {
@Override
public void onRefresh() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.jcodecraeer.xrecyclerview;

import android.view.View;

/**
* 作者:林冠宏
* <p>
* My GitHub : https://github.com/af913337456/
* <p>
* My Blog : http://www.cnblogs.com/linguanh/
* <p>
* on 2017/11/8.
*/

public interface CustomFooterViewCallBack {

void onLoadingMore(View yourFooterView);
void onLoadMoreComplete(View yourFooterView);
void onSetNoMore(View yourFooterView,boolean noMore);

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CoordinatorLayout;
import android.support.v7.widget.GridLayoutManager;
Expand All @@ -28,6 +29,7 @@ public class XRecyclerView extends RecyclerView {
private WrapAdapter mWrapAdapter;
private float mLastY = -1;
private static final float DRAG_RATE = 3;
private CustomFooterViewCallBack footerViewCallBack;
private LoadingListener mLoadingListener;
private ArrowRefreshHeader mRefreshHeader;
private boolean pullRefreshEnabled = true;
Expand Down Expand Up @@ -118,16 +120,23 @@ private boolean isReservedItemViewType(int itemViewType) {
}
}

public void setFootView(final View view) {
@SuppressWarnings("all")
public void setFootView(@NonNull final View view,@NonNull CustomFooterViewCallBack footerViewCallBack) {
if(view == null || footerViewCallBack == null){
return;
}
mFootView = view;
this.footerViewCallBack = footerViewCallBack;
}

public void loadMoreComplete() {
isLoadingData = false;
if (mFootView instanceof LoadingMoreFooter) {
((LoadingMoreFooter) mFootView).setState(LoadingMoreFooter.STATE_COMPLETE);
} else {
mFootView.setVisibility(View.GONE);
if(footerViewCallBack != null){
footerViewCallBack.onLoadMoreComplete(mFootView);
}
}
}

Expand All @@ -137,7 +146,9 @@ public void setNoMore(boolean noMore){
if (mFootView instanceof LoadingMoreFooter) {
((LoadingMoreFooter) mFootView).setState(isNoMore ? LoadingMoreFooter.STATE_NOMORE:LoadingMoreFooter.STATE_COMPLETE);
} else {
mFootView.setVisibility(View.GONE);
if(footerViewCallBack != null){
footerViewCallBack.onSetNoMore(mFootView,noMore);
}
}
}
public void refresh() {
Expand Down Expand Up @@ -259,7 +270,9 @@ public void onScrollStateChanged(int state) {
if (mFootView instanceof LoadingMoreFooter) {
((LoadingMoreFooter) mFootView).setState(LoadingMoreFooter.STATE_LOADING);
} else {
mFootView.setVisibility(View.VISIBLE);
if(footerViewCallBack != null){
footerViewCallBack.onLoadingMore(mFootView);
}
}
mLoadingListener.onLoadMore();
}
Expand Down

0 comments on commit 1dd9d22

Please sign in to comment.