Skip to content
This repository has been archived by the owner on Sep 15, 2023. It is now read-only.

Commit

Permalink
Move zebra broadcast receiver from onViewCreated/onDestroyView to onR…
Browse files Browse the repository at this point in the history
…esume/onPause
  • Loading branch information
M-Wong committed Oct 13, 2021
1 parent 2687309 commit be10120
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() {
Expand Down

0 comments on commit be10120

Please sign in to comment.