Kaynağa Gözat

处理快递柜取件页面图片加载不了的问题

wcq 1 yıl önce
ebeveyn
işleme
897b824bdf

+ 2 - 2
app/build.gradle

@@ -13,12 +13,12 @@ android {
             keyAlias ALIAS_NAME
             keyPassword ALIAS_PASS
         }
-        debug {
+  /*      debug {
             storeFile file(KEY_PATH)
             storePassword KEY_PASS
             keyAlias ALIAS_NAME
             keyPassword ALIAS_PASS
-        }
+        }*/
     }
 
     defaultConfig {

+ 9 - 22
app/src/main/java/com/emato/ich/fragment/MainFragment.java

@@ -1,9 +1,11 @@
 package com.emato.ich.fragment;
 
+import android.graphics.drawable.Drawable;
 import android.os.Bundle;
 
 import com.bumptech.glide.Glide;
 import com.bumptech.glide.load.engine.DiskCacheStrategy;
+import com.emato.ich.api.ICSPClient;
 import com.emato.ich.utils.Log;
 import android.view.LayoutInflater;
 import android.view.View;
@@ -24,6 +26,13 @@ import com.emato.ich.utils.StringUtils;
 
 import org.jetbrains.annotations.NotNull;
 
+import java.io.IOException;
+import java.io.InputStream;
+
+import okhttp3.Call;
+import okhttp3.Callback;
+import okhttp3.Response;
+
 /**
  * 主页
  */
@@ -64,28 +73,6 @@ public class MainFragment extends Fragment {
                 LoggingUtils.sendErrorLog("业务异常: Glide请求微信公众号图片异常! ", e);
             }
 
-/*            ICSPClient.getWeChatMPImage(url, new Callback() {
-                @Override
-                public void onFailure(@NotNull Call call, @NotNull IOException e) {
-                    Log.e(TAG, "onFailure: 请求微信公众号图片错误! 网络异常! ", e);
-                    LoggingUtils.sendErrorLog("业务异常: 请求微信公众号图片错误! 网络异常! ", e);
-                }
-
-                @Override
-                public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
-                    getActivity().runOnUiThread(() -> {
-                        try {
-                            InputStream is = response.body().byteStream();
-                            final Drawable d = Drawable.createFromStream(is, "src");
-                            binding.fastTakeSend.setBackground(d);
-                            is.close();
-                        } catch (Exception e) {
-                            Log.e(TAG, "onResponse: 设置图片异常! ", e);
-                            LoggingUtils.sendErrorLog("业务异常: 请求微信公众号图片异常! ", e);
-                        }
-                    });
-                }
-            });*/
         }
 
         // 投递页面跳转

+ 15 - 21
app/src/main/java/com/emato/ich/fragment/TakeCodeFragment.java

@@ -4,11 +4,15 @@ import android.graphics.drawable.Drawable;
 import android.os.Bundle;
 import android.os.CountDownTimer;
 import android.text.Editable;
+
+import com.bumptech.glide.Glide;
+import com.bumptech.glide.load.engine.DiskCacheStrategy;
 import com.emato.ich.utils.Log;
 import android.view.Gravity;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
+import android.widget.ImageView;
 import android.widget.TextView;
 import android.widget.Toast;
 
@@ -88,28 +92,18 @@ public class TakeCodeFragment extends Fragment {
         String url = activity.getConfigMap().get(SystemConfigConstant.cabinet_take_object_qrcode_url);
 
         if (getActivity() != null && activity.getConfigMap().size() > 0 && !StringUtils.isNullOrEmpty(url)) {
-            ICSPClient.getWeChatMPImage(url, new Callback() {
-                @Override
-                public void onFailure(@NotNull Call call, @NotNull IOException e) {
-                    Log.e(TAG, "onFailure: 请求微信公众号图片错误! 网络异常! ", e);
-                    LoggingUtils.sendErrorLog("业务异常: 请求微信公众号图片错误! 网络异常! ", e);
-                }
 
-                @Override
-                public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
-                    getActivity().runOnUiThread(() -> {
-                        try {
-                            InputStream is = response.body().byteStream();
-                            final Drawable d = Drawable.createFromStream(is, "src");
-                            binding.textView.setBackground(d);
-                            is.close();
-                        } catch (Exception e) {
-                            Log.e(TAG, "onResponse: 设置图片异常! ", e);
-                            LoggingUtils.sendErrorLog("业务异常: 取件码输入页面设置图片异常! ", e);
-                        }
-                    });
-                }
-            });
+            try {
+                ImageView imageView = view.findViewById(R.id.textView);
+                Glide.with(view).load(url)
+                        .skipMemoryCache(true)//跳过内存缓存
+                        .diskCacheStrategy(DiskCacheStrategy.NONE)//不缓冲disk硬盘中
+                        .into(imageView);
+            } catch (Exception e) {
+                Log.e(TAG, "onResponse: Glide设置图片异常! ", e);
+                LoggingUtils.sendErrorLog("业务异常: Glide请求微信公众号图片异常! ", e);
+            }
+
         }
 
         // 选中输入框

+ 15 - 33
app/src/main/java/com/emato/ich/fragment/TakeFragment.java

@@ -1,24 +1,24 @@
 package com.emato.ich.fragment;
 
-import android.graphics.drawable.Drawable;
 import android.os.Bundle;
 import android.os.CountDownTimer;
-import com.emato.ich.utils.Log;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
+import android.widget.ImageView;
 
 import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
 import androidx.fragment.app.Fragment;
-import androidx.navigation.fragment.NavHostFragment;
 
+import com.bumptech.glide.Glide;
+import com.bumptech.glide.load.engine.DiskCacheStrategy;
 import com.emato.ich.MainActivity;
 import com.emato.ich.R;
-import com.emato.ich.api.ICSPClient;
 import com.emato.ich.contant.SystemConfigConstant;
 import com.emato.ich.databinding.FragmentTakeBinding;
 import com.emato.ich.utils.ButtonUtils;
+import com.emato.ich.utils.Log;
 import com.emato.ich.utils.LoggingUtils;
 import com.emato.ich.utils.NavUtils;
 import com.emato.ich.utils.StringUtils;
@@ -26,13 +26,6 @@ import com.emato.ich.utils.TimeOutUtils;
 
 import org.jetbrains.annotations.NotNull;
 
-import java.io.IOException;
-import java.io.InputStream;
-
-import okhttp3.Call;
-import okhttp3.Callback;
-import okhttp3.Response;
-
 /**
  * 取件提示页面
  */
@@ -71,28 +64,17 @@ public class TakeFragment extends Fragment {
         String url = activity.getConfigMap().get(SystemConfigConstant.cabinet_take_object_qrcode_url);
 
         if (getActivity() != null && activity.getConfigMap().size() > 0 && !StringUtils.isNullOrEmpty(url)) {
-            ICSPClient.getWeChatMPImage(url, new Callback() {
-                @Override
-                public void onFailure(@NotNull Call call, @NotNull IOException e) {
-                    Log.e(TAG, "onFailure: 请求微信公众号图片错误! 网络异常! ", e);
-                    LoggingUtils.sendErrorLog("业务异常: 请求微信公众号图片错误! 网络异常!", e);
-                }
-
-                @Override
-                public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
-                    getActivity().runOnUiThread(() -> {
-                        try {
-                            InputStream is = response.body().byteStream();
-                            final Drawable d = Drawable.createFromStream(is, "src");
-                            binding.textView.setBackground(d);
-                            is.close();
-                        } catch (Exception e) {
-                            Log.e(TAG, "onResponse: 设置图片异常! ", e);
-                            LoggingUtils.sendErrorLog("业务异常: 设置图片异常! ", e);
-                        }
-                    });
-                }
-            });
+
+            try {
+                ImageView imageView = view.findViewById(R.id.textView);
+                Glide.with(view).load(url)
+                        .skipMemoryCache(true)//跳过内存缓存
+                        .diskCacheStrategy(DiskCacheStrategy.NONE)//不缓冲disk硬盘中
+                        .into(imageView);
+            } catch (Exception e) {
+                Log.e(TAG, "onResponse: Glide设置图片异常! ", e);
+                LoggingUtils.sendErrorLog("业务异常: Glide请求微信公众号图片异常! ", e);
+            }
         }
 
         // TODO 对接微信

+ 1 - 1
app/src/main/res/layout/fragment_take.xml

@@ -46,7 +46,7 @@
         android:textSize="15dp"
         android:textStyle="bold" />
 
-    <TextView
+    <ImageView
         android:id="@+id/textView"
         android:layout_width="134dp"
         android:layout_height="135dp"

+ 1 - 1
app/src/main/res/layout/fragment_take_code.xml

@@ -27,7 +27,7 @@
         android:text="@string/wx_scan_take"
         android:textSize="20dp" />
 
-    <TextView
+    <ImageView
         android:id="@+id/textView"
         android:layout_width="134dp"
         android:layout_height="135dp"