Java Code Examples for com.chad.library.adapter.base.BaseQuickAdapter#loadMoreComplete()

The following examples show how to use com.chad.library.adapter.base.BaseQuickAdapter#loadMoreComplete() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PagingUtils.java    From TikTok with Apache License 2.0 4 votes vote down vote up
/**
     * 检查当前的页数计算出下次应该请求的页数(开启上拉加载和判断当前是否是最后一页)
     * 理论上讲,如果失败的话页数应该是不变的(所以不考虑请求时失败的情况,在请求成功的时候检查一下即可)
     *
     * @param adapter     基于 BaseQuickAdapter
     * @param page        当前页数
     * @param isRefresh   是否是刷新
     * @param allList     当前所有的list
     * @param currentList 请求到的list数据
     */
    @Deprecated
    public static int CheckUpPageOrAdapter(BaseQuickAdapter adapter, int page, boolean isRefresh, List allList, List currentList) {
        if (adapter != null) {
            if (page == 1) {
                if (currentList == null || currentList.size() < LIMIT) {
                    //关闭上拉加载
                    adapter.setEnableLoadMore(false);
                }
            } else {
                //开启上拉加载
                adapter.setEnableLoadMore(true);
                if (currentList == null || currentList.size() < LIMIT) {
                    //加载完成没有更多数据了
                    adapter.loadMoreEnd();
                } else {
                    //加载完成还有更多数据
                    adapter.loadMoreComplete();
                }
            }

            //如果不是刷新
            if (currentList == null || currentList.size() < 1) {
                //如果请求到的数据是空的,或者请求到数据长度为0,那么页数就不应该再改变
                //这里提示没有更多数据了
//            Toast.makeText(mContext, "没有更多数据了", Toast.LENGTH_SHORT).show();
            } else {
                //如果list非空,并且长度大于0
                page++;
            }
            if (isRefresh) {
                allList.clear();
                allList.addAll(currentList);
                adapter.notifyDataSetChanged();
            } else {
                int preEndIndex = allList.size();
                allList.addAll(currentList);
                adapter.notifyItemRangeInserted(preEndIndex, currentList.size());
            }
        }
        return page;
    }
 
Example 2
Source File: PagingUtils.java    From TikTok with Apache License 2.0 4 votes vote down vote up
/**
     * 检查当前的页数计算出下次应该请求的页数(开启上拉加载和判断当前是否是最后一页)
     * 理论上讲,如果失败的话页数应该是不变的(所以不考虑请求时失败的情况,在请求成功的时候检查一下即可)
     *
     * @param adapter     基于 BaseQuickAdapter
     * @param page        当前页数
     * @param allList     当前所有的list
     * @param currentList 请求到的list数据
     */
    public static int CheckUpPageOrAdapter(BaseQuickAdapter adapter, int page, List allList, List currentList) {
        if (adapter != null) {
            if (page == 1) {
                if (currentList == null || currentList.size() < LIMIT) {
                    //关闭上拉加载
                    adapter.setEnableLoadMore(false);
                }
            } else {
                //开启上拉加载
                adapter.setEnableLoadMore(true);
                if (currentList == null || currentList.size() < LIMIT) {
                    //加载完成没有更多数据了
                    adapter.loadMoreEnd();
                } else {
                    //加载完成还有更多数据
                    adapter.loadMoreComplete();
                }
            }
            if (page == 1) {
                allList.clear();
                allList.addAll(currentList);
                adapter.notifyDataSetChanged();
            } else {
                int preEndIndex = allList.size();
                allList.addAll(currentList);
                adapter.notifyItemRangeInserted(preEndIndex, currentList.size());
            }

            //如果不是刷新
            if (currentList == null || currentList.size() < 1) {
                //如果请求到的数据是空的,或者请求到数据长度为0,那么页数就不应该再改变
                //这里提示没有更多数据了
//            Toast.makeText(mContext, "没有更多数据了", Toast.LENGTH_SHORT).show();
            } else {
                //如果list非空,并且长度大于0
                page++;
            }
        }
        return page;
    }
 
Example 3
Source File: HttpRequestControlImpl.java    From FastLib with Apache License 2.0 4 votes vote down vote up
@Override
public void httpRequestSuccess(IHttpRequestControl httpRequestControl, List<?> list, OnHttpRequestListener listener) {
    if (httpRequestControl == null) {
        return;
    }
    SmartRefreshLayout smartRefreshLayout = httpRequestControl.getRefreshLayout();
    BaseQuickAdapter adapter = httpRequestControl.getRecyclerAdapter();
    StatusLayoutManager statusLayoutManager = httpRequestControl.getStatusLayoutManager();
    int page = httpRequestControl.getCurrentPage();
    int size = httpRequestControl.getPageSize();

    LoggerManager.i(TAG, "smartRefreshLayout:" + smartRefreshLayout + ";adapter:" + adapter + ";status:" + ";page:" + page + ";class:" + httpRequestControl.getRequestClass());
    if (smartRefreshLayout != null) {
        smartRefreshLayout.finishRefresh();
    }
    if (adapter == null) {
        return;
    }
    adapter.loadMoreComplete();
    if (list == null || list.size() == 0) {
        //第一页没有
        if (page == 0) {
            adapter.setNewData(new ArrayList());
            statusLayoutManager.showEmptyLayout();
            if (listener != null) {
                listener.onEmpty();
            }
        } else {
            adapter.loadMoreEnd();
            if (listener != null) {
                listener.onNoMore();
            }
        }
        return;
    }
    statusLayoutManager.showSuccessLayout();
    if (smartRefreshLayout.getState() == RefreshState.Refreshing || page == 0) {
        adapter.setNewData(new ArrayList());
    }
    adapter.addData(list);
    if (listener != null) {
        listener.onNext();
    }
    if (list.size() < size) {
        adapter.loadMoreEnd();
        if (listener != null) {
            listener.onNoMore();
        }
    }
}
 
Example 4
Source File: HttpRequestControlImpl.java    From FastLib with Apache License 2.0 4 votes vote down vote up
@Override
    public void httpRequestError(IHttpRequestControl httpRequestControl, Throwable e) {
        LoggerManager.e(TAG, "httpRequestError:" + e.getMessage());
        int reason = R.string.fast_exception_other_error;
//        int code = FastError.EXCEPTION_OTHER_ERROR;
        if (!NetworkUtil.isConnected(App.getContext())) {
            reason = R.string.fast_exception_network_not_connected;
        } else {
            //网络异常--继承于AccountsException
            if (e instanceof NetworkErrorException) {
                reason = R.string.fast_exception_network_error;
                //账户异常
            } else if (e instanceof AccountsException) {
                reason = R.string.fast_exception_accounts;
                //连接异常--继承于SocketException
            } else if (e instanceof ConnectException) {
                reason = R.string.fast_exception_connect;
                //socket异常
            } else if (e instanceof SocketException) {
                reason = R.string.fast_exception_socket;
                // http异常
            } else if (e instanceof HttpException) {
                reason = R.string.fast_exception_http;
                //DNS错误
            } else if (e instanceof UnknownHostException) {
                reason = R.string.fast_exception_unknown_host;
            } else if (e instanceof JsonSyntaxException
                    || e instanceof JsonIOException
                    || e instanceof JsonParseException) {
                //数据格式化错误
                reason = R.string.fast_exception_json_syntax;
            } else if (e instanceof SocketTimeoutException || e instanceof TimeoutException) {
                reason = R.string.fast_exception_time_out;
            } else if (e instanceof ClassCastException) {
                reason = R.string.fast_exception_class_cast;
            }
        }
        if (httpRequestControl == null || httpRequestControl.getStatusLayoutManager() == null) {
            ToastUtil.show(reason);
            return;
        }
        SmartRefreshLayout smartRefreshLayout = httpRequestControl.getRefreshLayout();
        BaseQuickAdapter adapter = httpRequestControl.getRecyclerAdapter();
        StatusLayoutManager statusLayoutManager = httpRequestControl.getStatusLayoutManager();
        int page = httpRequestControl.getCurrentPage();
        if (smartRefreshLayout != null) {
            smartRefreshLayout.finishRefresh(false);
        }
        if (adapter != null) {
            adapter.loadMoreComplete();
            if (statusLayoutManager == null) {
                return;
            }
            //初始页
            if (page == 0) {
//                if (!NetworkUtil.isConnected(App.getContext())) {
//                    //可自定义网络错误页面展示
//                    statusLayoutManager.showCustomLayout(R.layout.layout_status_layout_manager_error);
//                } else {
                    statusLayoutManager.showErrorLayout();
//                }
                return;
            }
            //可根据不同错误展示不同错误布局  showCustomLayout(R.layout.xxx);
            statusLayoutManager.showErrorLayout();
        }
    }
 
Example 5
Source File: HttpRequestControlImpl.java    From FastLib with Apache License 2.0 4 votes vote down vote up
@Override
public void httpRequestSuccess(IHttpRequestControl httpRequestControl, List<?> list, OnHttpRequestListener listener) {
    if (httpRequestControl == null) {
        return;
    }
    SmartRefreshLayout smartRefreshLayout = httpRequestControl.getRefreshLayout();
    BaseQuickAdapter adapter = httpRequestControl.getRecyclerAdapter();
    StatusLayoutManager statusLayoutManager = httpRequestControl.getStatusLayoutManager();
    int page = httpRequestControl.getCurrentPage();
    int size = httpRequestControl.getPageSize();

    LoggerManager.i(TAG, "smartRefreshLayout:" + smartRefreshLayout + ";adapter:" + adapter + ";status:" + ";page:" + page + ";class:" + httpRequestControl.getRequestClass());
    if (smartRefreshLayout != null) {
        smartRefreshLayout.finishRefresh();
    }
    if (adapter == null) {
        return;
    }
    adapter.loadMoreComplete();
    if (list == null || list.size() == 0) {
        //第一页没有
        if (page == 0) {
            adapter.setNewData(new ArrayList());
            statusLayoutManager.showEmptyLayout();
            if (listener != null) {
                listener.onEmpty();
            }
        } else {
            adapter.loadMoreEnd();
            if (listener != null) {
                listener.onNoMore();
            }
        }
        return;
    }
    statusLayoutManager.showSuccessLayout();
    if (smartRefreshLayout.getState() == RefreshState.Refreshing || page == 0) {
        adapter.setNewData(new ArrayList());
    }
    adapter.addData(list);
    if (listener != null) {
        listener.onNext();
    }
    if (list.size() < size) {
        adapter.loadMoreEnd();
        if (listener != null) {
            listener.onNoMore();
        }
    }
}
 
Example 6
Source File: HttpRequestControlImpl.java    From FastLib with Apache License 2.0 4 votes vote down vote up
@Override
    public void httpRequestError(IHttpRequestControl httpRequestControl, Throwable e) {
        LoggerManager.e(TAG, "httpRequestError:" + e.getMessage());
        int reason = R.string.fast_exception_other_error;
//        int code = FastError.EXCEPTION_OTHER_ERROR;
        if (!NetworkUtil.isConnected(App.getContext())) {
            reason = R.string.fast_exception_network_not_connected;
        } else {
            //网络异常--继承于AccountsException
            if (e instanceof NetworkErrorException) {
                reason = R.string.fast_exception_network_error;
                //账户异常
            } else if (e instanceof AccountsException) {
                reason = R.string.fast_exception_accounts;
                //连接异常--继承于SocketException
            } else if (e instanceof ConnectException) {
                reason = R.string.fast_exception_connect;
                //socket异常
            } else if (e instanceof SocketException) {
                reason = R.string.fast_exception_socket;
                // http异常
            } else if (e instanceof HttpException) {
                reason = R.string.fast_exception_http;
                //DNS错误
            } else if (e instanceof UnknownHostException) {
                reason = R.string.fast_exception_unknown_host;
            } else if (e instanceof JsonSyntaxException
                    || e instanceof JsonIOException
                    || e instanceof JsonParseException) {
                //数据格式化错误
                reason = R.string.fast_exception_json_syntax;
            } else if (e instanceof SocketTimeoutException || e instanceof TimeoutException) {
                reason = R.string.fast_exception_time_out;
            } else if (e instanceof ClassCastException) {
                reason = R.string.fast_exception_class_cast;
            }
        }
        if (httpRequestControl == null || httpRequestControl.getStatusLayoutManager() == null) {
            ToastUtil.show(reason);
            return;
        }
        SmartRefreshLayout smartRefreshLayout = httpRequestControl.getRefreshLayout();
        BaseQuickAdapter adapter = httpRequestControl.getRecyclerAdapter();
        StatusLayoutManager statusLayoutManager = httpRequestControl.getStatusLayoutManager();
        int page = httpRequestControl.getCurrentPage();
        if (smartRefreshLayout != null) {
            smartRefreshLayout.finishRefresh(false);
        }
        if (adapter != null) {
            adapter.loadMoreComplete();
            if (statusLayoutManager == null) {
                return;
            }
            //初始页
            if (page == 0) {
//                if (!NetworkUtil.isConnected(App.getContext())) {
//                    //可自定义网络错误页面展示
//                    statusLayoutManager.showCustomLayout(R.layout.layout_status_layout_manager_error);
//                } else {
                    statusLayoutManager.showErrorLayout();
//                }
                return;
            }
            //可根据不同错误展示不同错误布局  showCustomLayout(R.layout.xxx);
            statusLayoutManager.showErrorLayout();
        }
    }