From e5a090685df3d5e96a37b141d9a1d002d36f16f2 Mon Sep 17 00:00:00 2001 From: zuoxiao <470321431@qq.com> Date: 星期五, 14 二月 2025 16:53:43 +0800 Subject: [PATCH] 1.web地图添加管网显示。 2.安卓原生添加管网信息的获取。 3.安卓原生添加管网信息的本地持久化(SQLite数据库)。 4.实现图例用户的选择状态按钮的持久化。 5.实现自定义搜索按钮的实现。 6.实现搜索后弹出界面的相关功能开发。 --- app/src/main/java/com/dayu/pipirrapp/net/MyIntercepterApplication.java | 31 ++++++++++++++++++------------- 1 files changed, 18 insertions(+), 13 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 cc1a62d..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,11 +1,10 @@ package com.dayu.pipirrapp.net; -import com.dayu.pipirrapp.MyApplication; -import com.dayu.pipirrapp.utils.CommonData; -import com.dayu.pipirrapp.utils.SharedPreferencesHelper; -import com.dayu.pipirrapp.utils.ToastUtil; -import com.tencent.bugly.crashreport.CrashReport; +import android.text.TextUtils; +import com.dayu.pipirrapp.MyApplication; +import com.dayu.pipirrapp.utils.NetUtils; +import com.tencent.bugly.crashreport.CrashReport; import java.io.IOException; import java.net.ConnectException; @@ -31,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); @@ -41,9 +39,11 @@ e.printStackTrace(); return getNullResponse(request); } + return response; } else { - ToastUtil.showToastLong(MyApplication.myApplication, "璇锋鏌ョ綉缁滆繛鎺�!!"); + return getNullResponse(request); + } } catch (Exception e) { e.printStackTrace(); @@ -56,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 { @@ -68,9 +68,12 @@ } } builder.addHeader("os", "app"); - builder.addHeader("Authorization", SharedPreferencesHelper.getInstance(MyApplication.myApplication).get("token", "")); + if (!TextUtils.isEmpty(MyApplication.myApplication.token)) { + builder.addHeader("token", MyApplication.myApplication.token); + } + } - builder.addHeader("tag", CommonData.Tag); + builder.addHeader("tag", MyApplication.myApplication.myTag); return builder.build(); } catch (Exception e) { e.printStackTrace(); @@ -89,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); @@ -97,4 +100,6 @@ builder.message(message); return builder.build(); } + + } -- Gitblit v1.8.0