|
@@ -2,6 +2,7 @@ package com.emato.ich.fragment;
|
|
|
|
|
|
import android.graphics.drawable.Drawable;
|
|
|
import android.os.Bundle;
|
|
|
+import android.util.Log;
|
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.View;
|
|
|
import android.view.ViewGroup;
|
|
@@ -12,15 +13,24 @@ import androidx.navigation.fragment.NavHostFragment;
|
|
|
|
|
|
import com.emato.ich.MainActivity;
|
|
|
import com.emato.ich.R;
|
|
|
+import com.emato.ich.api.ICSPClient;
|
|
|
import com.emato.ich.api.SystemConfigConstant;
|
|
|
import com.emato.ich.databinding.FragmentMainBinding;
|
|
|
+import com.emato.ich.utils.StringUtils;
|
|
|
+
|
|
|
+import org.jetbrains.annotations.NotNull;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
import java.net.URL;
|
|
|
|
|
|
+import okhttp3.Call;
|
|
|
+import okhttp3.Callback;
|
|
|
+import okhttp3.Response;
|
|
|
+
|
|
|
public class MainFragment extends Fragment {
|
|
|
|
|
|
+ private static final String TAG = MainFragment.class.getName();
|
|
|
private FragmentMainBinding binding;
|
|
|
|
|
|
@Override
|
|
@@ -39,26 +49,28 @@ public class MainFragment extends Fragment {
|
|
|
MainActivity activity = (MainActivity) getActivity();
|
|
|
String url = activity.getConfigMap().get(SystemConfigConstant.cabinet_take_object_qrcode_url);
|
|
|
|
|
|
- new Thread(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- try {
|
|
|
- InputStream is = (InputStream) new URL(url).getContent();
|
|
|
- final Drawable d = Drawable.createFromStream(is, "src");
|
|
|
- is.close();
|
|
|
- if (null != d) {
|
|
|
- activity.runOnUiThread(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- binding.fastTakeSend.setBackground(d);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ @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);
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
- }
|
|
|
- }).start();
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
// 投递页面跳转
|
|
|
binding.sendBtn.setOnClickListener(view12 -> NavHostFragment.findNavController(MainFragment.this)
|