From 5e9dd007bdd971123f392bf89d8dd234459f89b6 Mon Sep 17 00:00:00 2001
From: harambasicluka <64483219+harambasicluka@users.noreply.github.com>
Date: Fri, 12 Jun 2020 12:57:42 +0200
Subject: [PATCH] Fix: Back after test result (#409)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* fix

* override default back

* fix

Co-authored-by: Jakob Möller <jakob.moeller@sap.com>
---
 .../ui/submission/SubmissionTestResultFragment.kt   | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/SubmissionTestResultFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/SubmissionTestResultFragment.kt
index c1ea49f3e..964b0feba 100644
--- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/SubmissionTestResultFragment.kt
+++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/SubmissionTestResultFragment.kt
@@ -6,6 +6,7 @@ import android.view.LayoutInflater
 import android.view.View
 import android.view.ViewGroup
 import android.view.accessibility.AccessibilityEvent
+import androidx.activity.OnBackPressedCallback
 import androidx.fragment.app.Fragment
 import androidx.fragment.app.activityViewModels
 import androidx.navigation.fragment.findNavController
@@ -34,6 +35,16 @@ class SubmissionTestResultFragment : Fragment() {
     private var _binding: FragmentSubmissionTestResultBinding? = null
     private val binding: FragmentSubmissionTestResultBinding get() = _binding!!
 
+    // Overrides default back behaviour
+    private val backCallback: OnBackPressedCallback =
+        object : OnBackPressedCallback(true) {
+            override fun handleOnBackPressed() {
+                findNavController().doNavigate(
+                    SubmissionTestResultFragmentDirections.actionSubmissionResultFragmentToMainFragment()
+                )
+            }
+        }
+
     override fun onCreateView(
         inflater: LayoutInflater,
         container: ViewGroup?,
@@ -43,6 +54,8 @@ class SubmissionTestResultFragment : Fragment() {
         _binding = FragmentSubmissionTestResultBinding.inflate(inflater)
         binding.submissionViewModel = submissionViewModel
         binding.lifecycleOwner = this
+        // registers callback when the os level back is pressed
+        requireActivity().onBackPressedDispatcher.addCallback(viewLifecycleOwner, backCallback)
         // Inflate the layout for this fragment
         return binding.root
     }
-- 
GitLab