0
0
Переглянути джерело

fix: 同时点击按钮重启,ui优化

lhm 3 роки тому
батько
коміт
4d6b5fe277

+ 5 - 2
app/src/main/java/com/emato/ich/MainActivity.java

@@ -5,8 +5,9 @@ import android.os.Bundle;
 import com.cherry.sdk.controller.utils.ScanGunKeyEventHelper;
 import com.emato.ich.api.ICSPApi;
 import com.emato.ich.api.ICSPClient;
+import com.emato.ich.api.ICSPConstant;
 import com.emato.ich.api.ICSPResponseCodeEnum;
-import com.emato.ich.contant.SystemConfigConstant;
+import com.emato.ich.api.SystemConfigConstant;
 import com.emato.ich.crash.CrashApplication;
 import com.emato.ich.device.DeviceControl;
 import com.emato.ich.entity.Cabinet;
@@ -16,6 +17,7 @@ import com.emato.ich.entity.vo.ShellVo;
 import com.emato.ich.local.LocalStorage;
 import com.emato.ich.message.ICHPublishClient;
 import com.emato.ich.message.ICHTopic;
+import com.emato.ich.update.APKUpdateDownload;
 import com.emato.ich.update.OnDownloadListener;
 import com.emato.ich.utils.BaseUtils;
 import com.emato.ich.utils.JacksonUtils;
@@ -49,6 +51,7 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.CountDownLatch;
@@ -90,7 +93,7 @@ public class MainActivity extends AppCompatActivity  {
         openLocker(ichPublishClient);
 
         // 注册柜子信息
-        //cabinetInfoReport(ichPublishClient);
+        cabinetInfoReport(ichPublishClient);
 
         // TODO 更新版本监听
         autoUpdateVersion(ichPublishClient);

+ 21 - 44
app/src/main/java/com/emato/ich/fragment/InputInfoFragment.java

@@ -25,18 +25,18 @@ import com.emato.ich.entity.vo.PreparedOrderResponseVo;
 import com.emato.ich.entity.vo.PreparedOrderVo;
 import com.emato.ich.local.LocalStorage;
 import com.emato.ich.utils.BaseUtils;
-import com.emato.ich.utils.ButtonUtils;
 import com.emato.ich.utils.JacksonUtils;
 import com.emato.ich.utils.StringUtils;
 import com.emato.ich.utils.TimeOutUtils;
-import com.emato.ich.utils.ToastUtils;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.core.type.TypeReference;
 import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.android.material.snackbar.Snackbar;
 
 import org.jetbrains.annotations.NotNull;
 
 import java.io.IOException;
+import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.regex.Pattern;
 
@@ -92,11 +92,6 @@ public class InputInfoFragment extends Fragment {
                 // 扫码成功回调
                 Log.d(TAG, "onScanSuccess: " + s);
 
-                if (timer == null) {
-                    // 防止连续扫描时, 倒计时已经到0了, 导致非法参数异常
-                    return;
-                }
-
                 if (mailNoLock.get() == 1) {
                     Editable text = binding.mailNo.getText();
                     text.clear();
@@ -107,8 +102,7 @@ public class InputInfoFragment extends Fragment {
                         @Override
                         public void onFailure(@NotNull Call call, @NotNull IOException e) {
                             // 请求失败
-                            mailNoLock.set(1);
-                            ToastUtils.make(getContext(), "服务器异常! 请手动输入! ");
+                            Snackbar.make(view, "服务器异常! 请手动输入! ", Snackbar.LENGTH_LONG).show();
                         }
 
                         @Override
@@ -126,17 +120,17 @@ public class InputInfoFragment extends Fragment {
                                         binding.delivererPhoneConfirm.setText(collectorPhone);
                                     }
 
-                                    ICSPResponseCodeEnum.responseHint(getContext(), responseData);
+                                    ICSPResponseCodeEnum.responseHint(view, responseData);
 
                                 } catch (JsonProcessingException e) {
                                     Log.e(TAG, "onResponse: 服务器响应错误! 自动获取用户手机号失败! ", e);
-                                    ToastUtils.make(getContext(), "网络异常! 请手动输入手机号!");
+                                    Snackbar.make(view, "网络异常! 请手动输入手机号! ", Snackbar.LENGTH_LONG).show();
                                 } catch (RuntimeException e) {
                                     Log.e(TAG, "onResponse: 获取用户手机号未知错误! ", e);
-                                    ToastUtils.make(getContext(), "未查询到手机号! 请手动输入! ");
+                                    Snackbar.make(view, "未查询到手机号! 请手动输入! ", Snackbar.LENGTH_LONG).show();
                                 }
                             });
-                            mailNoLock.set(1);
+
                         }
                     });
                 }
@@ -154,17 +148,14 @@ public class InputInfoFragment extends Fragment {
         if (submitLock.get() == 1) {
             submitLock.incrementAndGet();
             binding.buttonConfirm.setOnClickListener(view1 -> {
-                if (ButtonUtils.isFastClick()) {
-                    return;
-                }
                 Bundle bundle = new Bundle();
                 String mailNo = binding.mailNo.getText().toString();
 //            String phone = binding.delivererPhone.getText().toString();
                 String phoneConfirm = binding.delivererPhoneConfirm.getText().toString();
                 if (!phonePattern.matcher(phoneConfirm).matches()) {
-                    ToastUtils.make(getContext(), "请输入正确的手机号!");
+                    Snackbar.make(view1, "请输入正确的手机号!", Snackbar.LENGTH_LONG).show();
                 } else if (StringUtils.isNullOrEmpty(mailNo)) {
-                    ToastUtils.make(getContext(), "运单号不能为空!请扫描运单号!");
+                    Snackbar.make(view1, "运单号不能为空!请扫描运单号!", Snackbar.LENGTH_LONG).show();
                 } else {
                     // 验证完 预下单
                     PreparedOrderVo preparedOrderVo = new PreparedOrderVo();
@@ -179,8 +170,7 @@ public class InputInfoFragment extends Fragment {
                         @Override
                         public void onFailure(@NotNull Call call, @NotNull IOException e) {
                             // TODO 预下单调用失败
-                            submitLock.set(1);
-                            ToastUtils.make(getContext(), "请求服务器失败!网络异常!");
+                            Snackbar.make(view, "请求服务器失败!网络异常!", Snackbar.LENGTH_LONG).show();
                             Log.e(TAG, "onFailure: 预下单失败! call: " + call.timeout().toString(), e);
                         }
 
@@ -208,7 +198,7 @@ public class InputInfoFragment extends Fragment {
                                         timer.cancel();
                                         NavHostFragment.findNavController(InputInfoFragment.this).navigate(R.id.action_inputInfoFragment_to_sendInfoConfirmFragment);
                                     } else {
-                                        ICSPResponseCodeEnum.responseHint(getContext(), responseData);
+                                        ICSPResponseCodeEnum.responseHint(view, responseData);
                                         Log.e(TAG, "onResponse: ICSP返回码: " + responseData.getCode() + ", 返回信息: " + responseData.getMsg(), new RuntimeException("系统异常"));
                                     }
                                 } catch (JsonProcessingException e) {
@@ -231,7 +221,7 @@ public class InputInfoFragment extends Fragment {
                 binding.inputButton0.setOnClickListener(v -> {
                     int length = binding.delivererPhoneConfirm.getText().length();
                     if (length >= 11) {
-                        ToastUtils.make(getContext(), "手机号不能超过11位!");
+                        Snackbar.make(view1, "手机号不能超过11位", Snackbar.LENGTH_LONG).show();
                         return;
                     }
                     int start = binding.delivererPhoneConfirm.getSelectionStart();
@@ -240,7 +230,7 @@ public class InputInfoFragment extends Fragment {
                 binding.inputButton1.setOnClickListener(v -> {
                     int length = binding.delivererPhoneConfirm.getText().length();
                     if (length >= 11) {
-                        ToastUtils.make(getContext(), "手机号不能超过11位!");
+                        Snackbar.make(view1, "手机号不能超过11位", Snackbar.LENGTH_LONG).show();
                         return;
                     }
                     int start = binding.delivererPhoneConfirm.getSelectionStart();
@@ -249,7 +239,7 @@ public class InputInfoFragment extends Fragment {
                 binding.inputButton2.setOnClickListener(v -> {
                     int length = binding.delivererPhoneConfirm.getText().length();
                     if (length >= 11) {
-                        ToastUtils.make(getContext(), "手机号不能超过11位!");
+                        Snackbar.make(view1, "手机号不能超过11位", Snackbar.LENGTH_LONG).show();
                         return;
                     }
                     int start = binding.delivererPhoneConfirm.getSelectionStart();
@@ -258,7 +248,7 @@ public class InputInfoFragment extends Fragment {
                 binding.inputButton3.setOnClickListener(v -> {
                     int length = binding.delivererPhoneConfirm.getText().length();
                     if (length >= 11) {
-                        ToastUtils.make(getContext(), "手机号不能超过11位!");
+                        Snackbar.make(view1, "手机号不能超过11位", Snackbar.LENGTH_LONG).show();
                         return;
                     }
                     int start = binding.delivererPhoneConfirm.getSelectionStart();
@@ -267,7 +257,7 @@ public class InputInfoFragment extends Fragment {
                 binding.inputButton4.setOnClickListener(v -> {
                     int length = binding.delivererPhoneConfirm.getText().length();
                     if (length >= 11) {
-                        ToastUtils.make(getContext(), "手机号不能超过11位!");
+                        Snackbar.make(view1, "手机号不能超过11位", Snackbar.LENGTH_LONG).show();
                         return;
                     }
                     int start = binding.delivererPhoneConfirm.getSelectionStart();
@@ -276,7 +266,7 @@ public class InputInfoFragment extends Fragment {
                 binding.inputButton5.setOnClickListener(v -> {
                     int length = binding.delivererPhoneConfirm.getText().length();
                     if (length >= 11) {
-                        ToastUtils.make(getContext(), "手机号不能超过11位!");
+                        Snackbar.make(view1, "手机号不能超过11位", Snackbar.LENGTH_LONG).show();
                         return;
                     }
                     int start = binding.delivererPhoneConfirm.getSelectionStart();
@@ -285,7 +275,7 @@ public class InputInfoFragment extends Fragment {
                 binding.inputButton6.setOnClickListener(v -> {
                     int length = binding.delivererPhoneConfirm.getText().length();
                     if (length >= 11) {
-                        ToastUtils.make(getContext(), "手机号不能超过11位!");
+                        Snackbar.make(view1, "手机号不能超过11位", Snackbar.LENGTH_LONG).show();
                         return;
                     }
                     int start = binding.delivererPhoneConfirm.getSelectionStart();
@@ -294,7 +284,7 @@ public class InputInfoFragment extends Fragment {
                 binding.inputButton7.setOnClickListener(v -> {
                     int length = binding.delivererPhoneConfirm.getText().length();
                     if (length >= 11) {
-                        ToastUtils.make(getContext(), "手机号不能超过11位!");
+                        Snackbar.make(view1, "手机号不能超过11位", Snackbar.LENGTH_LONG).show();
                         return;
                     }
                     int start = binding.delivererPhoneConfirm.getSelectionStart();
@@ -303,7 +293,7 @@ public class InputInfoFragment extends Fragment {
                 binding.inputButton8.setOnClickListener(v -> {
                     int length = binding.delivererPhoneConfirm.getText().length();
                     if (length >= 11) {
-                        ToastUtils.make(getContext(), "手机号不能超过11位!");
+                        Snackbar.make(view1, "手机号不能超过11位", Snackbar.LENGTH_LONG).show();
                         return;
                     }
                     int start = binding.delivererPhoneConfirm.getSelectionStart();
@@ -312,7 +302,7 @@ public class InputInfoFragment extends Fragment {
                 binding.inputButton9.setOnClickListener(v -> {
                     int length = binding.delivererPhoneConfirm.getText().length();
                     if (length >= 11) {
-                        ToastUtils.make(getContext(), "手机号不能超过11位!");
+                        Snackbar.make(view1, "手机号不能超过11位", Snackbar.LENGTH_LONG).show();
                         return;
                     }
                     int start = binding.delivererPhoneConfirm.getSelectionStart();
@@ -326,11 +316,6 @@ public class InputInfoFragment extends Fragment {
                         binding.delivererPhoneConfirm.setSelection(binding.delivererPhoneConfirm.getText().length());
                     }
                 });
-                // 长按删除
-                binding.inputButtonCancel.setOnLongClickListener(v -> {
-                    binding.delivererPhoneConfirm.getText().clear();
-                    return false;
-                });
             }
         });
 
@@ -384,18 +369,10 @@ public class InputInfoFragment extends Fragment {
                         binding.mailNo.setSelection(binding.mailNo.getText().length());
                     }
                 });
-                // 长按删除
-                binding.inputButtonCancel.setOnLongClickListener(v -> {
-                    binding.mailNo.getText().clear();
-                    return false;
-                });
             }
         });
 
         binding.returnBtn.setOnClickListener(view1 -> {
-            if (ButtonUtils.isFastClick()) {
-                return;
-            }
             timer.cancel();
             NavHostFragment.findNavController(InputInfoFragment.this)
                     .navigate(R.id.action_inputInfoFragment_to_chooseCabinetFragment);

+ 16 - 71
app/src/main/java/com/emato/ich/fragment/SendInfoConfirmFragment.java

@@ -1,6 +1,5 @@
 package com.emato.ich.fragment;
 
-import android.app.AlertDialog;
 import android.os.Bundle;
 import android.os.CountDownTimer;
 import android.util.Log;
@@ -24,16 +23,16 @@ import com.emato.ich.entity.vo.ConfirmOrderVo;
 import com.emato.ich.entity.vo.PreparedOrderResponseVo;
 import com.emato.ich.local.LocalStorage;
 import com.emato.ich.utils.BaseUtils;
-import com.emato.ich.utils.ButtonUtils;
 import com.emato.ich.utils.JacksonUtils;
 import com.emato.ich.utils.TimeOutUtils;
-import com.emato.ich.utils.ToastUtils;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.android.material.snackbar.Snackbar;
 
 import org.jetbrains.annotations.NotNull;
 
 import java.io.IOException;
+import java.util.Map;
 
 import okhttp3.Call;
 import okhttp3.Callback;
@@ -77,12 +76,10 @@ public class SendInfoConfirmFragment extends Fragment {
         String orderSn = null;
         String collectorPhone;
         PreparedOrderResponseVo orderResponseVo;
-        String sectionType = null;
         // 设置订单提示属性
         if (null != arguments) {
+            String response = arguments.getString("preparedOrderResponse");
             try {
-                String response = arguments.getString("preparedOrderResponse");
-                sectionType = arguments.getString("sectionType");
                 orderResponseVo = JacksonUtils.objectmapper.readValue(response, PreparedOrderResponseVo.class);
                 collectorPhone = orderResponseVo.getCollectorPhone();
                 orderSn = orderResponseVo.getOrderSn();
@@ -99,9 +96,6 @@ public class SendInfoConfirmFragment extends Fragment {
         // 投递完成确认
         String finalOrderSn = orderSn;
         binding.alreadySend.setOnClickListener(view1 -> {
-            if (ButtonUtils.isFastClick()) {
-                return;
-            }
             // TODO 确认投递, 真正下单
             String clientId = BaseUtils.getClientId();
             // /order/deliverer/confirm
@@ -116,7 +110,7 @@ public class SendInfoConfirmFragment extends Fragment {
 //                    getActivity().runOnUiThread(() -> {
 //
 //                    });
-                    ToastUtils.make(getContext(), "投递失败!网络异常!");
+                    Snackbar.make(view, "投递失败!网络异常!", Snackbar.LENGTH_LONG).show();
                     Log.e(TAG, "onFailure: 确认投递失败! ", e);
                 }
 
@@ -130,13 +124,13 @@ public class SendInfoConfirmFragment extends Fragment {
                             String code = responseData.getCode();
                             if (code.equals(ICSPResponseCodeEnum.OK.getCode())) {
                                 // TODO 确认投递成功逻辑处理
-                                ToastUtils.make(getContext(), "投递成功!");
+                                Snackbar.make(view, "投递成功! ", Snackbar.LENGTH_LONG).show();
                                 timer.cancel();
                                 NavHostFragment.findNavController(SendInfoConfirmFragment.this)
                                         .navigate(R.id.action_sendInfoConfirmFragment_to_sendSuccessFragment);
                             } else {
                                 // TODO 确认投递失败逻辑处理
-                                ICSPResponseCodeEnum.responseHint(getContext(), responseData);
+                                ICSPResponseCodeEnum.responseHint(view, responseData);
                                 Log.w(TAG, "onResponse: " + responseData.getMsg());
                             }
                         } catch (JsonProcessingException e) {
@@ -154,9 +148,6 @@ public class SendInfoConfirmFragment extends Fragment {
         // 异常页面跳转
         MainActivity finalActivity = activity;
         binding.exceptionBtn.setOnClickListener(view1 -> {
-            if (ButtonUtils.isFastClick()) {
-                return;
-            }
             Bundle bundle = new Bundle();
             timer.cancel();
             bundle.putString("exception", "exception_page");
@@ -166,66 +157,20 @@ public class SendInfoConfirmFragment extends Fragment {
         });
 
         // 未投递按钮
-        String finalSectionType = sectionType;
         binding.noneSend.setOnClickListener(view1 -> {
-            if (ButtonUtils.isFastClick()) {
-                return;
-            }
-//            Bundle bundle = new Bundle();
-//            bundle.putString("exception", "exception_page");
-//            finalActivity.getBundleMap().put(SendInfoConfirmFragment.class.getName(), bundle);
-            AlertDialog alertDialog = new AlertDialog.Builder(finalActivity)
-                    .setTitle("e站通")
-                    .setMessage("确定要取消本次投递吗?")
-                    .setPositiveButton("是", (dialog, which) -> {
-                        // 是, 取消本次投递
-                        ConfirmOrderVo confirmOrderVo = new ConfirmOrderVo();
-                        confirmOrderVo.setOrderSn(finalOrderSn);
-                        confirmOrderVo.setClientId(BaseUtils.getClientId());
-                        confirmOrderVo.setDecision(DecisionEnum.CANCEL_11.getDecision());
-                        confirmOrderVo.setLockerType(finalSectionType);
-                        ICSPClient.confirmOrder(LocalStorage.getInstance().getSession().getToken(), confirmOrderVo, 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 {
-                                        timer.cancel();
-                                        NavHostFragment.findNavController(SendInfoConfirmFragment.this)
-                                                .navigate(R.id.action_sendInfoConfirmFragment_to_sendSuccessFragment);
-                                    } catch (Exception e) {
-
-                                    }
-                                });
-                            }
-                        });
-                    }).setNegativeButton("否", (dialog, which) -> {
-                        // 否
-                        dialog.dismiss();
-                    }).create();
-            alertDialog.show();
+            Bundle bundle = new Bundle();
+            bundle.putString("exception", "exception_page");
+            finalActivity.getBundleMap().put(SendInfoConfirmFragment.class.getName(), bundle);
+            timer.cancel();
+            NavHostFragment.findNavController(SendInfoConfirmFragment.this)
+                    .navigate(R.id.action_sendInfoConfirmFragment_to_exceptionFragment);
         });
 
         binding.returnMainBtn.setOnClickListener(view1 -> {
-            if (ButtonUtils.isFastClick()) {
-                return;
-            }
-            AlertDialog alertDialog = new AlertDialog.Builder(finalActivity)
-                    .setTitle("e站通")
-                    .setMessage("返回主页会取消本次投递!确认取消吗?")
-                    .setPositiveButton("是", ((dialog, which) -> {
-                        timer.cancel();
-                        LocalStorage.getInstance().cleanSession(((MainActivity) getActivity()));
-                        NavHostFragment.findNavController(SendInfoConfirmFragment.this)
-                                .navigate(R.id.action_sendInfoConfirmFragment_to_mainFragment);
-                    })).setNegativeButton("否", ((dialog, which) -> {
-                        dialog.dismiss();
-                    })).create();
-            alertDialog.show();
+            timer.cancel();
+            LocalStorage.getInstance().cleanSession(((MainActivity) getActivity()));
+            NavHostFragment.findNavController(SendInfoConfirmFragment.this)
+                    .navigate(R.id.action_sendInfoConfirmFragment_to_mainFragment);
         });
 
     }

+ 5 - 9
app/src/main/res/values/colors.xml

@@ -1,19 +1,15 @@
 <?xml version="1.0" encoding="utf-8"?>
 <resources>
     <color name="purple_200">#FFBB86FC</color>
-<!--    <color name="purple_500">#FF6200EE</color>-->
-    <color name="purple_500">#c9dd22</color>
-    <color name="purple_700">#c9dd22</color>
+    <color name="purple_500">#FF6200EE</color>
+    <color name="purple_700">#FF3700B3</color>
     <color name="teal_200">#FF03DAC5</color>
     <color name="teal_700">#FF018786</color>
     <color name="black">#FF000000</color>
     <color name="white">#FFFFFFFF</color>
-    <color name="send_btn">#75FF90</color>
+    <color name="send_btn">#44CE3B</color>
     <color name="take_btn">#EBBA3A</color>
     <color name="main_label_bg">#4E4C4D</color>
     <color name="choose_cabinet_view">#9DDA99</color>
-    <color name="input_confirm">#20E45E</color>
-    <color name="confirm_btn">#0eb83a</color>
-    <color name="return_color">#c9dd22</color>
-    <color name="status_bar_color">#798E91</color>
-=</resources>
+
+</resources>

+ 2 - 15
app/src/main/res/values/themes.xml

@@ -3,7 +3,7 @@
     <style name="Theme.Ichandroid" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
         <!-- Primary brand color. -->
         <item name="colorPrimary">@color/send_btn</item>
-        <item name="colorPrimaryVariant">@color/status_bar_color</item>
+        <item name="colorPrimaryVariant">@color/purple_700</item>
         <item name="colorOnPrimary">@color/white</item>
         <!-- Secondary brand color. -->
         <item name="colorSecondary">@color/teal_200</item>
@@ -30,20 +30,7 @@
         <item name="windowActionBar">false</item>
         <item name="windowNoTitle">true</item>
     </style>
-    <!-- 返回键 -->
-    <style name="Theme.ButtonStyle" parent="Theme.MaterialComponents.Light.NoActionBar">
-        <item name="colorPrimary">@color/return_color</item>
-        <item name="colorPrimaryVariant">@color/main_label_bg</item>
-        <item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
-    </style>
-    <!-- 部分按钮 -->
-    <style name="Theme.ButtonStyle.GREEN" parent="Theme.MaterialComponents.Light.NoActionBar">
-        <item name="colorPrimary">@color/confirm_btn</item>
-    </style>
-    <!-- 确认按钮 -->
-    <style name="Theme.ButtonStyle.CONFIRM" parent="Theme.MaterialComponents.Light.NoActionBar">
-        <item name="colorPrimary">@color/input_confirm</item>
-    </style>
+
     <style name="Theme.Ichandroid.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
 
     <style name="Theme.Ichandroid.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />