From be10120e4581ef8c242ccbb882fec93cb8ef1c47 Mon Sep 17 00:00:00 2001 From: Mike Wong Date: Wed, 13 Oct 2021 16:59:39 +0200 Subject: [PATCH] Move zebra broadcast receiver from onViewCreated/onDestroyView to onResume/onPause --- .../admin/bag/covidcertificate/verifier/HomeFragment.kt | 9 ++++++++- .../verifier/qr/VerifierQrScanFragment.kt | 9 ++++++++- .../verifier/verification/VerificationFragment.kt | 9 ++++++--- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/verifier/src/main/java/ch/admin/bag/covidcertificate/verifier/HomeFragment.kt b/verifier/src/main/java/ch/admin/bag/covidcertificate/verifier/HomeFragment.kt index 47b3566e..a0a4f2e7 100644 --- a/verifier/src/main/java/ch/admin/bag/covidcertificate/verifier/HomeFragment.kt +++ b/verifier/src/main/java/ch/admin/bag/covidcertificate/verifier/HomeFragment.kt @@ -108,14 +108,21 @@ class HomeFragment : Fragment() { } setupInfoBox() + } + override fun onResume() { + super.onResume() zebraBroadcastReceiver.registerWith(requireContext()) { decodeQrCodeData(it) } } + override fun onPause() { + super.onPause() + zebraBroadcastReceiver.unregisterWith(requireContext()) + } + override fun onDestroyView() { super.onDestroyView() _binding = null - zebraBroadcastReceiver.unregisterWith(requireContext()) } private fun setupDebugFragment() { diff --git a/verifier/src/main/java/ch/admin/bag/covidcertificate/verifier/qr/VerifierQrScanFragment.kt b/verifier/src/main/java/ch/admin/bag/covidcertificate/verifier/qr/VerifierQrScanFragment.kt index 0fb516e4..7996c626 100644 --- a/verifier/src/main/java/ch/admin/bag/covidcertificate/verifier/qr/VerifierQrScanFragment.kt +++ b/verifier/src/main/java/ch/admin/bag/covidcertificate/verifier/qr/VerifierQrScanFragment.kt @@ -84,14 +84,21 @@ class VerifierQrScanFragment : QrScanFragment() { } setupActivateCameraButton() + } + override fun onResume() { + super.onResume() zebraBroadcastReceiver.registerWith(requireContext()) { decodeQrCodeData(it, {}, {}) } } + override fun onPause() { + super.onPause() + zebraBroadcastReceiver.unregisterWith(requireContext()) + } + override fun onDestroyView() { super.onDestroyView() _binding = null - zebraBroadcastReceiver.unregisterWith(requireContext()) } override fun decodeQrCodeData(qrCodeData: String, onDecodeSuccess: () -> Unit, onDecodeError: (StateError) -> Unit) { diff --git a/verifier/src/main/java/ch/admin/bag/covidcertificate/verifier/verification/VerificationFragment.kt b/verifier/src/main/java/ch/admin/bag/covidcertificate/verifier/verification/VerificationFragment.kt index 4256b905..d3023494 100644 --- a/verifier/src/main/java/ch/admin/bag/covidcertificate/verifier/verification/VerificationFragment.kt +++ b/verifier/src/main/java/ch/admin/bag/covidcertificate/verifier/verification/VerificationFragment.kt @@ -114,11 +114,14 @@ class VerificationFragment : Fragment() { updateHeaderAndVerificationView(it) } - zebraBroadcastReceiver.registerWith(requireContext()) { decodeQrCodeData(it) } - verifyAndDisplayCertificateHolder() } + override fun onResume() { + super.onResume() + zebraBroadcastReceiver.registerWith(requireContext()) { decodeQrCodeData(it) } + } + override fun onPause() { super.onPause() // Pop the backstack back to the QR scanner screen when the verification fragment is put into the background, unless @@ -127,12 +130,12 @@ class VerificationFragment : Fragment() { onBackPressedCallback.remove() parentFragmentManager.popBackStack() } + zebraBroadcastReceiver.unregisterWith(requireContext()) } override fun onDestroyView() { super.onDestroyView() _binding = null - zebraBroadcastReceiver.unregisterWith(requireContext()) } private fun verifyAndDisplayCertificateHolder() {