SendSuccessFragment.java 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package com.emato.ich.fragment;
  2. import android.os.Bundle;
  3. import android.os.CountDownTimer;
  4. import android.util.Log;
  5. import android.view.LayoutInflater;
  6. import android.view.View;
  7. import android.view.ViewGroup;
  8. import androidx.annotation.NonNull;
  9. import androidx.annotation.Nullable;
  10. import androidx.fragment.app.Fragment;
  11. import androidx.navigation.fragment.NavHostFragment;
  12. import com.emato.ich.MainActivity;
  13. import com.emato.ich.R;
  14. import com.emato.ich.databinding.FragmentSendSuccessBinding;
  15. import com.emato.ich.local.LocalStorage;
  16. import com.emato.ich.utils.TimeOutUtils;
  17. import org.jetbrains.annotations.NotNull;
  18. public class SendSuccessFragment extends Fragment {
  19. private static final String TAG = SendSuccessFragment.class.getName();
  20. private FragmentSendSuccessBinding binding;
  21. private CountDownTimer timer;
  22. @Nullable
  23. @org.jetbrains.annotations.Nullable
  24. @Override
  25. public View onCreateView(@NonNull @NotNull LayoutInflater inflater, @Nullable @org.jetbrains.annotations.Nullable ViewGroup container, @Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
  26. binding = FragmentSendSuccessBinding.inflate(inflater, container, false);
  27. return binding.getRoot();
  28. }
  29. public void onViewCreated(@NonNull @NotNull View view, @Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
  30. try {
  31. MainActivity activity = ((MainActivity) getActivity());
  32. timer = TimeOutUtils.timeout(activity, SendSuccessFragment.this, binding.timeout, 60);
  33. timer.start();
  34. } catch (Exception e) {
  35. Log.e(TAG, "onViewCreated: 倒计时出现异常! ", e);
  36. }
  37. // 继续投递
  38. binding.continueSendBtn.setOnClickListener(view1 -> {
  39. timer.cancel();
  40. NavHostFragment.findNavController(SendSuccessFragment.this)
  41. .navigate(R.id.action_sendSuccessFragment_to_chooseCabinetFragment);
  42. });
  43. // 退出账号
  44. binding.exitAccountBtn.setOnClickListener(view1 -> {
  45. // 清空Session
  46. LocalStorage.getInstance().cleanSession();
  47. ((MainActivity) getActivity()).getBundleMap().clear();
  48. timer.cancel();
  49. NavHostFragment.findNavController(SendSuccessFragment.this)
  50. .navigate(R.id.action_sendSuccessFragment_to_mainFragment);
  51. });
  52. }
  53. @Override
  54. public void onDestroy() {
  55. super.onDestroy();
  56. binding = null;
  57. timer.cancel();
  58. }
  59. }