From 092bf21368ea824e9dc22467166960219165dc00 Mon Sep 17 00:00:00 2001
From: zuoxiao <470321431@qq.com>
Date: 星期五, 21 二月 2025 17:32:59 +0800
Subject: [PATCH] 1.我的界面每个item添加点击效果。 2.更新本地数据添加二次确认。
---
app/src/main/java/com/dayu/pipirrapp/net/MyIntercepterApplication.java | 24 ++++++++++++++++--------
1 files changed, 16 insertions(+), 8 deletions(-)
diff --git a/app/src/main/java/com/dayu/pipirrapp/net/MyIntercepterApplication.java b/app/src/main/java/com/dayu/pipirrapp/net/MyIntercepterApplication.java
index b32dfb5..67b62ab 100644
--- a/app/src/main/java/com/dayu/pipirrapp/net/MyIntercepterApplication.java
+++ b/app/src/main/java/com/dayu/pipirrapp/net/MyIntercepterApplication.java
@@ -1,7 +1,9 @@
package com.dayu.pipirrapp.net;
+import android.text.TextUtils;
+
import com.dayu.pipirrapp.MyApplication;
-import com.dayu.pipirrapp.utils.ToastUtil;
+import com.dayu.pipirrapp.utils.NetUtils;
import com.tencent.bugly.crashreport.CrashReport;
import java.io.IOException;
@@ -28,9 +30,8 @@
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
try {
-
- Request myRequest = createRequest(chain.request());
- if (myRequest != null) {
+ if (NetUtils.isNetworkAvailable(MyApplication.myApplication)) {
+ Request myRequest = createRequest(chain.request());
Response response = null;
try {
response = chain.proceed(myRequest);
@@ -38,9 +39,11 @@
e.printStackTrace();
return getNullResponse(request);
}
+
return response;
} else {
- ToastUtil.showToastLong(MyApplication.myApplication, "璇锋鏌ョ綉缁滆繛鎺�!!");
+ return getNullResponse(request);
+
}
} catch (Exception e) {
e.printStackTrace();
@@ -53,7 +56,7 @@
try {
Request.Builder builder = request.newBuilder();
Map params = new HashMap();
- if (request.method().equals("GET")) {
+ if ("GET".equals(request.method())) {
builder.url(request.url().toString());
} else {
@@ -65,7 +68,10 @@
}
}
builder.addHeader("os", "app");
- builder.addHeader("token", MyApplication.myApplication.token);
+ if (!TextUtils.isEmpty(MyApplication.myApplication.token)) {
+ builder.addHeader("token", MyApplication.myApplication.token);
+ }
+
}
builder.addHeader("tag", MyApplication.myApplication.myTag);
return builder.build();
@@ -86,7 +92,7 @@
public Response getNullResponse(Request request) {
int code = 20010;
String message = "鍜︼紝璇锋鏌ョ綉缁�";
- String errJson = "{\"code\":" + code + ",\"message\":\"" + message + "\"}";
+ String errJson = "{\"code\":" + code + ",\"msg\":\"" + message + "\"}";
Response.Builder builder = new Response.Builder().body(ResponseBody.create(MediaType.parse("application/json"), errJson));
builder.request(request);
builder.protocol(Protocol.HTTP_1_1);
@@ -94,4 +100,6 @@
builder.message(message);
return builder.build();
}
+
+
}
--
Gitblit v1.8.0