1
0
Prechádzať zdrojové kódy

快递柜改造
1.首页图片显示不了的问题

zyh 1 rok pred
rodič
commit
80fd6e4223

+ 36 - 29
app/src/main/java/com/emato/ich/MainActivity.java

@@ -27,6 +27,7 @@ import com.emato.ich.utils.StringUtils;
 import com.emato.ich.utils.ToastUtils;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.JsonMappingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
 
 import androidx.appcompat.app.AppCompatActivity;
@@ -180,37 +181,43 @@ public class MainActivity extends AppCompatActivity  {
             @Override
             public void onResponse
                     (@NotNull Call call, @NotNull Response response) throws IOException {
-
-                try {
-                    String parseResponse = ICSPClient.isSuccessfulAndParseResponse(response);
-                    ObjectMapper objectMapper = JacksonUtils.objectmapper;
-                    ResponseData<Map<String, String>> readValue = objectMapper.readValue(parseResponse, new TypeReference<ResponseData<Map<String, String>>>() {
-                    });
-                    if (null != readValue && readValue.getCode().equals(ICSPConstant.OK)) {
-                        configMap.putAll(readValue.getData());
-                        // 系统配置的session过期时间
-                        String time = configMap.get(SystemConfigConstant.deliverer_token_expire_seconds);
-                        if (!StringUtils.isNullOrEmpty(time)) {
-                            LocalStorage.getInstance().getSession().setTime(Long.parseLong(time));
-                        }
-                        // 获取轮播图数组字符串
-                        String cabImgListStr = configMap.get(SystemConfigConstant.CAB_IMG_LIST);
-                        // 转为 List
-                        List<String> cabImgList = objectMapper.readValue(cabImgListStr, new TypeReference<List<String>>() {});
-                        banner = findViewById(R.id.banner);
-                        // 加入 banner
-                        if (!cabImgList.isEmpty()){
-                            Log.i(TAG, "onResponse: =====================>获取图片轮播图系统配置成功! ");
-                            banner.initBanner(cabImgList);
+                MainActivity.this.runOnUiThread(() -> {
+                    try {
+                        String parseResponse = ICSPClient.isSuccessfulAndParseResponse(response);
+                        ObjectMapper objectMapper = JacksonUtils.objectmapper;
+                        ResponseData<Map<String, String>> readValue = objectMapper.readValue(parseResponse, new TypeReference<ResponseData<Map<String, String>>>() {
+                        });
+                        if (null != readValue && readValue.getCode().equals(ICSPConstant.OK)) {
+                            configMap.putAll(readValue.getData());
+                            // 系统配置的session过期时间
+                            String time = configMap.get(SystemConfigConstant.deliverer_token_expire_seconds);
+                            if (!StringUtils.isNullOrEmpty(time)) {
+                                LocalStorage.getInstance().getSession().setTime(Long.parseLong(time));
+                            }
+                            // 获取轮播图数组字符串
+                            String cabImgListStr = configMap.get(SystemConfigConstant.CAB_IMG_LIST);
+                            // 转为 List
+                            List<String> cabImgList = objectMapper.readValue(cabImgListStr, new TypeReference<List<String>>() {
+                            });
+                            banner = findViewById(R.id.banner);
+                            // 加入 banner
+                            if (!cabImgList.isEmpty()) {
+                                Log.i(TAG, "onResponse: =====================>获取图片轮播图系统配置成功! ");
+                                banner.initBanner(cabImgList);
+                            }
+
+                            Log.i(TAG, "onResponse: =====================>获取系统配置成功! ");
+                        } else {
+                            Log.w(TAG, "onResponse: code==>" + readValue.getCode() + ", msg==>" + readValue.getMsg());
                         }
-
-                        Log.i(TAG, "onResponse: =====================>获取系统配置成功! ");
-                    } else {
-                        Log.w(TAG, "onResponse: code==>" + readValue.getCode() + ", msg==>" + readValue.getMsg());
+                    } catch (RuntimeException e) {
+                        Log.e(TAG, "onResponse: 获取系统配置错误! 未知错误! ", e);
+                    } catch (JsonMappingException e) {
+                        e.printStackTrace();
+                    } catch (JsonProcessingException e) {
+                        e.printStackTrace();
                     }
-                } catch (RuntimeException e) {
-                    Log.e(TAG, "onResponse: 获取系统配置错误! 未知错误! ", e);
-                }
+                });
             }
         });
     }