123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- package com.emato.ich.fragment;
- import android.os.Bundle;
- import android.os.CountDownTimer;
- import android.util.Log;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import androidx.annotation.NonNull;
- import androidx.annotation.Nullable;
- import androidx.fragment.app.Fragment;
- 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.ICSPResponseCodeEnum;
- import com.emato.ich.data.DecisionEnum;
- import com.emato.ich.databinding.FragmentSendInfoConfirmBinding;
- import com.emato.ich.entity.vo.ResponseData;
- 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.JacksonUtils;
- import com.emato.ich.utils.TimeOutUtils;
- 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 okhttp3.Call;
- import okhttp3.Callback;
- import okhttp3.Response;
- public class SendInfoConfirmFragment extends Fragment {
- private FragmentSendInfoConfirmBinding binding;
- private static final String TAG = SendInfoConfirmFragment.class.getName();
- private CountDownTimer timer;
- @Nullable
- @org.jetbrains.annotations.Nullable
- @Override
- public View onCreateView(@NonNull @NotNull LayoutInflater inflater, @Nullable @org.jetbrains.annotations.Nullable ViewGroup container, @Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
- binding = FragmentSendInfoConfirmBinding.inflate(inflater, container, false);
- return binding.getRoot();
- }
- public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
- try {
- MainActivity activity = (MainActivity) getActivity();
- timer = TimeOutUtils.timeout(activity, SendInfoConfirmFragment.this, binding.timeout, 60);
- timer.start();
- } catch (Exception e) {
- Log.e(TAG, "onViewCreated: 倒计时出现异常! ", e);
- }
- Bundle arguments = null;
- MainActivity activity = null;
- try {
- activity = (MainActivity) getActivity();
- arguments = activity.getBundleMap().get(InputInfoFragment.class.getName());
- } catch (RuntimeException e) {
- Log.e(TAG, "onResponse: SendInfoConfirmFragment页面获取InputInfoFragment传值错误! ", e);
- }
- String orderSn = null;
- String collectorPhone;
- PreparedOrderResponseVo orderResponseVo;
- // 设置订单提示属性
- if (null != arguments) {
- String response = arguments.getString("preparedOrderResponse");
- try {
- orderResponseVo = JacksonUtils.objectmapper.readValue(response, PreparedOrderResponseVo.class);
- collectorPhone = orderResponseVo.getCollectorPhone();
- orderSn = orderResponseVo.getOrderSn();
- binding.openCabinetNo.setText(orderResponseVo.getLockerName());
- binding.takeNo.setText(arguments.getString("takeNo"));
- binding.takeNumber.setText(collectorPhone);
- } catch (JsonProcessingException e) {
- Log.e(TAG, "onViewCreated: 解析预下单页面传递信息错误! ", e);
- }
- }
- // 投递完成确认
- String finalOrderSn = orderSn;
- binding.alreadySend.setOnClickListener(view1 -> {
- // TODO 确认投递, 真正下单
- String clientId = BaseUtils.getClientId();
- // /order/deliverer/confirm
- ConfirmOrderVo confirmOrderVo = new ConfirmOrderVo();
- confirmOrderVo.setClientId(clientId);
- confirmOrderVo.setOrderSn(finalOrderSn);
- confirmOrderVo.setDecision(DecisionEnum.CONFIRM_00.getDecision());
- ICSPClient.confirmOrder(LocalStorage.getInstance().getSession().getToken(), confirmOrderVo, new Callback() {
- @Override
- public void onFailure(@NotNull Call call, @NotNull IOException e) {
- // TODO 确认失败
- // getActivity().runOnUiThread(() -> {
- //
- // });
- Snackbar.make(view, "投递失败!网络异常!", Snackbar.LENGTH_LONG).show();
- Log.e(TAG, "onFailure: 确认投递失败! ", e);
- }
- @Override
- public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
- getActivity().runOnUiThread(() -> {
- String parseResponse = ICSPClient.isSuccessfulAndParseResponse(response);
- ObjectMapper objectMapper = JacksonUtils.objectmapper;
- try {
- ResponseData responseData = objectMapper.readValue(parseResponse, ResponseData.class);
- String code = responseData.getCode();
- if (code.equals(ICSPResponseCodeEnum.OK.getCode())) {
- // TODO 确认投递成功逻辑处理
- Snackbar.make(view, "投递成功! ", Snackbar.LENGTH_LONG).show();
- NavHostFragment.findNavController(SendInfoConfirmFragment.this)
- .navigate(R.id.action_sendInfoConfirmFragment_to_sendSuccessFragment);
- } else {
- // TODO 确认投递失败逻辑处理
- ICSPResponseCodeEnum.responseHint(view, responseData);
- Log.w(TAG, "onResponse: " + responseData.getMsg());
- }
- } catch (JsonProcessingException e) {
- Log.e(TAG, "onResponse: 确认投递解析响应信息失败!", e);
- } catch (RuntimeException e) {
- Log.e(TAG, "onResponse: 投递失败! ", e);
- }
- });
- }
- });
- });
- // 异常页面跳转
- MainActivity finalActivity = activity;
- binding.exceptionBtn.setOnClickListener(view1 -> {
- Bundle bundle = new Bundle();
- bundle.getString("exception", "exception_page");
- finalActivity.getBundleMap().put(SendInfoConfirmFragment.class.getName(), bundle);
- NavHostFragment.findNavController(SendInfoConfirmFragment.this)
- .navigate(R.id.action_sendInfoConfirmFragment_to_exceptionFragment);
- });
- // 未投递按钮
- binding.noneSend.setOnClickListener(view1 -> {
- Bundle bundle = new Bundle();
- bundle.getString("exception", "exception_page");
- finalActivity.getBundleMap().put(SendInfoConfirmFragment.class.getName(), bundle);
- NavHostFragment.findNavController(SendInfoConfirmFragment.this)
- .navigate(R.id.action_sendInfoConfirmFragment_to_exceptionFragment);
- });
- }
- @Override
- public void onDestroy() {
- super.onDestroy();
- binding = null;
- timer.cancel();
- }
- }
|