Skip to content

Commit

Permalink
#Update 语言
Browse files Browse the repository at this point in the history
  • Loading branch information
MirkoWu committed Jul 7, 2021
1 parent 3897aa6 commit 5099479
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/com/mirkowu/mvm/mvvm/MVVMActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void onItemChildClick(View view, Object item, int position) {
} else if (responseData.isFailure()) {
refreshHelper.finishLoad();
ErrorBean errorBean = responseData.error;
if (errorBean.isNetError()) {
if (errorBean.isNetError() && refreshHelper.isFirstPage()) {
binding.stateview.setShowState(R.drawable.widget_svg_disconnect, errorBean.msg(), true);
} else if (errorBean.isApiError()) {
Toast.makeText(MVVMActivity.this, errorBean.code() + ":" + errorBean.msg(), Toast.LENGTH_SHORT).show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class RefreshHelper implements OnRefreshListener, OnRefreshLoadMoreListen
/*** 起始页下标*/
private int FIRST_PAGE = 0;
/*** 当前页*/
protected int mPage = FIRST_PAGE;
protected int mCurPage = FIRST_PAGE;

public RefreshHelper(@NonNull RecyclerView mInnerContainer, OnRefreshListener onRefreshListener) {
this(null, mInnerContainer, onRefreshListener);
Expand Down Expand Up @@ -59,6 +59,18 @@ public int getFirstPageIndex() {
return FIRST_PAGE;
}

public int getCurPage() {
return mCurPage;
}

public void setCurPage(int curPage) {
mCurPage = curPage;
}

public boolean isFirstPage() {
return mCurPage == FIRST_PAGE;
}

/**
* 设置每页加载多少条数据
*
Expand Down Expand Up @@ -101,7 +113,7 @@ public void setLoadMore(BaseRVAdapter adapter, List<?> list, boolean hasMore) {
mRefreshLayout.finishRefresh();
}

if (mPage == FIRST_PAGE) {
if (mCurPage == FIRST_PAGE) {
adapter.setData(list);

if (mOnRefreshListener != null) {
Expand Down Expand Up @@ -137,14 +149,14 @@ public void refresh() {

@Override
public void onRefresh(RefreshLayout refreshLayout) {
mPage = FIRST_PAGE;
mCurPage = FIRST_PAGE;
loadData();
}


@Override
public void onLoadMore(RefreshLayout refreshLayout) {
mPage++;
mCurPage++;
loadData();
}

Expand All @@ -153,7 +165,7 @@ public void onLoadMore(RefreshLayout refreshLayout) {
*/
public void loadData() {
if (mOnRefreshListener != null) {
mOnRefreshListener.onLoadData(mPage);
mOnRefreshListener.onLoadData(mCurPage);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mirkowu.lib_network;

import com.mirkowu.lib_util.LogUtil;
import com.mirkowu.lib_util.utilcode.util.StringUtils;

import java.net.ConnectException;
import java.net.SocketTimeoutException;
Expand Down Expand Up @@ -46,13 +47,13 @@ public void onError(@NonNull Throwable e) {
HttpException httpException = (HttpException) e;
onFailure(ErrorType.NET, httpException.code(), httpException.message());
} else if (e instanceof ConnectException) {
onFailure(ErrorType.NET, ErrorCode.NET_CONNECT, "网络连接失败,请检查网络!");
onFailure(ErrorType.NET, ErrorCode.NET_CONNECT, StringUtils.getString(R.string.network_connect_failed_please_check));
} else if (e instanceof SocketTimeoutException) {
onFailure(ErrorType.NET, ErrorCode.NET_TIMEOUT, "请求超时,请稍候重试!");
onFailure(ErrorType.NET, ErrorCode.NET_TIMEOUT, StringUtils.getString(R.string.network_request_timeout_please_retry));
} else if (e instanceof UnknownHostException) {
onFailure(ErrorType.NET, ErrorCode.NET_UNKNOWNHOST, "请求失败,无法连接到服务器!");
onFailure(ErrorType.NET, ErrorCode.NET_UNKNOWNHOST, StringUtils.getString(R.string.network_request_failed_cant_connect_server));
} else {
onFailure(ErrorType.UNKONW, ErrorCode.UNKNOW, "请求失败," + e.getMessage());
onFailure(ErrorType.UNKONW, ErrorCode.UNKNOW, StringUtils.getString(R.string.network_request_failed_) + e.getMessage());
}
}

Expand Down
7 changes: 7 additions & 0 deletions lib_network/src/main/res/values-zh/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="network_connect_failed_please_check">网络连接失败,请检查网络!</string>
<string name="network_request_timeout_please_retry">请求超时,请稍候重试!</string>
<string name="network_request_failed_cant_connect_server">请求失败,无法连接到服务器!</string>
<string name="network_request_failed_">请求失败,</string>
</resources>
7 changes: 7 additions & 0 deletions lib_network/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="network_connect_failed_please_check">Network connection failed, please check the network!</string>
<string name="network_request_timeout_please_retry">Request timeout, please try again later!</string>
<string name="network_request_failed_cant_connect_server">Request failed, unable to connect to server!</string>
<string name="network_request_failed_">Request failed, </string>
</resources>

0 comments on commit 5099479

Please sign in to comment.