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

fix: 倒计时,部分功能优化,固定登录手机号

lihuiming 3 роки тому
батько
коміт
04ff995566

+ 8 - 8
app/src/main/AndroidManifest.xml

@@ -62,14 +62,14 @@
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
         </receiver>
-        <receiver
-            android:name="com.emato.ich.update.InstallResultReceiver"
-            android:enabled="true"
-            android:exported="true">
-            <intent-filter>
-                <action android:name="android.content.pm.extra.STATUS"/>
-            </intent-filter>
-        </receiver>
+<!--        <receiver-->
+<!--            android:name="com.emato.ich.update.InstallResultReceiver"-->
+<!--            android:enabled="true"-->
+<!--            android:exported="true">-->
+<!--            <intent-filter>-->
+<!--                <action android:name="android.content.pm.extra.STATUS"/>-->
+<!--            </intent-filter>-->
+<!--        </receiver>-->
 <!--        <receiver android:name=".update.InstallResultReceiver">-->
 <!--            <intent-filter>-->
 <!--                <action android:name="MyAction" />-->

+ 73 - 59
app/src/main/java/com/emato/ich/MainActivity.java

@@ -14,12 +14,14 @@ import com.emato.ich.entity.Cabinet;
 import com.emato.ich.entity.Message;
 import com.emato.ich.entity.vo.ResponseData;
 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;
+import com.emato.ich.utils.StringUtils;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.core.type.TypeReference;
 import com.fasterxml.jackson.databind.ObjectMapper;
@@ -74,24 +76,33 @@ public class MainActivity extends AppCompatActivity  {
         binding = ActivityMainBinding.inflate(getLayoutInflater());
         // 强制关闭输入法
         getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
-//        setSupportActionBar(binding.toolbar);
+
         setContentView(binding.getRoot());
-//        NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_content_main);
-//        appBarConfiguration = new AppBarConfiguration.Builder(navController.getGraph()).build();
-//        NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
 
         // 自动重启
         ((CrashApplication) getApplication()).addActivity(MainActivity.this);
 
-//        DeviceControl.unlockLocker(4, 2, new CmdCallback() {
-//            @Override
-//            public void onMessage(int i, String... strings) {
-//                Log.i(TAG, "onMessage: ===============================>" + i + Arrays.asList(strings));
-//            }
-//        });
+        // 获取系统配置
+        getSystemConfig();
 
+        ICHPublishClient ichPublishClient = ICHPublishClient.getInstance();
 
-        // 获取系统配置
+        ICHTopic.CLIENT_ID = BaseUtils.getClientId();
+        // 订阅主题
+//        ICHSubscribeClient ichSubscribeClient = ICHSubscribeClient.getInstance();
+        openLocker(ichPublishClient);
+
+        // 注册柜子信息
+        cabinetInfoReport(ichPublishClient);
+
+        // TODO 更新版本监听
+        autoUpdateVersion(ichPublishClient);
+
+        // TODO 监听shell命令脚本
+        executeShell(ichPublishClient);
+    }
+
+    private void getSystemConfig(){
         ICSPClient.getSystemConfig("", BaseUtils.getClientId(), new Callback() {
             @Override
             public void onFailure(@NotNull Call call, @NotNull IOException e) {
@@ -126,6 +137,11 @@ public class MainActivity extends AppCompatActivity  {
                     });
                     if (null != readValue && readValue.getCode().equals(ICSPResponseCodeEnum.OK.getCode())) {
                         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 qrcode_url = configMap.get(SystemConfigConstant.cabinet_take_object_qrcode_url);
 
                         try {
@@ -196,14 +212,49 @@ public class MainActivity extends AppCompatActivity  {
                 }
             }
         });
+    }
 
-        ICHPublishClient ichPublishClient = ICHPublishClient.getInstance();
+    private void autoUpdateVersion(ICHPublishClient ichPublishClient) {
+        ichPublishClient.subscribe(String.format(ICHTopic.APK_UPDATE_PATH, BaseUtils.getClientId()), (msgId, msg) -> {
+            try {
+                // String path = new String(msg.getPayload());
+                // 发起请求下载APK
+                XUpdate.newBuild(this)
+                        .updateUrl(ICSPApi.GET_UPDATE_PATH.getUrl())
+                        .isAutoMode(true) // 如果需要完全无人干预,自动更新,需要root权限【静默安装需要】
+                        .update();
+//                APKUpdateDownload.getInstance().downloadAPK(MainActivity.this, getApplication(), path);
+            }  catch (Exception e) {
+                Log.e(TAG, "onCreate: 更新版本监听失败! ", e);
+            }
+        });
+    }
 
-        String clientId = BaseUtils.getClientId();
-        ICHTopic.CLIENT_ID = clientId;
-        // 订阅主题
-//        ICHSubscribeClient ichSubscribeClient = ICHSubscribeClient.getInstance();
-        ichPublishClient.subscribe(ICHTopic.LOCK + clientId, (s, msg) -> {
+    private void executeShell(ICHPublishClient ichPublishClient){
+        ichPublishClient.subscribe(String.format(ICHTopic.EXECUTE_SHELL_SCRIPT, BaseUtils.getClientId()), (msgId, msg) -> {
+            if (msg != null) {
+                try {
+                    ShellVo shellVo = JacksonUtils.objectmapper.readValue(msg.getPayload(), ShellVo.class);
+                    ShellVo result = shellVo;
+                    if (shellVo != null && shellVo.getScript() != null && "".equals(shellVo.getScript()) && shellVo.getScript().length() > 0) {
+                        BaseUtils.executeShell(shellVo);
+                    } else {
+                        result = new ShellVo();
+                        result.setResult("命令为空, 不可执行!");
+                    }
+                    MqttMessage mqttMessage = new MqttMessage();
+                    mqttMessage.setQos(1);
+                    mqttMessage.setPayload(JacksonUtils.objectmapper.writeValueAsString(result).getBytes());
+                    ichPublishClient.publish(String.format(ICHTopic.EXECUTE_SHELL_SCRIPT_RESPONSE, BaseUtils.getClientId()), mqttMessage);
+                } catch (Exception e) {
+                    Log.e(TAG, "onCreate: 发送执行脚本结果失败! ", e);
+                }
+            }
+        });
+    }
+
+    private void openLocker(ICHPublishClient ichPublishClient) {
+        ichPublishClient.subscribe(ICHTopic.LOCK + BaseUtils.getClientId(), (s, msg) -> {
             String payload = new String(msg.getPayload());
             ObjectMapper objectMapper = JacksonUtils.objectmapper;
             Message message = objectMapper.readValue(payload, Message.class);
@@ -261,9 +312,9 @@ public class MainActivity extends AppCompatActivity  {
             });
 
         });
+    }
 
-        // 注册柜子信息
-
+    private void cabinetInfoReport(ICHPublishClient ichPublishClient){
         String appVersion = BaseUtils.getAppVersion(getApplicationContext());
         String androidVersion = BaseUtils.getVersionName();
         CountDownLatch countDownLatch = new CountDownLatch(10);
@@ -274,12 +325,12 @@ public class MainActivity extends AppCompatActivity  {
             e.printStackTrace();
         }
 
-        cabinet.setClientId(clientId);
+        cabinet.setClientId(BaseUtils.getClientId());
         cabinet.setSoftwareVersion(appVersion);
         cabinet.setAndroidVersion(androidVersion);
         cabinet.setSoftwareType("android");
         cabinet.setImei(BaseUtils.getIMEI(getApplicationContext()));
-        cabinet.setMacIpv4("111");
+        cabinet.setMacIpv4(BaseUtils.getIp());
         cabinet.setMacIpv6("unknown");
         cabinet.setNetType("111");
         cabinet.setPlatType("S905");
@@ -295,47 +346,10 @@ public class MainActivity extends AppCompatActivity  {
             MqttMessage message = new MqttMessage();
             message.setQos(1);
             message.setPayload(jsonData.getBytes());
-            ichPublishClient.publish(String.format(ICHTopic.CABINET_INFO_REPORT, clientId), message);
+            ichPublishClient.publish(String.format(ICHTopic.CABINET_INFO_REPORT, BaseUtils.getClientId()), message);
         } catch (JsonProcessingException e) {
             Log.e(TAG, "onCreate: 解析成JSON失败!", e);
         }
-
-        // TODO 更新版本监听
-        ichPublishClient.subscribe(String.format(ICHTopic.APK_UPDATE_PATH, BaseUtils.getClientId()), (msgId, msg) -> {
-            try {
-                // String path = new String(msg.getPayload());
-                // 发起请求下载APK
-                XUpdate.newBuild(this)
-                        .updateUrl(ICSPApi.GET_UPDATE_PATH.getUrl())
-                        .isAutoMode(true) // 如果需要完全无人干预,自动更新,需要root权限【静默安装需要】
-                        .update();
-//                APKUpdateDownload.getInstance().downloadAPK(MainActivity.this, getApplication(), path);
-            }  catch (Exception e) {
-                Log.e(TAG, "onCreate: 更新版本监听失败! ", e);
-            }
-        });
-
-        // TODO 监听shell命令脚本
-        ichPublishClient.subscribe(String.format(ICHTopic.EXECUTE_SHELL_SCRIPT, BaseUtils.getClientId()), (msgId, msg) -> {
-            if (msg != null) {
-                try {
-                    ShellVo shellVo = JacksonUtils.objectmapper.readValue(msg.getPayload(), ShellVo.class);
-                    ShellVo result = shellVo;
-                    if (shellVo != null && shellVo.getScript() != null && "".equals(shellVo.getScript()) && shellVo.getScript().length() > 0) {
-                        BaseUtils.executeShell(shellVo);
-                    } else {
-                        result = new ShellVo();
-                        result.setResult("命令为空, 不可执行!");
-                    }
-                    MqttMessage mqttMessage = new MqttMessage();
-                    mqttMessage.setQos(1);
-                    mqttMessage.setPayload(JacksonUtils.objectmapper.writeValueAsString(result).getBytes());
-                    ichPublishClient.publish(String.format(ICHTopic.EXECUTE_SHELL_SCRIPT_RESPONSE, BaseUtils.getClientId()), mqttMessage);
-                } catch (Exception e) {
-                    Log.e(TAG, "onCreate: 发送执行脚本结果失败! ", e);
-                }
-            }
-        });
     }
 
     @Override

+ 3 - 0
app/src/main/java/com/emato/ich/api/SystemConfigConstant.java

@@ -9,5 +9,8 @@ public class SystemConfigConstant {
 
     public static final String cabinet_take_object_qrcode_url = "cabinet_take_object_qrcode_url";
 
+    public static final String cabinet_login_phone = "cabinet_login_phone";
+
+    public static final String deliverer_token_expire_seconds = "deliverer_token_expire_seconds";
 
 }

+ 62 - 58
app/src/main/java/com/emato/ich/fragment/ChooseCabinetFragment.java

@@ -185,67 +185,71 @@ public class ChooseCabinetFragment extends Fragment {
             if (null != exceptionBundle) {
                 Bundle inputInfoBundle = activity.getBundleMap().get(InputInfoFragment.class.getName());
                 ObjectMapper objectMapper = JacksonUtils.objectmapper;
-                String orderResponse = inputInfoBundle.getString("preparedOrderResponse");
-                if (null != orderResponse && orderResponse.trim().length() > 0) {
-                    PreparedOrderResponseVo preparedOrderResponse = objectMapper.readValue(orderResponse, PreparedOrderResponseVo.class);
-
-                    ConfirmOrderVo confirmOrderVo = new ConfirmOrderVo();
-                    confirmOrderVo.setLockerType(sectionType);
-                    confirmOrderVo.setDecision(DecisionEnum.REOPEN_01.getDecision());
-                    confirmOrderVo.setClientId(BaseUtils.getClientId());
-                    confirmOrderVo.setOrderSn(preparedOrderResponse.getOrderSn());
-
-                    ICSPClient.confirmOrder(LocalStorage.getInstance().getSession().getToken(), confirmOrderVo, new Callback() {
-                        @Override
-                        public void onFailure(@NotNull Call call, @NotNull IOException e) {
-                            //
-                            Snackbar.make(view, "换柜子失败!网络异常!", Snackbar.LENGTH_LONG).show();
-                            Log.e(TAG, "onFailure: 大小不合适, 换柜子更新预下单失败! ", e);
-                        }
+                if (inputInfoBundle == null) {
+                    Snackbar.make(view, "您还没有投递! ", Snackbar.LENGTH_SHORT).show();
+                } else {
+                    String orderResponse = inputInfoBundle.getString("preparedOrderResponse");
+                    if (null != orderResponse && orderResponse.trim().length() > 0) {
+                        PreparedOrderResponseVo preparedOrderResponse = objectMapper.readValue(orderResponse, PreparedOrderResponseVo.class);
+
+                        ConfirmOrderVo confirmOrderVo = new ConfirmOrderVo();
+                        confirmOrderVo.setLockerType(sectionType);
+                        confirmOrderVo.setDecision(DecisionEnum.REOPEN_01.getDecision());
+                        confirmOrderVo.setClientId(BaseUtils.getClientId());
+                        confirmOrderVo.setOrderSn(preparedOrderResponse.getOrderSn());
+
+                        ICSPClient.confirmOrder(LocalStorage.getInstance().getSession().getToken(), confirmOrderVo, new Callback() {
+                            @Override
+                            public void onFailure(@NotNull Call call, @NotNull IOException e) {
+                                //
+                                Snackbar.make(view, "换柜子失败!网络异常!", Snackbar.LENGTH_LONG).show();
+                                Log.e(TAG, "onFailure: 大小不合适, 换柜子更新预下单失败! ", e);
+                            }
 
-                        @Override
-                        public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
-                            // 换柜子成功, 跳转到确认投递页面
-                            ((MainActivity) getActivity()).runOnUiThread(() -> {
-                                try {
-                                    String responseStr = ICSPClient.isSuccessfulAndParseResponse(response);
-                                    ObjectMapper objectMapper = JacksonUtils.objectmapper;
-                                    ResponseData<PreparedOrderResponseVo> responseData = objectMapper.readValue(responseStr, new TypeReference<ResponseData<PreparedOrderResponseVo>>() {});
-                                    // 响应信息
-                                    if (responseData.getCode().equals(ICSPResponseCodeEnum.OK.getCode())) {
-                                        PreparedOrderResponseVo data = responseData.getData();
-                                        if (null != data) {
-                                            data.setOrderSn(preparedOrderResponse.getOrderSn());
-                                            data.setCollectorPhone(preparedOrderResponse.getCollectorPhone());
-                                            String mailNo = inputInfoBundle.getString("takeNo");
-                                            bundle.putString("preparedOrderResponse", objectMapper.writeValueAsString(data));
-                                            bundle.putString("takeNo", mailNo);
-                                            bundle.putString("section_type", data.getLockerName());
-
-                                            // 跳转到确认投递
-                                            try {
-                                                MainActivity activity = (MainActivity) getActivity();
-                                                activity.getBundleMap().put(InputInfoFragment.class.getName(), bundle);
-                                                activity.getBundleMap().remove(ExceptionFragment.class.getName());
-                                                timer.cancel();
-                                                NavHostFragment.findNavController(ChooseCabinetFragment.this)
-                                                        .navigate(R.id.action_chooseCabinetFragment_to_sendInfoConfirmFragment);
-                                            } catch (RuntimeException e) {
-                                                Log.e(TAG, "onResponse: InputInfoFragment页面获取SendInfoConfirmFragment传值错误! ", e);
+                            @Override
+                            public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
+                                // 换柜子成功, 跳转到确认投递页面
+                                ((MainActivity) getActivity()).runOnUiThread(() -> {
+                                    try {
+                                        String responseStr = ICSPClient.isSuccessfulAndParseResponse(response);
+                                        ObjectMapper objectMapper = JacksonUtils.objectmapper;
+                                        ResponseData<PreparedOrderResponseVo> responseData = objectMapper.readValue(responseStr, new TypeReference<ResponseData<PreparedOrderResponseVo>>() {});
+                                        // 响应信息
+                                        if (responseData.getCode().equals(ICSPResponseCodeEnum.OK.getCode())) {
+                                            PreparedOrderResponseVo data = responseData.getData();
+                                            if (null != data) {
+                                                data.setOrderSn(preparedOrderResponse.getOrderSn());
+                                                data.setCollectorPhone(preparedOrderResponse.getCollectorPhone());
+                                                String mailNo = inputInfoBundle.getString("takeNo");
+                                                bundle.putString("preparedOrderResponse", objectMapper.writeValueAsString(data));
+                                                bundle.putString("takeNo", mailNo);
+                                                bundle.putString("section_type", data.getLockerName());
+
+                                                // 跳转到确认投递
+                                                try {
+                                                    MainActivity activity = (MainActivity) getActivity();
+                                                    activity.getBundleMap().put(InputInfoFragment.class.getName(), bundle);
+                                                    activity.getBundleMap().remove(ExceptionFragment.class.getName());
+                                                    timer.cancel();
+                                                    NavHostFragment.findNavController(ChooseCabinetFragment.this)
+                                                            .navigate(R.id.action_chooseCabinetFragment_to_sendInfoConfirmFragment);
+                                                } catch (RuntimeException e) {
+                                                    Log.e(TAG, "onResponse: InputInfoFragment页面获取SendInfoConfirmFragment传值错误! ", e);
+                                                }
                                             }
+                                        } else {
+                                            ICSPResponseCodeEnum.responseHint(view, responseData);
+                                            Log.e(TAG, "onResponse: ICSP返回码: " + responseData.getCode() + ", 返回信息: " + responseData.getMsg(), new RuntimeException("系统异常"));
                                         }
-                                    } else {
-                                        ICSPResponseCodeEnum.responseHint(view, responseData);
-                                        Log.e(TAG, "onResponse: ICSP返回码: " + responseData.getCode() + ", 返回信息: " + responseData.getMsg(), new RuntimeException("系统异常"));
+                                    } catch (JsonProcessingException e) {
+                                        Log.e(TAG, "onResponse: 预下单转换成JSON出错! ", e);
+                                    } catch (RuntimeException e) {
+                                        Log.e(TAG, "onResponse: 换柜子错误! ", e);
                                     }
-                                } catch (JsonProcessingException e) {
-                                    Log.e(TAG, "onResponse: 预下单转换成JSON出错! ", e);
-                                } catch (RuntimeException e) {
-                                    Log.e(TAG, "onResponse: 换柜子错误! ", e);
-                                }
-                            });
-                        }
-                    });
+                                });
+                            }
+                        });
+                    }
                 }
             } else {
                 // 为空走正常投递流程
@@ -263,8 +267,8 @@ public class ChooseCabinetFragment extends Fragment {
 
     @Override
     public void onDestroy() {
+        timer.cancel();
         super.onDestroy();
         binding = null;
-        timer.cancel();
     }
 }

+ 3 - 2
app/src/main/java/com/emato/ich/fragment/ExceptionFragment.java

@@ -148,6 +148,7 @@ public class ExceptionFragment extends Fragment {
                     // 拿出快递 取消
                     confirmOrderVo.setDecision(DecisionEnum.CANCEL_12.getDecision());
                     Snackbar.make(view, "异常处理只能处理一次! 如未处理您的问题! 请联系我们处理! ", Snackbar.LENGTH_LONG).show();
+                    NavHostFragment.findNavController(ExceptionFragment.this).navigate(R.id.action_exceptionFragment_to_sendSuccessFragment);
                     break;
                 case REOPEN_01:
                     // 大小不合适
@@ -199,7 +200,7 @@ public class ExceptionFragment extends Fragment {
                                     switch (decisionEnum) {
                                         case CANCEL_11:
                                             // 未投递 取消投递 并清空Session
-                                            LocalStorage.getInstance().cleanSession();
+                                            LocalStorage.getInstance().cleanSession(((MainActivity) getActivity()));
                                             timer.cancel();
                                             NavHostFragment.findNavController(ExceptionFragment.this)
                                                     .navigate(R.id.actionExceptionFragment_to_mainFragment);
@@ -246,9 +247,9 @@ public class ExceptionFragment extends Fragment {
 
     @Override
     public void onDestroy() {
+        timer.cancel();
         super.onDestroy();
         binding = null;
-        timer.cancel();
     }
 
 

+ 8 - 2
app/src/main/java/com/emato/ich/fragment/InputInfoFragment.java

@@ -93,7 +93,11 @@ public class InputInfoFragment extends Fragment {
                 Log.d(TAG, "onScanSuccess: " + s);
 
                 if (mailNoLock.get() == 1) {
-                    binding.mailNo.setText(s);
+                    Editable text = binding.mailNo.getText();
+                    if (text != null) {
+                        text.clear();
+                        binding.mailNo.setText(text);
+                    }
                     mailNoLock.incrementAndGet();
                     // TODO 预定义,实际参数可能不一致 oms获取用户手机号 自动填充
                     ICSPClient.getUserPhoneNumber(LocalStorage.getInstance().getSession().getToken(), BaseUtils.getClientId(), s, new Callback() {
@@ -122,8 +126,10 @@ public class InputInfoFragment extends Fragment {
 
                                 } catch (JsonProcessingException e) {
                                     Log.e(TAG, "onResponse: 服务器响应错误! 自动获取用户手机号失败! ", e);
+                                    Snackbar.make(view, "网络异常! 请手动输入手机号! ", Snackbar.LENGTH_LONG).show();
                                 } catch (RuntimeException e) {
                                     Log.e(TAG, "onResponse: 获取用户手机号未知错误! ", e);
+                                    Snackbar.make(view, "未查询到手机号! 请手动输入! ", Snackbar.LENGTH_LONG).show();
                                 }
                             });
 
@@ -381,8 +387,8 @@ public class InputInfoFragment extends Fragment {
 
     @Override
     public void onDestroy() {
+        timer.cancel();
         super.onDestroy();
         binding = null;
-        timer.cancel();
     }
 }

+ 70 - 54
app/src/main/java/com/emato/ich/fragment/SendFragment.java

@@ -18,6 +18,7 @@ import com.emato.ich.MainActivity;
 import com.emato.ich.R;
 import com.emato.ich.api.ICSPClient;
 import com.emato.ich.api.ICSPResponseCodeEnum;
+import com.emato.ich.api.SystemConfigConstant;
 import com.emato.ich.databinding.FragmentSendBinding;
 import com.emato.ich.entity.vo.ResponseData;
 import com.emato.ich.entity.vo.ResponseTokenVo;
@@ -135,7 +136,74 @@ public class SendFragment extends Fragment {
         });
 
 
-        // 数字输入 5 手机号   4 密码
+        // 如果有配置账号密码, 账号定死
+        String loginPhone = null;
+        try {
+            MainActivity activity = (MainActivity) getActivity();
+            loginPhone = activity.getConfigMap().get(SystemConfigConstant.cabinet_login_phone);
+        } catch (Exception e) {
+            Log.e(TAG, "onViewCreated: 配置登录手机号出错! ", e);
+        }
+        if (!StringUtils.isNullOrEmpty(loginPhone)) {
+            binding.editTextTextPersonName4.setText(loginPhone);
+            binding.editTextTextPersonName4.setEnabled(false);
+        } else {
+            // 4 手机
+            binding.editTextTextPersonName4.setOnFocusChangeListener((view1, hasFocus) -> {
+                if (hasFocus) {
+                    binding.inputButton0.setOnClickListener(v -> {
+                        int start = binding.editTextTextPersonName4.getSelectionStart();
+                        binding.editTextTextPersonName4.getText().insert(start, "0");
+                    });
+                    binding.inputButton1.setOnClickListener(v -> {
+                        int start = binding.editTextTextPersonName4.getSelectionStart();
+                        binding.editTextTextPersonName4.getText().insert(start, "1");
+                    });
+                    binding.inputButton2.setOnClickListener(v -> {
+                        int start = binding.editTextTextPersonName4.getSelectionStart();
+                        binding.editTextTextPersonName4.getText().insert(start, "2");
+                    });
+                    binding.inputButton3.setOnClickListener(v -> {
+                        int start = binding.editTextTextPersonName4.getSelectionStart();
+                        binding.editTextTextPersonName4.getText().insert(start, "3");
+                    });
+                    binding.inputButton4.setOnClickListener(v -> {
+                        int start = binding.editTextTextPersonName4.getSelectionStart();
+                        binding.editTextTextPersonName4.getText().insert(start, "4");
+                    });
+                    binding.inputButton5.setOnClickListener(v -> {
+                        int start = binding.editTextTextPersonName4.getSelectionStart();
+                        binding.editTextTextPersonName4.getText().insert(start, "5");
+                    });
+                    binding.inputButton6.setOnClickListener(v -> {
+                        int start = binding.editTextTextPersonName4.getSelectionStart();
+                        binding.editTextTextPersonName4.getText().insert(start, "6");
+                    });
+                    binding.inputButton7.setOnClickListener(v -> {
+                        int start = binding.editTextTextPersonName4.getSelectionStart();
+                        binding.editTextTextPersonName4.getText().insert(start, "7");
+                    });
+                    binding.inputButton8.setOnClickListener(v -> {
+                        int start = binding.editTextTextPersonName4.getSelectionStart();
+                        binding.editTextTextPersonName4.getText().insert(start, "8");
+                    });
+                    binding.inputButton9.setOnClickListener(v -> {
+                        int start = binding.editTextTextPersonName4.getSelectionStart();
+                        binding.editTextTextPersonName4.getText().insert(start, "9");
+                    });
+                    binding.inputButtonCancel.setOnClickListener(v -> {
+                        Editable text = binding.editTextTextPersonName4.getText();
+                        if (text.length() > 0) {
+                            text.delete(text.length()-1, text.length());
+                            binding.editTextTextPersonName4.setText(text, TextView.BufferType.EDITABLE);
+                            binding.editTextTextPersonName4.setSelection(binding.editTextTextPersonName4.getText().length());
+                        }
+                    });
+                }
+            });
+        }
+
+        // 密码
         binding.editTextTextPersonName5.setOnFocusChangeListener((view1, hasFocus) -> {
             if (hasFocus) {
                 binding.inputButton0.setOnClickListener(v -> {
@@ -189,58 +257,6 @@ public class SendFragment extends Fragment {
             }
         });
 
-        binding.editTextTextPersonName4.setOnFocusChangeListener((view1, hasFocus) -> {
-            if (hasFocus) {
-                binding.inputButton0.setOnClickListener(v -> {
-                    int start = binding.editTextTextPersonName4.getSelectionStart();
-                    binding.editTextTextPersonName4.getText().insert(start, "0");
-                });
-                binding.inputButton1.setOnClickListener(v -> {
-                    int start = binding.editTextTextPersonName4.getSelectionStart();
-                    binding.editTextTextPersonName4.getText().insert(start, "1");
-                });
-                binding.inputButton2.setOnClickListener(v -> {
-                    int start = binding.editTextTextPersonName4.getSelectionStart();
-                    binding.editTextTextPersonName4.getText().insert(start, "2");
-                });
-                binding.inputButton3.setOnClickListener(v -> {
-                    int start = binding.editTextTextPersonName4.getSelectionStart();
-                    binding.editTextTextPersonName4.getText().insert(start, "3");
-                });
-                binding.inputButton4.setOnClickListener(v -> {
-                    int start = binding.editTextTextPersonName4.getSelectionStart();
-                    binding.editTextTextPersonName4.getText().insert(start, "4");
-                });
-                binding.inputButton5.setOnClickListener(v -> {
-                    int start = binding.editTextTextPersonName4.getSelectionStart();
-                    binding.editTextTextPersonName4.getText().insert(start, "5");
-                });
-                binding.inputButton6.setOnClickListener(v -> {
-                    int start = binding.editTextTextPersonName4.getSelectionStart();
-                    binding.editTextTextPersonName4.getText().insert(start, "6");
-                });
-                binding.inputButton7.setOnClickListener(v -> {
-                    int start = binding.editTextTextPersonName4.getSelectionStart();
-                    binding.editTextTextPersonName4.getText().insert(start, "7");
-                });
-                binding.inputButton8.setOnClickListener(v -> {
-                    int start = binding.editTextTextPersonName4.getSelectionStart();
-                    binding.editTextTextPersonName4.getText().insert(start, "8");
-                });
-                binding.inputButton9.setOnClickListener(v -> {
-                    int start = binding.editTextTextPersonName4.getSelectionStart();
-                    binding.editTextTextPersonName4.getText().insert(start, "9");
-                });
-                binding.inputButtonCancel.setOnClickListener(v -> {
-                    Editable text = binding.editTextTextPersonName4.getText();
-                    if (text.length() > 0) {
-                        text.delete(text.length()-1, text.length());
-                        binding.editTextTextPersonName4.setText(text, TextView.BufferType.EDITABLE);
-                        binding.editTextTextPersonName4.setSelection(binding.editTextTextPersonName4.getText().length());
-                    }
-                });
-            }
-        });
         binding.returnBtn.setOnClickListener(view1 -> {
             timer.cancel();
             NavHostFragment.findNavController(SendFragment.this)
@@ -250,9 +266,9 @@ public class SendFragment extends Fragment {
 
     @Override
     public void onDestroyView() {
+        timer.cancel();
         super.onDestroyView();
         binding = null;
-        timer.cancel();
     }
 
 }

+ 6 - 2
app/src/main/java/com/emato/ich/fragment/SendInfoConfirmFragment.java

@@ -32,6 +32,7 @@ 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;
@@ -140,6 +141,8 @@ public class SendInfoConfirmFragment extends Fragment {
                     });
                 }
             });
+            // 投递完成后已经是另外一单, 可以继续异常处理
+            LocalStorage.getInstance().getSession().setException(true);
         });
 
         // 异常页面跳转
@@ -163,8 +166,9 @@ public class SendInfoConfirmFragment extends Fragment {
                     .navigate(R.id.action_sendInfoConfirmFragment_to_exceptionFragment);
         });
 
-        binding.returnBtn.setOnClickListener(view1 -> {
+        binding.returnMainBtn.setOnClickListener(view1 -> {
             timer.cancel();
+            LocalStorage.getInstance().cleanSession(((MainActivity) getActivity()));
             NavHostFragment.findNavController(SendInfoConfirmFragment.this)
                     .navigate(R.id.action_takeSuccessFragment_to_mainFragment);
         });
@@ -173,8 +177,8 @@ public class SendInfoConfirmFragment extends Fragment {
 
     @Override
     public void onDestroy() {
+        timer.cancel();
         super.onDestroy();
         binding = null;
-        timer.cancel();
     }
 }

+ 1 - 1
app/src/main/java/com/emato/ich/fragment/SendMainFragment.java

@@ -73,8 +73,8 @@ public class SendMainFragment extends Fragment {
 
     @Override
     public void onDestroy() {
+        timer.cancel();
         super.onDestroy();
         binding = null;
-        timer.cancel();
     }
 }

+ 12 - 3
app/src/main/java/com/emato/ich/fragment/SendSuccessFragment.java

@@ -20,6 +20,8 @@ import com.emato.ich.utils.TimeOutUtils;
 
 import org.jetbrains.annotations.NotNull;
 
+import java.util.Map;
+
 public class SendSuccessFragment extends Fragment {
 
     private static final String TAG = SendSuccessFragment.class.getName();
@@ -57,20 +59,27 @@ public class SendSuccessFragment extends Fragment {
         // 退出账号
         binding.exitAccountBtn.setOnClickListener(view1 -> {
             // 清空Session
-            LocalStorage.getInstance().cleanSession();
-            ((MainActivity) getActivity()).getBundleMap().clear();
+            MainActivity activity = (MainActivity) getActivity();
+            LocalStorage.getInstance().cleanSession(activity);
             timer.cancel();
             NavHostFragment.findNavController(SendSuccessFragment.this)
                     .navigate(R.id.action_sendSuccessFragment_to_mainFragment);
         });
 
+        binding.returnMainBtn.setOnClickListener(view1 -> {
+            timer.cancel();
+            MainActivity activity = (MainActivity) getActivity();
+            LocalStorage.getInstance().cleanSession(activity);
+            NavHostFragment.findNavController(SendSuccessFragment.this)
+                    .navigate(R.id.action_sendSuccessFragment_to_mainFragment);
+        });
 
     }
 
     @Override
     public void onDestroy() {
+        timer.cancel();
         super.onDestroy();
         binding = null;
-        timer.cancel();
     }
 }

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

@@ -226,8 +226,8 @@ public class TakeCodeFragment extends Fragment {
 
     @Override
     public void onDestroy() {
+        timer.cancel();
         super.onDestroy();
         binding = null;
-        timer.cancel();
     }
 }

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

@@ -104,8 +104,8 @@ public class TakeFragment extends Fragment {
 
     @Override
     public void onDestroy() {
+        timer.cancel();
         super.onDestroy();
         binding = null;
-        timer.cancel();
     }
 }

+ 7 - 2
app/src/main/java/com/emato/ich/fragment/TakeSuccessFragment.java

@@ -33,6 +33,7 @@ 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;
@@ -68,12 +69,16 @@ public class TakeSuccessFragment extends Fragment {
 
         binding.continueTakeBtn.setOnClickListener(view1 -> {
             timer.cancel();
+            timer2.cancel();
             NavHostFragment.findNavController(TakeSuccessFragment.this)
                     .navigate(R.id.action_takeSuccessFragment_to_takeCodeFragment);
         });
 
         binding.returnMainBtn.setOnClickListener(view1 -> {
             timer.cancel();
+            timer2.cancel();
+            MainActivity activity = (MainActivity) getActivity();
+            LocalStorage.getInstance().cleanSession(activity);
             NavHostFragment.findNavController(TakeSuccessFragment.this)
                     .navigate(R.id.action_takeSuccessFragment_to_mainFragment);
         });
@@ -169,9 +174,9 @@ public class TakeSuccessFragment extends Fragment {
 
     @Override
     public void onDestroy() {
-        super.onDestroy();
-        binding = null;
         timer.cancel();
         timer2.cancel();
+        super.onDestroy();
+        binding = null;
     }
 }

+ 10 - 1
app/src/main/java/com/emato/ich/local/LocalStorage.java

@@ -1,7 +1,11 @@
 package com.emato.ich.local;
 
+import android.os.Bundle;
+
+import com.emato.ich.MainActivity;
 import com.emato.ich.utils.StringUtils;
 
+import java.util.Map;
 import java.util.concurrent.TimeUnit;
 
 public class LocalStorage {
@@ -32,9 +36,14 @@ public class LocalStorage {
         return SESSION;
     }
 
-    public void cleanSession(){
+    public void cleanSession(MainActivity activity){
         SESSION.phone = "";
         SESSION.token = "";
+        SESSION.exception = true;
+        Map<String, Bundle> bundleMap = activity.getBundleMap();
+        if (activity != null && bundleMap != null && bundleMap.size() > 0) {
+            bundleMap.clear();
+        }
     }
 
     /**

+ 1 - 1
app/src/main/java/com/emato/ich/utils/BaseUtils.java

@@ -112,7 +112,7 @@ public class BaseUtils {
 
     public static String getClientId() {
         return Md5Utils.string2Md5_16(getMac()).toUpperCase();
-//        return "285F18D92D0B6568";8F00B204E9800998
+//        return "285F18D92D0B6568";// 8F00B204E9800998
     }
 
     public static String getMac2() {

+ 2 - 2
app/src/main/java/com/emato/ich/utils/TimeOutUtils.java

@@ -35,8 +35,8 @@ public class TimeOutUtils {
             public void onFinish() {
                 int fragmentAction = getFragmentAction(fragment);
                 if (fragmentAction != 0) {
-                    mainActivity.getBundleMap().clear();
-                    LocalStorage.getInstance().cleanSession();
+                    // 清空session和页面传值
+                    LocalStorage.getInstance().cleanSession(mainActivity);
                     NavHostFragment.findNavController(fragment).navigate(fragmentAction);
                 }
             }

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

@@ -4,7 +4,7 @@
     android:layout_height="match_parent">
 
     <Button
-        android:id="@+id/return_btn"
+        android:id="@+id/return_main_btn"
         android:layout_width="70dp"
         android:layout_height="30dp"
         android:layout_x="16dp"

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

@@ -13,7 +13,7 @@
         android:textSize="15dp" />
 
     <Button
-        android:id="@+id/return_btn"
+        android:id="@+id/return_main_btn"
         android:layout_width="70dp"
         android:layout_height="30dp"
         android:layout_x="25dp"

+ 3 - 0
app/src/main/res/navigation/nav_graph.xml

@@ -152,6 +152,9 @@
         <action
             android:id="@+id/action_exceptionFragment_to_sendInfoConfirmMainFragment"
             app:destination="@id/SendInfoConfirmFragment"/>
+        <action
+            android:id="@+id/action_exceptionFragment_to_sendSuccessFragment"
+            app:destination="@id/SendSuccessFragment"/>
     </fragment>
 
     <!--  投递确认页面  -->