From 5099479d586ffb10b1c7a4b84d967256d54944fc Mon Sep 17 00:00:00 2001
From: MirkoWu <709651717@qq.com>
Date: Wed, 7 Jul 2021 23:15:02 +0800
Subject: [PATCH] =?UTF-8?q?#Update=20=E8=AF=AD=E8=A8=80?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../com/mirkowu/mvm/mvvm/MVVMActivity.java | 2 +-
.../lib_base/widget/RefreshHelper.java | 22 ++++++++++++++-----
.../mirkowu/lib_network/AbsRxObserver.java | 9 ++++----
.../src/main/res/values-zh/strings.xml | 7 ++++++
lib_network/src/main/res/values/strings.xml | 7 ++++++
5 files changed, 37 insertions(+), 10 deletions(-)
create mode 100644 lib_network/src/main/res/values-zh/strings.xml
create mode 100644 lib_network/src/main/res/values/strings.xml
diff --git a/app/src/main/java/com/mirkowu/mvm/mvvm/MVVMActivity.java b/app/src/main/java/com/mirkowu/mvm/mvvm/MVVMActivity.java
index 61f03ca..4da5f94 100644
--- a/app/src/main/java/com/mirkowu/mvm/mvvm/MVVMActivity.java
+++ b/app/src/main/java/com/mirkowu/mvm/mvvm/MVVMActivity.java
@@ -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();
diff --git a/lib_base/src/main/java/com/mirkowu/lib_base/widget/RefreshHelper.java b/lib_base/src/main/java/com/mirkowu/lib_base/widget/RefreshHelper.java
index c19ade8..4aa4708 100644
--- a/lib_base/src/main/java/com/mirkowu/lib_base/widget/RefreshHelper.java
+++ b/lib_base/src/main/java/com/mirkowu/lib_base/widget/RefreshHelper.java
@@ -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);
@@ -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;
+ }
+
/**
* 设置每页加载多少条数据
*
@@ -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) {
@@ -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();
}
@@ -153,7 +165,7 @@ public void onLoadMore(RefreshLayout refreshLayout) {
*/
public void loadData() {
if (mOnRefreshListener != null) {
- mOnRefreshListener.onLoadData(mPage);
+ mOnRefreshListener.onLoadData(mCurPage);
}
}
diff --git a/lib_network/src/main/java/com/mirkowu/lib_network/AbsRxObserver.java b/lib_network/src/main/java/com/mirkowu/lib_network/AbsRxObserver.java
index 6298b7c..e2dd95a 100644
--- a/lib_network/src/main/java/com/mirkowu/lib_network/AbsRxObserver.java
+++ b/lib_network/src/main/java/com/mirkowu/lib_network/AbsRxObserver.java
@@ -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;
@@ -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());
}
}
diff --git a/lib_network/src/main/res/values-zh/strings.xml b/lib_network/src/main/res/values-zh/strings.xml
new file mode 100644
index 0000000..0a68f92
--- /dev/null
+++ b/lib_network/src/main/res/values-zh/strings.xml
@@ -0,0 +1,7 @@
+
+
+ 网络连接失败,请检查网络!
+ 请求超时,请稍候重试!
+ 请求失败,无法连接到服务器!
+ 请求失败,
+
\ No newline at end of file
diff --git a/lib_network/src/main/res/values/strings.xml b/lib_network/src/main/res/values/strings.xml
new file mode 100644
index 0000000..e038122
--- /dev/null
+++ b/lib_network/src/main/res/values/strings.xml
@@ -0,0 +1,7 @@
+
+
+ Network connection failed, please check the network!
+ Request timeout, please try again later!
+ Request failed, unable to connect to server!
+ Request failed,
+
\ No newline at end of file