|
@@ -75,80 +75,6 @@ public class SendFragment extends Fragment {
|
|
|
LoggingUtils.sendErrorLog("业务异常: 投递员登录页面倒计时异常! ", e);
|
|
|
}
|
|
|
|
|
|
- binding.inputButtonConfirm.setOnClickListener(view1 -> {
|
|
|
- if (ButtonUtils.isFastClick()) {
|
|
|
- return;
|
|
|
- }
|
|
|
- // 登录逻辑 editTextTextPersonName4 手机 editTextTextPersonName5 密码
|
|
|
- String sendPhone = binding.editTextTextPersonName4.getText().toString();
|
|
|
- String password = binding.editTextTextPersonName5.getText().toString();
|
|
|
-
|
|
|
- Pattern phonePattern = Pattern.compile("^((13[0-9])|(14[0,1,4-9])|(15[0-3,5-9])|(16[2,5,6,7])|(17[0-8])|(18[0-9])|(19[0-3,5-9]))\\d{8}$");
|
|
|
- Pattern pwdPattern = Pattern.compile("^[0-9]{8,16}$");
|
|
|
-
|
|
|
- if (phonePattern.matcher(sendPhone).matches() && pwdPattern.matcher(password).matches()) {
|
|
|
-
|
|
|
- ICSPClient.login(sendPhone, password, new Callback() {
|
|
|
- @Override
|
|
|
- public void onFailure(@NotNull Call call, @NotNull IOException e) {
|
|
|
- // TODO 登录失败处理
|
|
|
- ToastUtils.make(getContext(), "登录失败!网络异常!");
|
|
|
- Log.e(TAG, "onFailure: 登录失败! call: " + call.timeout().toString(), e);
|
|
|
- LoggingUtils.sendErrorLog("业务异常: 登录失败!网络异常! ", e);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
|
|
|
- ((MainActivity) getActivity()).runOnUiThread(() -> {
|
|
|
- String responseStr = ICSPClient.isSuccessfulAndParseResponse(response);
|
|
|
- if (!StringUtils.isNullOrEmpty(responseStr)) {
|
|
|
- try {
|
|
|
- ResponseData<ResponseTokenVo> responseData = JacksonUtils.objectmapper.readValue(responseStr, new TypeReference<ResponseData<ResponseTokenVo>>() {});
|
|
|
- ResponseTokenVo data = responseData.getData();
|
|
|
-
|
|
|
- if (responseData.getCode().equals(ICSPResponseCodeEnum.OK.getCode())) {
|
|
|
- LocalStorage.Session session = new LocalStorage.Session();
|
|
|
- session.setPhone(sendPhone);
|
|
|
- session.setTime(System.currentTimeMillis());
|
|
|
- session.setToken(data.getToken());
|
|
|
- LocalStorage.getInstance().setSession(session);
|
|
|
- // 登录成功
|
|
|
- ToastUtils.make(getContext(), "登录成功!");
|
|
|
- timer.cancel();
|
|
|
- NavHostFragment.findNavController(SendFragment.this).navigate(R.id.action_sendFragment_to_sendMainFragment);
|
|
|
- } else {
|
|
|
- ICSPResponseCodeEnum.responseHint(getContext(), responseData);
|
|
|
- Log.w(TAG, "onResponse: " + responseData.getMsg());
|
|
|
- }
|
|
|
-
|
|
|
- } catch (JsonProcessingException e) {
|
|
|
- Log.e(TAG, "onViewCreated: 解析登录响应信息错误! response body: " + responseStr, e);
|
|
|
- ToastUtils.make(getContext(), "登录失败!");
|
|
|
- LoggingUtils.sendErrorLog("业务异常: 登录失败!", e);
|
|
|
- } catch (ClassCastException e) {
|
|
|
- Log.e(TAG, "onResponse: 解析登录响应信息类型转换错误! response body: " + responseStr, e);
|
|
|
- ToastUtils.make(getContext(), "登录失败!");
|
|
|
- LoggingUtils.sendErrorLog("业务异常: 登录失败!", e);
|
|
|
- } catch (RuntimeException e) {
|
|
|
- Log.e(TAG, "onResponse: 登录失败! ", e);
|
|
|
- ToastUtils.make(getContext(), "登录失败!");
|
|
|
- LoggingUtils.sendErrorLog("业务异常: 登录失败!未知错误! ", e);
|
|
|
- }
|
|
|
- } else {
|
|
|
- // 登录失败
|
|
|
- ToastUtils.make(getContext(), "服务异常!请稍后重试!");
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- });
|
|
|
- } else if (!phonePattern.matcher(sendPhone).matches()){
|
|
|
- ToastUtils.make(getContext(), "输入正确的手机号!");
|
|
|
- } else if (!pwdPattern.matcher(password).matches()) {
|
|
|
- ToastUtils.make(getContext(), "密码格式错误!请输入8-16位的数字!");
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
-
|
|
|
// 如果有配置账号密码, 账号定死
|
|
|
String loginPhone = null;
|
|
|
try {
|
|
@@ -159,7 +85,8 @@ public class SendFragment extends Fragment {
|
|
|
LoggingUtils.sendErrorLog("业务异常: 配置登录手机号出错! ", e);
|
|
|
}
|
|
|
if (!StringUtils.isNullOrEmpty(loginPhone)) {
|
|
|
- binding.editTextTextPersonName4.setText(loginPhone);
|
|
|
+ String loginPhoneShow = toHidePhone(loginPhone);
|
|
|
+ binding.editTextTextPersonName4.setText(loginPhoneShow);
|
|
|
binding.editTextTextPersonName4.setEnabled(false);
|
|
|
} else {
|
|
|
// 4 手机
|
|
@@ -272,6 +199,80 @@ public class SendFragment extends Fragment {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ String finalLoginPhone = loginPhone;
|
|
|
+ binding.inputButtonConfirm.setOnClickListener(view1 -> {
|
|
|
+ if (ButtonUtils.isFastClick()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 登录逻辑 editTextTextPersonName4 手机 editTextTextPersonName5 密码
|
|
|
+ String sendPhone = !StringUtils.isNullOrEmpty(finalLoginPhone) ? finalLoginPhone : binding.editTextTextPersonName4.getText().toString();
|
|
|
+ String password = binding.editTextTextPersonName5.getText().toString();
|
|
|
+
|
|
|
+ Pattern phonePattern = Pattern.compile("^((13[0-9])|(14[0,1,4-9])|(15[0-3,5-9])|(16[2,5,6,7])|(17[0-8])|(18[0-9])|(19[0-3,5-9]))\\d{8}$");
|
|
|
+ Pattern pwdPattern = Pattern.compile("^[0-9]{8,16}$");
|
|
|
+
|
|
|
+ if (phonePattern.matcher(sendPhone).matches() && pwdPattern.matcher(password).matches()) {
|
|
|
+
|
|
|
+ ICSPClient.login(sendPhone, password, new Callback() {
|
|
|
+ @Override
|
|
|
+ public void onFailure(@NotNull Call call, @NotNull IOException e) {
|
|
|
+ // TODO 登录失败处理
|
|
|
+ ToastUtils.make(getContext(), "登录失败!网络异常!");
|
|
|
+ Log.e(TAG, "onFailure: 登录失败! call: " + call.timeout().toString(), e);
|
|
|
+ LoggingUtils.sendErrorLog("业务异常: 登录失败!网络异常! ", e);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
|
|
|
+ ((MainActivity) getActivity()).runOnUiThread(() -> {
|
|
|
+ String responseStr = ICSPClient.isSuccessfulAndParseResponse(response);
|
|
|
+ if (!StringUtils.isNullOrEmpty(responseStr)) {
|
|
|
+ try {
|
|
|
+ ResponseData<ResponseTokenVo> responseData = JacksonUtils.objectmapper.readValue(responseStr, new TypeReference<ResponseData<ResponseTokenVo>>() {});
|
|
|
+ ResponseTokenVo data = responseData.getData();
|
|
|
+
|
|
|
+ if (responseData.getCode().equals(ICSPResponseCodeEnum.OK.getCode())) {
|
|
|
+ LocalStorage.Session session = new LocalStorage.Session();
|
|
|
+ session.setPhone(sendPhone);
|
|
|
+ session.setTime(System.currentTimeMillis());
|
|
|
+ session.setToken(data.getToken());
|
|
|
+ LocalStorage.getInstance().setSession(session);
|
|
|
+ // 登录成功
|
|
|
+ ToastUtils.make(getContext(), "登录成功!");
|
|
|
+ timer.cancel();
|
|
|
+ NavHostFragment.findNavController(SendFragment.this).navigate(R.id.action_sendFragment_to_sendMainFragment);
|
|
|
+ } else {
|
|
|
+ ICSPResponseCodeEnum.responseHint(getContext(), responseData);
|
|
|
+ Log.w(TAG, "onResponse: " + responseData.getMsg());
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ Log.e(TAG, "onViewCreated: 解析登录响应信息错误! response body: " + responseStr, e);
|
|
|
+ ToastUtils.make(getContext(), "登录失败!");
|
|
|
+ LoggingUtils.sendErrorLog("业务异常: 登录失败!", e);
|
|
|
+ } catch (ClassCastException e) {
|
|
|
+ Log.e(TAG, "onResponse: 解析登录响应信息类型转换错误! response body: " + responseStr, e);
|
|
|
+ ToastUtils.make(getContext(), "登录失败!");
|
|
|
+ LoggingUtils.sendErrorLog("业务异常: 登录失败!", e);
|
|
|
+ } catch (RuntimeException e) {
|
|
|
+ Log.e(TAG, "onResponse: 登录失败! ", e);
|
|
|
+ ToastUtils.make(getContext(), "登录失败!");
|
|
|
+ LoggingUtils.sendErrorLog("业务异常: 登录失败!未知错误! ", e);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 登录失败
|
|
|
+ ToastUtils.make(getContext(), "服务异常!请稍后重试!");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else if (!phonePattern.matcher(sendPhone).matches()){
|
|
|
+ ToastUtils.make(getContext(), "输入正确的手机号!");
|
|
|
+ } else if (!pwdPattern.matcher(password).matches()) {
|
|
|
+ ToastUtils.make(getContext(), "密码格式错误!请输入8-16位的数字!");
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
// 密码
|
|
|
binding.editTextTextPersonName5.setOnFocusChangeListener((view1, hasFocus) -> {
|
|
|
if (hasFocus) {
|
|
@@ -399,6 +400,24 @@ public class SendFragment extends Fragment {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 隐藏部分信息
|
|
|
+ * @param loginPhone 投递员手机号
|
|
|
+ * @return 隐藏后的手机号
|
|
|
+ */
|
|
|
+ private String toHidePhone(String loginPhone) {
|
|
|
+ StringBuilder stringBuilder = new StringBuilder();
|
|
|
+ char[] chars = loginPhone.toCharArray();
|
|
|
+ for (int i = 0; i < chars.length; i++) {
|
|
|
+ if (i > 2 && i < 8) {
|
|
|
+ stringBuilder.append('*');
|
|
|
+ } else {
|
|
|
+ stringBuilder.append(chars[i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return stringBuilder.toString();
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void onDestroyView() {
|
|
|
timer.cancel();
|