Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import com.simprints.infra.resources.R as IDR


/**
* This is the class presented as the user is capturing theface, they are presented with this fragment, which displays
* As the user is capturing subject's face, they are presented with this fragment, which displays
* live information about distance and whether the face is ready to be captured or not.
* It also displays the capture process of the face and then sends this result to
* [com.simprints.face.capture.screens.confirmation.ConfirmationFragment]
Expand Down Expand Up @@ -66,18 +66,14 @@ internal class LiveFeedbackFragment : Fragment(R.layout.fragment_live_feedback)
IDR.string.face_capturing_permission_denied,
Toast.LENGTH_LONG
).show()
} else {
setUpCamera()
}
// init fragment anyway
initFragment()
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
if (requireActivity().hasPermission(Manifest.permission.CAMERA)) {
initFragment()
} else {
launchPermissionRequest.launch(Manifest.permission.CAMERA)
}
initFragment()
}

private fun initFragment() {
Expand All @@ -96,13 +92,15 @@ internal class LiveFeedbackFragment : Fragment(R.layout.fragment_live_feedback)
binding.captureOverlay.rectInCanvas,
Size(binding.captureOverlay.width, binding.captureOverlay.height),
)
setUpCamera()
}
}
}

/** Initialize CameraX, and prepare to bind the camera use cases */
private fun setUpCamera() = lifecycleScope.launch {
if (::cameraExecutor.isInitialized) {
return@launch
}
// Initialize our background executor
cameraExecutor = Executors.newSingleThreadExecutor()
// ImageAnalysis
Expand All @@ -121,6 +119,18 @@ internal class LiveFeedbackFragment : Fragment(R.layout.fragment_live_feedback)
preview.setSurfaceProvider(binding.faceCaptureCamera.surfaceProvider)
}

override fun onStart() {
super.onStart()

// Check permission in onStart() so that if user left the app to go to Settings
// and give the permission, it's reflected when they come back to SID
if (requireActivity().hasPermission(Manifest.permission.CAMERA)) {
setUpCamera()
} else {
launchPermissionRequest.launch(Manifest.permission.CAMERA)
}
}

override fun onStop() {
// Shut down our background executor
if(::cameraExecutor.isInitialized) {
Expand Down